-
Notifications
You must be signed in to change notification settings - Fork 1
169 lines (144 loc) · 6.29 KB
/
reusable-carvel-test.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
name: Reusable workflow for testing Carvel packages
on:
workflow_call:
inputs:
repo_version:
type: string
required: true
package_version:
type: string
required: true
package_prerelease:
type: string
required: true
package_name:
type: string
required: true
package_provider:
type: string
required: true
packages_basedir:
type: string
description: Packages base directory path
default: packages
package_path:
type: string
required: true
pull_request_number:
type: string
required: true
kubernetes_version:
type: string
default: v1.24.6
kind_version:
type: string
default: v0.16.0
kapp_controller_version:
type: string
default: v0.43.2
secretgen_controller_version:
type: string
default: v0.12.0
secrets:
AZURE_CONFIG:
required: false
jobs:
test:
runs-on: ubuntu-latest
env:
PACKAGE_VERSION: ${{ inputs.package_version }}
steps:
- name: Install Carvel tools
uses: vmware-tanzu/carvel-setup-action@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Create k8s Kind Cluster
uses: helm/[email protected]
with:
verbosity: 5
version: ${{ inputs.kind_version }}
kubectl_version: ${{ inputs.kubernetes_version }}
node_image: kindest/node:${{ inputs.kubernetes_version }}
- name: Verify Cluster
run: |
kubectl version
which kubectl
kubectl cluster-info
kubectl get storageclass standard
- name: Install kapp-controller
run: |
MANIFEST="https://github.com/vmware-tanzu/carvel-kapp-controller/releases/download/${{ inputs.kapp_controller_version }}/release.yml"
if [[ "${{ inputs.kapp_controller_version }}" == "latest" ]]; then
MANIFEST="https://github.com/vmware-tanzu/carvel-kapp-controller/releases/latest/download/release.yml"
fi
kubectl apply -f ${MANIFEST}
time kubectl wait --for=condition=Available=True -n kapp-controller deploy kapp-controller
time kubectl wait --for=condition=Available=True apiservices.apiregistration.k8s.io v1alpha1.data.packaging.carvel.dev
# determine the kapp-controller global namespace
echo KAPP_GLOBAL_NAMESPACE=$(kubectl -n kapp-controller get deployment kapp-controller -o json | jq -r '.spec.template.spec.containers[]|select(.name=="kapp-controller").args[]|select(.|startswith("-packaging-global-namespace"))|split("=")[1]') >> $GITHUB_ENV
- name: Install secretgen-controller
run: |
MANIFEST="https://github.com/vmware-tanzu/carvel-secretgen-controller/releases/download/${{ inputs.secretgen_controller_version }}/release.yml"
if [[ "${{ inputs.secretgen_controller_version }}" == "latest" ]]; then
MANIFEST="https://github.com/vmware-tanzu/carvel-secretgen-controller/releases/latest/download/release.yml"
fi
kubectl apply -f ${MANIFEST}
time kubectl wait --for=condition=Available=True -n secretgen-controller deploy secretgen-controller
time kubectl wait --for=condition=Available=True apiservices.apiregistration.k8s.io v1alpha1.secretgen.carvel.dev
- name: Install Carvel repository
run: |
REPO_MANIFEST="https://github.com/${{ github.repository }}/releases/download/${{ inputs.repo_version }}/package-repository.yml"
REPO_MANIFEST_FILE=$(mktemp)
curl -sSfL -o ${REPO_MANIFEST_FILE} ${REPO_MANIFEST}
REPO_NAME=$(yq '.metadata.name' ${REPO_MANIFEST_FILE})
kubectl apply -n ${KAPP_GLOBAL_NAMESPACE} -f ${REPO_MANIFEST_FILE}
time kubectl wait --for=condition=ReconcileSucceeded=True packagerepositories.packaging.carvel.dev -n ${KAPP_GLOBAL_NAMESPACE} ${REPO_NAME}
- name: List available packages
run: |
kubectl get packages.data.packaging.carvel.dev
- name: Mask secret
if: inputs.package_provider == 'azure'
uses: matteo-magni/secret-mask-action@main
with:
secret: ${{ secrets.AZURE_CONFIG }}
- name: Checkout
uses: actions/checkout@v3
- name: Test Carvel package
run: |
if [[ "${{ inputs.package_provider }}" == "azure" ]]; then
# transforms the keys in the input JSON secret from camelCase to UPPER_SNAKE_CASE with the AZURE_ prefix
# in order not to divert from the official ASO docs and the client JSON file generated by az CLI
for k in $(jq -r 'keys[]' <<<"$AZURE_CONFIG"); do
K=$(echo azure_$k | sed -r 's/([a-z0-9])([A-Z])/\1_\L\2/g' | tr '[:lower:]' '[:upper:]')
eval export $K=$(jq -r '.'$k <<<"$AZURE_CONFIG")
done
fi
export PACKAGE_METADATA_NAME=$(yq e '.metadata.name' ${PACKAGE_DIR}/package-metadata.yml)
echo PACKAGE_METADATA_NAME=${PACKAGE_METADATA_NAME} >> $GITHUB_ENV
if [[ "$PRERELEASE" =~ ^[tT][rR][uU][eE]$ ]]; then
if [ -x ${SCRIPT} ]; then
${SCRIPT}
elif [ ! -z "$PULL_REQUEST_NUMBER" ]; then
# no pre-release test script provided
LABEL=untested
gh label create -c ffaa00 --force $LABEL
gh pr edit $PULL_REQUEST_NUMBER --add-label $LABEL
gh pr comment $PULL_REQUEST_NUMBER --body "WARNING - package ${PACKAGE_METADATA_NAME}/${PACKAGE_VERSION} has not been tested"
fi
else
${SCRIPT}
fi
env:
SCRIPT: ./scripts/carvel-e2e-${{ inputs.package_provider }}-${{ inputs.package_name }}.sh
PACKAGE_DIR: ${{ inputs.packages_basedir }}/${{ inputs.package_path }}
PRERELEASE: ${{ inputs.package_prerelease }}
PULL_REQUEST_NUMBER: ${{ inputs.pull_request_number }}
GH_TOKEN: ${{ github.token }}
# Azure-specific variable
AZURE_CONFIG: ${{ secrets.AZURE_CONFIG }}
- name: Cleanup
if: always()
run: |
if [ -x ${SCRIPT} ]; then ${SCRIPT}; fi
env:
SCRIPT: ./scripts/carvel-e2e-${{ inputs.package_provider }}-${{ inputs.package_name }}/cleanup.sh