From fe70713d5d84bec798bca3c99bbfbb3a5df68e54 Mon Sep 17 00:00:00 2001 From: Danny Zaken Date: Sun, 17 Mar 2024 09:42:13 +0200 Subject: [PATCH] Removed Mongo related code and files Removed all mongo related code: * Making DBType to only accept postgres * removed mongo external URL * removed mongo related envs from deployments\statefulsets * remove Mongo related CLI commands (e.g. dbdump) Signed-off-by: Danny Zaken --- README.md | 4 +- deploy/crds/noobaa.io_noobaas.yaml | 10 +- deploy/internal/deployment-endpoint.yaml | 17 +- deploy/internal/job-upgrade-db.yaml | 25 -- deploy/internal/service-db.yaml | 10 +- deploy/internal/statefulset-core.yaml | 23 +- deploy/internal/statefulset-db.yaml | 56 --- doc/noobaa-crd.md | 8 +- pkg/apis/noobaa/v1alpha1/noobaa_types.go | 11 +- pkg/bundle/deploy.go | 155 ++----- pkg/diagnostics/dbdump.go | 107 +---- pkg/options/options.go | 22 +- pkg/system/phase1_verifying.go | 4 - pkg/system/phase2_creating.go | 517 +++-------------------- pkg/system/phase4_configuring.go | 4 - pkg/system/reconciler.go | 29 +- pkg/system/system.go | 94 +---- test/cli/test_cli_flow.sh | 8 - 18 files changed, 141 insertions(+), 963 deletions(-) delete mode 100644 deploy/internal/job-upgrade-db.yaml delete mode 100644 deploy/internal/statefulset-db.yaml diff --git a/README.md b/README.md index d1df1ce5f..c4d453d7d 100644 --- a/README.md +++ b/README.md @@ -143,9 +143,8 @@ The following options can be passed to any command: --aws-sts-arn='': The AWS STS Role ARN which will assume role --cosi-driver-path='/var/lib/cosi/cosi.sock': unix socket path for COSI --cosi-sidecar-image='gcr.io/k8s-staging-sig-storage/objectstorage-sidecar/objectstorage-sidecar:v20221117-v0.1.0-22-g0e67387': The cosi side car container image - --db-image='centos/mongodb-36-centos7': The database container image + --db-image='"quay.io/sclorg/postgresql-15-c9s"': The database container image --db-storage-class='': The database volume storage class name - --db-type='postgres': The type of database container image (mongodb, postgres) --db-volume-size-gb=0: The database volume size in GB --debug-level='default_level': The type of debug sets that the system prints (all, nsfs, warn, default_level) --dev=false: Set sufficient resources for dev env @@ -154,7 +153,6 @@ The following options can be passed to any command: --kubeconfig='': Paths to a kubeconfig. Only required if out-of-cluster. --manual-default-backingstore=false: allow to delete the default backingstore --mini=false: Signal the operator that it is running in a low resource environment - --mongodb-url='': url for mongodb -n, --namespace='default': Target namespace --noobaa-image='noobaa/noobaa-core:5.16.0': NooBaa image --operator-image='noobaa/noobaa-operator:5.16.0': Operator image diff --git a/deploy/crds/noobaa.io_noobaas.yaml b/deploy/crds/noobaa.io_noobaas.yaml index 1e3bd346a..5f42ce6a3 100644 --- a/deploy/crds/noobaa.io_noobaas.yaml +++ b/deploy/crds/noobaa.io_noobaas.yaml @@ -991,10 +991,10 @@ spec: buckets, objects meta-data and mapping file parts to storage locations. type: string dbType: - description: DBType (optional) overrides the default type image for - the db container + description: |- + DBType (optional) overrides the default type image for the db container. + The only possible value is postgres enum: - - mongodb - postgres type: string dbVolumeResources: @@ -1565,10 +1565,6 @@ spec: account with new BackingStore in order to delete the DefaultBackingStore nullable: true type: boolean - mongoDbURL: - description: MongoDbURL (optional) overrides the default mongo db - remote url - type: string pvPoolDefaultStorageClass: description: |- PVPoolDefaultStorageClass (optional) overrides the default cluster StorageClass for the pv-pool volumes. diff --git a/deploy/internal/deployment-endpoint.yaml b/deploy/internal/deployment-endpoint.yaml index 6ef5411ef..23fe2fdf2 100644 --- a/deploy/internal/deployment-endpoint.yaml +++ b/deploy/internal/deployment-endpoint.yaml @@ -32,15 +32,15 @@ spec: secret: secretName: noobaa-s3-serving-cert optional: true - # This service account token can be used to provide identity outside the cluster. - # For example, this token can be used with AssumeRoleWithWebIdentity to authenticate with AWS using IAM OIDC provider and STS. + # This service account token can be used to provide identity outside the cluster. + # For example, this token can be used with AssumeRoleWithWebIdentity to authenticate with AWS using IAM OIDC provider and STS. - name: bound-sa-token projected: sources: - - serviceAccountToken: - path: token - # For testing purposes change the audience to api - audience: openshift + - serviceAccountToken: + path: token + # For testing purposes change the audience to api + audience: openshift - name: noobaa-auth-token secret: secretName: noobaa-endpoints @@ -48,7 +48,7 @@ spec: - name: noobaa-server secret: secretName: noobaa-server - optional: true + optional: true containers: - name: endpoint image: NOOBAA_CORE_IMAGE @@ -89,7 +89,6 @@ spec: - name: MD_ADDR - name: HOSTED_AGENTS_ADDR - name: DB_TYPE - - name: MONGODB_URL - name: POSTGRES_HOST - name: POSTGRES_PORT - name: POSTGRES_DBNAME @@ -145,6 +144,6 @@ spec: tcpSocket: port: 6001 # ready when s3 port is open timeoutSeconds: 5 - securityContext: + securityContext: runAsUser: 0 runAsGroup: 0 diff --git a/deploy/internal/job-upgrade-db.yaml b/deploy/internal/job-upgrade-db.yaml deleted file mode 100644 index 8a83a9dd6..000000000 --- a/deploy/internal/job-upgrade-db.yaml +++ /dev/null @@ -1,25 +0,0 @@ -apiVersion: batch/v1 -kind: Job -metadata: - name: db-migrate - labels: - app: noobaa -spec: - template: - spec: - containers: - - name: migrate-job - image: NOOBAA_CORE_IMAGE - command: ["/noobaa_init_files/noobaa_init.sh", "db_migrate"] - env: - - name: MONGODB_URL - value: "mongodb://noobaa-db-0.noobaa-db/nbcore" - - name: POSTGRES_HOST - value: "noobaa-db-pg-0.noobaa-db-pg" - - name: POSTGRES_DBNAME - value: nbcore - - name: POSTGRES_USER - - name: POSTGRES_PASSWORD - - name: CONTAINER_PLATFORM - value: KUBERNETES - restartPolicy: OnFailure \ No newline at end of file diff --git a/deploy/internal/service-db.yaml b/deploy/internal/service-db.yaml index 4203a5327..0adfab2c5 100644 --- a/deploy/internal/service-db.yaml +++ b/deploy/internal/service-db.yaml @@ -5,13 +5,13 @@ metadata: labels: app: noobaa annotations: - service.beta.openshift.io/serving-cert-secret-name: 'noobaa-db-serving-cert' - service.alpha.openshift.io/serving-cert-secret-name: 'noobaa-db-serving-cert' + service.beta.openshift.io/serving-cert-secret-name: "noobaa-db-serving-cert" + service.alpha.openshift.io/serving-cert-secret-name: "noobaa-db-serving-cert" spec: type: ClusterIP selector: noobaa-db: SYSNAME ports: - - port: 27017 - targetPort: 27017 - name: mongodb + - port: 5432 + targetPort: 5432 + name: postgres diff --git a/deploy/internal/statefulset-core.yaml b/deploy/internal/statefulset-core.yaml index dbd2b39ba..44c9e237d 100644 --- a/deploy/internal/statefulset-core.yaml +++ b/deploy/internal/statefulset-core.yaml @@ -37,15 +37,15 @@ spec: secret: secretName: noobaa-server optional: true - # This service account token can be used to provide identity outside the cluster. - # For example, this token can be used with AssumeRoleWithWebIdentity to authenticate with AWS using IAM OIDC provider and STS. + # This service account token can be used to provide identity outside the cluster. + # For example, this token can be used with AssumeRoleWithWebIdentity to authenticate with AWS using IAM OIDC provider and STS. - name: bound-sa-token projected: sources: - - serviceAccountToken: - path: token - # For testing purposes change the audience to api - audience: openshift + - serviceAccountToken: + path: token + # For testing purposes change the audience to api + audience: openshift containers: #----------------# # CORE CONTAINER # @@ -97,8 +97,6 @@ spec: configMapKeyRef: name: noobaa-config key: NOOBAA_LOG_LEVEL - - name: MONGODB_URL - value: "mongodb://noobaa-db-0.noobaa-db/nbcore" - name: POSTGRES_HOST value: "noobaa-db-pg-0.noobaa-db-pg" - name: POSTGRES_PORT @@ -110,7 +108,7 @@ spec: - name: POSTGRES_SSL_REQUIRED - name: POSTGRES_SSL_UNAUTHORIZED - name: DB_TYPE - value: mongodb + value: postgres - name: CONTAINER_PLATFORM value: KUBERNETES - name: NOOBAA_ROOT_SECRET @@ -143,7 +141,10 @@ spec: resource: limits.memory - name: noobaa-log-processor image: NOOBAA_CORE_IMAGE - command: ["/root/node_modules/noobaa-core/src/deploy/NVA_build/noobaa_logs.sh"] + command: + [ + "/root/node_modules/noobaa-core/src/deploy/NVA_build/noobaa_logs.sh", + ] volumeMounts: - name: logs mountPath: /log @@ -173,4 +174,4 @@ spec: - name: CONTAINER_MEM_LIMIT valueFrom: resourceFieldRef: - resource: limits.memory \ No newline at end of file + resource: limits.memory diff --git a/deploy/internal/statefulset-db.yaml b/deploy/internal/statefulset-db.yaml deleted file mode 100644 index adaa0998d..000000000 --- a/deploy/internal/statefulset-db.yaml +++ /dev/null @@ -1,56 +0,0 @@ -apiVersion: apps/v1 -kind: StatefulSet -metadata: - name: noobaa-db - labels: - app: noobaa -spec: - replicas: 1 - selector: - matchLabels: - noobaa-db: noobaa - serviceName: noobaa-db - updateStrategy: - type: RollingUpdate - template: - metadata: - labels: - app: noobaa - noobaa-db: noobaa - spec: - serviceAccountName: noobaa-db - terminationGracePeriodSeconds: 60 - containers: - #--------------------# - # DATABASE CONTAINER # - #--------------------# - - name: db - image: NOOBAA_DB_IMAGE - command: - - bash - - -c - - /opt/rh/rh-mongodb36/root/usr/bin/mongod --port 27017 --bind_ip_all --dbpath /data/mongo/cluster/shard1 - resources: - requests: - cpu: "2" - memory: "4Gi" - limits: - cpu: "2" - memory: "4Gi" - volumeMounts: - - name: db - mountPath: /data - securityContext: - runAsUser: 10001 - runAsGroup: 0 - volumeClaimTemplates: - - metadata: - name: db - labels: - app: noobaa - spec: - accessModes: - - ReadWriteOnce - resources: - requests: - storage: 50Gi diff --git a/doc/noobaa-crd.md b/doc/noobaa-crd.md index ceb371ea7..ff5d42ed8 100644 --- a/doc/noobaa-crd.md +++ b/doc/noobaa-crd.md @@ -165,7 +165,7 @@ metadata: namespace: noobaa spec: image: noobaa/noobaa-core:v9999.9.9 - dbImage: centos/mongodb-36-centos7 + dbImage: "quay.io/sclorg/postgresql-15-c9s" imagePullSecret: name: ``` @@ -236,7 +236,6 @@ metadata: spec: image: noobaa/noobaa-core:5.9.0 dbImage: centos/postgresql-12-centos7 - dbType: postgres dbConf: |+ max_connections = 1000 ``` @@ -258,6 +257,5 @@ topologySpreadConstraints: Users can make changes to `topologySpreadConstraints` configuration after the operator creates it and the changes will not override it. But once user remove the custome `topologySpreadConstraints` default value is resotored. ## Notes -1. `dbConf` field will have no effect if `dbType` is not "postgres". -2. `dbConf` configuration is not validated. -3. NooBaa uses `ConfigMap` to pass database configuration to the databases. Althought the ConfigMap is editable, it should not and cannot be used to pass custom database overrides. The reason being that NooBaa operator, as part of its reconcile process will overwrite the ConfigMap to the default values. \ No newline at end of file +1. `dbConf` configuration is not validated. +2. NooBaa uses `ConfigMap` to pass database configuration to the databases. Althought the ConfigMap is editable, it should not and cannot be used to pass custom database overrides. The reason being that NooBaa operator, as part of its reconcile process will overwrite the ConfigMap to the default values. \ No newline at end of file diff --git a/pkg/apis/noobaa/v1alpha1/noobaa_types.go b/pkg/apis/noobaa/v1alpha1/noobaa_types.go index 9c5d9660b..afdc8578a 100644 --- a/pkg/apis/noobaa/v1alpha1/noobaa_types.go +++ b/pkg/apis/noobaa/v1alpha1/noobaa_types.go @@ -85,9 +85,10 @@ type NooBaaSpec struct { // +optional DBConf *string `json:"dbConf,omitempty"` - // DBType (optional) overrides the default type image for the db container + // DBType (optional) overrides the default type image for the db container. + // The only possible value is postgres // +optional - // +kubebuilder:validation:Enum=mongodb;postgres + // +kubebuilder:validation:Enum=postgres DBType DBTypes `json:"dbType,omitempty"` // CoreResources (optional) overrides the default resource requirements for the server container @@ -118,10 +119,6 @@ type NooBaaSpec struct { // +optional DBStorageClass *string `json:"dbStorageClass,omitempty"` - // MongoDbURL (optional) overrides the default mongo db remote url - // +optional - MongoDbURL string `json:"mongoDbURL,omitempty"` - // ExternalPgSecret (optional) holds an optional secret with a url to an extrenal Postgres DB to be used // +optional ExternalPgSecret *corev1.SecretReference `json:"externalPgSecret,omitempty"` @@ -528,8 +525,6 @@ type DBTypes string // These are the valid DB types: const ( - // DBTypeMongo is mongodb - DBTypeMongo DBTypes = "mongodb" // DBTypePostgres is postgres DBTypePostgres DBTypes = "postgres" ) diff --git a/pkg/bundle/deploy.go b/pkg/bundle/deploy.go index c39401b87..02cd34453 100644 --- a/pkg/bundle/deploy.go +++ b/pkg/bundle/deploy.go @@ -1510,7 +1510,7 @@ spec: status: {} ` -const Sha256_deploy_crds_noobaa_io_noobaas_yaml = "47a277036f04f662bb8c3e9d5314177b0d804fb8714167cbe7ae2c14bc4ff4b0" +const Sha256_deploy_crds_noobaa_io_noobaas_yaml = "c4b94816d2f833de237fb6b815e4b1d2639e86633826a9e170fc7938481de0ac" const File_deploy_crds_noobaa_io_noobaas_yaml = `--- apiVersion: apiextensions.k8s.io/v1 @@ -2505,10 +2505,10 @@ spec: buckets, objects meta-data and mapping file parts to storage locations. type: string dbType: - description: DBType (optional) overrides the default type image for - the db container + description: |- + DBType (optional) overrides the default type image for the db container. + The only possible value is postgres enum: - - mongodb - postgres type: string dbVolumeResources: @@ -3079,10 +3079,6 @@ spec: account with new BackingStore in order to delete the DefaultBackingStore nullable: true type: boolean - mongoDbURL: - description: MongoDbURL (optional) overrides the default mongo db - remote url - type: string pvPoolDefaultStorageClass: description: |- PVPoolDefaultStorageClass (optional) overrides the default cluster StorageClass for the pv-pool volumes. @@ -3886,7 +3882,7 @@ data: exit 0 ` -const Sha256_deploy_internal_deployment_endpoint_yaml = "ffcf95c206c68b6d6b783d847d219e45a61e79d374cad4f36e6a7ec4f7fb4d0a" +const Sha256_deploy_internal_deployment_endpoint_yaml = "bcce4839c69c3353ba36fd94aea2c8d7cf46e570a0106467f8bd7430acea18b7" const File_deploy_internal_deployment_endpoint_yaml = `apiVersion: apps/v1 kind: Deployment @@ -3922,15 +3918,15 @@ spec: secret: secretName: noobaa-s3-serving-cert optional: true - # This service account token can be used to provide identity outside the cluster. - # For example, this token can be used with AssumeRoleWithWebIdentity to authenticate with AWS using IAM OIDC provider and STS. + # This service account token can be used to provide identity outside the cluster. + # For example, this token can be used with AssumeRoleWithWebIdentity to authenticate with AWS using IAM OIDC provider and STS. - name: bound-sa-token projected: sources: - - serviceAccountToken: - path: token - # For testing purposes change the audience to api - audience: openshift + - serviceAccountToken: + path: token + # For testing purposes change the audience to api + audience: openshift - name: noobaa-auth-token secret: secretName: noobaa-endpoints @@ -3938,7 +3934,7 @@ spec: - name: noobaa-server secret: secretName: noobaa-server - optional: true + optional: true containers: - name: endpoint image: NOOBAA_CORE_IMAGE @@ -3979,7 +3975,6 @@ spec: - name: MD_ADDR - name: HOSTED_AGENTS_ADDR - name: DB_TYPE - - name: MONGODB_URL - name: POSTGRES_HOST - name: POSTGRES_PORT - name: POSTGRES_DBNAME @@ -4035,7 +4030,7 @@ spec: tcpSocket: port: 6001 # ready when s3 port is open timeoutSeconds: 5 - securityContext: + securityContext: runAsUser: 0 runAsGroup: 0 ` @@ -4339,34 +4334,6 @@ metadata: data: {} ` -const Sha256_deploy_internal_job_upgrade_db_yaml = "4ae1ae1f6009e578ea4cc937c305068dd8f21b93b0d7fd43350628e84725f337" - -const File_deploy_internal_job_upgrade_db_yaml = `apiVersion: batch/v1 -kind: Job -metadata: - name: db-migrate - labels: - app: noobaa -spec: - template: - spec: - containers: - - name: migrate-job - image: NOOBAA_CORE_IMAGE - command: ["/noobaa_init_files/noobaa_init.sh", "db_migrate"] - env: - - name: MONGODB_URL - value: "mongodb://noobaa-db-0.noobaa-db/nbcore" - - name: POSTGRES_HOST - value: "noobaa-db-pg-0.noobaa-db-pg" - - name: POSTGRES_DBNAME - value: nbcore - - name: POSTGRES_USER - - name: POSTGRES_PASSWORD - - name: CONTAINER_PLATFORM - value: KUBERNETES - restartPolicy: OnFailure` - const Sha256_deploy_internal_pod_agent_yaml = "204e11eea569564b507010d13c43a2d3ad5feae9e86666a08904508eab231830" const File_deploy_internal_pod_agent_yaml = `apiVersion: v1 @@ -4751,7 +4718,7 @@ type: Opaque data: {} ` -const Sha256_deploy_internal_service_db_yaml = "64559363daddd9caf781f104b876b33fb63e4f2551570e73bdb2bfae736f33ee" +const Sha256_deploy_internal_service_db_yaml = "7bf9f8bd18c07c5d768392f2bdfcac7f3398c1137eecb0f48983f468234a5a96" const File_deploy_internal_service_db_yaml = `apiVersion: v1 kind: Service @@ -4760,16 +4727,16 @@ metadata: labels: app: noobaa annotations: - service.beta.openshift.io/serving-cert-secret-name: 'noobaa-db-serving-cert' - service.alpha.openshift.io/serving-cert-secret-name: 'noobaa-db-serving-cert' + service.beta.openshift.io/serving-cert-secret-name: "noobaa-db-serving-cert" + service.alpha.openshift.io/serving-cert-secret-name: "noobaa-db-serving-cert" spec: type: ClusterIP selector: noobaa-db: SYSNAME ports: - - port: 27017 - targetPort: 27017 - name: mongodb + - port: 5432 + targetPort: 5432 + name: postgres ` const Sha256_deploy_internal_service_mgmt_yaml = "fa5f052fb360e6893fc446a318413a6f494a8610706ae7e36ff985b3b3a5c070" @@ -4928,7 +4895,7 @@ spec: noobaa-s3-svc: "true" ` -const Sha256_deploy_internal_statefulset_core_yaml = "93ae460c2a8080a03c87320eb0ea5f585bb20aeebd7fae562837e89b5fd0cdcf" +const Sha256_deploy_internal_statefulset_core_yaml = "56bc0da847d71be17138025a208dbf8dc0b02e6f4817bbbac4ce828429d86c26" const File_deploy_internal_statefulset_core_yaml = `apiVersion: apps/v1 kind: StatefulSet @@ -4969,15 +4936,15 @@ spec: secret: secretName: noobaa-server optional: true - # This service account token can be used to provide identity outside the cluster. - # For example, this token can be used with AssumeRoleWithWebIdentity to authenticate with AWS using IAM OIDC provider and STS. + # This service account token can be used to provide identity outside the cluster. + # For example, this token can be used with AssumeRoleWithWebIdentity to authenticate with AWS using IAM OIDC provider and STS. - name: bound-sa-token projected: sources: - - serviceAccountToken: - path: token - # For testing purposes change the audience to api - audience: openshift + - serviceAccountToken: + path: token + # For testing purposes change the audience to api + audience: openshift containers: #----------------# # CORE CONTAINER # @@ -5029,8 +4996,6 @@ spec: configMapKeyRef: name: noobaa-config key: NOOBAA_LOG_LEVEL - - name: MONGODB_URL - value: "mongodb://noobaa-db-0.noobaa-db/nbcore" - name: POSTGRES_HOST value: "noobaa-db-pg-0.noobaa-db-pg" - name: POSTGRES_PORT @@ -5042,7 +5007,7 @@ spec: - name: POSTGRES_SSL_REQUIRED - name: POSTGRES_SSL_UNAUTHORIZED - name: DB_TYPE - value: mongodb + value: postgres - name: CONTAINER_PLATFORM value: KUBERNETES - name: NOOBAA_ROOT_SECRET @@ -5075,7 +5040,10 @@ spec: resource: limits.memory - name: noobaa-log-processor image: NOOBAA_CORE_IMAGE - command: ["/root/node_modules/noobaa-core/src/deploy/NVA_build/noobaa_logs.sh"] + command: + [ + "/root/node_modules/noobaa-core/src/deploy/NVA_build/noobaa_logs.sh", + ] volumeMounts: - name: logs mountPath: /log @@ -5105,66 +5073,7 @@ spec: - name: CONTAINER_MEM_LIMIT valueFrom: resourceFieldRef: - resource: limits.memory` - -const Sha256_deploy_internal_statefulset_db_yaml = "25924f84967caebdeb5d61c2181f0ba04da92306fed7e44834dbcc7480b8d48a" - -const File_deploy_internal_statefulset_db_yaml = `apiVersion: apps/v1 -kind: StatefulSet -metadata: - name: noobaa-db - labels: - app: noobaa -spec: - replicas: 1 - selector: - matchLabels: - noobaa-db: noobaa - serviceName: noobaa-db - updateStrategy: - type: RollingUpdate - template: - metadata: - labels: - app: noobaa - noobaa-db: noobaa - spec: - serviceAccountName: noobaa-db - terminationGracePeriodSeconds: 60 - containers: - #--------------------# - # DATABASE CONTAINER # - #--------------------# - - name: db - image: NOOBAA_DB_IMAGE - command: - - bash - - -c - - /opt/rh/rh-mongodb36/root/usr/bin/mongod --port 27017 --bind_ip_all --dbpath /data/mongo/cluster/shard1 - resources: - requests: - cpu: "2" - memory: "4Gi" - limits: - cpu: "2" - memory: "4Gi" - volumeMounts: - - name: db - mountPath: /data - securityContext: - runAsUser: 10001 - runAsGroup: 0 - volumeClaimTemplates: - - metadata: - name: db - labels: - app: noobaa - spec: - accessModes: - - ReadWriteOnce - resources: - requests: - storage: 50Gi + resource: limits.memory ` const Sha256_deploy_internal_statefulset_postgres_db_yaml = "0accc047982dbd1b8c207c81ef2bb1ae8c61c312915d3c2d196799ca6f146816" diff --git a/pkg/diagnostics/dbdump.go b/pkg/diagnostics/dbdump.go index 3a84248f3..db1223270 100644 --- a/pkg/diagnostics/dbdump.go +++ b/pkg/diagnostics/dbdump.go @@ -17,7 +17,6 @@ import ( type CollectorDbDump struct { folderName string // Local folder to store the raw db dump dbDumpFolderPath string // Local path of the folder containing the raw dump file - remoteFolderPath string // Remote folder (at pod) to store the raw db dump remoteTarPath string // Remote path (at pod) of tar'd db dump kubeconfig string kubeCommand string @@ -107,48 +106,13 @@ func (c *CollectorDbDump) generatePostgresDump(destDir string) error { return nil } -// Create mongodb dump -func (c *CollectorDbDump) generateMongoDBDump(destDir string) error { - // In case of a mongo db, the dump is a dir containing multiple entries, in the case we - // can't redirect the output to a local file, so we generate the dump on the remote machine - // and tar it - - // Compose the path containing the dump folder at the remote machine - c.remoteFolderPath = fmt.Sprintf("%s/%s", "/tmp", c.folderName) - cmd := exec.Command(c.kubeCommand, "exec", "pod/noobaa-db-0", "--", "mongodump", "--db", "nbcore", "-o", c.remoteFolderPath) - // handle custom path for kubeconfig file, - // see --kubeconfig cli options - if len(c.kubeconfig) > 0 { - cmd.Env = append(cmd.Env, "KUBECONFIG="+c.kubeconfig) - } - - // Generate db dump folder - if err := cmd.Run(); err != nil { - c.log.Printf(`❌ cannot generate db dump: %v`, err) - return err - } - - // Tar the raw db dump - cmd = exec.Command(c.kubeCommand, "exec", "pod/noobaa-db-0", "--", "tar", "-C", "/tmp", "-cvzf", c.remoteTarPath, c.folderName) - if err := cmd.Run(); err != nil { - c.log.Printf(`❌ failed to tar remote dump folder`) - return err - } - - return nil -} - // Create the dump resources func (c *CollectorDbDump) generateDBDump(destDir string) error { var err error c.log.Println("Generating db dump at pod") - if options.DBType == "postgres" { - err = c.generatePostgresDump(destDir) - } else { - err = c.generateMongoDBDump(destDir) - } + err = c.generatePostgresDump(destDir) return err } @@ -178,50 +142,13 @@ func (c *CollectorDbDump) exportPostgresDump(destDir string) error { return nil } -// Copy dump resources from remote machine -func (c *CollectorDbDump) exportMongoDBDump(destDir string) error { - // In case of a mongo db, the db dump was generated and tar'd at the remote machine, - // all is left to do is copy the tarball to the local machine - var localPath string - - // Compose the local path to export the tarball - if destDir != "" { - localPath = fmt.Sprintf("%s/%s%s", destDir, c.folderName, ".tar.gz") - } else { - localPath = fmt.Sprintf("%s%s", c.folderName, ".tar.gz") - } - - // Compose the full path to copy the tarball from - fullTarPath := fmt.Sprintf("%s:%s", "noobaa-db-0", c.remoteTarPath) - - // Create the command to copy the tarball - cmd := exec.Command(c.kubeCommand, "cp", fullTarPath, localPath) - // handle custom path for kubeconfig file, - // see --kubeconfig cli options - if len(c.kubeconfig) > 0 { - cmd.Env = append(cmd.Env, "KUBECONFIG="+c.kubeconfig) - } - - // Execute the command, copying the tarball - if err := cmd.Run(); err != nil { - c.log.Printf(`❌ failed to copy remote tar file`) - return err - } - - return nil -} - -// Tar local resources (Postgres) or copy from the remote machine (mongodb) +// Tar local resources (Postgres) func (c *CollectorDbDump) exportDBDump(destDir string) error { var err error c.log.Println("Exporting db dump") - if options.DBType == "postgres" { - err = c.exportPostgresDump(destDir) - } else { - err = c.exportMongoDBDump(destDir) - } + err = c.exportPostgresDump(destDir) return err } @@ -240,33 +167,7 @@ func (c *CollectorDbDump) deletePostgresRawResources() { } } -// Delete dump on mongodb remote machine -func (c *CollectorDbDump) deleteMongoDBRawResources() { - // In case of mongo db, the dump was created and tar'd at the remote machine, - // all is left to do is clean the remote machine - - // Compose the deletion command of the raw resources - cmd := exec.Command(c.kubeCommand, "exec", "pod/noobaa-db-0", "--", "rm", "-rf", c.remoteFolderPath) - - // Execute deletion of the raw resources - if err := cmd.Run(); err != nil { - c.log.Printf(`❌ failed to remove remote dump folder`) - } - - // Compose the deletion command of the tar'd resources - cmd = exec.Command(c.kubeCommand, "exec", "pod/noobaa-db-0", "--", "rm", c.remoteTarPath) - - // Execute deletion of the tar'd resources - if err := cmd.Run(); err != nil { - c.log.Printf(`❌ failed to tar remove dump tar file`) - } -} - // Remove raw resources from local or remote machines func (c *CollectorDbDump) deleteRawResources() { - if options.DBType == "postgres" { - c.deletePostgresRawResources() - } else { - c.deleteMongoDBRawResources() - } + c.deletePostgresRawResources() } diff --git a/pkg/options/options.go b/pkg/options/options.go index 62b117e41..97ad2e5e6 100644 --- a/pkg/options/options.go +++ b/pkg/options/options.go @@ -72,20 +72,12 @@ var NooBaaImage = ContainerImage // DBImage is the default db image url // it can be overridden for testing or different registry locations. -var DBImage = "centos/mongodb-36-centos7" - -// DBPostgresImage is the default postgres db image url -// currently it can not be overridden. -var DBPostgresImage = "quay.io/sclorg/postgresql-15-c9s" +var DBImage = "quay.io/sclorg/postgresql-15-c9s" // Psql12Image is the default postgres12 db image url // currently it can not be overridden. var Psql12Image = "centos/postgresql-12-centos7" -// DBMongoImage is the default mongo db image url -// this is used during migration to solve issues where mongo STS referencing to postgres image -var DBMongoImage = "centos/mongodb-36-centos7" - // DBType is the default db image type // it can be overridden for testing or different types. var DBType = "postgres" @@ -97,10 +89,6 @@ var DBVolumeSizeGB = 0 // it can be overridden for testing or different PV providers. var DBStorageClass = "" -// MongoDbURL is used for providing mongodb url -// it can be overridden for testing or different url. -var MongoDbURL = "" - // PostgresDbURL is used for providing postgres url // it can be overridden for testing or different url. var PostgresDbURL = "" @@ -238,10 +226,6 @@ func init() { &CosiSideCarImage, "cosi-sidecar-image", CosiSideCarImage, "The cosi side car container image", ) - FlagSet.StringVar( - &DBType, "db-type", - DBType, "The type of database container image (mongodb, postgres)", - ) FlagSet.IntVar( &DBVolumeSizeGB, "db-volume-size-gb", DBVolumeSizeGB, "The database volume size in GB", @@ -250,10 +234,6 @@ func init() { &DBStorageClass, "db-storage-class", DBStorageClass, "The database volume storage class name", ) - FlagSet.StringVar( - &MongoDbURL, "mongodb-url", - MongoDbURL, "url for mongodb", - ) FlagSet.StringVar( &PostgresDbURL, "postgres-url", PostgresDbURL, "url for postgresql", diff --git a/pkg/system/phase1_verifying.go b/pkg/system/phase1_verifying.go index f0dafcc9c..916b5f820 100644 --- a/pkg/system/phase1_verifying.go +++ b/pkg/system/phase1_verifying.go @@ -158,10 +158,6 @@ func (r *Reconciler) CheckSystemCR() error { } } - err = CheckMongoURL(r.NooBaa) - if err != nil { - return util.NewPersistentError("InvalidMongoDbURL", fmt.Sprintf(`%s`, err)) - } // Validate the DefaultBackingStore Spec // nolint: staticcheck if r.NooBaa.Spec.DefaultBackingStoreSpec != nil { diff --git a/pkg/system/phase2_creating.go b/pkg/system/phase2_creating.go index 7c3691a40..ca84db5f2 100644 --- a/pkg/system/phase2_creating.go +++ b/pkg/system/phase2_creating.go @@ -31,15 +31,13 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/util/intstr" "sigs.k8s.io/controller-runtime/pkg/client" ) const ( - upgradeJobBackoffLimit = int32(4) - webIdentityTokenPath string = "/var/run/secrets/openshift/serviceaccount/token" - roleARNEnvVar string = "ROLEARN" + webIdentityTokenPath string = "/var/run/secrets/openshift/serviceaccount/token" + roleARNEnvVar string = "ROLEARN" ) // ReconcilePhaseCreating runs the reconcile phase @@ -51,13 +49,6 @@ func (r *Reconciler) ReconcilePhaseCreating() error { "noobaa operator started phase 2/4 - \"Creating\"", ) - if r.NooBaa.Spec.MongoDbURL != "" { - r.MongoConnectionString = r.NooBaa.Spec.MongoDbURL - } else { - r.MongoConnectionString = fmt.Sprintf(`mongodb://%s-0.%s/nbcore`, - r.NooBaaMongoDB.Name, r.NooBaaMongoDB.Spec.ServiceName) - } - if err := r.ReconcileCAInject(); err != nil { return err } @@ -121,7 +112,7 @@ func (r *Reconciler) ReconcilePhaseCreatingForMainClusters() error { if err := r.ReconcileObject(r.SecretServer, nil); err != nil { return err } - if r.NooBaa.Spec.DBType == "postgres" && r.NooBaa.Spec.ExternalPgSecret == nil { + if r.NooBaa.Spec.ExternalPgSecret == nil { if err := r.ReconcileObject(r.SecretDB, nil); err != nil { return err } @@ -129,57 +120,25 @@ func (r *Reconciler) ReconcilePhaseCreatingForMainClusters() error { if err := r.ReconcileRootSecret(); err != nil { return err } - if err := r.UpgradeSplitDB(); err != nil { - return err - } - // create the db only if mongo db url is not given, and postgres secret as well - if r.NooBaa.Spec.MongoDbURL == "" && r.NooBaa.Spec.ExternalPgSecret == nil { - if err := r.UpgradeSplitDB(); err != nil { - return err - } - if r.NooBaa.Spec.DBType == "postgres" { - if err := r.UpgradePostgresDB(); err != nil { - return err - } + // create the db only if postgres secret is not given + if r.NooBaa.Spec.ExternalPgSecret == nil { + if err := r.UpgradePostgresDB(); err != nil { + return err } if err := r.ReconcileDB(); err != nil { return err } - if r.NooBaa.Spec.DBType == "postgres" { - if err := r.ReconcileObject(r.ServiceDbPg, r.SetDesiredServiceDBForPostgres); err != nil { - return err - } - // fix for https://bugzilla.redhat.com/show_bug.cgi?id=1955328 - // if DBType=postgres was passed in version 5.6 (OCS 4.6) the operator reconciled - // the mongo service with postgres values. see here: - // https://github.com/noobaa/noobaa-operator/blob/112c510650612b1a6b88582cf41c53b30068161c/pkg/system/phase2_creating.go#L121-L126 - // to fix that, reconcile mongo service as well if it exists - if util.KubeCheckQuiet(r.ServiceDb) { - r.Logger.Infof("found existing mongo db service [%q] will reconcile", r.ServiceDb.Name) - if err := r.ReconcileObject(r.ServiceDb, r.SetDesiredServiceDBForMongo); err != nil { - r.Logger.Errorf("got error when trying to reconcile mongo service. %v", err) - return err - } - } - - } else { - if err := r.ReconcileObject(r.ServiceDb, r.SetDesiredServiceDBForMongo); err != nil { - return err - } + if err := r.ReconcileObject(r.ServiceDbPg, r.SetDesiredServiceDBForPostgres); err != nil { + return err } } if err := r.ReconcileObject(r.ServiceMgmt, r.SetDesiredServiceMgmt); err != nil { return err } - if r.NooBaa.Spec.DBType == "postgres" { - if err := r.UpgradeMigrateDB(); err != nil { - return err - } - } if err := r.ReconcileObject(r.CoreApp, r.SetDesiredCoreApp); err != nil { return err } @@ -253,15 +212,6 @@ func (r *Reconciler) SetDesiredServiceSts() error { return nil } -// SetDesiredServiceDBForMongo updates the mongodb service -func (r *Reconciler) SetDesiredServiceDBForMongo() error { - r.ServiceDb.Spec.Selector["noobaa-db"] = r.Request.Name - r.ServiceDb.Spec.Ports[0].Name = "mongodb" - r.ServiceDb.Spec.Ports[0].Port = 27017 - r.ServiceDb.Spec.Ports[0].TargetPort = intstr.FromInt(27017) - return nil -} - // SetDesiredServiceDBForPostgres updates the postgres service func (r *Reconciler) SetDesiredServiceDBForPostgres() error { r.ServiceDbPg.Spec.Selector["noobaa-db"] = "postgres" @@ -273,34 +223,19 @@ func (r *Reconciler) SetDesiredServiceDBForPostgres() error { // SetDesiredNooBaaDB updates the NooBaaDB as desired for reconciling func (r *Reconciler) SetDesiredNooBaaDB() error { - var NooBaaDB *appsv1.StatefulSet = nil var NooBaaDBTemplate *appsv1.StatefulSet = nil - if r.NooBaa.Spec.DBType == "postgres" { - NooBaaDB = r.NooBaaPostgresDB - if dbLabels, ok := r.NooBaa.Spec.Labels["db"]; ok { - NooBaaDB.Spec.Template.Labels = dbLabels - } - if dbAnnotations, ok := r.NooBaa.Spec.Annotations["db"]; ok { - NooBaaDB.Spec.Template.Annotations = dbAnnotations - } - NooBaaDB.Spec.Template.Labels["noobaa-db"] = "postgres" - NooBaaDB.Spec.Selector.MatchLabels["noobaa-db"] = "postgres" - NooBaaDB.Spec.ServiceName = r.ServiceDbPg.Name - NooBaaDBTemplate = util.KubeObject(bundle.File_deploy_internal_statefulset_postgres_db_yaml).(*appsv1.StatefulSet) - } else { - NooBaaDB = r.NooBaaMongoDB - if dbLabels, ok := r.NooBaa.Spec.Labels["db"]; ok { - NooBaaDB.Spec.Template.Labels = dbLabels - } - if dbAnnotations, ok := r.NooBaa.Spec.Annotations["db"]; ok { - NooBaaDB.Spec.Template.Annotations = dbAnnotations - } - NooBaaDB.Spec.Template.Labels["noobaa-db"] = r.Request.Name - NooBaaDB.Spec.Selector.MatchLabels["noobaa-db"] = r.Request.Name - NooBaaDB.Spec.ServiceName = r.ServiceDb.Name - NooBaaDBTemplate = util.KubeObject(bundle.File_deploy_internal_statefulset_db_yaml).(*appsv1.StatefulSet) + var NooBaaDB = r.NooBaaPostgresDB + if dbLabels, ok := r.NooBaa.Spec.Labels["db"]; ok { + NooBaaDB.Spec.Template.Labels = dbLabels } + if dbAnnotations, ok := r.NooBaa.Spec.Annotations["db"]; ok { + NooBaaDB.Spec.Template.Annotations = dbAnnotations + } + NooBaaDB.Spec.Template.Labels["noobaa-db"] = "postgres" + NooBaaDB.Spec.Selector.MatchLabels["noobaa-db"] = "postgres" + NooBaaDB.Spec.ServiceName = r.ServiceDbPg.Name + NooBaaDBTemplate = util.KubeObject(bundle.File_deploy_internal_statefulset_postgres_db_yaml).(*appsv1.StatefulSet) podSpec := &NooBaaDB.Spec.Template.Spec podSpec.ServiceAccountName = "noobaa-db" @@ -433,22 +368,13 @@ func (r *Reconciler) setDesiredCoreEnv(c *corev1.Container) { case "AGENT_PROFILE": c.Env[j].Value = r.SetDesiredAgentProfile(c.Env[j].Value) - case "MONGODB_URL": - if r.NooBaa.Spec.MongoDbURL != "" { - c.Env[j].Value = r.NooBaa.Spec.MongoDbURL - } else { - c.Env[j].Value = "mongodb://" + r.NooBaaMongoDB.Name + "-0." + r.NooBaaMongoDB.Spec.ServiceName + "/nbcore" - } - case "POSTGRES_HOST": if r.NooBaa.Spec.ExternalPgSecret == nil { c.Env[j].Value = r.NooBaaPostgresDB.Name + "-0." + r.NooBaaPostgresDB.Spec.ServiceName } case "DB_TYPE": - if r.NooBaa.Spec.DBType == "postgres" { - c.Env[j].Value = "postgres" - } + c.Env[j].Value = "postgres" case "OAUTH_AUTHORIZATION_ENDPOINT": if r.OAuthEndpoints != nil { @@ -460,7 +386,7 @@ func (r *Reconciler) setDesiredCoreEnv(c *corev1.Container) { c.Env[j].Value = r.OAuthEndpoints.TokenEndpoint } case "POSTGRES_USER": - if r.NooBaa.Spec.DBType == "postgres" && r.NooBaa.Spec.ExternalPgSecret == nil { + if r.NooBaa.Spec.ExternalPgSecret == nil { if c.Env[j].Value != "" { c.Env[j].Value = "" } @@ -474,7 +400,7 @@ func (r *Reconciler) setDesiredCoreEnv(c *corev1.Container) { } } case "POSTGRES_PASSWORD": - if r.NooBaa.Spec.DBType == "postgres" && r.NooBaa.Spec.ExternalPgSecret == nil { + if r.NooBaa.Spec.ExternalPgSecret == nil { if c.Env[j].Value != "" { c.Env[j].Value = "" } @@ -488,7 +414,7 @@ func (r *Reconciler) setDesiredCoreEnv(c *corev1.Container) { } } case "POSTGRES_CONNECTION_STRING": - if r.NooBaa.Spec.DBType == "postgres" && r.NooBaa.Spec.ExternalPgSecret != nil { + if r.NooBaa.Spec.ExternalPgSecret != nil { if c.Env[j].Value != "" { c.Env[j].Value = "" } @@ -502,11 +428,11 @@ func (r *Reconciler) setDesiredCoreEnv(c *corev1.Container) { } } case "POSTGRES_SSL_REQUIRED": - if r.NooBaa.Spec.DBType == "postgres" && r.NooBaa.Spec.ExternalPgSSLRequired { + if r.NooBaa.Spec.ExternalPgSSLRequired { c.Env[j].Value = "true" } case "POSTGRES_SSL_UNAUTHORIZED": - if r.NooBaa.Spec.DBType == "postgres" && r.NooBaa.Spec.ExternalPgSSLUnauthorized { + if r.NooBaa.Spec.ExternalPgSSLUnauthorized { c.Env[j].Value = "true" } case "NOOBAA_ROOT_SECRET": @@ -1182,59 +1108,49 @@ func (r *Reconciler) reconcileDBRBAC() error { // ReconcileDB choose between different types of DB func (r *Reconciler) ReconcileDB() error { - var err error if r.NooBaa.Spec.ExternalPgSecret != nil { return nil } - if err = r.reconcileDBRBAC(); err != nil { + if err := r.reconcileDBRBAC(); err != nil { return err } - if r.NooBaa.Spec.DBType == "postgres" { - - // those are config maps required by the NooBaaPostgresDB StatefulSet, - // if the configMap was not created at this step, NooBaaPostgresDB - // would fail to start. - - isDBInitUpdated, reconcileDbError := r.ReconcileDBConfigMap(r.PostgresDBInitDb, r.SetDesiredPostgresDBInitDb) - if reconcileDbError != nil { - return reconcileDbError - } + // those are config maps required by the NooBaaPostgresDB StatefulSet, + // if the configMap was not created at this step, NooBaaPostgresDB + // would fail to start. - isDBConfUpdated, reconcileDbError := r.ReconcileDBConfigMap(r.PostgresDBConf, r.SetDesiredPostgresDBConf) - if reconcileDbError != nil { - return reconcileDbError - } + isDBInitUpdated, reconcileDbError := r.ReconcileDBConfigMap(r.PostgresDBInitDb, r.SetDesiredPostgresDBInitDb) + if reconcileDbError != nil { + return reconcileDbError + } - phase := r.NooBaa.Status.PostgresUpdatePhase - // during postgres upgrade, don't reconcile DB - if phase != nbv1.UpgradePhaseFinished && phase != nbv1.UpgradePhaseNone { - r.Logger.Infof("during postgres db upgrade") - return nil - } + isDBConfUpdated, reconcileDbError := r.ReconcileDBConfigMap(r.PostgresDBConf, r.SetDesiredPostgresDBConf) + if reconcileDbError != nil { + return reconcileDbError + } - result, reconcilePostgresError := r.reconcileObjectAndGetResult(r.NooBaaPostgresDB, r.SetDesiredNooBaaDB, false) - if reconcilePostgresError != nil { - return reconcilePostgresError - } - if !r.isObjectUpdated(result) && (isDBInitUpdated || isDBConfUpdated) { - r.Logger.Warn("One of the db configMap was updated but not postgres db") - restartError := r.RestartDbPods() - if restartError != nil { - r.Logger.Warn("Unable to restart db pods") - } + phase := r.NooBaa.Status.PostgresUpdatePhase + // during postgres upgrade, don't reconcile DB + if phase != nbv1.UpgradePhaseFinished && phase != nbv1.UpgradePhaseNone { + r.Logger.Infof("during postgres db upgrade") + return nil + } + result, reconcilePostgresError := r.reconcileObjectAndGetResult(r.NooBaaPostgresDB, r.SetDesiredNooBaaDB, false) + if reconcilePostgresError != nil { + return reconcilePostgresError + } + if !r.isObjectUpdated(result) && (isDBInitUpdated || isDBConfUpdated) { + r.Logger.Warn("One of the db configMap was updated but not postgres db") + restartError := r.RestartDbPods() + if restartError != nil { + r.Logger.Warn("Unable to restart db pods") } - // Making sure that previous CRs without the value will deploy MongoDB - } else if r.NooBaa.Spec.DBType == "" || r.NooBaa.Spec.DBType == "mongodb" { - err = r.ReconcileObject(r.NooBaaMongoDB, r.SetDesiredNooBaaDB) - } else { - err = util.NewPersistentError("UnknownDBType", "Unknown dbType is specified in NooBaa spec") } - return err + return nil } // ReconcileDBConfigMap reconcile provided postgres db config map @@ -1287,280 +1203,6 @@ func (r *Reconciler) RestartDbPods() error { return nil } -// UpgradeSplitDB removes the old pvc and create a new one with the same PV -func (r *Reconciler) UpgradeSplitDB() error { - oldPvc := &corev1.PersistentVolumeClaim{ - TypeMeta: metav1.TypeMeta{Kind: "PersistentVolumeClaim"}, - ObjectMeta: metav1.ObjectMeta{ - Name: "db-noobaa-core-0", - Namespace: options.Namespace, - }, - } - if util.KubeCheckQuiet(oldPvc) { - r.Logger.Infof("UpgradeSplitDB: Old OVC found, upgrading...") - if err := r.UpgradeSplitDBSetReclaimPolicy(oldPvc, corev1.PersistentVolumeReclaimRetain); err != nil { - return err - } - if err := r.UpgradeSplitDBCreateNewPVC(oldPvc); err != nil { - return err - } - if err := r.UpgradeSplitDBSetReclaimPolicy(oldPvc, corev1.PersistentVolumeReclaimDelete); err != nil { - return err - } - if err := r.UpgradeSplitDBDeleteOldSTS(); err != nil { - return err - } - if err := r.UpgradeSplitDBDeleteOldPVC(oldPvc); err != nil { - return err - } - } - return nil -} - -// UpgradeSplitDBSetReclaimPolicy sets the reclaim policy to reclaim parameter and checks it -func (r *Reconciler) UpgradeSplitDBSetReclaimPolicy(oldPvc *corev1.PersistentVolumeClaim, reclaim corev1.PersistentVolumeReclaimPolicy) error { - pv := &corev1.PersistentVolume{ - TypeMeta: metav1.TypeMeta{Kind: "PersistentVolume"}, - ObjectMeta: metav1.ObjectMeta{Name: oldPvc.Spec.VolumeName}, - } - if !util.KubeCheck(pv) { - return fmt.Errorf("UpgradeSplitDBSetReclaimPolicy(%s): PV not found", reclaim) - } - if pv.Spec.PersistentVolumeReclaimPolicy != reclaim { - pv.Spec.PersistentVolumeReclaimPolicy = reclaim - if pv.Spec.ClaimRef != nil && - pv.Spec.ClaimRef.Name == oldPvc.Name && - pv.Spec.ClaimRef.Namespace == oldPvc.Namespace { - pv.Spec.ClaimRef = nil - } - util.KubeUpdate(pv) - if !util.KubeCheck(pv) { - return fmt.Errorf("UpgradeSplitDBSetReclaimPolicy(%s): PV not found after update", reclaim) - } - if pv.Spec.PersistentVolumeReclaimPolicy != reclaim { - return fmt.Errorf("UpgradeSplitDBSetReclaimPolicy(%s): PV reclaim policy could not be updated", reclaim) - } - } - return nil -} - -// UpgradeSplitDBCreateNewPVC creates new pvc and checks it -func (r *Reconciler) UpgradeSplitDBCreateNewPVC(oldPvc *corev1.PersistentVolumeClaim) error { - newPvc := &corev1.PersistentVolumeClaim{ - TypeMeta: metav1.TypeMeta{Kind: "PersistentVolumeClaim"}, - ObjectMeta: metav1.ObjectMeta{ - Name: "db-" + r.NooBaaMongoDB.Name + "-0", - Namespace: options.Namespace, - }, - Spec: oldPvc.Spec, - } - util.KubeCreateSkipExisting(newPvc) - time.Sleep(2 * time.Second) - if !util.KubeCheck(newPvc) { - return fmt.Errorf("UpgradeSplitDBCreateNewPVC: New PVC not found") - } - if newPvc.Status.Phase != corev1.ClaimBound { - return fmt.Errorf("UpgradeSplitDBCreateNewPVC: New PVC not bound yet") - } - if newPvc.Spec.VolumeName != oldPvc.Spec.VolumeName { - // TODO how to recover?? since this is not expected maybe just return persistent error and wait for manual fix - return fmt.Errorf("UpgradeSplitDBCreateNewPVC: New PVC bound to another PV") - } - return nil -} - -// UpgradeSplitDBDeleteOldSTS deletes old STS named noobaa-core and checks it -func (r *Reconciler) UpgradeSplitDBDeleteOldSTS() error { - oldSts := &appsv1.StatefulSet{ - TypeMeta: metav1.TypeMeta{Kind: "StatefulSet"}, - ObjectMeta: metav1.ObjectMeta{ - Name: "noobaa-core", - Namespace: options.Namespace, - }, - } - util.KubeDelete(oldSts) - if util.KubeCheck(oldSts) { - return fmt.Errorf("UpgradeSplitDBDeleteOldSTS: Old STS still exists") - } - return nil -} - -// UpgradeSplitDBDeleteOldPVC deletes the parameter oldPvc and checks it -func (r *Reconciler) UpgradeSplitDBDeleteOldPVC(oldPVC *corev1.PersistentVolumeClaim) error { - util.KubeDelete(oldPVC) - if util.KubeCheck(oldPVC) { - return fmt.Errorf("UpgradeSplitDBDeleteOldPVC: Old PVC still exists") - } - return nil -} - -// UpgradeMigrateDB performs a db upgrade between mongodb to postgres -func (r *Reconciler) UpgradeMigrateDB() error { - phase := r.NooBaa.Status.UpgradePhase - if phase == nbv1.UpgradePhaseFinished || phase == nbv1.UpgradePhaseNone { - return nil - } - - r.Logger.Infof("UpgradeMigrateDB: upgrade phase - %s", phase) - mongoSts := &appsv1.StatefulSet{ - TypeMeta: metav1.TypeMeta{Kind: "StatefulSet"}, - ObjectMeta: metav1.ObjectMeta{ - Name: "noobaa-db", - Namespace: options.Namespace, - }, - } - - mongoExists := util.KubeCheck(mongoSts) - - switch phase { - - case "": - if mongoExists { - r.Logger.Infof("UpgradeMigrateDB: setting phase to %s", nbv1.UpgradePhasePrepare) - phase = nbv1.UpgradePhasePrepare - } else { - // no mongo STS. skip migration - r.Logger.Info("Old (mongo) STS was not found. skipping migration") - phase = nbv1.UpgradePhaseNone - } - - case nbv1.UpgradePhasePrepare: - r.Logger.Infof("UpgradeMigrateDB:: prepare phase") - - // update mongo sts with the new noobaa-core image as the init container image - r.Logger.Infof("UpgradeMigrateDB:: updating mongo STS init container") - if err := r.ReconcileObject(mongoSts, func() error { // remove old sts pods when finish migrating - podSpec := &mongoSts.Spec.Template.Spec - podSpec.ServiceAccountName = "noobaa" - for i := range podSpec.Containers { - c := &podSpec.Containers[i] - if c.Name == "db" { - r.Logger.Infof("UpgradeMigrateDB:: setting mongo image to %v", options.DBMongoImage) - c.Image = options.DBMongoImage - } - } - - defaultUID := int64(10001) - defaulfGID := int64(0) - podSpec.SecurityContext.RunAsUser = &defaultUID - podSpec.SecurityContext.RunAsGroup = &defaulfGID - - return nil - }); err != nil { - r.Logger.Errorf("got error on mongo STS reconcile %v", err) - return err - } - - // when starting - restart the db pod. This is a fix for https://bugzilla.redhat.com/show_bug.cgi?id=1922113 - r.Logger.Info("getting noobaa-db-0 pod and restarting it if needed") - dbPod := &corev1.Pod{} - err := r.Client.Get(r.Ctx, types.NamespacedName{Namespace: options.Namespace, Name: "noobaa-db-0"}, dbPod) - if err != nil { - r.Logger.Errorf("got error when trying to get noobaa-db-0 pod - %v", err) - return err - } - if dbPod.Spec.Containers[0].Image != options.DBMongoImage { - r.Logger.Info("identified incorrect DB image - deleting noobaa-db-0 pod ") - err = r.Client.Delete(r.Ctx, dbPod) - if err != nil { - r.Logger.Errorf("got error on deletion of noobaa-db-0 pod") - return err - } - } - - // remove endpoints pods. set replicas to 0 - // setting the deployment's replica count to 0 should disable the HPA - // https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale/#implicit-maintenance-mode-deactivation - if err := r.SetEndpointsDeploymentReplicas(0); err != nil { - r.Logger.Errorf("UpgradeMigrateDB::got error on endpoints deployment reconcile %v", err) - return err - } - - // wait for endpoints and core pods to stop - corePodList := &corev1.PodList{} - corePodSelector, _ := labels.Parse("noobaa-core=" + r.Request.Name) - epPodList := &corev1.PodList{} - epPodSelector, _ := labels.Parse("noobaa-s3=" + r.Request.Name) - if util.KubeList(epPodList, &client.ListOptions{Namespace: options.Namespace, LabelSelector: epPodSelector}) && - util.KubeList(corePodList, &client.ListOptions{Namespace: options.Namespace, LabelSelector: corePodSelector}) && - (len(corePodList.Items) == 0 && len(epPodList.Items) == 0) && - (mongoSts.Status.ReadyReplicas == 1 && r.NooBaaPostgresDB.Status.ReadyReplicas == 1) { - r.Logger.Infof("UpgradeMigrateDB:: system is ready for migration. setting phase to %s", nbv1.UpgradePhaseMigrate) - phase = nbv1.UpgradePhaseMigrate - } else { - r.Logger.Infof("UpgradeMigrateDB:: system not fully ready for migrate") - return fmt.Errorf("system not fully ready for migrate") - } - - case nbv1.UpgradePhaseMigrate: - r.Logger.Infof("UpgradeMigrateDB:: data migration phase") - - r.Logger.Infof("UpgradeMigrateDB:: reconciling migration job") - if err := r.ReconcileObject(r.UpgradeJob, r.SetDesiredJobUpgradeDB); err != nil { - return err - } - if r.UpgradeJob.Status.Succeeded > 0 { - r.Logger.Infof("UpgradeMigrateDB:: migration completed successfuly. setting phase to %s", nbv1.UpgradePhaseClean) - phase = nbv1.UpgradePhaseClean - } else if r.UpgradeJob.Status.Failed > upgradeJobBackoffLimit { - r.Logger.Errorf("migration failed. upgrade job exceeded the backoff limit of %d. manually delete the job %q to retry", - upgradeJobBackoffLimit, r.UpgradeJob.Name) - } else { - r.Logger.Infof("UpgradeMigrateDB:: migration not finished yet") - return fmt.Errorf("job didn't finish yet") - } - - case nbv1.UpgradePhaseClean: - r.Logger.Infof("UpgradeMigrateDB:: cleanup phase") - - r.Logger.Infof("UpgradeMigrateDB:: deleting mongodb STS") - if err := r.Client.Delete(r.Ctx, mongoSts); err != nil && !errors.IsNotFound(err) { - r.Logger.Errorf("got error on mongo sts deletion: %v", err) - return err - } - - oldDbPodList := &corev1.PodList{} - oldDbPodSelector, _ := labels.Parse("noobaa-db=" + r.Request.Name) - if !util.KubeList(oldDbPodList, &client.ListOptions{Namespace: options.Namespace, LabelSelector: oldDbPodSelector}) { - return nil - } - if len(oldDbPodList.Items) == 0 { - r.Logger.Infof("UpgradeMigrateDB:: mongo pod terminated") - } else { - r.Logger.Infof("UpgradeMigrateDB:: mongo pod is still running. waiting for termination") - return fmt.Errorf("mongo is still alive") - } - - if util.KubeCheckQuiet(r.ServiceDb) { - r.Logger.Infof("UpgradeMigrateDB:: deleting mongodb service") - - if err := r.Client.Delete(r.Ctx, r.ServiceDb); err != nil && !errors.IsNotFound(err) { - r.Logger.Errorf("got error on mongo service deletion: %v", err) - return err - } - } - // set endpoints replica count to 1. this should enable HPA back again - if err := r.SetEndpointsDeploymentReplicas(1); err != nil { - r.Logger.Errorf("UpgradeMigrateDB::got error on endpoints deployment reconcile %v", err) - return err - } - - if err := r.CleanupMigrationJob(); err != nil { - return err - } - - r.Logger.Infof("UpgradeMigrateDB:: Completed migration to postgres. setting upgrade phase to DoneUpgrade") - phase = nbv1.UpgradePhaseFinished - - } - - r.NooBaa.Status.UpgradePhase = phase - if err := r.UpdateStatus(); err != nil { - return err - } - return nil -} - // ReconcileSetDbImageAndInitCode changes postgres image and upgrade-db command script func (r *Reconciler) ReconcileSetDbImageAndInitCode(targetImage string, initScript string, addInit bool) error { r.Logger.Infof("ReconcileSetDbImageAndInitCode:: changing DB image: %s and init contatiners script: %s", @@ -1657,10 +1299,8 @@ func (r *Reconciler) UpgradePostgresDB() error { r.Logger.Infof("UpgradePostgresDB: annotation for retrying the upgrade was set, restarting upgrade") fallthrough case "": - sts := util.KubeObject(bundle.File_deploy_internal_statefulset_db_yaml).(*appsv1.StatefulSet) - if r.NooBaa.Spec.DBType == "postgres" { - sts.Name = "noobaa-db-pg" - } + sts := util.KubeObject(bundle.File_deploy_internal_statefulset_postgres_db_yaml).(*appsv1.StatefulSet) + sts.Name = "noobaa-db-pg" sts.Namespace = options.Namespace //postgres database doesn't exists, no need to upgrade. if !util.KubeCheckQuiet(sts) { @@ -1854,53 +1494,6 @@ func (r *Reconciler) removeUpgradeContainer() error { return nil } -// CleanupMigrationJob deletes the migration job and all its pods -func (r *Reconciler) CleanupMigrationJob() error { - - // delete the migration job - r.Logger.Infof("UpgradeMigrateDB:: deleting migration job") - if err := r.Client.Delete(r.Ctx, r.UpgradeJob); err != nil { - r.Logger.Errorf("UpgradeMigrateDB:: got error on migration job deletion: %v", err) - return err - } - - // it seems that completed pods are not delete after job deletion. delete all job pods explicitly - r.Logger.Infof("UpgradeMigrateDB:: deleting migration job pods") - jobPods := &corev1.PodList{} - jobPodsSelector, _ := labels.Parse("job-name=" + r.UpgradeJob.Name) - if !util.KubeList(jobPods, &client.ListOptions{Namespace: options.Namespace, LabelSelector: jobPodsSelector}) { - return nil - } - - hadErrors := false - for _, pod := range jobPods.Items { - if err := r.Client.Delete(r.Ctx, &pod); err != nil && !errors.IsNotFound(err) { - r.Logger.Errorf("got error on pod %v deletion. %v", pod.Name, err) - hadErrors = true - } - } - if hadErrors { - return fmt.Errorf("had errors in migration job pods deletion") - } - - return nil - -} - -// SetDesiredJobUpgradeDB updates the UpgradeJob as desired for reconciling -func (r *Reconciler) SetDesiredJobUpgradeDB() error { - backoffLimit := upgradeJobBackoffLimit - r.UpgradeJob.Spec.Template.Spec.Containers[0].Image = r.NooBaa.Status.ActualImage - r.UpgradeJob.Spec.Template.Spec.Containers[0].Command = []string{"/noobaa_init_files/noobaa_init.sh", "db_migrate"} - r.setDesiredCoreEnv(&r.UpgradeJob.Spec.Template.Spec.Containers[0]) - - // setting the restart policy to never to keep the pods around after failed migrations - // also reducing the backoff limit to avoid to many pods staying around in case of an issue - r.UpgradeJob.Spec.Template.Spec.RestartPolicy = corev1.RestartPolicyNever - r.UpgradeJob.Spec.BackoffLimit = &backoffLimit - return nil -} - // SetEndpointsDeploymentReplicas updates the number of replicas on the endpoints deployment func (r *Reconciler) SetEndpointsDeploymentReplicas(replicas int32) error { r.Logger.Infof("SetEndpointsDeploymentReplicas:: setting endpoints replica count to %d", replicas) diff --git a/pkg/system/phase4_configuring.go b/pkg/system/phase4_configuring.go index d089d0647..c898ba592 100644 --- a/pkg/system/phase4_configuring.go +++ b/pkg/system/phase4_configuring.go @@ -356,10 +356,6 @@ func (r *Reconciler) SetDesiredDeploymentEndpoint() error { } else { c.Env[j].Value = r.JoinSecret.StringData["hosted_agents_addr"] } - case "MONGODB_URL": - if r.JoinSecret == nil { - c.Env[j].Value = r.MongoConnectionString - } case "LOCAL_MD_SERVER": if r.JoinSecret == nil { c.Env[j].Value = "true" diff --git a/pkg/system/reconciler.go b/pkg/system/reconciler.go index eb0490ab6..a0fbe4433 100644 --- a/pkg/system/reconciler.go +++ b/pkg/system/reconciler.go @@ -26,7 +26,6 @@ import ( "github.com/sirupsen/logrus" appsv1 "k8s.io/api/apps/v1" autoscalingv2 "k8s.io/api/autoscaling/v2" - batchv1 "k8s.io/api/batch/v1" corev1 "k8s.io/api/core/v1" storagev1 "k8s.io/api/storage/v1" "k8s.io/apimachinery/pkg/api/meta" @@ -66,7 +65,6 @@ type Reconciler struct { CoreVersion string OperatorVersion string OAuthEndpoints *util.OAuth2Endpoints - MongoConnectionString string PostgresConnectionString string ApplyCAsToPods string @@ -75,7 +73,6 @@ type Reconciler struct { CoreApp *appsv1.StatefulSet CoreAppConfig *corev1.ConfigMap DefaultCoreApp *corev1.Container - NooBaaMongoDB *appsv1.StatefulSet PostgresDBConf *corev1.ConfigMap PostgresDBInitDb *corev1.ConfigMap NooBaaPostgresDB *appsv1.StatefulSet @@ -115,7 +112,6 @@ type Reconciler struct { DeploymentEndpoint *appsv1.Deployment DefaultDeploymentEndpoint *corev1.PodSpec JoinSecret *corev1.Secret - UpgradeJob *batchv1.Job CaBundleConf *corev1.ConfigMap KedaTriggerAuthentication *kedav1alpha1.TriggerAuthentication KedaScaled *kedav1alpha1.ScaledObject @@ -145,7 +141,6 @@ func NewReconciler( ServiceAccount: util.KubeObject(bundle.File_deploy_service_account_yaml).(*corev1.ServiceAccount), CoreApp: util.KubeObject(bundle.File_deploy_internal_statefulset_core_yaml).(*appsv1.StatefulSet), CoreAppConfig: util.KubeObject(bundle.File_deploy_internal_configmap_empty_yaml).(*corev1.ConfigMap), - NooBaaMongoDB: util.KubeObject(bundle.File_deploy_internal_statefulset_db_yaml).(*appsv1.StatefulSet), PostgresDBConf: util.KubeObject(bundle.File_deploy_internal_configmap_postgres_db_yaml).(*corev1.ConfigMap), PostgresDBInitDb: util.KubeObject(bundle.File_deploy_internal_configmap_postgres_initdb_yaml).(*corev1.ConfigMap), NooBaaPostgresDB: util.KubeObject(bundle.File_deploy_internal_statefulset_postgres_db_yaml).(*appsv1.StatefulSet), @@ -178,7 +173,6 @@ func NewReconciler( RouteS3: util.KubeObject(bundle.File_deploy_internal_route_s3_yaml).(*routev1.Route), RouteSts: util.KubeObject(bundle.File_deploy_internal_route_sts_yaml).(*routev1.Route), DeploymentEndpoint: util.KubeObject(bundle.File_deploy_internal_deployment_endpoint_yaml).(*appsv1.Deployment), - UpgradeJob: util.KubeObject(bundle.File_deploy_internal_job_upgrade_db_yaml).(*batchv1.Job), CaBundleConf: util.KubeObject(bundle.File_deploy_internal_configmap_ca_inject_yaml).(*corev1.ConfigMap), KedaTriggerAuthentication: util.KubeObject(bundle.File_deploy_internal_hpa_keda_trigger_authentication_yaml).(*kedav1alpha1.TriggerAuthentication), KedaScaled: util.KubeObject(bundle.File_deploy_internal_hpa_keda_scaled_object_yaml).(*kedav1alpha1.ScaledObject), @@ -190,7 +184,6 @@ func NewReconciler( r.ServiceAccount.Namespace = r.Request.Namespace r.CoreApp.Namespace = r.Request.Namespace r.CoreAppConfig.Namespace = r.Request.Namespace - r.NooBaaMongoDB.Namespace = r.Request.Namespace r.PostgresDBConf.Namespace = r.Request.Namespace r.PostgresDBInitDb.Namespace = r.Request.Namespace r.NooBaaPostgresDB.Namespace = r.Request.Namespace @@ -225,7 +218,6 @@ func NewReconciler( r.RouteS3.Namespace = r.Request.Namespace r.RouteSts.Namespace = r.Request.Namespace r.DeploymentEndpoint.Namespace = r.Request.Namespace - r.UpgradeJob.Namespace = r.Request.Namespace r.CaBundleConf.Namespace = r.Request.Namespace r.KedaTriggerAuthentication.Namespace = r.Request.Namespace r.KedaScaled.Namespace = r.Request.Namespace @@ -236,7 +228,6 @@ func NewReconciler( r.ServiceAccount.Name = r.Request.Name r.CoreApp.Name = r.Request.Name + "-core" r.CoreAppConfig.Name = "noobaa-config" - r.NooBaaMongoDB.Name = r.Request.Name + "-db" r.NooBaaPostgresDB.Name = r.Request.Name + "-db-pg" r.ServiceMgmt.Name = r.Request.Name + "-mgmt" r.ServiceSyslog.Name = "noobaa-syslog" @@ -269,7 +260,6 @@ func NewReconciler( r.RouteS3.Name = r.ServiceS3.Name r.RouteSts.Name = r.ServiceSts.Name r.DeploymentEndpoint.Name = r.Request.Name + "-endpoint" - r.UpgradeJob.Name = r.Request.Name + "-upgrade-job" r.CaBundleConf.Name = r.Request.Name + "-ca-inject" r.KedaScaled.Name = r.Request.Name r.AdapterHPA.Name = r.Request.Name + "-hpav2" @@ -313,18 +303,13 @@ func (r *Reconciler) CheckAll() { util.KubeCheck(r.ServiceS3) util.KubeCheck(r.ServiceSts) util.KubeCheck(r.ServiceSyslog) - if r.NooBaa.Spec.MongoDbURL == "" && r.NooBaa.Spec.ExternalPgSecret == nil { - if r.NooBaa.Spec.DBType == "postgres" { - util.KubeCheck(r.SecretDB) - if r.NooBaa.Spec.ExternalPgSecret == nil { - util.KubeCheck(r.PostgresDBConf) - util.KubeCheck(r.PostgresDBInitDb) - util.KubeCheck(r.NooBaaPostgresDB) - util.KubeCheck(r.ServiceDbPg) - } - } else { - util.KubeCheck(r.NooBaaMongoDB) - util.KubeCheck(r.ServiceDb) + if r.NooBaa.Spec.ExternalPgSecret == nil { + util.KubeCheck(r.SecretDB) + if r.NooBaa.Spec.ExternalPgSecret == nil { + util.KubeCheck(r.PostgresDBConf) + util.KubeCheck(r.PostgresDBInitDb) + util.KubeCheck(r.NooBaaPostgresDB) + util.KubeCheck(r.ServiceDbPg) } } util.KubeCheck(r.SecretServer) diff --git a/pkg/system/system.go b/pkg/system/system.go index dbe0f5a76..3bad159be 100644 --- a/pkg/system/system.go +++ b/pkg/system/system.go @@ -171,11 +171,6 @@ func LoadSystemDefaults() *nbv1.NooBaa { dbImage := options.DBImage sys.Spec.DBImage = &dbImage } - // naively changing the db postgres image to the hardcoded one if the db type is postgres - if options.DBType == "postgres" { - dbPostgresImage := options.DBPostgresImage - sys.Spec.DBImage = &dbPostgresImage - } if options.DBVolumeSizeGB != 0 { sys.Spec.DBVolumeResources = &corev1.ResourceRequirements{ Requests: corev1.ResourceList{ @@ -187,10 +182,6 @@ func LoadSystemDefaults() *nbv1.NooBaa { sc := options.DBStorageClass sys.Spec.DBStorageClass = &sc } - if options.MongoDbURL != "" { - mongoDbURL := options.MongoDbURL - sys.Spec.MongoDbURL = mongoDbURL - } if options.PostgresDbURL != "" { sys.Spec.ExternalPgSecret = &corev1.SecretReference{ Name: "noobaa-external-pg-db", @@ -389,23 +380,12 @@ func RunCreate(cmd *cobra.Command, args []string) { util.Panic(json.Unmarshal([]byte(endpointResourcesJSON), &sys.Spec.Endpoints.Resources)) } - err := CheckMongoURL(sys) - if err != nil { - log.Fatalf(`❌ %s`, err) - } - if options.PostgresDbURL != "" { - if sys.Spec.MongoDbURL != "" { - log.Fatalf("❌ Can't use both options: postgres-url and mongodb-url, please use only one") - } - if sys.Spec.DBType != "postgres" { - log.Fatalf("❌ expecting the DBType to be postgres when using external PostgresDbURL, got %s", sys.Spec.DBType) - } if (options.PostgresSSLCert != "" && options.PostgresSSLKey == "") || (options.PostgresSSLCert == "" && options.PostgresSSLKey != "") { log.Fatalf("❌ Can't provide only ssl-cert or only ssl-key - please provide both!") } - err = CheckPostgresURL(options.PostgresDbURL) + err := CheckPostgresURL(options.PostgresDbURL) if err != nil { log.Fatalf(`❌ %s`, err) } @@ -505,7 +485,6 @@ func RunDelete(cmd *cobra.Command, args []string) { } } - isMongoDbURL := sys.Spec.MongoDbURL util.KubeDelete(sys) if sys.Spec.ExternalPgSecret != nil { @@ -516,23 +495,6 @@ func RunDelete(cmd *cobra.Command, args []string) { }, } util.KubeDelete(secret) - } else if isMongoDbURL == "" { - // NoobaaDB - noobaaDB := util.KubeObject(bundle.File_deploy_internal_statefulset_db_yaml).(*appsv1.StatefulSet) - if sys.Spec.DBType == "postgres" { - noobaaDB = util.KubeObject(bundle.File_deploy_internal_statefulset_postgres_db_yaml).(*appsv1.StatefulSet) - } - for i := range noobaaDB.Spec.VolumeClaimTemplates { - t := &noobaaDB.Spec.VolumeClaimTemplates[i] - pvc := &corev1.PersistentVolumeClaim{ - TypeMeta: metav1.TypeMeta{Kind: "PersistentVolumeClaim"}, - ObjectMeta: metav1.ObjectMeta{ - Name: t.Name + "-" + noobaaDB.Name + "-0", - Namespace: options.Namespace, - }, - } - util.KubeDelete(pvc) - } } backingStores := &nbv1.BackingStoreList{} util.KubeList(backingStores, &client.ListOptions{Namespace: options.Namespace}) @@ -692,10 +654,8 @@ func CheckNooBaaDBImages(cmd *cobra.Command, sys *nbv1.NooBaa, args []string) st if sys.Spec.DBImage != nil { desiredImage = *sys.Spec.DBImage } - sts := util.KubeObject(bundle.File_deploy_internal_statefulset_db_yaml).(*appsv1.StatefulSet) - if sys.Spec.DBType == "postgres" { - sts.Name = "noobaa-db-pg" - } + sts := util.KubeObject(bundle.File_deploy_internal_statefulset_postgres_db_yaml).(*appsv1.StatefulSet) + sts.Name = "noobaa-db-pg" sts.Namespace = options.Namespace if util.KubeCheckQuiet(sts) { runningImage = sts.Spec.Template.Spec.Containers[0].Image @@ -739,11 +699,7 @@ func RunSystemVersionsStatus(cmd *cobra.Command, args []string) { noobaaOperatorImage = CheckOperatorImage(cmd, args) } else { noobaaImage = options.NooBaaImage - if options.DBType == "postgres" { - noobaaDbImage = options.DBPostgresImage - } else { - noobaaDbImage = options.DBImage - } + noobaaDbImage = options.DBImage noobaaOperatorImage = options.OperatorImage } @@ -763,14 +719,9 @@ func RunStatus(cmd *cobra.Command, args []string) { sysKey := client.ObjectKey{Namespace: options.Namespace, Name: options.SystemName} r := NewReconciler(sysKey, klient, scheme.Scheme, nil) r.CheckAll() - var NooBaaDB *appsv1.StatefulSet = nil - if r.NooBaa.Spec.DBType == "postgres" { - NooBaaDB = r.NooBaaPostgresDB - } else { - NooBaaDB = r.NooBaaMongoDB - } - // create the mongo db only if mongo db url is not given. - if r.NooBaa.Spec.MongoDbURL == "" && r.NooBaa.Spec.ExternalPgSecret == nil { + var NooBaaDB *appsv1.StatefulSet = r.NooBaaPostgresDB + + if r.NooBaa.Spec.ExternalPgSecret == nil { // NoobaaDB for i := range NooBaaDB.Spec.VolumeClaimTemplates { t := &NooBaaDB.Spec.VolumeClaimTemplates[i] @@ -1201,40 +1152,9 @@ func CheckSystem(sys *nbv1.NooBaa) bool { sys.Status.Services = &nbv1.ServicesStatus{} } - // a hack to better set the DBType in cases where DBType is not set. - // if dbtype is not set, try to infer it from the db image. this only update dbtype in memory - if sys.Spec.DBType == "" { - dbImage := GetDesiredDBImage(sys) - if strings.Contains(dbImage, "postgres") { - log.Infof("dbType was not supplied. according to image (%s) setting dbType to postgres", dbImage) - sys.Spec.DBType = "postgres" - } else { - if strings.Contains(dbImage, "mongo") { - log.Infof("dbType was not supplied. according to image (%s) setting dbType to mongodb", dbImage) - } else { - log.Warnf("dbType was not supplied and it cannot be guessed from from the dbImage (%s). setting dbType to mongodb", dbImage) - } - sys.Spec.DBType = "mongodb" - } - } - return found && sys.UID != "" } -// CheckMongoURL checks if the mongourl structure is valid and if we use mongo as db -func CheckMongoURL(sys *nbv1.NooBaa) error { - if sys.Spec.MongoDbURL != "" { - if sys.Spec.DBType != "mongodb" { - return fmt.Errorf("expecting the DBType to be mongodb when using external MongoDbURL, got %s", sys.Spec.DBType) - } - if !strings.Contains(sys.Spec.MongoDbURL, "mongodb://") && - !strings.Contains(sys.Spec.MongoDbURL, "mongodb+srv://") { - return fmt.Errorf("invalid mongo db url %s, expecting the url to start with mongodb:// or mongodb+srv://", sys.Spec.MongoDbURL) - } - } - return nil -} - // CheckPostgresURL checks if the postgresurl structure is valid and if we use postgres as db func CheckPostgresURL(postgresDbURL string) error { // This is temporary checks - In next PRs we will change to psql client checks instead diff --git a/test/cli/test_cli_flow.sh b/test/cli/test_cli_flow.sh index 5d579acff..aa35cc334 100755 --- a/test/cli/test_cli_flow.sh +++ b/test/cli/test_cli_flow.sh @@ -66,7 +66,6 @@ function usage { set +x echo -e "\nUsage: ${0} [options]" echo "--namespace - Change the namespace (default: ${NAMESPACE})" - echo "--mongo-image - Change the mongo image" echo "--noobaa-image - Change the noobaa image" echo "--operator-image - Change the operator image" echo "--check_core_config_map - Check Only core config map" @@ -75,11 +74,6 @@ function usage { } function set_nonstandard_options { - if [ ! -z ${MONGO_IMAGE} ] - then - noobaa+=" --mongo-image ${MONGO_IMAGE}" - fi - if [ ! -z ${NOOBAA_IMAGE} ] then noobaa+=" --noobaa-image ${NOOBAA_IMAGE}" @@ -98,8 +92,6 @@ do fi case ${1} in - --mongo-image) MONGO_IMAGE=${2} - shift 2;; --noobaa-image) NOOBAA_IMAGE=${2} shift 2;; --operator-image) OPERATOR_IMAGE=${2}