diff --git a/test/e2e/e2e_test.go b/test/e2e/e2e_test.go index 5c34f2a..e3fa2fd 100644 --- a/test/e2e/e2e_test.go +++ b/test/e2e/e2e_test.go @@ -68,20 +68,47 @@ func TestOperator(t *testing.T) { // Deploying the controller-manager _, err = kind("make", "deploy", "install", fmt.Sprintf("IMG=%s", img)) require.NoError(t, err) + // Accept the EULA and set the PID + _, err = kind("kubectl", "set", "env", + "-n", nsController, controller, + "MSSQL_ACCEPT_EULA=Y", "MSSQL_PID=Developer") + require.NoError(t, err) // Restarting the controller-manager, to ensure the latest image is used _, err = kind("kubectl", "rollout", "restart", "-n", nsController, controller) require.NoError(t, err) // Waiting for the controller-manager to be ready _, err = kind("kubectl", "rollout", "status", - "-n", nsController, controller, "--timeout", "2m") + "-n", nsController, controller, + "--timeout", "2m") require.NoError(t, err) + var controllerPod string + for range 5 { + // Wait for the old pods to be deleted + <-time.After(time.Second) + // Getting the controller-manager pod name + output, err := kind("kubectl", "wait", "pod", + "-n", nsController, + "-l", "control-plane=controller-manager", + "--for", "condition=Ready", + "--timeout", "2m", + "-o", "go-template", + "--template", "{{.metadata.name}}", + ) + require.NoError(t, err) + pods := strings.Split(output, "\n") + if len(pods) == 1 { + controllerPod = pods[0] + break + } + } + require.NotEmpty(t, controllerPod, "controller-manager pod not found") // Running the test script testscript.Run(t, testscript.Params{ Dir: filepath.Join("testdata", "atlas-schema"), Setup: func(e *testscript.Env) (err error) { e.Setenv("CONTROLLER_NS", nsController) - e.Setenv("CONTROLLER", controller) + e.Setenv("CONTROLLER", controllerPod) // Sharing the atlas token with the test e.Setenv("ATLAS_TOKEN", os.Getenv("ATLAS_TOKEN")) // Ensure the test in running in the right kube context @@ -123,9 +150,7 @@ func TestOperator(t *testing.T) { }, // kubectl runs kubectl with the namespace set to the test namespace "kubectl": func(ts *testscript.TestScript, neg bool, args []string) { - err := ts.Exec("kubectl", append([]string{ - "--namespace", ts.Getenv("NAMESPACE"), - }, args...)...) + err := ts.Exec("kubectl", append([]string{"-n", ts.Getenv("NAMESPACE")}, args...)...) if !neg { ts.Check(err) } else if err == nil { diff --git a/test/e2e/testdata/atlas-schema/registry.txtar b/test/e2e/testdata/atlas-schema/registry.txtar index c5395b0..f4f388c 100644 --- a/test/e2e/testdata/atlas-schema/registry.txtar +++ b/test/e2e/testdata/atlas-schema/registry.txtar @@ -7,6 +7,13 @@ kubectl wait --for=condition=ready --timeout=60s -l app=postgres pods # Create the secret to store ATLAS_TOKEN kubectl create secret generic atlas-token --from-literal=ATLAS_TOKEN=${ATLAS_TOKEN} +# Sync the $WORK directory to the controller pod +kubectl cp -n ${CONTROLLER_NS} ${WORK} ${CONTROLLER}:/tmp/${NAMESPACE}/ +# Push the schemas to the registry +env DEV_URL=postgres://root:pass@postgres.${NAMESPACE}:5433/postgres?sslmode=disable +atlas schema push atlas-operator --tag=registry-v1 --dev-url=${DEV_URL} --url=file:///tmp/${NAMESPACE}/schema-v1.hcl +atlas schema push atlas-operator --tag=registry-v2 --dev-url=${DEV_URL} --url=file:///tmp/${NAMESPACE}/schema-v2.hcl + # Create the schema kubectl apply -f schema.yaml kubectl wait --for=condition=ready --timeout=120s AtlasSchema/atlasschema-postgres @@ -17,7 +24,7 @@ cmp stdout schema-v1.hcl kubectl patch -f schema.yaml --type merge --patch-file patch-v2.yaml # Ensure the controller is aware of the change -kubectl wait --for=condition=ready=false --timeout=60s AtlasSchemas/atlasschema-postgres +kubectl wait --for=condition=ready=false --timeout=60s AtlasSchema/atlasschema-postgres kubectl wait --for=condition=ready --timeout=120s AtlasSchema/atlasschema-postgres # Inspect the schema to ensure it's correct @@ -94,6 +101,9 @@ spec: - name: postgres port: 5432 targetPort: postgres + - name: postgres-dev + port: 5433 + targetPort: postgres-dev type: ClusterIP --- apiVersion: apps/v1 @@ -134,4 +144,27 @@ spec: periodSeconds: 2 timeoutSeconds: 1 exec: - command: [ "pg_isready", "-U", "postgres" ] + command: [ "pg_isready" ] + - name: postgres-dev + image: postgres:15.4 + securityContext: + allowPrivilegeEscalation: false + capabilities: + drop: + - all + env: + - name: POSTGRES_PASSWORD + value: pass + - name: POSTGRES_USER + value: root + - name: PGPORT + value: "5433" + ports: + - containerPort: 5433 + name: postgres-dev + readinessProbe: + initialDelaySeconds: 5 + periodSeconds: 2 + timeoutSeconds: 1 + exec: + command: [ "pg_isready" ] diff --git a/test/e2e/testdata/atlas-schema/sqlserver.txtar b/test/e2e/testdata/atlas-schema/sqlserver.txtar index 44288f8..c891e48 100644 --- a/test/e2e/testdata/atlas-schema/sqlserver.txtar +++ b/test/e2e/testdata/atlas-schema/sqlserver.txtar @@ -1,6 +1,3 @@ -# Accept the EULA and set the PID -kubectl set env -n ${CONTROLLER_NS} ${CONTROLLER} MSSQL_ACCEPT_EULA=Y MSSQL_PID=Developer - env DB_URL=sqlserver://sa:P%40ssw0rd0995@sqlserver.${NAMESPACE}:1433?database=master kubectl apply -f database.yaml kubectl create secret generic sqlserver-credentials --from-literal=url=${DB_URL}