From 206871ea30d302b46edce98287e3addcd466bf21 Mon Sep 17 00:00:00 2001 From: shivaprasadmb Date: Tue, 19 May 2026 19:45:40 +0530 Subject: [PATCH 1/3] initial changes --- automation/constants.go | 8 - .../mongo-si_test/config/database.yaml | 21 - .../mongo-si_test/config/db-secret.yaml | 8 - .../mongo-si_test/config/ndb-secret.yaml | 9 - .../cloning/mongo-si_test/config/ndb.yaml | 10 - .../cloning/mongo-si_test/config/pod.yaml | 33 - .../cloning/mongo-si_test/mongo_si_test.go | 16 +- .../mssql-si_test/config/database.yaml | 25 - .../mssql-si_test/config/db-secret.yaml | 8 - .../mssql-si_test/config/ndb-secret.yaml | 9 - .../cloning/mssql-si_test/config/ndb.yaml | 10 - .../cloning/mssql-si_test/config/pod.yaml | 35 - .../cloning/mssql-si_test/mssql_si_test.go | 16 +- .../mysql-si_test/config/database.yaml | 22 - .../mysql-si_test/config/db-secret.yaml | 8 - .../mysql-si_test/config/ndb-secret.yaml | 9 - .../cloning/mysql-si_test/config/ndb.yaml | 10 - .../cloning/mysql-si_test/config/pod.yaml | 33 - .../cloning/mysql-si_test/mysql_si_test.go | 16 +- .../cloning/pg-si_test/config/database.yaml | 21 - .../cloning/pg-si_test/config/db-secret.yaml | 8 - .../cloning/pg-si_test/config/ndb-secret.yaml | 9 - .../tests/cloning/pg-si_test/config/ndb.yaml | 10 - .../tests/cloning/pg-si_test/config/pod.yaml | 30 - .../tests/cloning/pg-si_test/pg_si_test.go | 16 +- .../mongo-si_test/config/database.yaml | 28 - .../mongo-si_test/config/db-secret.yaml | 8 - .../mongo-si_test/config/ndb-secret.yaml | 9 - .../mongo-si_test/config/ndb.yaml | 10 - .../mongo-si_test/config/pod.yaml | 33 - .../mongo-si_test/mongo-si_test.go | 16 +- .../mssql-si_test/config/database.yaml | 34 - .../mssql-si_test/config/db-secret.yaml | 8 - .../mssql-si_test/config/ndb-secret.yaml | 9 - .../mssql-si_test/config/ndb.yaml | 10 - .../mssql-si_test/config/pod.yaml | 35 - .../mssql-si_test/mssql-si_test.go | 16 +- .../mysql-si_test/config/database.yaml | 28 - .../mysql-si_test/config/db-secret.yaml | 9 - .../mysql-si_test/config/ndb-secret.yaml | 9 - .../mysql-si_test/config/ndb.yaml | 10 - .../mysql-si_test/config/pod.yaml | 33 - .../mysql-si_test/mysql-si_test.go | 16 +- .../pg-si_test/config/database.yaml | 30 - .../pg-si_test/config/db-secret.yaml | 8 - .../pg-si_test/config/ndb-secret.yaml | 9 - .../provisioning/pg-si_test/config/ndb.yaml | 10 - .../provisioning/pg-si_test/config/pod.yaml | 30 - .../provisioning/pg-si_test/pg-si_test.go | 16 +- automation/util/builders.go | 615 ++++++++++++++++++ automation/util/setup.go | 105 --- go.mod | 2 +- 52 files changed, 648 insertions(+), 898 deletions(-) delete mode 100644 automation/tests/cloning/mongo-si_test/config/database.yaml delete mode 100644 automation/tests/cloning/mongo-si_test/config/db-secret.yaml delete mode 100644 automation/tests/cloning/mongo-si_test/config/ndb-secret.yaml delete mode 100644 automation/tests/cloning/mongo-si_test/config/ndb.yaml delete mode 100644 automation/tests/cloning/mongo-si_test/config/pod.yaml delete mode 100644 automation/tests/cloning/mssql-si_test/config/database.yaml delete mode 100644 automation/tests/cloning/mssql-si_test/config/db-secret.yaml delete mode 100644 automation/tests/cloning/mssql-si_test/config/ndb-secret.yaml delete mode 100644 automation/tests/cloning/mssql-si_test/config/ndb.yaml delete mode 100644 automation/tests/cloning/mssql-si_test/config/pod.yaml delete mode 100644 automation/tests/cloning/mysql-si_test/config/database.yaml delete mode 100644 automation/tests/cloning/mysql-si_test/config/db-secret.yaml delete mode 100644 automation/tests/cloning/mysql-si_test/config/ndb-secret.yaml delete mode 100644 automation/tests/cloning/mysql-si_test/config/ndb.yaml delete mode 100644 automation/tests/cloning/mysql-si_test/config/pod.yaml delete mode 100644 automation/tests/cloning/pg-si_test/config/database.yaml delete mode 100644 automation/tests/cloning/pg-si_test/config/db-secret.yaml delete mode 100644 automation/tests/cloning/pg-si_test/config/ndb-secret.yaml delete mode 100644 automation/tests/cloning/pg-si_test/config/ndb.yaml delete mode 100644 automation/tests/cloning/pg-si_test/config/pod.yaml delete mode 100644 automation/tests/provisioning/mongo-si_test/config/database.yaml delete mode 100644 automation/tests/provisioning/mongo-si_test/config/db-secret.yaml delete mode 100644 automation/tests/provisioning/mongo-si_test/config/ndb-secret.yaml delete mode 100644 automation/tests/provisioning/mongo-si_test/config/ndb.yaml delete mode 100644 automation/tests/provisioning/mongo-si_test/config/pod.yaml delete mode 100644 automation/tests/provisioning/mssql-si_test/config/database.yaml delete mode 100644 automation/tests/provisioning/mssql-si_test/config/db-secret.yaml delete mode 100644 automation/tests/provisioning/mssql-si_test/config/ndb-secret.yaml delete mode 100644 automation/tests/provisioning/mssql-si_test/config/ndb.yaml delete mode 100644 automation/tests/provisioning/mssql-si_test/config/pod.yaml delete mode 100644 automation/tests/provisioning/mysql-si_test/config/database.yaml delete mode 100644 automation/tests/provisioning/mysql-si_test/config/db-secret.yaml delete mode 100644 automation/tests/provisioning/mysql-si_test/config/ndb-secret.yaml delete mode 100644 automation/tests/provisioning/mysql-si_test/config/ndb.yaml delete mode 100644 automation/tests/provisioning/mysql-si_test/config/pod.yaml delete mode 100644 automation/tests/provisioning/pg-si_test/config/database.yaml delete mode 100644 automation/tests/provisioning/pg-si_test/config/db-secret.yaml delete mode 100644 automation/tests/provisioning/pg-si_test/config/ndb-secret.yaml delete mode 100644 automation/tests/provisioning/pg-si_test/config/ndb.yaml delete mode 100644 automation/tests/provisioning/pg-si_test/config/pod.yaml create mode 100644 automation/util/builders.go diff --git a/automation/constants.go b/automation/constants.go index cabef795..a95765fe 100644 --- a/automation/constants.go +++ b/automation/constants.go @@ -7,14 +7,6 @@ const ( // cluster-scoped NDBServer without needing access to the secret. NDB_CREDENTIALS_NAMESPACE = "ndb-credentials" - // Resource paths - NDBSERVER_PATH = "./config/ndb.yaml" - DATABASE_PATH = "./config/database.yaml" - DB_SECRET_PATH = "./config/db-secret.yaml" - NDB_SECRET_PATH = "./config/ndb-secret.yaml" - APP_POD_PATH = "./config/pod.yaml" - APP_SVC_PATH = "./config/service.yaml" - // Environment Variables KUBECONFIG_ENV = "KUBECONFIG" DB_SECRET_PASSWORD_ENV = "DB_SECRET_PASSWORD" diff --git a/automation/tests/cloning/mongo-si_test/config/database.yaml b/automation/tests/cloning/mongo-si_test/config/database.yaml deleted file mode 100644 index 116a91dd..00000000 --- a/automation/tests/cloning/mongo-si_test/config/database.yaml +++ /dev/null @@ -1,21 +0,0 @@ -apiVersion: ndb.nutanix.com/v1alpha1 -kind: Database -metadata: - name: clone-mongo-si -spec: - ndbRef: clone-ndb-mongo-si - isClone: true - clone: - name: clone-mongo-si - type: "mongodb" - description: Cloning mongoDB single instance testing - # clusterId: "" # Alternative: use UUID instead of name - clusterName: "" # Set by test framework from NX_CLUSTER_NAME_ENV - profiles: {} - credentialSecret: clone-db-secret-mongo-si - timezone: America/Los_Angeles - # sourceDatabaseId: "" # Alternative: use UUID instead of name - sourceDatabaseName: "" # Set by test framework from MONGO_SI_CLONING_NAME_ENV - # snapshotId: "" # Alternative: use specific snapshot UUID - snapshotName: "" # Optional: use specific snapshot name, or leave empty for auto-selection - additionalArguments: {} diff --git a/automation/tests/cloning/mongo-si_test/config/db-secret.yaml b/automation/tests/cloning/mongo-si_test/config/db-secret.yaml deleted file mode 100644 index 3d4877ba..00000000 --- a/automation/tests/cloning/mongo-si_test/config/db-secret.yaml +++ /dev/null @@ -1,8 +0,0 @@ -apiVersion: v1 -kind: Secret -metadata: - name: clone-db-secret-mongo-si -type: Opaque -stringData: - password: - ssh_public_key: ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCwyAhpllp2WwrUB1aO/0/DN5nIWNXJWQ3ybhuEG4U+kHl8xFFKnPOTDQtTK8UwByoSf6wqIfTr10ESAoHySOpxHk2gyVHVmUmRZ1WFiNR5tW3Q4qbq1qKpIVy1jH9ZRoTJwzg0J33W9W8SZzhM8Nj0nwuDqp6FS8ui7q9H3tgM+9bYYxETTg52NEw7jTVQx6KaZgG+p/8armoYPKh9DGhBYGY3oCmGiOYlm/phSlj3R63qghZIsBXKxeJDEs4cLolQ+9QYoRqqusdEGVCp7Ba/GtUPdBPYdTy+xuXGiALEpsCrqyUstxypHZVJEQfmqS8uy9UB8KFg2YepwhPgX1oN noname diff --git a/automation/tests/cloning/mongo-si_test/config/ndb-secret.yaml b/automation/tests/cloning/mongo-si_test/config/ndb-secret.yaml deleted file mode 100644 index d938fc43..00000000 --- a/automation/tests/cloning/mongo-si_test/config/ndb-secret.yaml +++ /dev/null @@ -1,9 +0,0 @@ -apiVersion: v1 -kind: Secret -metadata: - name: clone-ndb-secret-pg-si -type: Opaque -stringData: - username: - password: - ca_certificate: "" diff --git a/automation/tests/cloning/mongo-si_test/config/ndb.yaml b/automation/tests/cloning/mongo-si_test/config/ndb.yaml deleted file mode 100644 index f005ae3b..00000000 --- a/automation/tests/cloning/mongo-si_test/config/ndb.yaml +++ /dev/null @@ -1,10 +0,0 @@ -apiVersion: ndb.nutanix.com/v1alpha1 -kind: NDBServer -metadata: - name: clone-ndb-mongo-si -spec: - credentialSecretRef: - name: clone-ndb-secret-pg-si - namespace: ndb-credentials - server: :8443/era/v0.9> - skipCertificateVerification: true diff --git a/automation/tests/cloning/mongo-si_test/config/pod.yaml b/automation/tests/cloning/mongo-si_test/config/pod.yaml deleted file mode 100644 index 54e516ea..00000000 --- a/automation/tests/cloning/mongo-si_test/config/pod.yaml +++ /dev/null @@ -1,33 +0,0 @@ -apiVersion: v1 -kind: Pod -metadata: - name: clone-app-mongo-si - labels: - app: clone-app-mongo-si -spec: - containers: - - name: app-mongo-container - image: mazins/ndb-operator-mongodb:latest - env: - - name: DBHOST - value: clone-mongo-si-svc - - name: DBPORT - value: "80" - - name: DATABASE - value: database_one - - name: USERNAME - value: admin - - name: PASSWORD - valueFrom: - secretKeyRef: - name: clone-db-secret-mongo-si - key: password - ports: - - containerPort: 3000 - initContainers: - - name: init-db - image: busybox:1.28 - command: ['sh', '-c', "until nslookup $(DB_HOST).$(cat /var/run/secrets/kubernetes.io/serviceaccount/namespace).svc.cluster.local; do echo waiting for $(DB_HOST); sleep 2; done"] - env: - - name: DB_HOST - value: clone-mongo-si-svc \ No newline at end of file diff --git a/automation/tests/cloning/mongo-si_test/mongo_si_test.go b/automation/tests/cloning/mongo-si_test/mongo_si_test.go index 1a018aad..e1b7bbb3 100644 --- a/automation/tests/cloning/mongo-si_test/mongo_si_test.go +++ b/automation/tests/cloning/mongo-si_test/mongo_si_test.go @@ -68,12 +68,8 @@ func (suite *MongoCloningSingleInstanceTestSuite) SetupSuite() { suite.T().FailNow() } - // Setup yaml types - setupTypes, err := util.SetupTypeTemplates(ctx) - if err != nil { - logger.Printf("%s! %s\n", errBaseMsg, err) - suite.T().FailNow() - } + // Build setup types + setupTypes := util.NewMongoCloningSetupTypes() // Get test suite manager tsm = util.GetTestSuiteManager(ctx, *setupTypes) @@ -102,12 +98,8 @@ func (suite *MongoCloningSingleInstanceTestSuite) TearDownSuite() { logger.Println("TearDownSuite() starting...") errBaseMsg := "Error: SetupSuite() ended" - // Setup yaml types - setupTypes, err := util.SetupTypeTemplates(suite.ctx) - if err != nil { - logger.Printf("%s! %s\n", errBaseMsg, err) - suite.T().FailNow() - } + // Build setup types + setupTypes := util.NewMongoCloningSetupTypes() // Delete resources and de-clone database if err = suite.tsm.TearDown(suite.ctx, setupTypes, suite.clientset, suite.v1alpha1ClientSet, suite.T()); err != nil { diff --git a/automation/tests/cloning/mssql-si_test/config/database.yaml b/automation/tests/cloning/mssql-si_test/config/database.yaml deleted file mode 100644 index ffac91fc..00000000 --- a/automation/tests/cloning/mssql-si_test/config/database.yaml +++ /dev/null @@ -1,25 +0,0 @@ -apiVersion: ndb.nutanix.com/v1alpha1 -kind: Database -metadata: - name: clone-mssql-si -spec: - ndbRef: clone-ndb-mssql-si - isClone: true - clone: - name: clone-mssql-si - type: mssql - description: Cloning mssql single instance testing - # clusterId: "" # Alternative: use UUID instead of name - clusterName: "" # Set by test framework from NX_CLUSTER_NAME_ENV - profiles: - software: - name: MSSQL-MAZIN2 - credentialSecret: clone-db-secret-mssql-si - timezone: UTC - # sourceDatabaseId: "" # Alternative: use UUID instead of name - sourceDatabaseName: "" # Set by test framework from MSSQL_SI_CLONING_NAME_ENV - # snapshotId: "" # Alternative: use specific snapshot UUID - snapshotName: "" # Optional: use specific snapshot name, or leave empty for auto-selection - additionalArguments: - "authentication_mode": "mixed" - \ No newline at end of file diff --git a/automation/tests/cloning/mssql-si_test/config/db-secret.yaml b/automation/tests/cloning/mssql-si_test/config/db-secret.yaml deleted file mode 100644 index 030475b5..00000000 --- a/automation/tests/cloning/mssql-si_test/config/db-secret.yaml +++ /dev/null @@ -1,8 +0,0 @@ -apiVersion: v1 -kind: Secret -metadata: - name: clone-db-secret-mssql-si -type: Opaque -stringData: - password: - ssh_public_key: ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCwyAhpllp2WwrUB1aO/0/DN5nIWNXJWQ3ybhuEG4U+kHl8xFFKnPOTDQtTK8UwByoSf6wqIfTr10ESAoHySOpxHk2gyVHVmUmRZ1WFiNR5tW3Q4qbq1qKpIVy1jH9ZRoTJwzg0J33W9W8SZzhM8Nj0nwuDqp6FS8ui7q9H3tgM+9bYYxETTg52NEw7jTVQx6KaZgG+p/8armoYPKh9DGhBYGY3oCmGiOYlm/phSlj3R63qghZIsBXKxeJDEs4cLolQ+9QYoRqqusdEGVCp7Ba/GtUPdBPYdTy+xuXGiALEpsCrqyUstxypHZVJEQfmqS8uy9UB8KFg2YepwhPgX1oN noname diff --git a/automation/tests/cloning/mssql-si_test/config/ndb-secret.yaml b/automation/tests/cloning/mssql-si_test/config/ndb-secret.yaml deleted file mode 100644 index 56dd39db..00000000 --- a/automation/tests/cloning/mssql-si_test/config/ndb-secret.yaml +++ /dev/null @@ -1,9 +0,0 @@ -apiVersion: v1 -kind: Secret -metadata: - name: clone-ndb-secret-mssql-si -type: Opaque -stringData: - username: - password: - ca_certificate: "" diff --git a/automation/tests/cloning/mssql-si_test/config/ndb.yaml b/automation/tests/cloning/mssql-si_test/config/ndb.yaml deleted file mode 100644 index a2d23870..00000000 --- a/automation/tests/cloning/mssql-si_test/config/ndb.yaml +++ /dev/null @@ -1,10 +0,0 @@ -apiVersion: ndb.nutanix.com/v1alpha1 -kind: NDBServer -metadata: - name: clone-ndb-mssql-si -spec: - credentialSecretRef: - name: clone-ndb-secret-mssql-si - namespace: ndb-credentials - server: :8443/era/v0.9> - skipCertificateVerification: true diff --git a/automation/tests/cloning/mssql-si_test/config/pod.yaml b/automation/tests/cloning/mssql-si_test/config/pod.yaml deleted file mode 100644 index bdc890c0..00000000 --- a/automation/tests/cloning/mssql-si_test/config/pod.yaml +++ /dev/null @@ -1,35 +0,0 @@ -apiVersion: v1 -kind: Pod -metadata: - name: clone-app-mssql-si - labels: - app: clone-app-mssql-si -spec: - containers: - - name: app-mssql-container - image: mazins/ndb-operator-mssql:latest - env: - - name: DBHOST - value: clone-mssql-si-svc - - name: USERNAME - value: sa - - name: DATABASE - value: database_one - - name: DBPORT - value: "80" - - name: MSSQL_INSTANCE_NAME - value: CDMINSTANCE - - name: PASSWORD - valueFrom: - secretKeyRef: - name: clone-db-secret-mssql-si - key: password - ports: - - containerPort: 3000 - initContainers: - - name: init-db - image: busybox:1.28 - command: ['sh', '-c', "until nslookup $(DB_HOST).$(cat /var/run/secrets/kubernetes.io/serviceaccount/namespace).svc.cluster.local; do echo waiting for $(DB_HOST); sleep 2; done"] - env: - - name: DB_HOST - value: clone-mssql-si-svc \ No newline at end of file diff --git a/automation/tests/cloning/mssql-si_test/mssql_si_test.go b/automation/tests/cloning/mssql-si_test/mssql_si_test.go index fd125c7c..1ee25b00 100644 --- a/automation/tests/cloning/mssql-si_test/mssql_si_test.go +++ b/automation/tests/cloning/mssql-si_test/mssql_si_test.go @@ -68,12 +68,8 @@ func (suite *MSSQLCloningSingleInstanceTestSuite) SetupSuite() { suite.T().FailNow() } - // Setup yaml types - setupTypes, err := util.SetupTypeTemplates(ctx) - if err != nil { - logger.Printf("%s! %s\n", errBaseMsg, err) - suite.T().FailNow() - } + // Build setup types + setupTypes := util.NewMSSQLCloningSetupTypes() // Get test suite manager tsm = util.GetTestSuiteManager(ctx, *setupTypes) @@ -102,12 +98,8 @@ func (suite *MSSQLCloningSingleInstanceTestSuite) TearDownSuite() { logger.Println("TearDownSuite() starting...") errBaseMsg := "Error: SetupSuite() ended" - // Setup yaml types - setupTypes, err := util.SetupTypeTemplates(suite.ctx) - if err != nil { - logger.Printf("%s! %s\n", errBaseMsg, err) - suite.T().FailNow() - } + // Build setup types + setupTypes := util.NewMSSQLCloningSetupTypes() // Delete resources and de-clone database if err = suite.tsm.TearDown(suite.ctx, setupTypes, suite.clientset, suite.v1alpha1ClientSet, suite.T()); err != nil { diff --git a/automation/tests/cloning/mysql-si_test/config/database.yaml b/automation/tests/cloning/mysql-si_test/config/database.yaml deleted file mode 100644 index 91ec28da..00000000 --- a/automation/tests/cloning/mysql-si_test/config/database.yaml +++ /dev/null @@ -1,22 +0,0 @@ -apiVersion: ndb.nutanix.com/v1alpha1 -kind: Database -metadata: - name: clone-mysql-si -spec: - ndbRef: clone-ndb-mysql-si - isClone: true - clone: - name: clone-mysql-si - type: mysql - description: Cloning mysql single instance testing - # clusterId: "" # Alternative: use UUID instead of name - clusterName: "" # Set by test framework from NX_CLUSTER_NAME_ENV - profiles: {} - credentialSecret: clone-db-secret-mysql-si - timezone: UTC - # sourceDatabaseId: "" # Alternative: use UUID instead of name - sourceDatabaseName: "" # Set by test framework from MYSQL_SI_CLONING_NAME_ENV - # snapshotId: "" # Alternative: use specific snapshot UUID - snapshotName: "" # Optional: use specific snapshot name, or leave empty for auto-selection - additionalArguments: {} - \ No newline at end of file diff --git a/automation/tests/cloning/mysql-si_test/config/db-secret.yaml b/automation/tests/cloning/mysql-si_test/config/db-secret.yaml deleted file mode 100644 index 87e3a41e..00000000 --- a/automation/tests/cloning/mysql-si_test/config/db-secret.yaml +++ /dev/null @@ -1,8 +0,0 @@ -apiVersion: v1 -kind: Secret -metadata: - name: clone-db-secret-mysql-si -type: Opaque -stringData: - password: - ssh_public_key: ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCwyAhpllp2WwrUB1aO/0/DN5nIWNXJWQ3ybhuEG4U+kHl8xFFKnPOTDQtTK8UwByoSf6wqIfTr10ESAoHySOpxHk2gyVHVmUmRZ1WFiNR5tW3Q4qbq1qKpIVy1jH9ZRoTJwzg0J33W9W8SZzhM8Nj0nwuDqp6FS8ui7q9H3tgM+9bYYxETTg52NEw7jTVQx6KaZgG+p/8armoYPKh9DGhBYGY3oCmGiOYlm/phSlj3R63qghZIsBXKxeJDEs4cLolQ+9QYoRqqusdEGVCp7Ba/GtUPdBPYdTy+xuXGiALEpsCrqyUstxypHZVJEQfmqS8uy9UB8KFg2YepwhPgX1oN noname diff --git a/automation/tests/cloning/mysql-si_test/config/ndb-secret.yaml b/automation/tests/cloning/mysql-si_test/config/ndb-secret.yaml deleted file mode 100644 index 4b66326a..00000000 --- a/automation/tests/cloning/mysql-si_test/config/ndb-secret.yaml +++ /dev/null @@ -1,9 +0,0 @@ -apiVersion: v1 -kind: Secret -metadata: - name: clone-ndb-secret-mysql-si -type: Opaque -stringData: - username: - password: - ca_certificate: "" diff --git a/automation/tests/cloning/mysql-si_test/config/ndb.yaml b/automation/tests/cloning/mysql-si_test/config/ndb.yaml deleted file mode 100644 index d8cf13b9..00000000 --- a/automation/tests/cloning/mysql-si_test/config/ndb.yaml +++ /dev/null @@ -1,10 +0,0 @@ -apiVersion: ndb.nutanix.com/v1alpha1 -kind: NDBServer -metadata: - name: clone-ndb-mysql-si -spec: - credentialSecretRef: - name: clone-ndb-secret-mysql-si - namespace: ndb-credentials - server: :8443/era/v0.9> - skipCertificateVerification: true diff --git a/automation/tests/cloning/mysql-si_test/config/pod.yaml b/automation/tests/cloning/mysql-si_test/config/pod.yaml deleted file mode 100644 index efd95184..00000000 --- a/automation/tests/cloning/mysql-si_test/config/pod.yaml +++ /dev/null @@ -1,33 +0,0 @@ -apiVersion: v1 -kind: Pod -metadata: - name: clone-app-mysql-si - labels: - app: clone-app-mysql-si -spec: - containers: - - name: app-mysql-container - image: mazins/ndb-operator-mysql:latest - env: - - name: DBHOST - value: clone-mysql-si-svc - - name: DATABASE - value: database_one - - name: DBPORT - value: '3306' - - name: USERNAME - value: root - - name: PASSWORD - valueFrom: - secretKeyRef: - name: clone-db-secret-mysql-si - key: password - ports: - - containerPort: 3000 - initContainers: - - name: init-db - image: busybox:1.28 - command: ['sh', '-c', "until nslookup $(DB_HOST).$(cat /var/run/secrets/kubernetes.io/serviceaccount/namespace).svc.cluster.local; do echo waiting for $(DB_HOST); sleep 2; done"] - env: - - name: DB_HOST - value: clone-mysql-si-svc \ No newline at end of file diff --git a/automation/tests/cloning/mysql-si_test/mysql_si_test.go b/automation/tests/cloning/mysql-si_test/mysql_si_test.go index 1c7cf936..10579fd9 100644 --- a/automation/tests/cloning/mysql-si_test/mysql_si_test.go +++ b/automation/tests/cloning/mysql-si_test/mysql_si_test.go @@ -68,12 +68,8 @@ func (suite *MySQLCloningSingleInstanceTestSuite) SetupSuite() { suite.T().FailNow() } - // Setup yaml types - setupTypes, err := util.SetupTypeTemplates(ctx) - if err != nil { - logger.Printf("%s! %s\n", errBaseMsg, err) - suite.T().FailNow() - } + // Build setup types + setupTypes := util.NewMySQLCloningSetupTypes() // Get test suite manager tsm = util.GetTestSuiteManager(ctx, *setupTypes) @@ -102,12 +98,8 @@ func (suite *MySQLCloningSingleInstanceTestSuite) TearDownSuite() { logger.Println("TearDownSuite() starting...") errBaseMsg := "Error: SetupSuite() ended" - // Setup yaml types - setupTypes, err := util.SetupTypeTemplates(suite.ctx) - if err != nil { - logger.Printf("%s! %s\n", errBaseMsg, err) - suite.T().FailNow() - } + // Build setup types + setupTypes := util.NewMySQLCloningSetupTypes() // Delete resources and de-clone database if err = suite.tsm.TearDown(suite.ctx, setupTypes, suite.clientset, suite.v1alpha1ClientSet, suite.T()); err != nil { diff --git a/automation/tests/cloning/pg-si_test/config/database.yaml b/automation/tests/cloning/pg-si_test/config/database.yaml deleted file mode 100644 index 5d60b15d..00000000 --- a/automation/tests/cloning/pg-si_test/config/database.yaml +++ /dev/null @@ -1,21 +0,0 @@ -apiVersion: ndb.nutanix.com/v1alpha1 -kind: Database -metadata: - name: clone-pg-si -spec: - ndbRef: clone-ndb-pg-si - isClone: true - clone: - name: clone-pg-si - type: postgres - description: Cloning pg single instance testing - # clusterId: "" # Alternative: use UUID instead of name - clusterName: "" # Set by test framework from NX_CLUSTER_NAME_ENV - profiles: {} - credentialSecret: clone-db-secret-pg-si - timezone: UTC - # sourceDatabaseId: "" # Alternative: use UUID instead of name - sourceDatabaseName: "" # Set by test framework from POSTGRES_SI_CLONING_NAME_ENV - # snapshotId: "" # Alternative: use specific snapshot UUID - snapshotName: "" # Optional: use specific snapshot name, or leave empty for auto-selection - additionalArguments: {} diff --git a/automation/tests/cloning/pg-si_test/config/db-secret.yaml b/automation/tests/cloning/pg-si_test/config/db-secret.yaml deleted file mode 100644 index 4610c19d..00000000 --- a/automation/tests/cloning/pg-si_test/config/db-secret.yaml +++ /dev/null @@ -1,8 +0,0 @@ -apiVersion: v1 -kind: Secret -metadata: - name: clone-db-secret-pg-si -type: Opaque -stringData: - password: - ssh_public_key: ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCwyAhpllp2WwrUB1aO/0/DN5nIWNXJWQ3ybhuEG4U+kHl8xFFKnPOTDQtTK8UwByoSf6wqIfTr10ESAoHySOpxHk2gyVHVmUmRZ1WFiNR5tW3Q4qbq1qKpIVy1jH9ZRoTJwzg0J33W9W8SZzhM8Nj0nwuDqp6FS8ui7q9H3tgM+9bYYxETTg52NEw7jTVQx6KaZgG+p/8armoYPKh9DGhBYGY3oCmGiOYlm/phSlj3R63qghZIsBXKxeJDEs4cLolQ+9QYoRqqusdEGVCp7Ba/GtUPdBPYdTy+xuXGiALEpsCrqyUstxypHZVJEQfmqS8uy9UB8KFg2YepwhPgX1oN noname diff --git a/automation/tests/cloning/pg-si_test/config/ndb-secret.yaml b/automation/tests/cloning/pg-si_test/config/ndb-secret.yaml deleted file mode 100644 index d938fc43..00000000 --- a/automation/tests/cloning/pg-si_test/config/ndb-secret.yaml +++ /dev/null @@ -1,9 +0,0 @@ -apiVersion: v1 -kind: Secret -metadata: - name: clone-ndb-secret-pg-si -type: Opaque -stringData: - username: - password: - ca_certificate: "" diff --git a/automation/tests/cloning/pg-si_test/config/ndb.yaml b/automation/tests/cloning/pg-si_test/config/ndb.yaml deleted file mode 100644 index 14b41a04..00000000 --- a/automation/tests/cloning/pg-si_test/config/ndb.yaml +++ /dev/null @@ -1,10 +0,0 @@ -apiVersion: ndb.nutanix.com/v1alpha1 -kind: NDBServer -metadata: - name: clone-ndb-pg-si -spec: - credentialSecretRef: - name: clone-ndb-secret-pg-si - namespace: ndb-credentials - server: :8443/era/v0.9> - skipCertificateVerification: true diff --git a/automation/tests/cloning/pg-si_test/config/pod.yaml b/automation/tests/cloning/pg-si_test/config/pod.yaml deleted file mode 100644 index 3fd864e6..00000000 --- a/automation/tests/cloning/pg-si_test/config/pod.yaml +++ /dev/null @@ -1,30 +0,0 @@ -apiVersion: v1 -kind: Pod -metadata: - name: clone-app-pg-si - labels: - app: clone-app-pg-si -spec: - containers: - - name: best-app - image: manavrajvanshinx/best-app:latest - resources: - limits: - memory: 512Mi - cpu: "1" - env: - - name: DBHOST - value: clone-pg-si-svc - - name: DBPORT - value: '80' - - name: PASSWORD - valueFrom: - secretKeyRef: - name: clone-db-secret-pg-si - key: password - ports: - - containerPort: 3000 - initContainers: - - name: init-db - image: busybox:1.28 - command: ['sh', '-c', "until nslookup clone-pg-si-svc.$(cat /var/run/secrets/kubernetes.io/serviceaccount/namespace).svc.cluster.local; do echo waiting for database service; sleep 2; done"] diff --git a/automation/tests/cloning/pg-si_test/pg_si_test.go b/automation/tests/cloning/pg-si_test/pg_si_test.go index 5c814103..f4c3c1fc 100644 --- a/automation/tests/cloning/pg-si_test/pg_si_test.go +++ b/automation/tests/cloning/pg-si_test/pg_si_test.go @@ -68,12 +68,8 @@ func (suite *PostgresCloningSingleInstanceTestSuite) SetupSuite() { suite.T().FailNow() } - // Setup yaml types - setupTypes, err := util.SetupTypeTemplates(ctx) - if err != nil { - logger.Printf("%s! %s\n", errBaseMsg, err) - suite.T().FailNow() - } + // Build setup types + setupTypes := util.NewPgCloningSetupTypes() // Get test suite manager tsm = util.GetTestSuiteManager(ctx, *setupTypes) @@ -102,12 +98,8 @@ func (suite *PostgresCloningSingleInstanceTestSuite) TearDownSuite() { logger.Println("TearDownSuite() starting...") errBaseMsg := "Error: SetupSuite() ended" - // Setup yaml types - setupTypes, err := util.SetupTypeTemplates(suite.ctx) - if err != nil { - logger.Printf("%s! %s\n", errBaseMsg, err) - suite.T().FailNow() - } + // Build setup types + setupTypes := util.NewPgCloningSetupTypes() // Delete resources and de-clone database if err = suite.tsm.TearDown(suite.ctx, setupTypes, suite.clientset, suite.v1alpha1ClientSet, suite.T()); err != nil { diff --git a/automation/tests/provisioning/mongo-si_test/config/database.yaml b/automation/tests/provisioning/mongo-si_test/config/database.yaml deleted file mode 100644 index 94a1eff0..00000000 --- a/automation/tests/provisioning/mongo-si_test/config/database.yaml +++ /dev/null @@ -1,28 +0,0 @@ -apiVersion: ndb.nutanix.com/v1alpha1 -kind: Database -metadata: - name: db-mongo-si -spec: - ndbRef: ndb-mongo - databaseInstance: - name: db-mongo-si - databaseNames: - - database_one - # clusterId: - clusterName: # Optional: use clusterName instead of clusterId - credentialSecret: db-secret-mongo-si - size: 10 - timezone: "UTC" - type: mongodb - profiles: {} - timeMachine: - name: db-mongo-si_TM - description: "TM provisioned by operator" - sla : "DEFAULT_OOB_GOLD_SLA" - dailySnapshotTime: "12:34:56" - snapshotsPerDay: 4 - logCatchUpFrequency: 90 - weeklySnapshotDay: "WEDNESDAY" - monthlySnapshotDay: 24 - quarterlySnapshotMonth: "Jan" - additionalArguments: {} diff --git a/automation/tests/provisioning/mongo-si_test/config/db-secret.yaml b/automation/tests/provisioning/mongo-si_test/config/db-secret.yaml deleted file mode 100644 index 6a2d2aee..00000000 --- a/automation/tests/provisioning/mongo-si_test/config/db-secret.yaml +++ /dev/null @@ -1,8 +0,0 @@ -apiVersion: v1 -kind: Secret -metadata: - name: db-secret-mongo-si -type: Opaque -stringData: - password: - ssh_public_key: ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCwyAhpllp2WwrUB1aO/0/DN5nIWNXJWQ3ybhuEG4U+kHl8xFFKnPOTDQtTK8UwByoSf6wqIfTr10ESAoHySOpxHk2gyVHVmUmRZ1WFiNR5tW3Q4qbq1qKpIVy1jH9ZRoTJwzg0J33W9W8SZzhM8Nj0nwuDqp6FS8ui7q9H3tgM+9bYYxETTg52NEw7jTVQx6KaZgG+p/8armoYPKh9DGhBYGY3oCmGiOYlm/phSlj3R63qghZIsBXKxeJDEs4cLolQ+9QYoRqqusdEGVCp7Ba/GtUPdBPYdTy+xuXGiALEpsCrqyUstxypHZVJEQfmqS8uy9UB8KFg2YepwhPgX1oN noname diff --git a/automation/tests/provisioning/mongo-si_test/config/ndb-secret.yaml b/automation/tests/provisioning/mongo-si_test/config/ndb-secret.yaml deleted file mode 100644 index 8d77f5e7..00000000 --- a/automation/tests/provisioning/mongo-si_test/config/ndb-secret.yaml +++ /dev/null @@ -1,9 +0,0 @@ -apiVersion: v1 -kind: Secret -metadata: - name: ndb-secret-mongo-si -type: Opaque -stringData: - username: - password: - ca_certificate: "" diff --git a/automation/tests/provisioning/mongo-si_test/config/ndb.yaml b/automation/tests/provisioning/mongo-si_test/config/ndb.yaml deleted file mode 100644 index b55c25b8..00000000 --- a/automation/tests/provisioning/mongo-si_test/config/ndb.yaml +++ /dev/null @@ -1,10 +0,0 @@ -apiVersion: ndb.nutanix.com/v1alpha1 -kind: NDBServer -metadata: - name: ndb-mongo -spec: - credentialSecretRef: - name: ndb-secret-mongo-si - namespace: ndb-credentials - server: :8443/era/v0.9> - skipCertificateVerification: true diff --git a/automation/tests/provisioning/mongo-si_test/config/pod.yaml b/automation/tests/provisioning/mongo-si_test/config/pod.yaml deleted file mode 100644 index fb952f38..00000000 --- a/automation/tests/provisioning/mongo-si_test/config/pod.yaml +++ /dev/null @@ -1,33 +0,0 @@ -apiVersion: v1 -kind: Pod -metadata: - name: app-mongo-si - labels: - app: app-mongo-si -spec: - containers: - - name: app-mongo-container - image: mazins/ndb-operator-mongodb:latest - env: - - name: DBHOST - value: db-mongo-si-svc - - name: DBPORT - value: "80" - - name: DATABASE - value: database_one - - name: USERNAME - value: admin - - name: PASSWORD - valueFrom: - secretKeyRef: - name: db-secret-mongo-si - key: password - ports: - - containerPort: 3000 - initContainers: - - name: init-db - image: busybox:1.28 - command: ['sh', '-c', "until nslookup $(DB_HOST).$(cat /var/run/secrets/kubernetes.io/serviceaccount/namespace).svc.cluster.local; do echo waiting for $(DB_HOST); sleep 2; done"] - env: - - name: DB_HOST - value: db-mongo-si-svc \ No newline at end of file diff --git a/automation/tests/provisioning/mongo-si_test/mongo-si_test.go b/automation/tests/provisioning/mongo-si_test/mongo-si_test.go index c10bcf98..726a9463 100644 --- a/automation/tests/provisioning/mongo-si_test/mongo-si_test.go +++ b/automation/tests/provisioning/mongo-si_test/mongo-si_test.go @@ -68,12 +68,8 @@ func (suite *MongoProvisioningSingleInstanceTestSuite) SetupSuite() { suite.T().FailNow() } - // Setup yaml types - setupTypes, err := util.SetupTypeTemplates(ctx) - if err != nil { - logger.Printf("%s! %s\n", errBaseMsg, err) - suite.T().FailNow() - } + // Build setup types + setupTypes := util.NewMongoProvisioningSetupTypes() // Get test suite manager tsm = util.GetTestSuiteManager(ctx, *setupTypes) @@ -102,12 +98,8 @@ func (suite *MongoProvisioningSingleInstanceTestSuite) TearDownSuite() { logger.Println("TearDownSuite() starting...") errBaseMsg := "Error: SetupSuite() ended" - // Setup yaml types - setupTypes, err := util.SetupTypeTemplates(suite.ctx) - if err != nil { - logger.Printf("%s! %s\n", errBaseMsg, err) - suite.T().FailNow() - } + // Build setup types + setupTypes := util.NewMongoProvisioningSetupTypes() // Delete resources and de-provision database if err = suite.tsm.TearDown(suite.ctx, setupTypes, suite.clientset, suite.v1alpha1ClientSet, suite.T()); err != nil { diff --git a/automation/tests/provisioning/mssql-si_test/config/database.yaml b/automation/tests/provisioning/mssql-si_test/config/database.yaml deleted file mode 100644 index 61f38a84..00000000 --- a/automation/tests/provisioning/mssql-si_test/config/database.yaml +++ /dev/null @@ -1,34 +0,0 @@ -apiVersion: ndb.nutanix.com/v1alpha1 -kind: Database -metadata: - name: db-mssql-si -spec: - ndbRef: ndb-mssql - databaseInstance: - name: db-mssql-si - databaseNames: - - database_one - # clusterId: - clusterName: # Optional: use clusterName instead of clusterId - credentialSecret: db-secret-mssql-si - size: 10 - timezone: "UTC" - type: mssql - profiles: - dbParam: - name: "DEFAULT_SQLSERVER_DATABASE_PARAMS" - dbParamInstance: - name: "DEFAULT_SQLSERVER_INSTANCE_PARAMS" - timeMachine: - name: db-mssql-si_TM - description: "TM provisioned by operator" - sla : "DEFAULT_OOB_GOLD_SLA" - dailySnapshotTime: "12:34:56" - snapshotsPerDay: 4 - logCatchUpFrequency: 90 - weeklySnapshotDay: "WEDNESDAY" - monthlySnapshotDay: 24 - quarterlySnapshotMonth: "Jan" - additionalArguments: - authentication_mode: "mixed" - sql_user_password: "Nutanix.1" diff --git a/automation/tests/provisioning/mssql-si_test/config/db-secret.yaml b/automation/tests/provisioning/mssql-si_test/config/db-secret.yaml deleted file mode 100644 index 1544e7b5..00000000 --- a/automation/tests/provisioning/mssql-si_test/config/db-secret.yaml +++ /dev/null @@ -1,8 +0,0 @@ -apiVersion: v1 -kind: Secret -metadata: - name: db-secret-mssql-si -type: Opaque -stringData: - password: - ssh_public_key: ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCwyAhpllp2WwrUB1aO/0/DN5nIWNXJWQ3ybhuEG4U+kHl8xFFKnPOTDQtTK8UwByoSf6wqIfTr10ESAoHySOpxHk2gyVHVmUmRZ1WFiNR5tW3Q4qbq1qKpIVy1jH9ZRoTJwzg0J33W9W8SZzhM8Nj0nwuDqp6FS8ui7q9H3tgM+9bYYxETTg52NEw7jTVQx6KaZgG+p/8armoYPKh9DGhBYGY3oCmGiOYlm/phSlj3R63qghZIsBXKxeJDEs4cLolQ+9QYoRqqusdEGVCp7Ba/GtUPdBPYdTy+xuXGiALEpsCrqyUstxypHZVJEQfmqS8uy9UB8KFg2YepwhPgX1oN noname diff --git a/automation/tests/provisioning/mssql-si_test/config/ndb-secret.yaml b/automation/tests/provisioning/mssql-si_test/config/ndb-secret.yaml deleted file mode 100644 index c004a314..00000000 --- a/automation/tests/provisioning/mssql-si_test/config/ndb-secret.yaml +++ /dev/null @@ -1,9 +0,0 @@ -apiVersion: v1 -kind: Secret -metadata: - name: ndb-secret-mssql-si -type: Opaque -stringData: - username: - password: - ca_certificate: "" diff --git a/automation/tests/provisioning/mssql-si_test/config/ndb.yaml b/automation/tests/provisioning/mssql-si_test/config/ndb.yaml deleted file mode 100644 index 6f4c024f..00000000 --- a/automation/tests/provisioning/mssql-si_test/config/ndb.yaml +++ /dev/null @@ -1,10 +0,0 @@ -apiVersion: ndb.nutanix.com/v1alpha1 -kind: NDBServer -metadata: - name: ndb-mssql -spec: - credentialSecretRef: - name: ndb-secret-mssql-si - namespace: ndb-credentials - server: :8443/era/v0.9> - skipCertificateVerification: true diff --git a/automation/tests/provisioning/mssql-si_test/config/pod.yaml b/automation/tests/provisioning/mssql-si_test/config/pod.yaml deleted file mode 100644 index 7e6f75a7..00000000 --- a/automation/tests/provisioning/mssql-si_test/config/pod.yaml +++ /dev/null @@ -1,35 +0,0 @@ -apiVersion: v1 -kind: Pod -metadata: - name: app-mssql-si - labels: - app: app-mssql-si -spec: - containers: - - name: app-mssql-container - image: mazins/ndb-operator-mssql:latest - env: - - name: DBHOST - value: db-mssql-si-svc - - name: USERNAME - value: sa - - name: DATABASE - value: database_one - - name: DBPORT - value: "80" - - name: MSSQL_INSTANCE_NAME - value: CDMINSTANCE - - name: PASSWORD - valueFrom: - secretKeyRef: - name: db-secret-mssql-si - key: password - ports: - - containerPort: 3000 - initContainers: - - name: init-db - image: busybox:1.28 - command: ['sh', '-c', "until nslookup $(DB_HOST).$(cat /var/run/secrets/kubernetes.io/serviceaccount/namespace).svc.cluster.local; do echo waiting for $(DB_HOST); sleep 2; done"] - env: - - name: DB_HOST - value: db-mssql-si-svc \ No newline at end of file diff --git a/automation/tests/provisioning/mssql-si_test/mssql-si_test.go b/automation/tests/provisioning/mssql-si_test/mssql-si_test.go index 15bb68c9..751e72a5 100644 --- a/automation/tests/provisioning/mssql-si_test/mssql-si_test.go +++ b/automation/tests/provisioning/mssql-si_test/mssql-si_test.go @@ -67,12 +67,8 @@ func (suite *MSSQLProvisioningSingleInstanceTestSuite) SetupSuite() { suite.T().FailNow() } - // Setup yaml types - setupTypes, err := util.SetupTypeTemplates(ctx) - if err != nil { - logger.Printf("%s! %s\n", errBaseMsg, err) - suite.T().FailNow() - } + // Build setup types + setupTypes := util.NewMSSQLProvisioningSetupTypes() // Get Test suite manager tsm = util.GetTestSuiteManager(ctx, *setupTypes) @@ -101,12 +97,8 @@ func (suite *MSSQLProvisioningSingleInstanceTestSuite) TearDownSuite() { logger.Println("TearDownSuite() starting...") errBaseMsg := "Error: SetupSuite() ended" - // Setup yaml types - setupTypes, err := util.SetupTypeTemplates(suite.ctx) - if err != nil { - logger.Printf("%s! %s\n", errBaseMsg, err) - suite.T().FailNow() - } + // Build setup types + setupTypes := util.NewMSSQLProvisioningSetupTypes() // Delete resources and de-provision database if err = suite.tsm.TearDown(suite.ctx, setupTypes, suite.clientset, suite.v1alpha1ClientSet, suite.T()); err != nil { diff --git a/automation/tests/provisioning/mysql-si_test/config/database.yaml b/automation/tests/provisioning/mysql-si_test/config/database.yaml deleted file mode 100644 index c3aaf518..00000000 --- a/automation/tests/provisioning/mysql-si_test/config/database.yaml +++ /dev/null @@ -1,28 +0,0 @@ -apiVersion: ndb.nutanix.com/v1alpha1 -kind: Database -metadata: - name: db-mysql-si -spec: - ndbRef: ndb-mysql - databaseInstance: - name: db-mysql-si - databaseNames: - - database_one - # clusterId: - clusterName: # Optional: use clusterName instead of clusterId - credentialSecret: db-secret-mysql-si - size: 10 - timezone: "UTC" - type: mysql - profiles: {} - timeMachine: - name: db-mysql-si_TM - description: "TM provisioned by operator" - sla : "DEFAULT_OOB_GOLD_SLA" - dailySnapshotTime: "12:34:56" - snapshotsPerDay: 4 - logCatchUpFrequency: 90 - weeklySnapshotDay: "WEDNESDAY" - monthlySnapshotDay: 24 - quarterlySnapshotMonth: "Jan" - additionalArguments: {} diff --git a/automation/tests/provisioning/mysql-si_test/config/db-secret.yaml b/automation/tests/provisioning/mysql-si_test/config/db-secret.yaml deleted file mode 100644 index da63efec..00000000 --- a/automation/tests/provisioning/mysql-si_test/config/db-secret.yaml +++ /dev/null @@ -1,9 +0,0 @@ -apiVersion: v1 -kind: Secret -metadata: - name: db-secret-mysql-si -type: Opaque -stringData: - password: - ssh_public_key: ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCwyAhpllp2WwrUB1aO/0/DN5nIWNXJWQ3ybhuEG4U+kHl8xFFKnPOTDQtTK8UwByoSf6wqIfTr10ESAoHySOpxHk2gyVHVmUmRZ1WFiNR5tW3Q4qbq1qKpIVy1jH9ZRoTJwzg0J33W9W8SZzhM8Nj0nwuDqp6FS8ui7q9H3tgM+9bYYxETTg52NEw7jTVQx6KaZgG+p/8armoYPKh9DGhBYGY3oCmGiOYlm/phSlj3R63qghZIsBXKxeJDEs4cLolQ+9QYoRqqusdEGVCp7Ba/GtUPdBPYdTy+xuXGiALEpsCrqyUstxypHZVJEQfmqS8uy9UB8KFg2YepwhPgX1oN noname - diff --git a/automation/tests/provisioning/mysql-si_test/config/ndb-secret.yaml b/automation/tests/provisioning/mysql-si_test/config/ndb-secret.yaml deleted file mode 100644 index 31f23450..00000000 --- a/automation/tests/provisioning/mysql-si_test/config/ndb-secret.yaml +++ /dev/null @@ -1,9 +0,0 @@ -apiVersion: v1 -kind: Secret -metadata: - name: ndb-secret-mysql-si -type: Opaque -stringData: - username: - password: - ca_certificate: "" diff --git a/automation/tests/provisioning/mysql-si_test/config/ndb.yaml b/automation/tests/provisioning/mysql-si_test/config/ndb.yaml deleted file mode 100644 index 331326dc..00000000 --- a/automation/tests/provisioning/mysql-si_test/config/ndb.yaml +++ /dev/null @@ -1,10 +0,0 @@ -apiVersion: ndb.nutanix.com/v1alpha1 -kind: NDBServer -metadata: - name: ndb-mysql -spec: - credentialSecretRef: - name: ndb-secret-mysql-si - namespace: ndb-credentials - server: :8443/era/v0.9> - skipCertificateVerification: true diff --git a/automation/tests/provisioning/mysql-si_test/config/pod.yaml b/automation/tests/provisioning/mysql-si_test/config/pod.yaml deleted file mode 100644 index 53bae86e..00000000 --- a/automation/tests/provisioning/mysql-si_test/config/pod.yaml +++ /dev/null @@ -1,33 +0,0 @@ -apiVersion: v1 -kind: Pod -metadata: - name: app-mysql-si - labels: - app: app-mysql-si -spec: - containers: - - name: app-mysql-container - image: mazins/ndb-operator-mysql:latest - env: - - name: DBHOST - value: db-mysql-si-svc - - name: DATABASE - value: database_one - - name: DBPORT - value: '80' - - name: USERNAME - value: root - - name: PASSWORD - valueFrom: - secretKeyRef: - name: db-secret-mysql-si - key: password - ports: - - containerPort: 3000 - initContainers: - - name: init-db - image: busybox:1.28 - command: ['sh', '-c', "until nslookup $(DB_HOST).$(cat /var/run/secrets/kubernetes.io/serviceaccount/namespace).svc.cluster.local; do echo waiting for $(DB_HOST); sleep 2; done"] - env: - - name: DB_HOST - value: db-mysql-si-svc \ No newline at end of file diff --git a/automation/tests/provisioning/mysql-si_test/mysql-si_test.go b/automation/tests/provisioning/mysql-si_test/mysql-si_test.go index f4cc8323..dc9e71f7 100644 --- a/automation/tests/provisioning/mysql-si_test/mysql-si_test.go +++ b/automation/tests/provisioning/mysql-si_test/mysql-si_test.go @@ -68,12 +68,8 @@ func (suite *MySQLProvisioningSingleInstanceTestSuite) SetupSuite() { suite.T().FailNow() } - // Setup yaml types - setupTypes, err := util.SetupTypeTemplates(ctx) - if err != nil { - logger.Printf("%s! %s\n", errBaseMsg, err) - suite.T().FailNow() - } + // Build setup types + setupTypes := util.NewMySQLProvisioningSetupTypes() // Get test suite manager tsm = util.GetTestSuiteManager(ctx, *setupTypes) @@ -102,12 +98,8 @@ func (suite *MySQLProvisioningSingleInstanceTestSuite) TearDownSuite() { logger.Println("TearDownSuite() starting...") errBaseMsg := "Error: SetupSuite() ended" - // Setup yaml types - setupTypes, err := util.SetupTypeTemplates(suite.ctx) - if err != nil { - logger.Printf("%s! %s\n", errBaseMsg, err) - suite.T().FailNow() - } + // Build setup types + setupTypes := util.NewMySQLProvisioningSetupTypes() // Delete resources and de-provision database if err = suite.tsm.TearDown(suite.ctx, setupTypes, suite.clientset, suite.v1alpha1ClientSet, suite.T()); err != nil { diff --git a/automation/tests/provisioning/pg-si_test/config/database.yaml b/automation/tests/provisioning/pg-si_test/config/database.yaml deleted file mode 100644 index f15f2716..00000000 --- a/automation/tests/provisioning/pg-si_test/config/database.yaml +++ /dev/null @@ -1,30 +0,0 @@ -apiVersion: ndb.nutanix.com/v1alpha1 -kind: Database -metadata: - name: db-pg-si -spec: - ndbRef: ndb-pg - databaseInstance: - Name: db-pg-si - databaseNames: - - database_one - - database_two - - database_three - # clusterId: - clusterName: # Optional: use clusterName instead of clusterId - credentialSecret: db-secret-pg-si - size: 10 - timezone: "UTC" - type: postgres - profiles: {} - timeMachine: - name: db-pg-si_TM - description: "TM provisioned by operator" - sla : "DEFAULT_OOB_GOLD_SLA" - dailySnapshotTime: "12:34:56" - snapshotsPerDay: 4 - logCatchUpFrequency: 90 - weeklySnapshotDay: "WEDNESDAY" - monthlySnapshotDay: 24 - quarterlySnapshotMonth: "Jan" - additionalArguments: {} diff --git a/automation/tests/provisioning/pg-si_test/config/db-secret.yaml b/automation/tests/provisioning/pg-si_test/config/db-secret.yaml deleted file mode 100644 index 0a2d8c7a..00000000 --- a/automation/tests/provisioning/pg-si_test/config/db-secret.yaml +++ /dev/null @@ -1,8 +0,0 @@ -apiVersion: v1 -kind: Secret -metadata: - name: db-secret-pg-si -type: Opaque -stringData: - password: - ssh_public_key: ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCwyAhpllp2WwrUB1aO/0/DN5nIWNXJWQ3ybhuEG4U+kHl8xFFKnPOTDQtTK8UwByoSf6wqIfTr10ESAoHySOpxHk2gyVHVmUmRZ1WFiNR5tW3Q4qbq1qKpIVy1jH9ZRoTJwzg0J33W9W8SZzhM8Nj0nwuDqp6FS8ui7q9H3tgM+9bYYxETTg52NEw7jTVQx6KaZgG+p/8armoYPKh9DGhBYGY3oCmGiOYlm/phSlj3R63qghZIsBXKxeJDEs4cLolQ+9QYoRqqusdEGVCp7Ba/GtUPdBPYdTy+xuXGiALEpsCrqyUstxypHZVJEQfmqS8uy9UB8KFg2YepwhPgX1oN noname diff --git a/automation/tests/provisioning/pg-si_test/config/ndb-secret.yaml b/automation/tests/provisioning/pg-si_test/config/ndb-secret.yaml deleted file mode 100644 index 0c238fdf..00000000 --- a/automation/tests/provisioning/pg-si_test/config/ndb-secret.yaml +++ /dev/null @@ -1,9 +0,0 @@ -apiVersion: v1 -kind: Secret -metadata: - name: ndb-secret-pg-si -type: Opaque -stringData: - username: - password: - ca_certificate: "" diff --git a/automation/tests/provisioning/pg-si_test/config/ndb.yaml b/automation/tests/provisioning/pg-si_test/config/ndb.yaml deleted file mode 100644 index eb68f65d..00000000 --- a/automation/tests/provisioning/pg-si_test/config/ndb.yaml +++ /dev/null @@ -1,10 +0,0 @@ -apiVersion: ndb.nutanix.com/v1alpha1 -kind: NDBServer -metadata: - name: ndb-pg -spec: - credentialSecretRef: - name: ndb-secret-pg-si - namespace: ndb-credentials - server: :8443/era/v0.9> - skipCertificateVerification: true diff --git a/automation/tests/provisioning/pg-si_test/config/pod.yaml b/automation/tests/provisioning/pg-si_test/config/pod.yaml deleted file mode 100644 index 5d966bb0..00000000 --- a/automation/tests/provisioning/pg-si_test/config/pod.yaml +++ /dev/null @@ -1,30 +0,0 @@ -apiVersion: v1 -kind: Pod -metadata: - name: app-pg-si - labels: - app: app-pg-si -spec: - containers: - - name: best-app - image: manavrajvanshinx/best-app:latest - resources: - limits: - memory: 512Mi - cpu: "1" - env: - - name: DBHOST - value: db-pg-si-svc - - name: DBPORT - value: '80' - - name: PASSWORD - valueFrom: - secretKeyRef: - name: db-secret-pg-si - key: password - ports: - - containerPort: 3000 - initContainers: - - name: init-db - image: busybox:1.28 - command: ['sh', '-c', "until nslookup db-pg-si-svc.$(cat /var/run/secrets/kubernetes.io/serviceaccount/namespace).svc.cluster.local; do echo waiting for database service; sleep 2; done"] diff --git a/automation/tests/provisioning/pg-si_test/pg-si_test.go b/automation/tests/provisioning/pg-si_test/pg-si_test.go index 19b7729e..c6c41d5b 100644 --- a/automation/tests/provisioning/pg-si_test/pg-si_test.go +++ b/automation/tests/provisioning/pg-si_test/pg-si_test.go @@ -68,12 +68,8 @@ func (suite *PostgresProvisioningSingleInstanceTestSuite) SetupSuite() { suite.T().FailNow() } - // Setup yaml types - setupTypes, err := util.SetupTypeTemplates(ctx) - if err != nil { - logger.Printf("%s! %s\n", errBaseMsg, err) - suite.T().FailNow() - } + // Build setup types + setupTypes := util.NewPgProvisioningSetupTypes() // Get test suite manager tsm = util.GetTestSuiteManager(ctx, *setupTypes) @@ -102,12 +98,8 @@ func (suite *PostgresProvisioningSingleInstanceTestSuite) TearDownSuite() { logger.Println("TearDownSuite() starting...") errBaseMsg := "Error: SetupSuite() ended" - // Setup yaml types - setupTypes, err := util.SetupTypeTemplates(suite.ctx) - if err != nil { - logger.Printf("%s! %s\n", errBaseMsg, err) - suite.T().FailNow() - } + // Build setup types + setupTypes := util.NewPgProvisioningSetupTypes() // Delete resources and de-provision database if err = suite.tsm.TearDown(suite.ctx, setupTypes, suite.clientset, suite.v1alpha1ClientSet, suite.T()); err != nil { diff --git a/automation/util/builders.go b/automation/util/builders.go new file mode 100644 index 00000000..f1c69047 --- /dev/null +++ b/automation/util/builders.go @@ -0,0 +1,615 @@ +package util + +import ( + ndbv1alpha1 "github.com/nutanix-cloud-native/ndb-operator/api/v1alpha1" + automation "github.com/nutanix-cloud-native/ndb-operator/automation" + "github.com/nutanix-cloud-native/ndb-operator/common" + corev1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/api/resource" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +const sshPublicKey = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCwyAhpllp2WwrUB1aO/0/DN5nIWNXJWQ3ybhuEG4U+kHl8xFFKnPOTDQtTK8UwByoSf6wqIfTr10ESAoHySOpxHk2gyVHVmUmRZ1WFiNR5tW3Q4qbq1qKpIVy1jH9ZRoTJwzg0J33W9W8SZzhM8Nj0nwuDqp6FS8ui7q9H3tgM+9bYYxETTg52NEw7jTVQx6KaZgG+p/8armoYPKh9DGhBYGY3oCmGiOYlm/phSlj3R63qghZIsBXKxeJDEs4cLolQ+9QYoRqqusdEGVCp7Ba/GtUPdBPYdTy+xuXGiALEpsCrqyUstxypHZVJEQfmqS8uy9UB8KFg2YepwhPgX1oN noname" + +const defaultTMSLA = "DEFAULT_OOB_GOLD_SLA" +const defaultTMDailySnapshotTime = "12:34:56" +const defaultTMSnapshotsPerDay = 4 +const defaultTMLogCatchUpFrequency = 90 +const defaultTMWeeklySnapshotDay = "WEDNESDAY" +const defaultTMMonthlySnapshotDay = 24 +const defaultTMQuarterlySnapshotMonth = "Jan" + +func defaultTMInfo(name string) *ndbv1alpha1.DBTimeMachineInfo { + return &ndbv1alpha1.DBTimeMachineInfo{ + Name: name, + Description: "TM provisioned by operator", + SLAName: defaultTMSLA, + DailySnapshotTime: defaultTMDailySnapshotTime, + SnapshotsPerDay: defaultTMSnapshotsPerDay, + LogCatchUpFrequency: defaultTMLogCatchUpFrequency, + WeeklySnapshotDay: defaultTMWeeklySnapshotDay, + MonthlySnapshotDay: defaultTMMonthlySnapshotDay, + QuarterlySnapshotMonth: defaultTMQuarterlySnapshotMonth, + } +} + +func ndbSecret(name string) *corev1.Secret { + return &corev1.Secret{ + ObjectMeta: metav1.ObjectMeta{Name: name}, + Type: corev1.SecretTypeOpaque, + StringData: map[string]string{ + common.SECRET_DATA_KEY_USERNAME: "", + common.SECRET_DATA_KEY_PASSWORD: "", + common.SECRET_DATA_KEY_CA_CERTIFICATE: "", + }, + } +} + +func dbSecret(name string) *corev1.Secret { + return &corev1.Secret{ + ObjectMeta: metav1.ObjectMeta{Name: name}, + Type: corev1.SecretTypeOpaque, + StringData: map[string]string{ + common.SECRET_DATA_KEY_PASSWORD: "", + common.SECRET_DATA_KEY_SSH_PUBLIC_KEY: sshPublicKey, + }, + } +} + +func ndbServer(name, ndbSecretName string) *ndbv1alpha1.NDBServer { + return &ndbv1alpha1.NDBServer{ + ObjectMeta: metav1.ObjectMeta{Name: name}, + Spec: ndbv1alpha1.NDBServerSpec{ + CredentialSecretRef: ndbv1alpha1.SecretReference{ + Name: ndbSecretName, + Namespace: automation.NDB_CREDENTIALS_NAMESPACE, + }, + SkipCertificateVerification: true, + // Server is set at runtime from NDB_SERVER_ENV + }, + } +} + +// --- Provisioning Builders --- + +func NewPgProvisioningSetupTypes() *SetupTypes { + return &SetupTypes{ + NdbServer: ndbServer("ndb-pg", "ndb-secret-pg-si"), + Database: &ndbv1alpha1.Database{ + ObjectMeta: metav1.ObjectMeta{ + Name: "db-pg-si", + Namespace: automation.NAMESPACE_DEFAULT, + }, + Spec: ndbv1alpha1.DatabaseSpec{ + NDBRef: "ndb-pg", + Instance: &ndbv1alpha1.Instance{ + Name: "db-pg-si", + Type: common.DATABASE_TYPE_POSTGRES, + DatabaseNames: []string{"database_one", "database_two", "database_three"}, + CredentialSecret: "db-secret-pg-si", + Size: 10, + TimeZone: common.TIMEZONE_UTC, + TMInfo: defaultTMInfo("db-pg-si_TM"), + AdditionalArguments: map[string]string{}, + }, + }, + }, + NdbSecret: ndbSecret("ndb-secret-pg-si"), + DbSecret: dbSecret("db-secret-pg-si"), + AppPod: &corev1.Pod{ + ObjectMeta: metav1.ObjectMeta{ + Name: "app-pg-si", + Labels: map[string]string{"app": "app-pg-si"}, + }, + Spec: corev1.PodSpec{ + Containers: []corev1.Container{ + { + Name: "best-app", + Image: "manavrajvanshinx/best-app:latest", + Resources: corev1.ResourceRequirements{ + Limits: corev1.ResourceList{ + corev1.ResourceMemory: resource.MustParse("512Mi"), + corev1.ResourceCPU: resource.MustParse("1"), + }, + }, + Env: []corev1.EnvVar{ + {Name: "DBHOST", Value: "db-pg-si-svc"}, + {Name: "DBPORT", Value: "80"}, + { + Name: "PASSWORD", + ValueFrom: &corev1.EnvVarSource{ + SecretKeyRef: &corev1.SecretKeySelector{ + LocalObjectReference: corev1.LocalObjectReference{Name: "db-secret-pg-si"}, + Key: common.SECRET_DATA_KEY_PASSWORD, + }, + }, + }, + }, + Ports: []corev1.ContainerPort{{ContainerPort: 3000}}, + }, + }, + InitContainers: []corev1.Container{ + { + Name: "init-db", + Image: "busybox:1.28", + Command: []string{"sh", "-c", "until nslookup db-pg-si-svc.$(cat /var/run/secrets/kubernetes.io/serviceaccount/namespace).svc.cluster.local; do echo waiting for database service; sleep 2; done"}, + }, + }, + }, + }, + } +} + +func NewMySQLProvisioningSetupTypes() *SetupTypes { + return &SetupTypes{ + NdbServer: ndbServer("ndb-mysql", "ndb-secret-mysql-si"), + Database: &ndbv1alpha1.Database{ + ObjectMeta: metav1.ObjectMeta{ + Name: "db-mysql-si", + Namespace: automation.NAMESPACE_DEFAULT, + }, + Spec: ndbv1alpha1.DatabaseSpec{ + NDBRef: "ndb-mysql", + Instance: &ndbv1alpha1.Instance{ + Name: "db-mysql-si", + Type: common.DATABASE_TYPE_MYSQL, + DatabaseNames: []string{"database_one"}, + CredentialSecret: "db-secret-mysql-si", + Size: 10, + TimeZone: common.TIMEZONE_UTC, + TMInfo: defaultTMInfo("db-mysql-si_TM"), + AdditionalArguments: map[string]string{}, + }, + }, + }, + NdbSecret: ndbSecret("ndb-secret-mysql-si"), + DbSecret: dbSecret("db-secret-mysql-si"), + AppPod: &corev1.Pod{ + ObjectMeta: metav1.ObjectMeta{ + Name: "app-mysql-si", + Labels: map[string]string{"app": "app-mysql-si"}, + }, + Spec: corev1.PodSpec{ + Containers: []corev1.Container{ + { + Name: "app-mysql-container", + Image: "mazins/ndb-operator-mysql:latest", + Env: []corev1.EnvVar{ + {Name: "DBHOST", Value: "db-mysql-si-svc"}, + {Name: "DATABASE", Value: "database_one"}, + {Name: "DBPORT", Value: "80"}, + {Name: "USERNAME", Value: "root"}, + { + Name: "PASSWORD", + ValueFrom: &corev1.EnvVarSource{ + SecretKeyRef: &corev1.SecretKeySelector{ + LocalObjectReference: corev1.LocalObjectReference{Name: "db-secret-mysql-si"}, + Key: common.SECRET_DATA_KEY_PASSWORD, + }, + }, + }, + }, + Ports: []corev1.ContainerPort{{ContainerPort: 3000}}, + }, + }, + InitContainers: []corev1.Container{ + { + Name: "init-db", + Image: "busybox:1.28", + Command: []string{"sh", "-c", "until nslookup $(DB_HOST).$(cat /var/run/secrets/kubernetes.io/serviceaccount/namespace).svc.cluster.local; do echo waiting for $(DB_HOST); sleep 2; done"}, + Env: []corev1.EnvVar{{Name: "DB_HOST", Value: "db-mysql-si-svc"}}, + }, + }, + }, + }, + } +} + +func NewMongoProvisioningSetupTypes() *SetupTypes { + return &SetupTypes{ + NdbServer: ndbServer("ndb-mongo", "ndb-secret-mongo-si"), + Database: &ndbv1alpha1.Database{ + ObjectMeta: metav1.ObjectMeta{ + Name: "db-mongo-si", + Namespace: automation.NAMESPACE_DEFAULT, + }, + Spec: ndbv1alpha1.DatabaseSpec{ + NDBRef: "ndb-mongo", + Instance: &ndbv1alpha1.Instance{ + Name: "db-mongo-si", + Type: common.DATABASE_TYPE_MONGODB, + DatabaseNames: []string{"database_one"}, + CredentialSecret: "db-secret-mongo-si", + Size: 10, + TimeZone: common.TIMEZONE_UTC, + TMInfo: defaultTMInfo("db-mongo-si_TM"), + AdditionalArguments: map[string]string{}, + }, + }, + }, + NdbSecret: ndbSecret("ndb-secret-mongo-si"), + DbSecret: dbSecret("db-secret-mongo-si"), + AppPod: &corev1.Pod{ + ObjectMeta: metav1.ObjectMeta{ + Name: "app-mongo-si", + Labels: map[string]string{"app": "app-mongo-si"}, + }, + Spec: corev1.PodSpec{ + Containers: []corev1.Container{ + { + Name: "app-mongo-container", + Image: "mazins/ndb-operator-mongodb:latest", + Env: []corev1.EnvVar{ + {Name: "DBHOST", Value: "db-mongo-si-svc"}, + {Name: "DBPORT", Value: "80"}, + {Name: "DATABASE", Value: "database_one"}, + {Name: "USERNAME", Value: "admin"}, + { + Name: "PASSWORD", + ValueFrom: &corev1.EnvVarSource{ + SecretKeyRef: &corev1.SecretKeySelector{ + LocalObjectReference: corev1.LocalObjectReference{Name: "db-secret-mongo-si"}, + Key: common.SECRET_DATA_KEY_PASSWORD, + }, + }, + }, + }, + Ports: []corev1.ContainerPort{{ContainerPort: 3000}}, + }, + }, + InitContainers: []corev1.Container{ + { + Name: "init-db", + Image: "busybox:1.28", + Command: []string{"sh", "-c", "until nslookup $(DB_HOST).$(cat /var/run/secrets/kubernetes.io/serviceaccount/namespace).svc.cluster.local; do echo waiting for $(DB_HOST); sleep 2; done"}, + Env: []corev1.EnvVar{{Name: "DB_HOST", Value: "db-mongo-si-svc"}}, + }, + }, + }, + }, + } +} + +func NewMSSQLProvisioningSetupTypes() *SetupTypes { + return &SetupTypes{ + NdbServer: ndbServer("ndb-mssql", "ndb-secret-mssql-si"), + Database: &ndbv1alpha1.Database{ + ObjectMeta: metav1.ObjectMeta{ + Name: "db-mssql-si", + Namespace: automation.NAMESPACE_DEFAULT, + }, + Spec: ndbv1alpha1.DatabaseSpec{ + NDBRef: "ndb-mssql", + Instance: &ndbv1alpha1.Instance{ + Name: "db-mssql-si", + Type: common.DATABASE_TYPE_MSSQL, + DatabaseNames: []string{"database_one"}, + CredentialSecret: "db-secret-mssql-si", + Size: 10, + TimeZone: common.TIMEZONE_UTC, + Profiles: &ndbv1alpha1.Profiles{ + DbParam: ndbv1alpha1.Profile{Name: "DEFAULT_SQLSERVER_DATABASE_PARAMS"}, + DbParamInstance: ndbv1alpha1.Profile{Name: "DEFAULT_SQLSERVER_INSTANCE_PARAMS"}, + }, + TMInfo: defaultTMInfo("db-mssql-si_TM"), + AdditionalArguments: map[string]string{ + "authentication_mode": "mixed", + "sql_user_password": "Nutanix.1", + }, + }, + }, + }, + NdbSecret: ndbSecret("ndb-secret-mssql-si"), + DbSecret: dbSecret("db-secret-mssql-si"), + AppPod: &corev1.Pod{ + ObjectMeta: metav1.ObjectMeta{ + Name: "app-mssql-si", + Labels: map[string]string{"app": "app-mssql-si"}, + }, + Spec: corev1.PodSpec{ + Containers: []corev1.Container{ + { + Name: "app-mssql-container", + Image: "mazins/ndb-operator-mssql:latest", + Env: []corev1.EnvVar{ + {Name: "DBHOST", Value: "db-mssql-si-svc"}, + {Name: "USERNAME", Value: "sa"}, + {Name: "DATABASE", Value: "database_one"}, + {Name: "DBPORT", Value: "80"}, + {Name: "MSSQL_INSTANCE_NAME", Value: "CDMINSTANCE"}, + { + Name: "PASSWORD", + ValueFrom: &corev1.EnvVarSource{ + SecretKeyRef: &corev1.SecretKeySelector{ + LocalObjectReference: corev1.LocalObjectReference{Name: "db-secret-mssql-si"}, + Key: common.SECRET_DATA_KEY_PASSWORD, + }, + }, + }, + }, + Ports: []corev1.ContainerPort{{ContainerPort: 3000}}, + }, + }, + InitContainers: []corev1.Container{ + { + Name: "init-db", + Image: "busybox:1.28", + Command: []string{"sh", "-c", "until nslookup $(DB_HOST).$(cat /var/run/secrets/kubernetes.io/serviceaccount/namespace).svc.cluster.local; do echo waiting for $(DB_HOST); sleep 2; done"}, + Env: []corev1.EnvVar{{Name: "DB_HOST", Value: "db-mssql-si-svc"}}, + }, + }, + }, + }, + } +} + +// --- Cloning Builders --- + +func NewPgCloningSetupTypes() *SetupTypes { + return &SetupTypes{ + NdbServer: ndbServer("clone-ndb-pg-si", "clone-ndb-secret-pg-si"), + Database: &ndbv1alpha1.Database{ + ObjectMeta: metav1.ObjectMeta{ + Name: "clone-pg-si", + Namespace: automation.NAMESPACE_DEFAULT, + }, + Spec: ndbv1alpha1.DatabaseSpec{ + NDBRef: "clone-ndb-pg-si", + IsClone: true, + Clone: &ndbv1alpha1.Clone{ + Name: "clone-pg-si", + Type: common.DATABASE_TYPE_POSTGRES, + Description: "Cloning pg single instance testing", + CredentialSecret: "clone-db-secret-pg-si", + TimeZone: common.TIMEZONE_UTC, + // ClusterName, SourceDatabaseName set at runtime from env vars + AdditionalArguments: map[string]string{}, + }, + }, + }, + NdbSecret: ndbSecret("clone-ndb-secret-pg-si"), + DbSecret: dbSecret("clone-db-secret-pg-si"), + AppPod: &corev1.Pod{ + ObjectMeta: metav1.ObjectMeta{ + Name: "clone-app-pg-si", + Labels: map[string]string{"app": "clone-app-pg-si"}, + }, + Spec: corev1.PodSpec{ + Containers: []corev1.Container{ + { + Name: "best-app", + Image: "manavrajvanshinx/best-app:latest", + Resources: corev1.ResourceRequirements{ + Limits: corev1.ResourceList{ + corev1.ResourceMemory: resource.MustParse("512Mi"), + corev1.ResourceCPU: resource.MustParse("1"), + }, + }, + Env: []corev1.EnvVar{ + {Name: "DBHOST", Value: "clone-pg-si-svc"}, + {Name: "DBPORT", Value: "80"}, + { + Name: "PASSWORD", + ValueFrom: &corev1.EnvVarSource{ + SecretKeyRef: &corev1.SecretKeySelector{ + LocalObjectReference: corev1.LocalObjectReference{Name: "clone-db-secret-pg-si"}, + Key: common.SECRET_DATA_KEY_PASSWORD, + }, + }, + }, + }, + Ports: []corev1.ContainerPort{{ContainerPort: 3000}}, + }, + }, + InitContainers: []corev1.Container{ + { + Name: "init-db", + Image: "busybox:1.28", + Command: []string{"sh", "-c", "until nslookup clone-pg-si-svc.$(cat /var/run/secrets/kubernetes.io/serviceaccount/namespace).svc.cluster.local; do echo waiting for database service; sleep 2; done"}, + }, + }, + }, + }, + } +} + +func NewMySQLCloningSetupTypes() *SetupTypes { + return &SetupTypes{ + NdbServer: ndbServer("clone-ndb-mysql-si", "clone-ndb-secret-mysql-si"), + Database: &ndbv1alpha1.Database{ + ObjectMeta: metav1.ObjectMeta{ + Name: "clone-mysql-si", + Namespace: automation.NAMESPACE_DEFAULT, + }, + Spec: ndbv1alpha1.DatabaseSpec{ + NDBRef: "clone-ndb-mysql-si", + IsClone: true, + Clone: &ndbv1alpha1.Clone{ + Name: "clone-mysql-si", + Type: common.DATABASE_TYPE_MYSQL, + Description: "Cloning mysql single instance testing", + CredentialSecret: "clone-db-secret-mysql-si", + TimeZone: common.TIMEZONE_UTC, + // ClusterName, SourceDatabaseName set at runtime from env vars + AdditionalArguments: map[string]string{}, + }, + }, + }, + NdbSecret: ndbSecret("clone-ndb-secret-mysql-si"), + DbSecret: dbSecret("clone-db-secret-mysql-si"), + AppPod: &corev1.Pod{ + ObjectMeta: metav1.ObjectMeta{ + Name: "clone-app-mysql-si", + Labels: map[string]string{"app": "clone-app-mysql-si"}, + }, + Spec: corev1.PodSpec{ + Containers: []corev1.Container{ + { + Name: "app-mysql-container", + Image: "mazins/ndb-operator-mysql:latest", + Env: []corev1.EnvVar{ + {Name: "DBHOST", Value: "clone-mysql-si-svc"}, + {Name: "DATABASE", Value: "database_one"}, + {Name: "DBPORT", Value: "3306"}, + {Name: "USERNAME", Value: "root"}, + { + Name: "PASSWORD", + ValueFrom: &corev1.EnvVarSource{ + SecretKeyRef: &corev1.SecretKeySelector{ + LocalObjectReference: corev1.LocalObjectReference{Name: "clone-db-secret-mysql-si"}, + Key: common.SECRET_DATA_KEY_PASSWORD, + }, + }, + }, + }, + Ports: []corev1.ContainerPort{{ContainerPort: 3000}}, + }, + }, + InitContainers: []corev1.Container{ + { + Name: "init-db", + Image: "busybox:1.28", + Command: []string{"sh", "-c", "until nslookup $(DB_HOST).$(cat /var/run/secrets/kubernetes.io/serviceaccount/namespace).svc.cluster.local; do echo waiting for $(DB_HOST); sleep 2; done"}, + Env: []corev1.EnvVar{{Name: "DB_HOST", Value: "clone-mysql-si-svc"}}, + }, + }, + }, + }, + } +} + +func NewMongoCloningSetupTypes() *SetupTypes { + return &SetupTypes{ + NdbServer: ndbServer("clone-ndb-mongo-si", "clone-ndb-secret-pg-si"), + Database: &ndbv1alpha1.Database{ + ObjectMeta: metav1.ObjectMeta{ + Name: "clone-mongo-si", + Namespace: automation.NAMESPACE_DEFAULT, + }, + Spec: ndbv1alpha1.DatabaseSpec{ + NDBRef: "clone-ndb-mongo-si", + IsClone: true, + Clone: &ndbv1alpha1.Clone{ + Name: "clone-mongo-si", + Type: common.DATABASE_TYPE_MONGODB, + Description: "Cloning mongoDB single instance testing", + CredentialSecret: "clone-db-secret-mongo-si", + TimeZone: "America/Los_Angeles", + // ClusterName, SourceDatabaseName set at runtime from env vars + AdditionalArguments: map[string]string{}, + }, + }, + }, + NdbSecret: ndbSecret("clone-ndb-secret-pg-si"), + DbSecret: dbSecret("clone-db-secret-mongo-si"), + AppPod: &corev1.Pod{ + ObjectMeta: metav1.ObjectMeta{ + Name: "clone-app-mongo-si", + Labels: map[string]string{"app": "clone-app-mongo-si"}, + }, + Spec: corev1.PodSpec{ + Containers: []corev1.Container{ + { + Name: "app-mongo-container", + Image: "mazins/ndb-operator-mongodb:latest", + Env: []corev1.EnvVar{ + {Name: "DBHOST", Value: "clone-mongo-si-svc"}, + {Name: "DBPORT", Value: "80"}, + {Name: "DATABASE", Value: "database_one"}, + {Name: "USERNAME", Value: "admin"}, + { + Name: "PASSWORD", + ValueFrom: &corev1.EnvVarSource{ + SecretKeyRef: &corev1.SecretKeySelector{ + LocalObjectReference: corev1.LocalObjectReference{Name: "clone-db-secret-mongo-si"}, + Key: common.SECRET_DATA_KEY_PASSWORD, + }, + }, + }, + }, + Ports: []corev1.ContainerPort{{ContainerPort: 3000}}, + }, + }, + InitContainers: []corev1.Container{ + { + Name: "init-db", + Image: "busybox:1.28", + Command: []string{"sh", "-c", "until nslookup $(DB_HOST).$(cat /var/run/secrets/kubernetes.io/serviceaccount/namespace).svc.cluster.local; do echo waiting for $(DB_HOST); sleep 2; done"}, + Env: []corev1.EnvVar{{Name: "DB_HOST", Value: "clone-mongo-si-svc"}}, + }, + }, + }, + }, + } +} + +func NewMSSQLCloningSetupTypes() *SetupTypes { + return &SetupTypes{ + NdbServer: ndbServer("clone-ndb-mssql-si", "clone-ndb-secret-mssql-si"), + Database: &ndbv1alpha1.Database{ + ObjectMeta: metav1.ObjectMeta{ + Name: "clone-mssql-si", + Namespace: automation.NAMESPACE_DEFAULT, + }, + Spec: ndbv1alpha1.DatabaseSpec{ + NDBRef: "clone-ndb-mssql-si", + IsClone: true, + Clone: &ndbv1alpha1.Clone{ + Name: "clone-mssql-si", + Type: common.DATABASE_TYPE_MSSQL, + Description: "Cloning mssql single instance testing", + Profiles: &ndbv1alpha1.Profiles{ + Software: ndbv1alpha1.Profile{Name: "MSSQL-MAZIN2"}, + }, + CredentialSecret: "clone-db-secret-mssql-si", + TimeZone: common.TIMEZONE_UTC, + // ClusterName, SourceDatabaseName set at runtime from env vars + AdditionalArguments: map[string]string{ + "authentication_mode": "mixed", + }, + }, + }, + }, + NdbSecret: ndbSecret("clone-ndb-secret-mssql-si"), + DbSecret: dbSecret("clone-db-secret-mssql-si"), + AppPod: &corev1.Pod{ + ObjectMeta: metav1.ObjectMeta{ + Name: "clone-app-mssql-si", + Labels: map[string]string{"app": "clone-app-mssql-si"}, + }, + Spec: corev1.PodSpec{ + Containers: []corev1.Container{ + { + Name: "app-mssql-container", + Image: "mazins/ndb-operator-mssql:latest", + Env: []corev1.EnvVar{ + {Name: "DBHOST", Value: "clone-mssql-si-svc"}, + {Name: "USERNAME", Value: "sa"}, + {Name: "DATABASE", Value: "database_one"}, + {Name: "DBPORT", Value: "80"}, + {Name: "MSSQL_INSTANCE_NAME", Value: "CDMINSTANCE"}, + { + Name: "PASSWORD", + ValueFrom: &corev1.EnvVarSource{ + SecretKeyRef: &corev1.SecretKeySelector{ + LocalObjectReference: corev1.LocalObjectReference{Name: "clone-db-secret-mssql-si"}, + Key: common.SECRET_DATA_KEY_PASSWORD, + }, + }, + }, + }, + Ports: []corev1.ContainerPort{{ContainerPort: 3000}}, + }, + }, + InitContainers: []corev1.Container{ + { + Name: "init-db", + Image: "busybox:1.28", + Command: []string{"sh", "-c", "until nslookup $(DB_HOST).$(cat /var/run/secrets/kubernetes.io/serviceaccount/namespace).svc.cluster.local; do echo waiting for $(DB_HOST); sleep 2; done"}, + Env: []corev1.EnvVar{{Name: "DB_HOST", Value: "clone-mssql-si-svc"}}, + }, + }, + }, + }, + } +} diff --git a/automation/util/setup.go b/automation/util/setup.go index 058b17f2..5ff3931c 100644 --- a/automation/util/setup.go +++ b/automation/util/setup.go @@ -2,13 +2,10 @@ package util import ( "context" - "encoding/json" - "errors" "fmt" "log" "os" "path/filepath" - "reflect" "time" "github.com/joho/godotenv" @@ -20,7 +17,6 @@ import ( "k8s.io/client-go/kubernetes/scheme" "k8s.io/client-go/rest" "k8s.io/client-go/tools/clientcmd" - "sigs.k8s.io/yaml" ) type key int @@ -159,74 +155,6 @@ func SetupSchemeAndClientSet(ctx context.Context, config *rest.Config) (v1alpha1 return v1alpha1ClientSet, clientset, err } -// Setup yaml types. Uses paths specified in automation.constants.go -func SetupTypeTemplates(ctx context.Context) (setupTypes *SetupTypes, err error) { - logger := GetLogger(ctx) - logger.Println("SetupTypeTemplates() started...") - - var logMsg string - var errMsg string - - // Create ndbServer template from automation.NDBSERVER_PATH - ndbServer := &ndbv1alpha1.NDBServer{} - if err := CreateTypeFromPath(ndbServer, automation.NDBSERVER_PATH); err != nil { - errMsg += fmt.Sprintf("NdbServer with path %s failed! %v. ", automation.NDBSERVER_PATH, err) - } else { - logMsg += fmt.Sprintf("NdbServer with path %s created. ", automation.NDBSERVER_PATH) - } - - // Create database template from automation.DATABASE_PATH - database := &ndbv1alpha1.Database{} - if err := CreateTypeFromPath(database, automation.DATABASE_PATH); err != nil { - errMsg += fmt.Sprintf("Database with path %s failed! %v. ", automation.DATABASE_PATH, err) - } else { - logMsg += fmt.Sprintf("Database with path %s created. ", automation.DATABASE_PATH) - } - - // Create ndbSecret template automation.NDB_SECRET_PATH - ndbSecret := &corev1.Secret{} - if err := CreateTypeFromPath(ndbSecret, automation.NDB_SECRET_PATH); err != nil { - errMsg += fmt.Sprintf("NdbSecret with path %s failed! %v. ", automation.NDB_SECRET_PATH, err) - } else { - logMsg += fmt.Sprintf("NdbSecret with path %s created. ", automation.NDB_SECRET_PATH) - } - - // Create dbSecret template from automation.DB_SECRET_PATH - dbSecret := &corev1.Secret{} - if err := CreateTypeFromPath(dbSecret, automation.DB_SECRET_PATH); err != nil { - errMsg += fmt.Sprintf("DbSecret with path %s failed! %v. ", automation.DB_SECRET_PATH, err) - } else { - logMsg += fmt.Sprintf("DbSecret with path %s created. ", automation.DB_SECRET_PATH) - } - - // Create appPod template from automation.APP_POD_PATH - appPod := &corev1.Pod{} - if err := CreateTypeFromPath(appPod, automation.APP_POD_PATH); err != nil { - errMsg += fmt.Sprintf("App Pod with path %s failed! %v. ", automation.APP_POD_PATH, err) - } else { - logMsg += fmt.Sprintf("App Pod with path %s created. ", automation.APP_POD_PATH) - } - - setupTypes = &SetupTypes{ - NdbServer: ndbServer, - Database: database, - DbSecret: dbSecret, - NdbSecret: ndbSecret, - AppPod: appPod, - } - - if errMsg == "" { - logger.Println(logMsg) - err = nil - } else { - err = errors.New("Error: SetupResourceTypes ended! " + errMsg) - } - - logger.Println("SetupTypeTemplates() ended!") - - return setupTypes, err -} - // YAML Resource types type SetupTypes struct { NdbServer *ndbv1alpha1.NDBServer @@ -236,39 +164,6 @@ type SetupTypes struct { AppPod *corev1.Pod } -// CreateTypeFromPath reads a file path, converts it to json, and unmarshals json to a pointer. -// Ensure that theType is a pointer. -func CreateTypeFromPath(theType any, path string) (err error) { - if theType == nil { - return errors.New("theType is nil") - } - - // Check if theType is not a pointer - if reflect.ValueOf(theType).Kind() != reflect.Ptr { - return errors.New("theType is not a pointer") - } - - // Reads file path - data, err := os.ReadFile(path) - if err != nil { - return err - } - - // Converts byte data to json - jsonData, err := yaml.YAMLToJSON(data) - if err != nil { - return err - } - - // Creates 'type' object by unmarshalling data - err = json.Unmarshal(jsonData, theType) - if err != nil { - return err - } - - return nil -} - // Performs an operation a certain number of times with a given interval func waitAndRetryOperation(ctx context.Context, interval time.Duration, retries int, operation func() error) (err error) { logger := GetLogger(ctx) diff --git a/go.mod b/go.mod index 72efc89b..7d2c958e 100644 --- a/go.mod +++ b/go.mod @@ -14,7 +14,6 @@ require ( k8s.io/apimachinery v0.35.1 k8s.io/client-go v0.35.1 sigs.k8s.io/controller-runtime v0.21.0 - sigs.k8s.io/yaml v1.6.0 ) require ( @@ -79,4 +78,5 @@ require ( sigs.k8s.io/json v0.0.0-20250730193827-2d320260d730 // indirect sigs.k8s.io/randfill v1.0.0 // indirect sigs.k8s.io/structured-merge-diff/v6 v6.3.0 // indirect + sigs.k8s.io/yaml v1.6.0 // indirect ) From de83b74c4b16e244fa2257f109f7a5830b20e356 Mon Sep 17 00:00:00 2001 From: shivaprasadmb Date: Wed, 20 May 2026 13:01:37 +0530 Subject: [PATCH 2/3] fixes --- automation/util/builders.go | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/automation/util/builders.go b/automation/util/builders.go index f1c69047..2ba53489 100644 --- a/automation/util/builders.go +++ b/automation/util/builders.go @@ -216,12 +216,16 @@ func NewMongoProvisioningSetupTypes() *SetupTypes { Spec: ndbv1alpha1.DatabaseSpec{ NDBRef: "ndb-mongo", Instance: &ndbv1alpha1.Instance{ - Name: "db-mongo-si", - Type: common.DATABASE_TYPE_MONGODB, - DatabaseNames: []string{"database_one"}, - CredentialSecret: "db-secret-mongo-si", - Size: 10, - TimeZone: common.TIMEZONE_UTC, + Name: "db-mongo-si", + Type: common.DATABASE_TYPE_MONGODB, + DatabaseNames: []string{"database_one"}, + CredentialSecret: "db-secret-mongo-si", + Size: 10, + TimeZone: common.TIMEZONE_UTC, + Profiles: &ndbv1alpha1.Profiles{ + Software: ndbv1alpha1.Profile{Name: "MONGODB_12debian_NDBoperator"}, + Network: ndbv1alpha1.Profile{Name: "DEFAULT_OOB_MONGODB_NETWORK"}, + }, TMInfo: defaultTMInfo("db-mongo-si_TM"), AdditionalArguments: map[string]string{}, }, @@ -288,6 +292,7 @@ func NewMSSQLProvisioningSetupTypes() *SetupTypes { Size: 10, TimeZone: common.TIMEZONE_UTC, Profiles: &ndbv1alpha1.Profiles{ + Software: ndbv1alpha1.Profile{Name: "MSSQL-4-NDBOperator"}, DbParam: ndbv1alpha1.Profile{Name: "DEFAULT_SQLSERVER_DATABASE_PARAMS"}, DbParamInstance: ndbv1alpha1.Profile{Name: "DEFAULT_SQLSERVER_INSTANCE_PARAMS"}, }, From 2a7b7dbedc45349146fc8b82f242d89f7e6fb3bf Mon Sep 17 00:00:00 2001 From: shivaprasadmb Date: Wed, 20 May 2026 21:33:02 +0530 Subject: [PATCH 3/3] fixes 2 --- .github/workflows/helm-release.yaml | 9 +- automation/util/test_suite_manager_common.go | 98 ++++++++++++++------ 2 files changed, 73 insertions(+), 34 deletions(-) diff --git a/.github/workflows/helm-release.yaml b/.github/workflows/helm-release.yaml index 9721f36f..114cc4ca 100644 --- a/.github/workflows/helm-release.yaml +++ b/.github/workflows/helm-release.yaml @@ -40,9 +40,8 @@ jobs: - name: Push charts to GHCR run: | VERSION=$(helm show chart deploy/helm | grep '^version:' | awk '{print $2}') - # TODO: Uncomment before next release (this is temporary fix) - # if helm show chart oci://ghcr.io/nutanix-cloud-native/chart/ndb-operator --version "$VERSION" 2>/dev/null | grep -q "^version:"; then - # echo "Chart $VERSION already exists on GHCR, skipping push." - # exit 0 - # fi + if helm show chart oci://ghcr.io/nutanix-cloud-native/chart/ndb-operator --version "$VERSION" 2>/dev/null | grep -q "^version:"; then + echo "Chart $VERSION already exists on GHCR, skipping push." + exit 0 + fi helm push .cr-release-packages/ndb-operator-${VERSION}.tgz oci://ghcr.io/nutanix-cloud-native/chart diff --git a/automation/util/test_suite_manager_common.go b/automation/util/test_suite_manager_common.go index 076baa3d..7cd830dd 100644 --- a/automation/util/test_suite_manager_common.go +++ b/automation/util/test_suite_manager_common.go @@ -66,7 +66,17 @@ func provisionOrClone(ctx context.Context, st *SetupTypes, clientset *kubernetes st.DbSecret.StringData[common.SECRET_DATA_KEY_PASSWORD] = os.Getenv(automation.DB_SECRET_PASSWORD_ENV) _, err = clientset.CoreV1().Secrets(ns).Create(ctx, st.DbSecret, metav1.CreateOptions{}) if err != nil { - logger.Printf("Error while creating db secret %s: %s\n", st.DbSecret.Name, err) + if k8serrors.IsAlreadyExists(err) { + logger.Printf("DB Secret %s already exists, updating.\n", st.DbSecret.Name) + _, err = clientset.CoreV1().Secrets(ns).Update(ctx, st.DbSecret, metav1.UpdateOptions{}) + if err != nil { + logger.Printf("Error while updating db secret %s: %s\n", st.DbSecret.Name, err) + } else { + logger.Printf("DB Secret %s updated.\n", st.DbSecret.Name) + } + } else { + logger.Printf("Error while creating db secret %s: %s\n", st.DbSecret.Name, err) + } } else { logger.Printf("DB Secret %s created.\n", st.DbSecret.Name) } @@ -80,7 +90,17 @@ func provisionOrClone(ctx context.Context, st *SetupTypes, clientset *kubernetes st.NdbSecret.StringData[common.SECRET_DATA_KEY_PASSWORD] = os.Getenv(automation.NDB_SECRET_PASSWORD_ENV) _, err = clientset.CoreV1().Secrets(ndbCredsNs).Create(context.TODO(), st.NdbSecret, metav1.CreateOptions{}) if err != nil { - logger.Printf("Error while creating ndb secret %s: %s\n", st.NdbSecret.Name, err) + if k8serrors.IsAlreadyExists(err) { + logger.Printf("NDB Secret %s already exists, updating.\n", st.NdbSecret.Name) + _, err = clientset.CoreV1().Secrets(ndbCredsNs).Update(context.TODO(), st.NdbSecret, metav1.UpdateOptions{}) + if err != nil { + logger.Printf("Error while updating ndb secret %s: %s\n", st.NdbSecret.Name, err) + } else { + logger.Printf("NDB Secret %s updated in namespace %s.\n", st.NdbSecret.Name, ndbCredsNs) + } + } else { + logger.Printf("Error while creating ndb secret %s: %s\n", st.NdbSecret.Name, err) + } } else { logger.Printf("NDB Secret %s created in namespace %s.\n", st.NdbSecret.Name, ndbCredsNs) } @@ -96,9 +116,20 @@ func provisionOrClone(ctx context.Context, st *SetupTypes, clientset *kubernetes st.NdbServer.Spec.CredentialSecretRef.Name = st.NdbSecret.Name } st.NdbServer.Namespace = "" // cluster-scoped has no namespace + ndbServerName := st.NdbServer.Name st.NdbServer, err = v1alpha1ClientSet.NDBServers().Create(st.NdbServer) if err != nil { - logger.Printf("Error while creating NDBServer %s: %s\n", st.NdbServer.Name, err) + if k8serrors.IsAlreadyExists(err) { + logger.Printf("NDBServer %s already exists, fetching existing.\n", ndbServerName) + st.NdbServer, err = v1alpha1ClientSet.NDBServers().Get(ndbServerName, metav1.GetOptions{}) + if err != nil { + logger.Printf("Error while fetching existing NDBServer %s: %s\n", ndbServerName, err) + } else { + logger.Printf("NDBServer %s fetched successfully.\n", st.NdbServer.Name) + } + } else { + logger.Printf("Error while creating NDBServer %s: %s\n", ndbServerName, err) + } } else { logger.Printf("NDBServer %s created.\n", st.NdbServer.Name) } @@ -142,9 +173,21 @@ func provisionOrClone(ctx context.Context, st *SetupTypes, clientset *kubernetes st.Database.Spec.Instance.ClusterId = nxClusterId } } - st.Database, err = v1alpha1ClientSet.Databases(st.Database.Namespace).Create(st.Database) + databaseName := st.Database.Name + databaseNamespace := st.Database.Namespace + st.Database, err = v1alpha1ClientSet.Databases(databaseNamespace).Create(st.Database) if err != nil { - logger.Printf("Error while creating Database %s: %s\n", st.Database.Name, err) + if k8serrors.IsAlreadyExists(err) { + logger.Printf("Database %s already exists, fetching existing.\n", databaseName) + st.Database, err = v1alpha1ClientSet.Databases(databaseNamespace).Get(databaseName, metav1.GetOptions{}) + if err != nil { + logger.Printf("Error while fetching existing Database %s: %s\n", databaseName, err) + } else { + logger.Printf("Database %s fetched successfully.\n", st.Database.Name) + } + } else { + logger.Printf("Error while creating Database %s: %s\n", databaseName, err) + } } else { logger.Printf("Database %s created.\n", st.Database.Name) } @@ -387,48 +430,45 @@ func getDatabaseOrCloneResponse(ctx context.Context, st *SetupTypes, clientset * func getAppResponse(ctx context.Context, st *SetupTypes, clientset *kubernetes.Clientset, localPort string) (res http.Response, err error) { logger := GetLogger(ctx) logger.Println("getAppResponse() started...") - errBaseMsg := "getAppResponse() ended" // Retrieve the pod name and targetPort podName := st.AppPod.Name podTargetPort := st.AppPod.Spec.Containers[0].Ports[0].ContainerPort - // Run port-forward command using kubectl - cmd := exec.Command("kubectl", "port-forward", podName, fmt.Sprintf("%s:%d", localPort, podTargetPort)) - err = cmd.Start() - if err != nil { - return http.Response{}, fmt.Errorf("%s! kubectl port-forward %s %s:%d failed! %v. ", errBaseMsg, podName, localPort, podTargetPort, err) - } else { - logger.Printf("kubectl port-forward %s %s:%d started.", podName, localPort, podTargetPort) - } - - // Wait for port-forwarding to establish - // Increased from 2s to 10s to ensure port-forward fully establishes before HTTP attempts - logger.Println("Waiting 10 seconds for port-forward to establish...") - time.Sleep(10 * time.Second) - - // Verify the forwarded port by making an HTTP request with retry logic url := fmt.Sprintf("http://localhost:%s", localPort) maxRetries := 10 retryDelay := 2 * time.Second var resp *http.Response for i := 0; i < maxRetries; i++ { + // Start a fresh port-forward on every attempt to handle cases where + // the previous port-forward process died (e.g. after an EOF) + cmd := exec.Command("kubectl", "port-forward", podName, fmt.Sprintf("%s:%d", localPort, podTargetPort)) + if startErr := cmd.Start(); startErr != nil { + logger.Printf("Attempt %d: kubectl port-forward failed to start: %v", i+1, startErr) + time.Sleep(retryDelay) + continue + } + logger.Printf("Attempt %d: kubectl port-forward %s %s:%d started.", i+1, podName, localPort, podTargetPort) + + // Give port-forward time to establish before making the HTTP request + time.Sleep(retryDelay) + resp, err = http.Get(url) if err == nil && resp.StatusCode == 200 { logger.Printf("http://localhost:%s successful on attempt %d.", localPort, i+1) + cmd.Process.Kill() break } - if i < maxRetries-1 { - logger.Printf("Attempt %d failed (err: %v), retrying in %v...", i+1, err, retryDelay) - if resp != nil { - resp.Body.Close() - } - time.Sleep(retryDelay) + + logger.Printf("Attempt %d failed (err: %v), retrying...", i+1, err) + if resp != nil { + resp.Body.Close() } + cmd.Process.Kill() } - if err != nil || resp.StatusCode != 200 { + if err != nil || resp == nil || resp.StatusCode != 200 { return http.Response{}, fmt.Errorf("http://localhost:%s failed after %d attempts! Last error: %v", localPort, maxRetries, err) } @@ -442,7 +482,7 @@ func getAppResponse(ctx context.Context, st *SetupTypes, clientset *kubernetes.C logger.Println("Response: ", string(body)) } - logger.Printf("%s!", errBaseMsg) + logger.Println("getAppResponse() ended!") return *resp, nil }