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