Skip to content

Commit

Permalink
test/e2e: increment timeout for wait
Browse files Browse the repository at this point in the history
  • Loading branch information
giautm committed Oct 23, 2024
1 parent c508aa0 commit 6e17281
Show file tree
Hide file tree
Showing 12 changed files with 91 additions and 73 deletions.
18 changes: 18 additions & 0 deletions test/e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,24 @@ func TestOperator(t *testing.T) {
ts.Fatalf("unexpected success")
}
},
// kubectl-wait-ready runs kubectl wait for the given resource to be ready
"kubectl-wait-ready": func(ts *testscript.TestScript, neg bool, args []string) {
if len(args) == 0 {
ts.Fatalf("usage: kubectl-wait-ready <resource> <name>")
}
err := ts.Exec("kubectl", append([]string{"-n", ts.Getenv("NAMESPACE"),
"wait", "--for=condition=ready",
// We need a timeout of 10m because we run the test in parallel
// and the controller-manager is not able to handle all the requests
// at the same time
"--timeout=10m",
}, args...)...)
if !neg {
ts.Check(err)
} else if err == nil {
ts.Fatalf("unexpected success")
}
},
// envfile read the file and using its content as environment variables
"envfile": func(ts *testscript.TestScript, neg bool, args []string) {
if neg {
Expand Down
20 changes: 10 additions & 10 deletions test/e2e/testscript/migration-mysql.txtar
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
env DB_URL=mysql://root:pass@mysql.${NAMESPACE}:3306/myapp
kubectl apply -f database.yaml
kubectl create secret generic mysql-credentials --from-literal=url=${DB_URL}
kubectl create secret generic db-creds --from-literal=url=${DB_URL}
# Wait for the DB ready before creating the schema
kubectl wait --for=condition=ready --timeout=60s -l app=mysql pods
kubectl-wait-ready -l app=mysql pods

# Create configmap to store the migrations directory
kubectl create configmap migration-dir --from-file=migrations-v1

# Create the resource
kubectl apply -f migration.yaml
kubectl wait --for=condition=ready --timeout=120s AtlasMigration/sample
kubectl-wait-ready AtlasMigration/mysql

# Inspect the schema to ensure it's correct
atlas schema inspect -u ${DB_URL} --exclude=atlas_schema_revisions
Expand All @@ -20,8 +20,8 @@ kubectl create configmap migration-dir --from-file=migrations-v2 --dry-run=clien
stdin stdout
kubectl apply -f -
# Ensure the controller is aware of the change
kubectl wait --for=condition=ready=false --timeout=60s AtlasMigration/sample
kubectl wait --for=condition=ready --timeout=120s AtlasMigration/sample
kubectl wait --for=condition=ready=false --timeout=60s AtlasMigration/mysql
kubectl-wait-ready AtlasMigration/mysql

# Inspect the schema to ensure it's correct
atlas schema inspect -u ${DB_URL} --exclude=atlas_schema_revisions
Expand All @@ -32,10 +32,10 @@ kubectl create configmap migration-dir --from-file=migrations-v1 --dry-run=clien
stdin stdout
kubectl apply -f -
# Expect migration is failured
kubectl wait --timeout=120s --for=jsonpath='{.status.conditions[*].message}'='"Migrate down is not allowed"' AtlasMigration/sample
kubectl wait --timeout=120s --for=jsonpath='{.status.conditions[*].message}'='"Migrate down is not allowed"' AtlasMigration/mysql
# Patch the migration to allow down migration
kubectl patch AtlasMigration/sample --type merge --patch-file ./migration-patch-down.yaml
kubectl wait --timeout=120s --for=condition=ready AtlasMigration/sample
kubectl patch AtlasMigration/mysql --type merge --patch-file ./migration-patch-down.yaml
kubectl wait --timeout=120s --for=condition=ready AtlasMigration/mysql

# Inspect the schema to ensure it's correct after down migration
atlas schema inspect -u ${DB_URL} --exclude=atlas_schema_revisions
Expand Down Expand Up @@ -206,15 +206,15 @@ ALTER TABLE posts ADD COLUMN created_at datetime NOT NULL DEFAULT CURRENT_TIMEST
apiVersion: db.atlasgo.io/v1alpha1
kind: AtlasMigration
metadata:
name: sample
name: mysql
spec:
dir:
configMapRef:
name: "migration-dir"
urlFrom:
secretKeyRef:
name: db-creds
key: url
name: mysql-credentials
-- migration-patch-down.yaml --
apiVersion: db.atlasgo.io/v1alpha1
kind: AtlasMigration
Expand Down
8 changes: 4 additions & 4 deletions test/e2e/testscript/schema-clickhouse.txtar
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
env DB_URL=clickhouse://root:pass@clickhouse.${NAMESPACE}:9000/myapp
kubectl apply -f database.yaml
kubectl create secret generic clickhouse-credentials --from-literal=url=${DB_URL}
kubectl create secret generic db-creds --from-literal=url=${DB_URL}
# Wait for the DB ready before creating the schema
kubectl wait --for=condition=ready --timeout=60s -l app=clickhouse pods
kubectl-wait-ready -l app=clickhouse pods

# Create the secret to store ATLAS_TOKEN
kubectl create secret generic atlas-token --from-literal=ATLAS_TOKEN=${ATLAS_TOKEN}
Expand All @@ -14,7 +14,7 @@ kubectl apply -f -

# Create the schema
kubectl apply -f schema.yaml
kubectl wait --for=condition=ready --timeout=120s AtlasSchema/clickhouse
kubectl-wait-ready AtlasSchema/clickhouse

# Inspect the schema to ensure it's correct
atlas schema inspect -u ${DB_URL}
Expand Down Expand Up @@ -65,8 +65,8 @@ metadata:
spec:
urlFrom:
secretKeyRef:
name: db-creds
key: url
name: clickhouse-credentials
policy:
lint:
destructive:
Expand Down
10 changes: 5 additions & 5 deletions test/e2e/testscript/schema-manual-changes.txtar
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
env DB_URL=postgres://root:pass@postgres.${NAMESPACE}:5432/postgres?sslmode=disable
kubectl apply -f database.yaml
kubectl create secret generic postgres-credentials --from-literal=url=${DB_URL}
kubectl create secret generic db-creds --from-literal=url=${DB_URL}
# Wait for the DB ready before creating the schema
kubectl wait --for=condition=ready --timeout=60s -l app=postgres pods
kubectl-wait-ready -l app=postgres pods

# Create the secret to store ATLAS_TOKEN
kubectl create secret generic atlas-token --from-literal=ATLAS_TOKEN=${ATLAS_TOKEN}
Expand All @@ -16,7 +16,7 @@ plans-rm stdout

# Create the schema
kubectl apply -f schema.yaml
kubectl wait --for=condition=ready --timeout=120s AtlasSchema/postgres
kubectl-wait-ready AtlasSchema/postgres

# Inspect the schema to ensure it's correct
atlas schema inspect -u ${DB_URL}
Expand All @@ -35,7 +35,7 @@ envfile PLAN_URL=stdout
atlas schema plan approve --url=${PLAN_URL}

# The schema should be updated now
kubectl wait --for=condition=ready --timeout=120s AtlasSchemas/postgres
kubectl-wait-ready AtlasSchemas/postgres
atlas schema inspect -u ${DB_URL}
cmp stdout schema-v1.hcl

Expand Down Expand Up @@ -84,7 +84,7 @@ metadata:
spec:
urlFrom:
secretKeyRef:
name: postgres-credentials
name: db-creds
key: url
cloud:
repo: atlas-operator
Expand Down
14 changes: 7 additions & 7 deletions test/e2e/testscript/schema-mariadb.txtar
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
env DB_URL=mariadb://root:pass@mariadb.${NAMESPACE}:3306/myapp
kubectl apply -f database.yaml
kubectl create secret generic mariadb-credentials --from-literal=url=${DB_URL}
kubectl create secret generic db-creds --from-literal=url=${DB_URL}
# Wait for the DB ready before creating the schema
kubectl wait --for=condition=ready --timeout=60s -l app=mariadb pods
kubectl-wait-ready -l app=mariadb pods

# Sync the $WORK directory to the controller pod
kubectl cp -n ${CONTROLLER_NS} ${WORK} ${CONTROLLER}:/tmp/${NAMESPACE}/
Expand All @@ -17,7 +17,7 @@ kubectl apply -f -

# Create the schema
kubectl apply -f schema.yaml
kubectl wait --for=condition=ready --timeout=120s AtlasSchema/atlasschema-mariadb
kubectl-wait-ready AtlasSchema/mariadb

# Inspect the schema to ensure it's correct
atlas schema inspect -u ${DB_URL}
Expand All @@ -29,8 +29,8 @@ stdin stdout
kubectl apply -f -

# Ensure the controller is aware of the change
kubectl wait --for=condition=ready=false --timeout=60s AtlasSchema/atlasschema-mariadb
kubectl wait --for=condition=ready --timeout=120s AtlasSchema/atlasschema-mariadb
kubectl wait --for=condition=ready=false --timeout=60s AtlasSchema/mariadb
kubectl-wait-ready AtlasSchema/mariadb

# Inspect the schema to ensure it's correct
atlas schema inspect -u ${DB_URL}
Expand Down Expand Up @@ -140,12 +140,12 @@ create table myapp.ignore_me (c int);
apiVersion: db.atlasgo.io/v1alpha1
kind: AtlasSchema
metadata:
name: atlasschema-mariadb
name: mariadb
spec:
urlFrom:
secretKeyRef:
name: db-creds
key: url
name: mariadb-credentials
policy:
lint:
destructive:
Expand Down
14 changes: 7 additions & 7 deletions test/e2e/testscript/schema-mysql.txtar
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
env DB_URL=mysql://root:pass@mysql.${NAMESPACE}:3306/myapp
kubectl apply -f database.yaml
kubectl create secret generic mysql-credentials --from-literal=url=${DB_URL}
kubectl create secret generic db-creds --from-literal=url=${DB_URL}
# Wait for the DB ready before creating the schema
kubectl wait --for=condition=ready --timeout=60s -l app=mysql pods
kubectl-wait-ready -l app=mysql pods

# Sync the $WORK directory to the controller pod
kubectl cp -n ${CONTROLLER_NS} ${WORK} ${CONTROLLER}:/tmp/${NAMESPACE}/
Expand All @@ -17,7 +17,7 @@ kubectl apply -f -

# Create the schema
kubectl apply -f schema.yaml
kubectl wait --for=condition=ready --timeout=120s AtlasSchema/atlasschema-mysql
kubectl-wait-ready AtlasSchema/mysql

# Inspect the schema to ensure it's correct
atlas schema inspect -u ${DB_URL}
Expand All @@ -29,8 +29,8 @@ stdin stdout
kubectl apply -f -

# Ensure the controller is aware of the change
kubectl wait --for=condition=ready=false --timeout=60s AtlasSchema/atlasschema-mysql
kubectl wait --for=condition=ready --timeout=120s AtlasSchema/atlasschema-mysql
kubectl wait --for=condition=ready=false --timeout=60s AtlasSchema/mysql
kubectl-wait-ready AtlasSchema/mysql

# Inspect the schema to ensure it's correct
atlas schema inspect -u ${DB_URL}
Expand Down Expand Up @@ -140,12 +140,12 @@ create table myapp.ignore_me (c int);
apiVersion: db.atlasgo.io/v1alpha1
kind: AtlasSchema
metadata:
name: atlasschema-mysql
name: mysql
spec:
urlFrom:
secretKeyRef:
name: db-creds
key: url
name: mysql-credentials
policy:
lint:
destructive:
Expand Down
16 changes: 8 additions & 8 deletions test/e2e/testscript/schema-plan-destructive.txtar
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
env DB_URL=postgres://root:pass@postgres.${NAMESPACE}:5432/postgres?sslmode=disable
kubectl apply -f database.yaml
kubectl create secret generic postgres-credentials --from-literal=url=${DB_URL}
kubectl create secret generic db-creds --from-literal=url=${DB_URL}
# Wait for the DB ready before creating the schema
kubectl wait --for=condition=ready --timeout=60s -l app=postgres pods
kubectl-wait-ready -l app=postgres pods

# Create the secret to store ATLAS_TOKEN
kubectl create secret generic atlas-token --from-literal=ATLAS_TOKEN=${ATLAS_TOKEN}
Expand All @@ -16,23 +16,23 @@ plans-rm stdout

# Create the schema
kubectl apply -f schema.yaml
kubectl wait --for=condition=ready --timeout=120s AtlasSchema/atlasschema-postgres
kubectl-wait-ready AtlasSchema/postgres

# Inspect the schema to ensure it's correct
atlas schema inspect -u ${DB_URL}
cmp stdout schema-v1.hcl

kubectl patch -f schema.yaml --type merge --patch-file patch-remove-c1.yaml
# Ensure the controller is aware of the change
kubectl wait --for=jsonpath='{.status.conditions[*].reason}'=ApprovalPending --timeout=60s AtlasSchemas/atlasschema-postgres
kubectl wait --for=jsonpath='{.status.conditions[*].reason}'=ApprovalPending --timeout=60s AtlasSchemas/postgres

# Get the plan URL from resource then approve it
kubectl get AtlasSchemas/atlasschema-postgres -o go-template --template='{{ .status.planURL }}'
kubectl get AtlasSchemas/postgres -o go-template --template='{{ .status.planURL }}'
envfile PLAN_URL=stdout
atlas schema plan approve --url=${PLAN_URL}

# The schema should be updated now
kubectl wait --for=condition=ready --timeout=120s AtlasSchemas/atlasschema-postgres
kubectl-wait-ready AtlasSchemas/postgres
atlas schema inspect -u ${DB_URL}
cmp stdout schema-v2.hcl

Expand Down Expand Up @@ -82,11 +82,11 @@ spec:
apiVersion: db.atlasgo.io/v1alpha1
kind: AtlasSchema
metadata:
name: atlasschema-postgres
name: postgres
spec:
urlFrom:
secretKeyRef:
name: postgres-credentials
name: db-creds
key: url
cloud:
repo: atlas-operator
Expand Down
16 changes: 8 additions & 8 deletions test/e2e/testscript/schema-plan-no-push.txtar
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
env DB_URL=postgres://root:pass@postgres.${NAMESPACE}:5432/postgres?sslmode=disable
kubectl apply -f database.yaml
kubectl create secret generic postgres-credentials --from-literal=url=${DB_URL}
kubectl create secret generic db-creds --from-literal=url=${DB_URL}
# Wait for the DB ready before creating the schema
kubectl wait --for=condition=ready --timeout=60s -l app=postgres pods
kubectl-wait-ready -l app=postgres pods

# Create the secret to store ATLAS_TOKEN
kubectl create secret generic atlas-token --from-literal=ATLAS_TOKEN=${ATLAS_TOKEN}
Expand All @@ -19,23 +19,23 @@ plans-rm stdout

# Create the schema
kubectl apply -f schema.yaml
kubectl wait --for=condition=ready --timeout=120s AtlasSchema/atlasschema-postgres
kubectl-wait-ready AtlasSchema/postgres

# Inspect the schema to ensure it's correct
atlas schema inspect -u ${DB_URL}
cmp stdout schema-v1.hcl

kubectl patch -f schema.yaml --type merge --patch-file patch-remove-c1.yaml
# Ensure the controller is aware of the change
kubectl wait --for=jsonpath='{.status.conditions[*].reason}'=ApprovalPending --timeout=60s AtlasSchemas/atlasschema-postgres
kubectl wait --for=jsonpath='{.status.conditions[*].reason}'=ApprovalPending --timeout=60s AtlasSchemas/postgres

# Get the plan URL from resource then approve it
kubectl get AtlasSchemas/atlasschema-postgres -o go-template --template='{{ .status.planURL }}'
kubectl get AtlasSchemas/postgres -o go-template --template='{{ .status.planURL }}'
envfile PLAN_URL=stdout
atlas schema plan approve --url=${PLAN_URL}

# The schema should be updated now
kubectl wait --for=condition=ready --timeout=120s AtlasSchemas/atlasschema-postgres
kubectl-wait-ready AtlasSchemas/postgres
atlas schema inspect -u ${DB_URL}
cmp stdout schema-v2.hcl

Expand Down Expand Up @@ -85,11 +85,11 @@ spec:
apiVersion: db.atlasgo.io/v1alpha1
kind: AtlasSchema
metadata:
name: atlasschema-postgres
name: postgres
spec:
urlFrom:
secretKeyRef:
name: postgres-credentials
name: db-creds
key: url
schema:
url: atlas://atlas-operator?tag=plan-v1
Expand Down
Loading

0 comments on commit 6e17281

Please sign in to comment.