1+ name : E2E Tests
2+
3+ on :
4+ pull_request : {}
5+ # workflow_run:
6+ # workflows: ["BuildnPush"]
7+ # types:
8+ # - completed
9+ concurrency : dev_environment
10+
11+ env :
12+ OCI_CLI_USER : ${{ secrets.OCI_CLI_USER }}
13+ OCI_CLI_TENANCY : ${{ secrets.OCI_CLI_TENANCY }}
14+ OCI_CLI_FINGERPRINT : ${{ secrets.OCI_CLI_FINGERPRINT }}
15+ OCI_CLI_KEY_CONTENT : ${{ secrets.OCI_CLI_KEY_CONTENT }}
16+ OCI_CLI_REGION : ${{ secrets.OCI_CLI_REGION }}
17+
18+ # OCI_CLUSTER_ID: ${{ vars.CLUSTER_ID }}
19+ # OCI_VAULT_ID: ${{ vars.VAULT_ID }}
20+ OCI_VAULT_SECRET_VALUE : ${{ vars.VAULT_SECRET_VALUE }}
21+ # OCI_DEBUG: "--debug"
22+
23+ jobs :
24+ build :
25+ uses : ./.github/workflows/build-n-push.yaml
26+ with :
27+ IMAGE_REGISTRY : ${{ vars.IMAGE_REGISTRY }}
28+ secrets : inherit
29+ setup-vault :
30+ runs-on : ubuntu-latest
31+ name : Setup Vault and secrets
32+ needs : [ build ]
33+ env :
34+ OCI_VAULT_ID : ${{ vars.VAULT_ID }}
35+ OCI_VAULT_KEY_ID : ${{ vars.VAULT_KEY_ID }}
36+ outputs :
37+ OCI_VAULT_ID : ${{ env.OCI_VAULT_ID }}
38+ OCI_VAULT_KEY_ID : ${{ env.OCI_VAULT_KEY_ID }}
39+ VAULT_SECRET_NAME : ${{ vars.SECRET_NAME_PREFIX }}-${{ env.OCI_RANDOM }}
40+ VAULT_SECRET_OCID : ${{ steps.extract-secret-ocid.outputs.VAULT_SECRET_OCID }}
41+ steps :
42+ - name : create env with random
43+ id : gen-random
44+ run : echo "OCI_RANDOM=${RANDOM}" >> $GITHUB_ENV
45+
46+ - name : Create vault if doesn't exist
47+ if : ${{ vars.USE_EXISTING_VAULT != 'true' }}
48+ uses :
oracle-actions/[email protected] 49+ id : create-vault
50+ with :
51+ silent : false
52+ command : " kms management vault create --compartment-id ${{ vars.COMPARTMENT_ID }} --display-name ${{ vars.VAULT_NAME_PREFIX }}-${{ env.OCI_RANDOM }} --vault-type default"
53+ query : " data.id"
54+
55+ - name : get vault from previous output
56+ if : ${{ vars.USE_EXISTING_VAULT != 'true' }}
57+ run : echo "OCI_VAULT_ID=${{ steps.create-vault.outputs.raw_output }}" >> $GITHUB_ENV
58+
59+ - name : create key if doesn't exist
60+ if : ${{ vars.USE_EXISTING_VAULT != 'true' }}
61+ uses :
oracle-actions/[email protected] 62+ id : create-vault-key
63+ with :
64+ silent : false
65+ command : " kms management key create --endpoint ${{ vars.VAULT_MGMT_ENDPOINT }} --compartment-id ${{ vars.COMPARTMENT_ID }} --display-name key-${RANDOM} --key-shape '{ \" algorithm\" : \" AES\" , \" length\" : 32 }'"
66+ query : " data.id"
67+
68+ - name : create env for key id from create-vault-key output
69+ if : ${{ vars.USE_EXISTING_VAULT != 'true' }}
70+ run : echo "OCI_VAULT_KEY_ID=${{ steps.create-vault-key.outputs.raw_output }}" >> $GITHUB_ENV
71+
72+ - name : create secret in vault
73+ uses :
oracle-actions/[email protected] 74+ id : create-secret
75+ with :
76+ silent : false
77+ command : vault secret create-base64 --compartment-id ${{ vars.COMPARTMENT_ID }} --vault-id ${{ env.OCI_VAULT_ID }} --key-id ${{ env.OCI_VAULT_KEY_ID }} --secret-name ${{ vars.SECRET_NAME_PREFIX }}-${{ env.OCI_RANDOM }} --secret-content-content ${{ env.OCI_VAULT_SECRET_VALUE }}"
78+ # query: "data.id"
79+
80+ - name : extract secret id
81+ id : extract-secret-ocid
82+ run : echo VAULT_SECRET_OCID=`echo ${{ steps.create-secret.outputs.output }} | jq -r ".data.id"` >> $GITHUB_OUTPUT
83+
84+ setup-cluster :
85+ runs-on : ubuntu-latest
86+ name : Setup Cluster
87+ needs : [ build ]
88+ env :
89+ OCI_CLUSTER_ID : ${{ vars.CLUSTER_ID }}
90+ outputs :
91+ OCI_CLUSTER_ID : ${{ steps.print-cluster-id.outputs.clusterId }}
92+ steps :
93+ # - name: create vcn if doesn't exist
94+ # - name: get vcn id from previous output or existing var
95+ # - name: create cluster
96+ # if: ${{ vars.USE_EXISTING_CLUSTER != 'true' }}
97+ # uses: oracle-actions/[email protected] 98+ # id: create-cluster
99+ # with:
100+ # silent: false
101+ # command: "ce cluster create --compartment-id ${{ vars.COMPARTMENT_ID }}
102+ # --vcn-id ${{ vars.VCN_ID }} --kubernetes-version ${{ vars.K8S_VERSION }}
103+ # --wait-for-state succeeded"
104+ # query: "data.secret-name"
105+
106+ # - name: create env for key id from create-vault-key output
107+ # if: ${{ vars.USE_EXISTING_CLUSTER != 'true' }}
108+ # run: echo "OCI_CLUSTER_ID=${{ steps.create-cluster.outputs.raw_output }}" >> $GITHUB_ENV
109+
110+ # - name: create nodepool
111+ # if: ${{ vars.USE_EXISTING_CLUSTER != 'true' }}
112+
113+ # - name: get kubeconfig
114+ # uses: oracle-actions/[email protected] 115+ # id: get-kube-config
116+ # with:
117+ # silent: false
118+ # command: "ce cluster create-kubeconfig --cluster-id ${{ env.OCI_CLUSTER_ID }} --file $HOME/.kube/config --region ${{ env.OCI_CLI_REGION }} --token-version 2.0.0 --kube-endpoint PUBLIC_ENDPOINT"
119+
120+ - name : print cluster id from vars
121+ id : print-cluster-id
122+ run : echo "clusterId=${{ env.OCI_CLUSTER_ID }}" >> $GITHUB_OUTPUT
123+
124+ deploy-provider :
125+ runs-on : ubuntu-latest
126+ name : Deploy Provider
127+ needs : [ setup-vault , setup-cluster , build ]
128+ env :
129+ OCI_VAULT_ID : ${{ needs.setup-vault.outputs.OCI_VAULT_ID }}
130+ OCI_VAULT_SECRET_NAME : ${{ needs.setup-vault.outputs.VAULT_SECRET_NAME }}
131+ OCI_VAULT_SECRET_OCID : ${{ needs.setup-vault.outputs.VAULT_SECRET_OCID }}
132+ OCI_VAULT_SECRET_OCID_1 : ${{ needs.setup-vault.outputs.VAULT_SECRET_OCID_1 }}
133+ OCI_CLUSTER_ID : ${{ needs.setup-cluster.outputs.OCI_CLUSTER_ID }}
134+ PROVIDER_NAMESPACE : ${{ vars.PROVIDER_NAMESPACE }}
135+ IMAGE_PATH : ${{ needs.build.outputs.IMAGE_PATH }}
136+ outputs :
137+ OCI_VAULT_SECRET_NAME : ${{ needs.setup-vault.outputs.VAULT_SECRET_NAME }}
138+ OCI_VAULT_SECRET_OCID : ${{ needs.setup-vault.outputs.VAULT_SECRET_OCID }}
139+ OCI_CLUSTER_ID : ${{ needs.setup-cluster.outputs.OCI_CLUSTER_ID }}
140+ steps :
141+ - name : Configure Kubectl
142+ uses :
oracle-actions/[email protected] 143+ id : test-configure-kubectl-oke-action
144+ with :
145+ cluster : ${{ env.OCI_CLUSTER_ID }}
146+
147+ - name : test cluster access
148+ run : kubectl get nodes -A
149+
150+ - name : create namespace in the cluster
151+ continue-on-error : true
152+ run : kubectl create namespace ${{ env.PROVIDER_NAMESPACE }}
153+
154+ # - name: Install Helm
155+ # uses: azure/setup-helm@v3
156+
157+ - name : Checkout
158+ uses : actions/checkout@v3
159+ with :
160+ fetch-depth : 0
161+
162+ - name : split image path into repo and tag
163+ id : split-image-path
164+ run : |
165+ echo PROVIDER_IMAGE_REPO=`echo ${{ env.IMAGE_PATH }} | sed -e "s/:.*$//"` >> $GITHUB_OUTPUT
166+ echo PROVIDER_IMAGE_TAG=`echo ${{ env.IMAGE_PATH }} | sed -e "s/.*://"` >> $GITHUB_OUTPUT
167+
168+ - name : print image values
169+ run : |
170+ echo ${{ steps.split-image-path.outputs.PROVIDER_IMAGE_REPO }}
171+ echo ${{ steps.split-image-path.outputs.PROVIDER_IMAGE_TAG }}
172+
173+ - name : Deploy Helm chart
174+ run : |
175+ helm upgrade --install oci-provider charts/oci-secrets-store-csi-driver-provider \
176+ --namespace ${{ env.PROVIDER_NAMESPACE }} \
177+ --set "provider.image.repository=${{ steps.split-image-path.outputs.PROVIDER_IMAGE_REPO }},provider.image.tag=${{ steps.split-image-path.outputs.PROVIDER_IMAGE_TAG }}"
178+
179+ - name : list pods
180+ run : |
181+ kubectl get daemonset --namespace oci-provider \
182+ --selector='app.kubernetes.io/name in (oci-secrets-store-csi-driver-provider, secrets-store-csi-driver)'
183+
184+ - name : update auth file with correct values
185+ run : |
186+ sed -e 's/region:.*/region: ${{ env.OCI_CLI_REGION }}/' \
187+ -e 's/tenancy:.*/tenancy: ${{ env.OCI_CLI_TENANCY }}/' \
188+ -e 's/user:.*/user: ${{ env.OCI_CLI_USER }}/' \
189+ -e 's/fingerprint:.*/fingerprint: ${{ env.OCI_CLI_FINGERPRINT }}/' e2e/example/user-auth-config-example.yaml > e2e/example/user-auth-config-example.yaml.tmp
190+
191+ # - name: print updated yaml file
192+ # run: cat e2e/example/user-auth-config-example.yaml.tmp
193+
194+ - name : delete secret if exists
195+ continue-on-error : true
196+ run : kubectl delete secret oci-config
197+
198+ - name : create kubernetes secret for user auth config
199+ run : |
200+ kubectl create secret generic oci-config \
201+ --from-file=config=e2e/example/user-auth-config-example.yaml.tmp \
202+ --from-literal=private-key="${{ env.OCI_CLI_KEY_CONTENT }}"
203+
204+ - name : update spc file with correct values
205+ run : |
206+ sed -e 's/vaultId:.*/vaultId: ${{ env.OCI_VAULT_ID }}/' \
207+ -e 's/authType:.*/authType: user/' \
208+ -e 's/- name:.*/- name: ${{ env.OCI_VAULT_SECRET_NAME }}/' e2e/example/secret-provider-class.yaml > e2e/example/secret-provider-class.yaml.tmp
209+
210+ - name : update deployment file with secret name
211+ run : |
212+ sed -e 's/testingSecretName:.*/testingSecretName: ${{ env.OCI_VAULT_SECRET_NAME }}/' \
213+ e2e/example/app.deployment.yaml > e2e/example/app.deployment.yaml.tmp
214+
215+ - name : print updated yaml file
216+ run : cat e2e/example/secret-provider-class.yaml.tmp
217+
218+ - name : deploy spc
219+ run : kubectl apply -f e2e/example/secret-provider-class.yaml.tmp
220+
221+ - name : deploy workload
222+ run : kubectl apply -f e2e/example/app.deployment.yaml.tmp
223+
224+ - name : Wait for pod to run
225+ id : wait-on-pod
226+ # run: kubectl wait --for=jsonpath='{.status.phase}'=Running pods/${{ env.POD_NAME }} --timeout=90s
227+ run : sleep 90
228+
229+ - name : Verify pods are running
230+ id : pod-names
231+ run : kubectl get pods -l testingSecretName=${{ env.OCI_VAULT_SECRET_NAME }} -o='custom-columns=PodName:.metadata.name' --no-headers
232+
233+ - name : capture pod name into env
234+ run : echo "POD_NAME=`kubectl get pods -l testingSecretName=${{ env.OCI_VAULT_SECRET_NAME }} -o='custom-columns=PodName:.metadata.name' --no-headers`" >> $GITHUB_ENV
235+
236+ - name : print secret value
237+ id : print-secret-content
238+ run : echo "SECRET_CONTENT=`kubectl exec -it ${{ env.POD_NAME }} -- cat /mnt/secrets-store/${{ env.OCI_VAULT_SECRET_NAME }} 2> /dev/null | base64`" >> $GITHUB_ENV
239+
240+ # - name: convert to base64
241+ # id: convert-to-base64
242+ # run: echo -n ${{ steps.print-secret-content.outputs.output }} | base64
243+
244+ - name : print values
245+ run : echo "${{ env.SECRET_CONTENT }} == ${{ env.OCI_VAULT_SECRET_VALUE}}"
246+
247+ - name : verify value
248+ run : if [ "${{ env.SECRET_CONTENT }}" == "${{ env.OCI_VAULT_SECRET_VALUE}}" ]; then exit 0; else exit 1; fi
249+
250+ # cleanup
251+ - name : remove deployment
252+ if : ${{ always() }}
253+ run : |
254+ kubectl delete -f e2e/example/app.deployment.yaml.tmp \
255+ -f e2e/example/secret-provider-class.yaml.tmp
256+
257+ - name : delete secret
258+ if : ${{ always() }}
259+ run : kubectl delete secret oci-config
260+
261+ - name : uninstall provider
262+ if : ${{ always() }}
263+ run : helm uninstall oci-provider -n ${{ env.PROVIDER_NAMESPACE }}
264+
265+ cleanup :
266+ runs-on : ubuntu-latest
267+ needs : [deploy-provider]
268+ name : Cleanup resources
269+ env :
270+ OCI_VAULT_SECRET_NAME : ${{ needs.deploy-provider.outputs.OCI_VAULT_SECRET_NAME }}
271+ OCI_VAULT_SECRET_OCID : ${{ needs.deploy-provider.outputs.OCI_VAULT_SECRET_OCID }}
272+ OCI_CLUSTER_ID : ${{ needs.deploy-provider.outputs.OCI_CLUSTER_ID }}
273+ steps :
274+ - name : delete cluster
275+ if : ${{ vars.USE_EXISTING_CLUSTER != 'true' }}
276+ uses :
oracle-actions/[email protected] 277+ with :
278+ command : " ce cluster delete --cluster-id ${{ env.OCI_CLUSTER_ID }} --wait-for-state SUCCEEDED"
279+
280+ # - name: get secret id
281+ # id: get-secret-ocid
282+ # uses: oracle-actions/[email protected] 283+ # with:
284+ # command: "vault secret list --name ${{ env.OCI_VAULT_SECRET_NAME }} --compartment-id ${{ vars.COMPARTMENT_ID }}"
285+ # query: data[0].id
286+
287+ - name : delete secrets
288+ uses :
oracle-actions/[email protected] 289+ with :
290+ command : " vault secret schedule-secret-deletion --secret-id ${{ env.OCI_VAULT_SECRET_OCID }}"
291+ # - name: delete vcn if created
292+ # - name: delete vault if created
0 commit comments