e2e-managed.yml 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381
  1. name: managed e2e tests
  2. on:
  3. repository_dispatch:
  4. types: [ok-to-test-managed-command]
  5. permissions:
  6. contents: read
  7. env:
  8. DOCKER_BUILDX_VERSION: 'v0.4.2'
  9. GHCR_USERNAME: ${{ github.actor }}
  10. USE_GKE_GCLOUD_AUTH_PLUGIN: true
  11. # GCP variables
  12. GCP_SERVICE_ACCOUNT_KEY: ${{ secrets.GCP_SERVICE_ACCOUNT_KEY }}
  13. GCP_SM_SA_GKE_JSON: ${{ secrets.GCP_SM_SA_GKE_JSON }}
  14. GCP_GKE_CLUSTER: e2e
  15. TF_VAR_GCP_GKE_CLUSTER: e2e
  16. GCP_FED_REGION: ${{ secrets.GCP_FED_REGION }}
  17. TF_VAR_GCP_FED_REGION: ${{ secrets.GCP_FED_REGION }}
  18. GCP_KSA_NAME: ${{ secrets.GCP_KSA_NAME }}
  19. TF_VAR_GCP_KSA_NAME: ${{ secrets.GCP_KSA_NAME }}
  20. GCP_FED_PROJECT_ID: ${{ secrets.GCP_FED_PROJECT_ID }}
  21. TF_VAR_GCP_FED_PROJECT_ID: ${{ secrets.GCP_FED_PROJECT_ID }}
  22. GCP_FED_SERVICE_ACCOUNT_EMAIL: ${{ secrets.GCP_FED_SERVICE_ACCOUNT_EMAIL }}
  23. GCP_FED_WORKLOAD_IDENTITY_PROVIDER: ${{ secrets.GCP_FED_WORKLOAD_IDENTITY_PROVIDER }}
  24. # AWS variables
  25. AWS_OIDC_ROLE_ARN: ${{ secrets.AWS_OIDC_ROLE_ARN }}
  26. AWS_SA_NAME: ${{ secrets.AWS_SA_NAME }}
  27. AWS_SA_NAMESPACE: ${{ secrets.AWS_SA_NAMESPACE }}
  28. AWS_REGION: "eu-central-1"
  29. AWS_CLUSTER_NAME: "eso-e2e-managed"
  30. TF_VAR_AWS_SA_NAME: ${{ secrets.AWS_SA_NAME }}
  31. TF_VAR_AWS_SA_NAMESPACE: ${{ secrets.AWS_SA_NAMESPACE }}
  32. TF_VAR_AWS_REGION: "eu-central-1"
  33. TF_VAR_AWS_CLUSTER_NAME: "eso-e2e-managed"
  34. # Azure variables
  35. TFC_AZURE_CLIENT_ID: ${{ secrets.TFC_AZURE_CLIENT_ID }}
  36. TFC_AZURE_CLIENT_SECRET: ${{ secrets.TFC_AZURE_CLIENT_SECRET }}
  37. TFC_AZURE_TENANT_ID: ${{ secrets.TFC_AZURE_TENANT_ID }}
  38. TFC_AZURE_SUBSCRIPTION_ID: ${{ secrets.TFC_AZURE_SUBSCRIPTION_ID }}
  39. TFC_VAULT_URL: ${{ secrets.TFC_VAULT_URL }}
  40. jobs:
  41. setup:
  42. runs-on: ubuntu-latest
  43. permissions:
  44. checks: write
  45. contents: read
  46. outputs:
  47. check_run_id: ${{ steps.create_check.outputs.check_run_id }}
  48. steps:
  49. - uses: step-security/harden-runner@a90bcbc6539c36a85cdfeb73f7e2f433735f215b # v2.15.0
  50. with:
  51. egress-policy: audit
  52. - name: Create status check
  53. id: create_check
  54. uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
  55. env:
  56. PROVIDER: ${{ github.event.client_payload.slash_command.args.named.provider }}
  57. HEAD_SHA: ${{ github.event.client_payload.pull_request.head.sha }}
  58. with:
  59. github-token: ${{ secrets.GITHUB_TOKEN }}
  60. script: |
  61. const job_name = "e2e-managed-" + process.env.PROVIDER
  62. const ref = process.env.HEAD_SHA
  63. const { data: checks } = await github.rest.checks.listForRef({
  64. ...context.repo,
  65. ref
  66. });
  67. const check = checks.check_runs.filter(c => c.name === job_name);
  68. if(check && check.length > 0){
  69. const { data: result } = await github.rest.checks.update({
  70. ...context.repo,
  71. check_run_id: check[0].id,
  72. status: 'in_progress',
  73. });
  74. core.setOutput('check_run_id', check[0].id);
  75. return result;
  76. }
  77. const { data: result } = await github.rest.checks.create({
  78. ...context.repo,
  79. name: job_name,
  80. head_sha: ref,
  81. status: 'in_progress',
  82. });
  83. core.setOutput('check_run_id', result.id);
  84. return result;
  85. # AWS-specific job
  86. test-aws:
  87. runs-on: ubuntu-latest
  88. if: github.event.client_payload.slash_command.args.named.provider == 'aws'
  89. needs: [setup]
  90. permissions:
  91. id-token: write
  92. contents: read
  93. packages: write
  94. steps:
  95. - uses: step-security/harden-runner@a90bcbc6539c36a85cdfeb73f7e2f433735f215b # v2.15.0
  96. with:
  97. egress-policy: audit
  98. - name: Fork based /ok-to-test-managed checkout
  99. uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
  100. with:
  101. ref: 'refs/pull/${{ github.event.client_payload.pull_request.number }}/merge'
  102. - name: Setup Go
  103. uses: actions/setup-go@4b73464bb391d4059bd26b0524d20df3927bd417 # v6.3.0
  104. with:
  105. go-version-file: go.mod
  106. - name: Find the Go Cache
  107. id: go
  108. run: |
  109. echo "build-cache=$(go env GOCACHE)" >> $GITHUB_OUTPUT
  110. echo "mod-cache=$(go env GOMODCACHE)" >> $GITHUB_OUTPUT
  111. - name: Cache the Go Build Cache
  112. uses: actions/cache@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5.0.3
  113. with:
  114. path: ${{ steps.go.outputs.build-cache }}
  115. key: ${{ runner.os }}-build-unit-tests-${{ github.sha }}-${{ hashFiles('**/go.sum') }}
  116. restore-keys: ${{ runner.os }}-build-unit-tests-${{ github.sha }}-
  117. - name: Cache Go Dependencies
  118. uses: actions/cache@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5.0.3
  119. with:
  120. path: ${{ steps.go.outputs.mod-cache }}
  121. key: ${{ runner.os }}-pkg-${{ github.sha }}-${{ hashFiles('**/go.sum') }}
  122. restore-keys: ${{ runner.os }}-pkg-${{ github.sha }}-
  123. - uses: hashicorp/setup-terraform@5e8dbf3c6d9deaf4193ca7a8fb23f2ac83bb6c85 # v3
  124. - name: Configure AWS Credentials
  125. uses: aws-actions/configure-aws-credentials@8df5847569e6427dd6c4fb1cf565c83acfa8afa7
  126. with:
  127. role-to-assume: ${{ secrets.AWS_OIDC_ROLE_ARN }}
  128. aws-region: ${{ env.AWS_REGION }}
  129. - name: Apply Terraform
  130. run: make tf.apply.aws
  131. - name: Get AWS EKS credentials
  132. run: aws --region $AWS_REGION eks update-kubeconfig --name $AWS_CLUSTER_NAME
  133. - name: Login to Docker
  134. uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9 # v3.7.0
  135. if: env.GHCR_USERNAME != ''
  136. with:
  137. registry: ghcr.io
  138. username: ${{ github.actor }}
  139. password: ${{ secrets.GITHUB_TOKEN }}
  140. - name: Run AWS e2e Tests
  141. run: |
  142. export PATH=$PATH:$(go env GOPATH)/bin
  143. make test.e2e.managed GINKGO_LABELS="aws && managed" TEST_SUITES="provider"
  144. - name: Destroy Terraform
  145. if: always()
  146. run: make tf.destroy.aws
  147. # GCP-specific job
  148. test-gcp:
  149. runs-on: ubuntu-latest
  150. if: github.event.client_payload.slash_command.args.named.provider == 'gcp'
  151. needs: [setup]
  152. permissions:
  153. id-token: write
  154. contents: read
  155. packages: write
  156. steps:
  157. - uses: step-security/harden-runner@a90bcbc6539c36a85cdfeb73f7e2f433735f215b # v2.15.0
  158. with:
  159. egress-policy: audit
  160. - name: Fork based /ok-to-test-managed checkout
  161. uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
  162. with:
  163. ref: 'refs/pull/${{ github.event.client_payload.pull_request.number }}/merge'
  164. - name: Setup Go
  165. uses: actions/setup-go@4b73464bb391d4059bd26b0524d20df3927bd417 # v6.3.0
  166. with:
  167. go-version-file: go.mod
  168. - name: Find the Go Cache
  169. id: go
  170. run: |
  171. echo "build-cache=$(go env GOCACHE)" >> $GITHUB_OUTPUT
  172. echo "mod-cache=$(go env GOMODCACHE)" >> $GITHUB_OUTPUT
  173. - name: Cache the Go Build Cache
  174. uses: actions/cache@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5.0.3
  175. with:
  176. path: ${{ steps.go.outputs.build-cache }}
  177. key: ${{ runner.os }}-build-unit-tests-${{ github.sha }}-${{ hashFiles('**/go.sum') }}
  178. restore-keys: ${{ runner.os }}-build-unit-tests-${{ github.sha }}-
  179. - name: Cache Go Dependencies
  180. uses: actions/cache@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5.0.3
  181. with:
  182. path: ${{ steps.go.outputs.mod-cache }}
  183. key: ${{ runner.os }}-pkg-${{ github.sha }}-${{ hashFiles('**/go.sum') }}
  184. restore-keys: ${{ runner.os }}-pkg-${{ github.sha }}-
  185. - uses: hashicorp/setup-terraform@5e8dbf3c6d9deaf4193ca7a8fb23f2ac83bb6c85 # v3
  186. - name: Authenticate to Google Cloud
  187. uses: 'google-github-actions/auth@fc2174804b84f912b1f6d334e9463f484f1c552d' # v3
  188. with:
  189. project_id: ${{ secrets.GCP_FED_PROJECT_ID }}
  190. service_account: ${{ secrets.GCP_FED_SERVICE_ACCOUNT_EMAIL }}
  191. workload_identity_provider: ${{ secrets.GCP_FED_WORKLOAD_IDENTITY_PROVIDER }}
  192. create_credentials_file: true
  193. - name: Apply Terraform
  194. run: make tf.apply.gcp
  195. - name: Setup gcloud CLI
  196. uses: google-github-actions/setup-gcloud@aa5489c8933f4cc7a4f7d45035b3b1440c9c10db # v3
  197. with:
  198. install_components: 'gke-gcloud-auth-plugin'
  199. - name: Get GKE credentials
  200. uses: google-github-actions/get-gke-credentials@3e00d2f47c840b194fc2ccc712879146e87f98cb # v3
  201. with:
  202. cluster_name: '${{ env.GCP_GKE_CLUSTER }}'
  203. location: 'europe-west1'
  204. project_id: '${{ secrets.GCP_FED_PROJECT_ID }}'
  205. - name: Login to Docker
  206. uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9 # v3.7.0
  207. if: env.GHCR_USERNAME != ''
  208. with:
  209. registry: ghcr.io
  210. username: ${{ github.actor }}
  211. password: ${{ secrets.GITHUB_TOKEN }}
  212. - name: Run GCP e2e Tests
  213. env:
  214. GCP_SERVICE_ACCOUNT_KEY: ${{ secrets.GCP_SERVICE_ACCOUNT_KEY }}
  215. run: |
  216. export PATH=$PATH:$(go env GOPATH)/bin
  217. make test.e2e.managed GINKGO_LABELS="gcp && managed" TEST_SUITES="provider"
  218. - name: Destroy Terraform
  219. if: always()
  220. run: make tf.destroy.gcp
  221. # Azure-specific job
  222. test-azure:
  223. runs-on: ubuntu-latest
  224. if: github.event.client_payload.slash_command.args.named.provider == 'azure'
  225. needs: [setup]
  226. permissions:
  227. id-token: write
  228. contents: read
  229. packages: write
  230. steps:
  231. - uses: step-security/harden-runner@a90bcbc6539c36a85cdfeb73f7e2f433735f215b # v2.15.0
  232. with:
  233. egress-policy: audit
  234. - name: Fork based /ok-to-test-managed checkout
  235. uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
  236. with:
  237. ref: 'refs/pull/${{ github.event.client_payload.pull_request.number }}/merge'
  238. - name: Setup Go
  239. uses: actions/setup-go@4b73464bb391d4059bd26b0524d20df3927bd417 # v6.3.0
  240. with:
  241. go-version-file: go.mod
  242. - name: Find the Go Cache
  243. id: go
  244. run: |
  245. echo "build-cache=$(go env GOCACHE)" >> $GITHUB_OUTPUT
  246. echo "mod-cache=$(go env GOMODCACHE)" >> $GITHUB_OUTPUT
  247. - name: Cache the Go Build Cache
  248. uses: actions/cache@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5.0.3
  249. with:
  250. path: ${{ steps.go.outputs.build-cache }}
  251. key: ${{ runner.os }}-build-unit-tests-${{ github.sha }}-${{ hashFiles('**/go.sum') }}
  252. restore-keys: ${{ runner.os }}-build-unit-tests-${{ github.sha }}-
  253. - name: Cache Go Dependencies
  254. uses: actions/cache@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5.0.3
  255. with:
  256. path: ${{ steps.go.outputs.mod-cache }}
  257. key: ${{ runner.os }}-pkg-${{ github.sha }}-${{ hashFiles('**/go.sum') }}
  258. restore-keys: ${{ runner.os }}-pkg-${{ github.sha }}-
  259. - uses: hashicorp/setup-terraform@5e8dbf3c6d9deaf4193ca7a8fb23f2ac83bb6c85 # v3
  260. - name: Azure CLI login
  261. uses: azure/login@a457da9ea143d694b1b9c7c869ebb04ebe844ef5
  262. with:
  263. client-id: ${{ secrets.TFC_AZURE_CLIENT_ID }}
  264. tenant-id: ${{ secrets.TFC_AZURE_TENANT_ID }}
  265. subscription-id: ${{ secrets.TFC_AZURE_SUBSCRIPTION_ID }}
  266. - name: Apply Terraform
  267. env:
  268. ARM_CLIENT_ID: "${{ secrets.TFC_AZURE_CLIENT_ID }}"
  269. ARM_SUBSCRIPTION_ID: "${{ secrets.TFC_AZURE_SUBSCRIPTION_ID }}"
  270. ARM_TENANT_ID: "${{ secrets.TFC_AZURE_TENANT_ID }}"
  271. run: make tf.apply.azure
  272. - name: Get AKS credentials
  273. run: az aks get-credentials --admin --name eso-cluster --resource-group external-secrets-e2e
  274. - name: Login to Docker
  275. uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9 # v3.7.0
  276. if: env.GHCR_USERNAME != ''
  277. with:
  278. registry: ghcr.io
  279. username: ${{ github.actor }}
  280. password: ${{ secrets.GITHUB_TOKEN }}
  281. - name: Run Azure e2e Tests
  282. run: |
  283. export PATH=$PATH:$(go env GOPATH)/bin
  284. make test.e2e.managed GINKGO_LABELS="azure && managed" TEST_SUITES="provider"
  285. - name: Destroy Terraform
  286. if: always()
  287. env:
  288. ARM_CLIENT_ID: "${{ secrets.TFC_AZURE_CLIENT_ID }}"
  289. ARM_SUBSCRIPTION_ID: "${{ secrets.TFC_AZURE_SUBSCRIPTION_ID }}"
  290. ARM_TENANT_ID: "${{ secrets.TFC_AZURE_TENANT_ID }}"
  291. run: make tf.destroy.azure
  292. # Final status update job
  293. update-status:
  294. runs-on: ubuntu-latest
  295. if: always()
  296. needs: [setup, test-aws, test-gcp, test-azure]
  297. permissions:
  298. checks: write
  299. contents: read
  300. steps:
  301. - name: Update status check
  302. uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
  303. env:
  304. AWS_RESULT: ${{ needs.test-aws.result }}
  305. GCP_RESULT: ${{ needs.test-gcp.result }}
  306. AZURE_RESULT: ${{ needs.test-azure.result }}
  307. CHECK_RUN_ID: ${{ needs.setup.outputs.check_run_id }}
  308. with:
  309. github-token: ${{ secrets.GITHUB_TOKEN }}
  310. script: |
  311. const conclusion = process.env.AWS_RESULT + process.env.GCP_RESULT + process.env.AZURE_RESULT;
  312. const checkRunId = process.env.CHECK_RUN_ID;
  313. // Determine the overall conclusion
  314. let finalConclusion = 'success';
  315. if (conclusion.includes('failure')) {
  316. finalConclusion = 'failure';
  317. } else if (conclusion.includes('cancelled')) {
  318. finalConclusion = 'cancelled';
  319. } else if (conclusion === '') {
  320. finalConclusion = 'skipped';
  321. }
  322. if (checkRunId) {
  323. await github.rest.checks.update({
  324. ...context.repo,
  325. check_run_id: checkRunId,
  326. status: 'completed',
  327. conclusion: finalConclusion
  328. });
  329. }