e2e-managed.yml 14 KB

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