From 7730677bd2084b0cb688e247068f20f37d0b921f Mon Sep 17 00:00:00 2001 From: "Giau. Tran Minh" Date: Sun, 13 Oct 2024 17:00:53 +0700 Subject: [PATCH] chore: test operator with e2e tests --- .github/workflows/push-chart.yaml | 42 +++++++++++-------------------- test/e2e/e2e_test.go | 23 ++++++++++------- 2 files changed, 29 insertions(+), 36 deletions(-) diff --git a/.github/workflows/push-chart.yaml b/.github/workflows/push-chart.yaml index 6cfafb9f..90f97ede 100644 --- a/.github/workflows/push-chart.yaml +++ b/.github/workflows/push-chart.yaml @@ -26,37 +26,25 @@ jobs: name: Test runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - name: start minikube - id: minikube - uses: medyagh/setup-minikube@master - - uses: azure/setup-helm@v3 + - uses: actions/checkout@v4 + - name: Create k8s Kind Cluster + uses: helm/kind-action@v1 + - name: Setup Helm + uses: azure/setup-helm@v4 - name: install atlas-operator run: | helm install atlas-operator charts/atlas-operator --wait \ - --set image.pullPolicy=Always - - name: apply test resources + --set image.pullPolicy=Always + - name: Run e2e tests with Operator run: | - kubectl apply -k config/integration - - name: wait for test resources - run: | - if ! kubectl wait --for=condition=ready --timeout=120s atlasschemas --all; then - kubectl describe atlasschemas - kubectl describe pods -l atlasgo.io/engine=postgres - kubectl describe pods -l atlasgo.io/engine=mysql - kubectl describe deployments - exit 1 - fi + make test-e2e \ + ATLAS_TOKEN=${{ secrets.ATLAS_TOKEN }} \ + KIND_CLUSTER=chart-testing \ + OPERATOR_E2E=true - name: test env vars run: | - kubectl apply -k config/integration/env - helm upgrade atlas-operator charts/atlas-operator -f ./config/integration/env/values.yaml --wait - # Find the operator pod - OPERATOR=$(kubectl get pods -o jsonpath='{.items[0].metadata.name}') - # Extract the env from the operator pod - kubectl exec $OPERATOR -- env | grep NORMAL_ENV - kubectl exec $OPERATOR -- env | grep CONFIGMAP_REF_ENV - kubectl exec $OPERATOR -- env | grep SECRET_REF_ENV + helm template atlas-operator charts/atlas-operator \ + --set-json=extraEnvs='[{"name":"NORMAL_ENV","value":"value"}]' | grep NORMAL_ENV helm-push: name: Push to ghcr.io needs: [helm-test] @@ -66,8 +54,8 @@ jobs: run: working-directory: charts/ steps: - - uses: actions/checkout@v3 - - uses: azure/setup-helm@v3 + - uses: actions/checkout@v4 + - uses: azure/setup-helm@v4 - name: get version id: version run: | diff --git a/test/e2e/e2e_test.go b/test/e2e/e2e_test.go index ff409c60..98372433 100644 --- a/test/e2e/e2e_test.go +++ b/test/e2e/e2e_test.go @@ -60,16 +60,21 @@ func TestOperator(t *testing.T) { } return string(output), nil } - // Deploying the controller-manager - _, err = kind("skaffold", "run", "--wait-for-connection=true", "-p", "integration") - require.NoError(t, err) - // Installing the CRDs - _, err = kind("make", "install") - require.NoError(t, err) - t.Cleanup(func() { - _, err = kind("make", "undeploy", "ignore-not-found=true") + // Deploying the controller-manager, installing the CRDs and cleaning up + // the resources after the test, if the environment variable is set + // to run the e2e test + if os.Getenv("OPERATOR_E2E") != "" { + // Deploying the controller-manager + _, err = kind("skaffold", "run", "--wait-for-connection=true", "-p", "integration") require.NoError(t, err) - }) + // Installing the CRDs + _, err = kind("make", "install") + require.NoError(t, err) + t.Cleanup(func() { + _, err = kind("make", "undeploy", "ignore-not-found=true") + require.NoError(t, err) + }) + } // Accept the EULA and set the PID _, err = kind("kubectl", "set", "env", "-n", nsController, controller,