From fb2b8067d12bf46e208e8601660652a26663ab3e Mon Sep 17 00:00:00 2001 From: Igor Karpukhin Date: Thu, 19 Oct 2023 15:58:32 +0200 Subject: [PATCH 1/8] Removed legacy deployment --- .github/workflows/test-e2e.yml | 11 + .../atlas.mongodb.com_atlasdeployments.yaml | 511 +++++------------- config/rbac/clusterwide/role.yaml | 4 +- config/rbac/namespaced/role.yaml | 4 +- .../atlas.mongodb.com_atlasdeployments.yaml | 511 +++++------------- helm-charts | 2 +- pkg/api/v1/atlasdeployment_types.go | 356 +++++------- pkg/api/v1/atlasdeployment_types_test.go | 177 +++--- pkg/api/v1/zz_generated.deepcopy.go | 157 ------ .../atlasdeployment/advanced_deployment.go | 16 +- .../advanced_deployment_test.go | 15 +- .../atlasdeployment_controller.go | 31 +- .../atlasdeployment_controller_test.go | 63 +-- pkg/controller/atlasdeployment/backup_test.go | 2 +- pkg/controller/atlasdeployment/deployment.go | 183 ------- .../atlasdeployment/deployment_test.go | 166 +++--- pkg/controller/validate/validate.go | 38 +- pkg/controller/validate/validate_test.go | 113 ++-- scripts/e2e_local.sh | 2 +- test/e2e/actions/deploy/deploy_operator.go | 4 + test/e2e/actions/helm_related.go | 4 +- test/e2e/actions/steps.go | 104 ++-- test/e2e/atlas_gov_test.go | 2 +- test/e2e/backup_config_test.go | 2 +- test/e2e/configuration_test.go | 4 +- .../data/atlasdeployment_advanced_helm.yaml | 8 +- ...deployment_advanced_multi_region_helm.yaml | 2 +- test/e2e/data/atlasdeployment_backup.yaml | 17 +- .../data/atlasdeployment_backup_update.yaml | 17 +- ...eployment_backup_update_remove_backup.yaml | 17 +- test/e2e/data/atlasdeployment_basic.yaml | 15 +- test/e2e/data/atlasdeployment_basic_free.yaml | 15 +- test/e2e/data/atlasdeployment_basic_helm.yaml | 15 +- .../data/atlasdeployment_basic_update.yaml | 15 +- ...yment_basic_with_keep_resource_policy.yaml | 15 +- .../data/atlasdeployment_multiregion_aws.yaml | 30 +- ...tlasdeployment_multiregion_aws_update.yaml | 26 +- .../atlasdeployment_multiregion_azure.yaml | 30 +- ...asdeployment_multiregion_azure_update.yaml | 27 +- .../data/atlasdeployment_multiregion_gcp.yaml | 29 +- ...oyment_multiregion_multicloud_gcp_aws.yaml | 29 + test/e2e/data/atlasdeployment_standard.yaml | 15 +- test/e2e/data/deployments.go | 203 +++---- test/e2e/free_tier_test.go | 2 +- test/e2e/global_deployment_test.go | 27 - test/e2e/helm_chart_test.go | 14 +- test/e2e/model/deployment.go | 3 - test/int/backup_protected_test.go | 2 +- test/int/deployment_test.go | 355 +++++++----- 49 files changed, 1272 insertions(+), 2138 deletions(-) delete mode 100644 pkg/controller/atlasdeployment/deployment.go create mode 100644 test/e2e/data/atlasdeployment_multiregion_multicloud_gcp_aws.yaml diff --git a/.github/workflows/test-e2e.yml b/.github/workflows/test-e2e.yml index acb53fb8f3..23ee0d9763 100644 --- a/.github/workflows/test-e2e.yml +++ b/.github/workflows/test-e2e.yml @@ -194,6 +194,17 @@ jobs: platform=$(echo ${{ matrix.k8s }} | awk -F "-" '{print $2}') echo "k8s_version=$version" >> $GITHUB_OUTPUT echo "k8s_platform=$platform" >> $GITHUB_OUTPUT + + - name: Generate configuration for the tests + uses: ./.github/actions/gen-install-scripts + with: + IMAGE_URL: ${{ env.DOCKER_REPO }}:${{ steps.prepare.outputs.tag }} + VERSION: ${{ steps.prepare.outputs.tag }} + ENV: dev + + - name: Change path for the test + run: | + awk '{gsub(/cloud.mongodb.com/, "cloud-qa.mongodb.com", $0); print}' bundle/manifests/mongodb-atlas-kubernetes.clusterserviceversion.yaml > tmp && mv tmp bundle/manifests/mongodb-atlas-kubernetes.clusterserviceversion.yaml - name: Create k8s Kind Cluster if: ${{ steps.properties.outputs.k8s_platform == 'kind' && !env.ACT }} uses: helm/kind-action@v1.8.0 diff --git a/config/crd/bases/atlas.mongodb.com_atlasdeployments.yaml b/config/crd/bases/atlas.mongodb.com_atlasdeployments.yaml index e3c50ede7a..14f6e0d76d 100644 --- a/config/crd/bases/atlas.mongodb.com_atlasdeployments.yaml +++ b/config/crd/bases/atlas.mongodb.com_atlasdeployments.yaml @@ -37,15 +37,30 @@ spec: Only one of DeploymentSpec, AdvancedDeploymentSpec and ServerlessSpec should be defined properties: - advancedDeploymentSpec: + backupRef: + description: Backup schedule for the AtlasDeployment + properties: + name: + description: Name is the name of the Kubernetes Resource + type: string + namespace: + description: Namespace is the namespace of the Kubernetes Resource + type: string + required: + - name + type: object + deploymentSpec: description: Configuration for the advanced (v1.5) deployment API - https://www.mongodb.com/docs/atlas/reference/api/clusters-advanced/ + https://www.mongodb.com/docs/atlas/reference/api/clusters/ properties: backupEnabled: + description: Applicable only for M10+ deployments. Flag that indicates + if the deployment uses Cloud Backups for backups. type: boolean biConnector: - description: BiConnectorSpec specifies BI Connector for Atlas - configuration on this deployment + description: Configuration of BI Connector for Atlas on this deployment. + The MongoDB Connector for Business Intelligence for Atlas (BI + Connector) is only available for M10 and larger deployments. properties: enabled: description: Flag that indicates whether or not BI Connector @@ -59,6 +74,13 @@ spec: type: string type: object clusterType: + description: Type of the deployment that you want to create. The + parameter is required if replicationSpecs are set or if Global + Deployments are deployed. + enum: + - REPLICASET + - SHARDED + - GEOSHARDED type: string customZoneMapping: items: @@ -73,10 +95,26 @@ spec: type: object type: array diskSizeGB: + description: Capacity, in gigabytes, of the host's root volume. + Increase this number to add capacity, up to a maximum possible + value of 4096 (i.e., 4 TB). This value must be a positive integer. + The parameter is required if replicationSpecs are configured. + maximum: 4096 + minimum: 0 type: integer encryptionAtRestProvider: + description: Cloud service provider that offers Encryption at + Rest. + enum: + - AWS + - GCP + - AZURE + - NONE type: string labels: + description: Collection of key-value pairs that tag and categorize + the deployment. Each key and value has a maximum length of 255 + characters. items: description: LabelSpec contains key-value pairs that tag and categorize the Cluster/DBUser @@ -116,6 +154,7 @@ spec: type: object type: array mongoDBMajorVersion: + description: Version of the deployment to deploy. type: string mongoDBVersion: type: string @@ -126,27 +165,66 @@ spec: pattern: ^[a-zA-Z0-9][a-zA-Z0-9-]*$ type: string paused: + description: Flag that indicates whether the deployment should + be paused. type: boolean pitEnabled: + description: Flag that indicates the deployment uses continuous + cloud backups. type: boolean replicationSpecs: + description: Configuration for deployment regions. items: properties: numShards: + description: Positive integer that specifies the number + of shards to deploy in each specified zone. If you set + this value to 1 and clusterType is SHARDED, MongoDB Cloud + deploys a single-shard sharded cluster. Don't create a + sharded cluster with a single shard for production environments. + Single-shard sharded clusters don't provide the same benefits + as multi-shard configurations type: integer regionConfigs: + description: Hardware specifications for nodes set for a + given region. Each regionConfigs object describes the + region's priority in elections and the number and type + of MongoDB nodes that MongoDB Cloud deploys to the region. + Each regionConfigs object must have either an analyticsSpecs + object, electableSpecs object, or readOnlySpecs object. + Tenant clusters only require electableSpecs. Dedicated + clusters can specify any of these specifications, but + must have at least one electableSpecs object within a + replicationSpec. Every hardware specification must use + the same instanceSize. items: properties: analyticsSpecs: properties: diskIOPS: + description: Disk IOPS setting for AWS storage. + Set only if you selected AWS as your cloud service + provider. format: int64 type: integer ebsVolumeType: + description: Disk IOPS setting for AWS storage. + Set only if you selected AWS as your cloud service + provider. + enum: + - STANDARD + - PROVISIONED type: string instanceSize: + description: Hardware specification for the instance + sizes in this region. Each instance size has + a default storage and memory capacity. The instance + size you select applies to all the data-bearing + hosts in your instance size type: string nodeCount: + description: Number of nodes of the given type + for MongoDB Cloud to deploy to the region. type: integer type: object autoScaling: @@ -192,40 +270,99 @@ spec: type: object type: object backingProviderName: + description: 'Cloud service provider on which the + host for a multi-tenant deployment is provisioned. + This setting only works when "providerName" : "TENANT" + and "providerSetting.instanceSizeName" : M2 or M5. + Otherwise it should be equal to "providerName" value' + enum: + - AWS + - GCP + - AZURE type: string electableSpecs: properties: diskIOPS: + description: Disk IOPS setting for AWS storage. + Set only if you selected AWS as your cloud service + provider. format: int64 type: integer ebsVolumeType: + description: Disk IOPS setting for AWS storage. + Set only if you selected AWS as your cloud service + provider. + enum: + - STANDARD + - PROVISIONED type: string instanceSize: + description: Hardware specification for the instance + sizes in this region. Each instance size has + a default storage and memory capacity. The instance + size you select applies to all the data-bearing + hosts in your instance size type: string nodeCount: + description: Number of nodes of the given type + for MongoDB Cloud to deploy to the region. type: integer type: object priority: + description: Precedence is given to this region when + a primary election occurs. If your regionConfigs + has only readOnlySpecs, analyticsSpecs, or both, + set this value to 0. If you have multiple regionConfigs + objects (your cluster is multi-region or multi-cloud), + they must have priorities in descending order. The + highest priority is 7 type: integer providerName: + enum: + - AWS + - GCP + - AZURE + - TENANT + - SERVERLESS type: string readOnlySpecs: properties: diskIOPS: + description: Disk IOPS setting for AWS storage. + Set only if you selected AWS as your cloud service + provider. format: int64 type: integer ebsVolumeType: + description: Disk IOPS setting for AWS storage. + Set only if you selected AWS as your cloud service + provider. + enum: + - STANDARD + - PROVISIONED type: string instanceSize: + description: Hardware specification for the instance + sizes in this region. Each instance size has + a default storage and memory capacity. The instance + size you select applies to all the data-bearing + hosts in your instance size type: string nodeCount: + description: Number of nodes of the given type + for MongoDB Cloud to deploy to the region. type: integer type: object regionName: + description: Physical location of your MongoDB deployment. + The region you choose can affect network latency + for clients accessing your databases. type: string type: object type: array zoneName: + description: Human-readable label that identifies the zone + in a Global Cluster. type: string type: object type: array @@ -256,372 +393,6 @@ spec: versionReleaseSystem: type: string type: object - backupRef: - description: Backup schedule for the AtlasDeployment - properties: - name: - description: Name is the name of the Kubernetes Resource - type: string - namespace: - description: Namespace is the namespace of the Kubernetes Resource - type: string - required: - - name - type: object - deploymentSpec: - description: Configuration for the normal (v1) deployment API https://www.mongodb.com/docs/atlas/reference/api/clusters/ - properties: - autoScaling: - description: Collection of settings that configures auto-scaling - information for the deployment. If you specify the autoScaling - object, you must also specify the providerSettings.autoScaling - object. - properties: - autoIndexingEnabled: - description: 'Deprecated: This flag is not supported anymore. - Flag that indicates whether autopilot mode for Performance - Advisor is enabled. The default is false.' - type: boolean - compute: - description: Collection of settings that configure how a deployment - might scale its deployment tier and whether the deployment - can scale down. - properties: - enabled: - description: Flag that indicates whether deployment tier - auto-scaling is enabled. The default is false. - type: boolean - maxInstanceSize: - description: 'Maximum instance size to which your deployment - can automatically scale (such as M40). Atlas requires - this parameter if "autoScaling.compute.enabled" : true.' - type: string - minInstanceSize: - description: 'Minimum instance size to which your deployment - can automatically scale (such as M10). Atlas requires - this parameter if "autoScaling.compute.scaleDownEnabled" - : true.' - type: string - scaleDownEnabled: - description: 'Flag that indicates whether the deployment - tier may scale down. Atlas requires this parameter if - "autoScaling.compute.enabled" : true.' - type: boolean - type: object - diskGBEnabled: - description: Flag that indicates whether disk auto-scaling - is enabled. The default is true. - type: boolean - type: object - biConnector: - description: Configuration of BI Connector for Atlas on this deployment. - The MongoDB Connector for Business Intelligence for Atlas (BI - Connector) is only available for M10 and larger deployments. - properties: - enabled: - description: Flag that indicates whether or not BI Connector - for Atlas is enabled on the deployment. - type: boolean - readPreference: - description: Source from which the BI Connector for Atlas - reads data. Each BI Connector for Atlas read preference - contains a distinct combination of readPreference and readPreferenceTags - options. - type: string - type: object - clusterType: - description: Type of the deployment that you want to create. The - parameter is required if replicationSpecs are set or if Global - Deployments are deployed. - enum: - - REPLICASET - - SHARDED - - GEOSHARDED - type: string - customZoneMapping: - items: - properties: - location: - type: string - zone: - type: string - required: - - location - - zone - type: object - type: array - diskSizeGB: - description: Capacity, in gigabytes, of the host's root volume. - Increase this number to add capacity, up to a maximum possible - value of 4096 (i.e., 4 TB). This value must be a positive integer. - The parameter is required if replicationSpecs are configured. - maximum: 4096 - minimum: 0 - type: integer - encryptionAtRestProvider: - description: Cloud service provider that offers Encryption at - Rest. - enum: - - AWS - - GCP - - AZURE - - NONE - type: string - labels: - description: Collection of key-value pairs that tag and categorize - the deployment. Each key and value has a maximum length of 255 - characters. - items: - description: LabelSpec contains key-value pairs that tag and - categorize the Cluster/DBUser - properties: - key: - maxLength: 255 - type: string - value: - type: string - required: - - key - - value - type: object - type: array - managedNamespaces: - items: - description: ManagedNamespace represents the information about - managed namespace configuration. - properties: - collection: - type: string - customShardKey: - type: string - db: - type: string - isCustomShardKeyHashed: - type: boolean - isShardKeyUnique: - type: boolean - numInitialChunks: - type: integer - presplitHashedZones: - type: boolean - required: - - collection - - db - type: object - type: array - mongoDBMajorVersion: - description: Version of the deployment to deploy. - type: string - name: - description: Name of the deployment as it appears in Atlas. After - Atlas creates the deployment, you can't change its name. Can - only contain ASCII letters, numbers, and hyphens. - pattern: ^[a-zA-Z0-9][a-zA-Z0-9-]*$ - type: string - numShards: - description: Positive integer that specifies the number of shards - to deploy for a sharded deployment. The parameter is required - if replicationSpecs are configured - maximum: 50 - minimum: 1 - type: integer - paused: - description: Flag that indicates whether the deployment should - be paused. - type: boolean - pitEnabled: - description: Flag that indicates the deployment uses continuous - cloud backups. - type: boolean - providerBackupEnabled: - description: Applicable only for M10+ deployments. Flag that indicates - if the deployment uses Cloud Backups for backups. - type: boolean - providerSettings: - description: Configuration for the provisioned hosts on which - MongoDB runs. The available options are specific to the cloud - service provider. - properties: - autoScaling: - description: Range of instance sizes to which your deployment - can scale. - properties: - autoIndexingEnabled: - description: 'Deprecated: This flag is not supported anymore. - Flag that indicates whether autopilot mode for Performance - Advisor is enabled. The default is false.' - type: boolean - compute: - description: Collection of settings that configure how - a deployment might scale its deployment tier and whether - the deployment can scale down. - properties: - enabled: - description: Flag that indicates whether deployment - tier auto-scaling is enabled. The default is false. - type: boolean - maxInstanceSize: - description: 'Maximum instance size to which your - deployment can automatically scale (such as M40). - Atlas requires this parameter if "autoScaling.compute.enabled" - : true.' - type: string - minInstanceSize: - description: 'Minimum instance size to which your - deployment can automatically scale (such as M10). - Atlas requires this parameter if "autoScaling.compute.scaleDownEnabled" - : true.' - type: string - scaleDownEnabled: - description: 'Flag that indicates whether the deployment - tier may scale down. Atlas requires this parameter - if "autoScaling.compute.enabled" : true.' - type: boolean - type: object - diskGBEnabled: - description: Flag that indicates whether disk auto-scaling - is enabled. The default is true. - type: boolean - type: object - backingProviderName: - description: 'Cloud service provider on which the host for - a multi-tenant deployment is provisioned. This setting only - works when "providerSetting.providerName" : "TENANT" and - "providerSetting.instanceSizeName" : M2 or M5.' - enum: - - AWS - - GCP - - AZURE - type: string - diskIOPS: - description: Disk IOPS setting for AWS storage. Set only if - you selected AWS as your cloud service provider. - format: int64 - type: integer - diskTypeName: - description: Type of disk if you selected Azure as your cloud - service provider. - type: string - encryptEBSVolume: - description: Flag that indicates whether the Amazon EBS encryption - feature encrypts the host's root volume for both data at - rest within the volume and for data moving between the volume - and the deployment. - type: boolean - instanceSizeName: - description: Atlas provides different deployment tiers, each - with a default storage capacity and RAM size. The deployment - you select is used for all the data-bearing hosts in your - deployment tier. - type: string - providerName: - description: Cloud service provider on which Atlas provisions - the hosts. - enum: - - AWS - - GCP - - AZURE - - TENANT - - SERVERLESS - type: string - regionName: - description: Physical location of your MongoDB deployment. - The region you choose can affect network latency for clients - accessing your databases. - type: string - volumeType: - description: Disk IOPS setting for AWS storage. Set only if - you selected AWS as your cloud service provider. - enum: - - STANDARD - - PROVISIONED - type: string - required: - - providerName - type: object - replicationSpecs: - description: Configuration for deployment regions. - items: - description: ReplicationSpec represents a configuration for - deployment regions - properties: - numShards: - description: Number of shards to deploy in each specified - zone. The default value is 1. - format: int64 - type: integer - regionsConfig: - additionalProperties: - description: RegionsConfig describes the region’s priority - in elections and the number and type of MongoDB nodes - Atlas deploys to the region. - properties: - analyticsNodes: - description: The number of analytics nodes for Atlas - to deploy to the region. Analytics nodes are useful - for handling analytic data such as reporting queries - from BI Connector for Atlas. Analytics nodes are - read-only, and can never become the primary. If - you do not specify this option, no analytics nodes - are deployed to the region. - format: int64 - type: integer - electableNodes: - description: Number of electable nodes for Atlas to - deploy to the region. Electable nodes can become - the primary and can facilitate local reads. - format: int64 - type: integer - priority: - description: Election priority of the region. For - regions with only replicationSpecs[n].regionsConfig..readOnlyNodes, - set this value to 0. - format: int64 - type: integer - readOnlyNodes: - description: Number of read-only nodes for Atlas to - deploy to the region. Read-only nodes can never - become the primary, but can facilitate local-reads. - format: int64 - type: integer - type: object - description: Configuration for a region. Each regionsConfig - object describes the region's priority in elections and - the number and type of MongoDB nodes that Atlas deploys - to the region. - type: object - zoneName: - description: Name for the zone in a Global Deployment. Don't - provide this value if deploymentType is not GEOSHARDED. - type: string - type: object - type: array - tags: - description: Key-value pairs for resource tagging. - items: - description: TagSpec holds a key-value pair for resource tagging - on this deployment. - properties: - key: - maxLength: 255 - minLength: 1 - pattern: ^[a-zA-Z0-9][a-zA-Z0-9 @_.+`;`-]*$ - type: string - value: - maxLength: 255 - minLength: 1 - pattern: ^[a-zA-Z0-9][a-zA-Z0-9@_.+`;`-]*$ - type: string - required: - - key - - value - type: object - maxItems: 50 - type: array - required: - - name - - providerSettings - type: object processArgs: description: ProcessArgs allows to modify Advanced Configuration Options properties: diff --git a/config/rbac/clusterwide/role.yaml b/config/rbac/clusterwide/role.yaml index 366935cb24..f2defc2155 100644 --- a/config/rbac/clusterwide/role.yaml +++ b/config/rbac/clusterwide/role.yaml @@ -167,7 +167,7 @@ rules: - apiGroups: - atlas.mongodb.com resources: - - atlasfederatedauths + - atlasfederatedauths verbs: - create - delete @@ -183,4 +183,4 @@ rules: verbs: - get - patch - - update \ No newline at end of file + - update diff --git a/config/rbac/namespaced/role.yaml b/config/rbac/namespaced/role.yaml index 6dcab4e4c1..ac6db90443 100644 --- a/config/rbac/namespaced/role.yaml +++ b/config/rbac/namespaced/role.yaml @@ -168,7 +168,7 @@ rules: - apiGroups: - atlas.mongodb.com resources: - - atlasfederatedauths + - atlasfederatedauths verbs: - create - delete @@ -184,4 +184,4 @@ rules: verbs: - get - patch - - update \ No newline at end of file + - update diff --git a/deploy/crds/atlas.mongodb.com_atlasdeployments.yaml b/deploy/crds/atlas.mongodb.com_atlasdeployments.yaml index e3c50ede7a..14f6e0d76d 100644 --- a/deploy/crds/atlas.mongodb.com_atlasdeployments.yaml +++ b/deploy/crds/atlas.mongodb.com_atlasdeployments.yaml @@ -37,15 +37,30 @@ spec: Only one of DeploymentSpec, AdvancedDeploymentSpec and ServerlessSpec should be defined properties: - advancedDeploymentSpec: + backupRef: + description: Backup schedule for the AtlasDeployment + properties: + name: + description: Name is the name of the Kubernetes Resource + type: string + namespace: + description: Namespace is the namespace of the Kubernetes Resource + type: string + required: + - name + type: object + deploymentSpec: description: Configuration for the advanced (v1.5) deployment API - https://www.mongodb.com/docs/atlas/reference/api/clusters-advanced/ + https://www.mongodb.com/docs/atlas/reference/api/clusters/ properties: backupEnabled: + description: Applicable only for M10+ deployments. Flag that indicates + if the deployment uses Cloud Backups for backups. type: boolean biConnector: - description: BiConnectorSpec specifies BI Connector for Atlas - configuration on this deployment + description: Configuration of BI Connector for Atlas on this deployment. + The MongoDB Connector for Business Intelligence for Atlas (BI + Connector) is only available for M10 and larger deployments. properties: enabled: description: Flag that indicates whether or not BI Connector @@ -59,6 +74,13 @@ spec: type: string type: object clusterType: + description: Type of the deployment that you want to create. The + parameter is required if replicationSpecs are set or if Global + Deployments are deployed. + enum: + - REPLICASET + - SHARDED + - GEOSHARDED type: string customZoneMapping: items: @@ -73,10 +95,26 @@ spec: type: object type: array diskSizeGB: + description: Capacity, in gigabytes, of the host's root volume. + Increase this number to add capacity, up to a maximum possible + value of 4096 (i.e., 4 TB). This value must be a positive integer. + The parameter is required if replicationSpecs are configured. + maximum: 4096 + minimum: 0 type: integer encryptionAtRestProvider: + description: Cloud service provider that offers Encryption at + Rest. + enum: + - AWS + - GCP + - AZURE + - NONE type: string labels: + description: Collection of key-value pairs that tag and categorize + the deployment. Each key and value has a maximum length of 255 + characters. items: description: LabelSpec contains key-value pairs that tag and categorize the Cluster/DBUser @@ -116,6 +154,7 @@ spec: type: object type: array mongoDBMajorVersion: + description: Version of the deployment to deploy. type: string mongoDBVersion: type: string @@ -126,27 +165,66 @@ spec: pattern: ^[a-zA-Z0-9][a-zA-Z0-9-]*$ type: string paused: + description: Flag that indicates whether the deployment should + be paused. type: boolean pitEnabled: + description: Flag that indicates the deployment uses continuous + cloud backups. type: boolean replicationSpecs: + description: Configuration for deployment regions. items: properties: numShards: + description: Positive integer that specifies the number + of shards to deploy in each specified zone. If you set + this value to 1 and clusterType is SHARDED, MongoDB Cloud + deploys a single-shard sharded cluster. Don't create a + sharded cluster with a single shard for production environments. + Single-shard sharded clusters don't provide the same benefits + as multi-shard configurations type: integer regionConfigs: + description: Hardware specifications for nodes set for a + given region. Each regionConfigs object describes the + region's priority in elections and the number and type + of MongoDB nodes that MongoDB Cloud deploys to the region. + Each regionConfigs object must have either an analyticsSpecs + object, electableSpecs object, or readOnlySpecs object. + Tenant clusters only require electableSpecs. Dedicated + clusters can specify any of these specifications, but + must have at least one electableSpecs object within a + replicationSpec. Every hardware specification must use + the same instanceSize. items: properties: analyticsSpecs: properties: diskIOPS: + description: Disk IOPS setting for AWS storage. + Set only if you selected AWS as your cloud service + provider. format: int64 type: integer ebsVolumeType: + description: Disk IOPS setting for AWS storage. + Set only if you selected AWS as your cloud service + provider. + enum: + - STANDARD + - PROVISIONED type: string instanceSize: + description: Hardware specification for the instance + sizes in this region. Each instance size has + a default storage and memory capacity. The instance + size you select applies to all the data-bearing + hosts in your instance size type: string nodeCount: + description: Number of nodes of the given type + for MongoDB Cloud to deploy to the region. type: integer type: object autoScaling: @@ -192,40 +270,99 @@ spec: type: object type: object backingProviderName: + description: 'Cloud service provider on which the + host for a multi-tenant deployment is provisioned. + This setting only works when "providerName" : "TENANT" + and "providerSetting.instanceSizeName" : M2 or M5. + Otherwise it should be equal to "providerName" value' + enum: + - AWS + - GCP + - AZURE type: string electableSpecs: properties: diskIOPS: + description: Disk IOPS setting for AWS storage. + Set only if you selected AWS as your cloud service + provider. format: int64 type: integer ebsVolumeType: + description: Disk IOPS setting for AWS storage. + Set only if you selected AWS as your cloud service + provider. + enum: + - STANDARD + - PROVISIONED type: string instanceSize: + description: Hardware specification for the instance + sizes in this region. Each instance size has + a default storage and memory capacity. The instance + size you select applies to all the data-bearing + hosts in your instance size type: string nodeCount: + description: Number of nodes of the given type + for MongoDB Cloud to deploy to the region. type: integer type: object priority: + description: Precedence is given to this region when + a primary election occurs. If your regionConfigs + has only readOnlySpecs, analyticsSpecs, or both, + set this value to 0. If you have multiple regionConfigs + objects (your cluster is multi-region or multi-cloud), + they must have priorities in descending order. The + highest priority is 7 type: integer providerName: + enum: + - AWS + - GCP + - AZURE + - TENANT + - SERVERLESS type: string readOnlySpecs: properties: diskIOPS: + description: Disk IOPS setting for AWS storage. + Set only if you selected AWS as your cloud service + provider. format: int64 type: integer ebsVolumeType: + description: Disk IOPS setting for AWS storage. + Set only if you selected AWS as your cloud service + provider. + enum: + - STANDARD + - PROVISIONED type: string instanceSize: + description: Hardware specification for the instance + sizes in this region. Each instance size has + a default storage and memory capacity. The instance + size you select applies to all the data-bearing + hosts in your instance size type: string nodeCount: + description: Number of nodes of the given type + for MongoDB Cloud to deploy to the region. type: integer type: object regionName: + description: Physical location of your MongoDB deployment. + The region you choose can affect network latency + for clients accessing your databases. type: string type: object type: array zoneName: + description: Human-readable label that identifies the zone + in a Global Cluster. type: string type: object type: array @@ -256,372 +393,6 @@ spec: versionReleaseSystem: type: string type: object - backupRef: - description: Backup schedule for the AtlasDeployment - properties: - name: - description: Name is the name of the Kubernetes Resource - type: string - namespace: - description: Namespace is the namespace of the Kubernetes Resource - type: string - required: - - name - type: object - deploymentSpec: - description: Configuration for the normal (v1) deployment API https://www.mongodb.com/docs/atlas/reference/api/clusters/ - properties: - autoScaling: - description: Collection of settings that configures auto-scaling - information for the deployment. If you specify the autoScaling - object, you must also specify the providerSettings.autoScaling - object. - properties: - autoIndexingEnabled: - description: 'Deprecated: This flag is not supported anymore. - Flag that indicates whether autopilot mode for Performance - Advisor is enabled. The default is false.' - type: boolean - compute: - description: Collection of settings that configure how a deployment - might scale its deployment tier and whether the deployment - can scale down. - properties: - enabled: - description: Flag that indicates whether deployment tier - auto-scaling is enabled. The default is false. - type: boolean - maxInstanceSize: - description: 'Maximum instance size to which your deployment - can automatically scale (such as M40). Atlas requires - this parameter if "autoScaling.compute.enabled" : true.' - type: string - minInstanceSize: - description: 'Minimum instance size to which your deployment - can automatically scale (such as M10). Atlas requires - this parameter if "autoScaling.compute.scaleDownEnabled" - : true.' - type: string - scaleDownEnabled: - description: 'Flag that indicates whether the deployment - tier may scale down. Atlas requires this parameter if - "autoScaling.compute.enabled" : true.' - type: boolean - type: object - diskGBEnabled: - description: Flag that indicates whether disk auto-scaling - is enabled. The default is true. - type: boolean - type: object - biConnector: - description: Configuration of BI Connector for Atlas on this deployment. - The MongoDB Connector for Business Intelligence for Atlas (BI - Connector) is only available for M10 and larger deployments. - properties: - enabled: - description: Flag that indicates whether or not BI Connector - for Atlas is enabled on the deployment. - type: boolean - readPreference: - description: Source from which the BI Connector for Atlas - reads data. Each BI Connector for Atlas read preference - contains a distinct combination of readPreference and readPreferenceTags - options. - type: string - type: object - clusterType: - description: Type of the deployment that you want to create. The - parameter is required if replicationSpecs are set or if Global - Deployments are deployed. - enum: - - REPLICASET - - SHARDED - - GEOSHARDED - type: string - customZoneMapping: - items: - properties: - location: - type: string - zone: - type: string - required: - - location - - zone - type: object - type: array - diskSizeGB: - description: Capacity, in gigabytes, of the host's root volume. - Increase this number to add capacity, up to a maximum possible - value of 4096 (i.e., 4 TB). This value must be a positive integer. - The parameter is required if replicationSpecs are configured. - maximum: 4096 - minimum: 0 - type: integer - encryptionAtRestProvider: - description: Cloud service provider that offers Encryption at - Rest. - enum: - - AWS - - GCP - - AZURE - - NONE - type: string - labels: - description: Collection of key-value pairs that tag and categorize - the deployment. Each key and value has a maximum length of 255 - characters. - items: - description: LabelSpec contains key-value pairs that tag and - categorize the Cluster/DBUser - properties: - key: - maxLength: 255 - type: string - value: - type: string - required: - - key - - value - type: object - type: array - managedNamespaces: - items: - description: ManagedNamespace represents the information about - managed namespace configuration. - properties: - collection: - type: string - customShardKey: - type: string - db: - type: string - isCustomShardKeyHashed: - type: boolean - isShardKeyUnique: - type: boolean - numInitialChunks: - type: integer - presplitHashedZones: - type: boolean - required: - - collection - - db - type: object - type: array - mongoDBMajorVersion: - description: Version of the deployment to deploy. - type: string - name: - description: Name of the deployment as it appears in Atlas. After - Atlas creates the deployment, you can't change its name. Can - only contain ASCII letters, numbers, and hyphens. - pattern: ^[a-zA-Z0-9][a-zA-Z0-9-]*$ - type: string - numShards: - description: Positive integer that specifies the number of shards - to deploy for a sharded deployment. The parameter is required - if replicationSpecs are configured - maximum: 50 - minimum: 1 - type: integer - paused: - description: Flag that indicates whether the deployment should - be paused. - type: boolean - pitEnabled: - description: Flag that indicates the deployment uses continuous - cloud backups. - type: boolean - providerBackupEnabled: - description: Applicable only for M10+ deployments. Flag that indicates - if the deployment uses Cloud Backups for backups. - type: boolean - providerSettings: - description: Configuration for the provisioned hosts on which - MongoDB runs. The available options are specific to the cloud - service provider. - properties: - autoScaling: - description: Range of instance sizes to which your deployment - can scale. - properties: - autoIndexingEnabled: - description: 'Deprecated: This flag is not supported anymore. - Flag that indicates whether autopilot mode for Performance - Advisor is enabled. The default is false.' - type: boolean - compute: - description: Collection of settings that configure how - a deployment might scale its deployment tier and whether - the deployment can scale down. - properties: - enabled: - description: Flag that indicates whether deployment - tier auto-scaling is enabled. The default is false. - type: boolean - maxInstanceSize: - description: 'Maximum instance size to which your - deployment can automatically scale (such as M40). - Atlas requires this parameter if "autoScaling.compute.enabled" - : true.' - type: string - minInstanceSize: - description: 'Minimum instance size to which your - deployment can automatically scale (such as M10). - Atlas requires this parameter if "autoScaling.compute.scaleDownEnabled" - : true.' - type: string - scaleDownEnabled: - description: 'Flag that indicates whether the deployment - tier may scale down. Atlas requires this parameter - if "autoScaling.compute.enabled" : true.' - type: boolean - type: object - diskGBEnabled: - description: Flag that indicates whether disk auto-scaling - is enabled. The default is true. - type: boolean - type: object - backingProviderName: - description: 'Cloud service provider on which the host for - a multi-tenant deployment is provisioned. This setting only - works when "providerSetting.providerName" : "TENANT" and - "providerSetting.instanceSizeName" : M2 or M5.' - enum: - - AWS - - GCP - - AZURE - type: string - diskIOPS: - description: Disk IOPS setting for AWS storage. Set only if - you selected AWS as your cloud service provider. - format: int64 - type: integer - diskTypeName: - description: Type of disk if you selected Azure as your cloud - service provider. - type: string - encryptEBSVolume: - description: Flag that indicates whether the Amazon EBS encryption - feature encrypts the host's root volume for both data at - rest within the volume and for data moving between the volume - and the deployment. - type: boolean - instanceSizeName: - description: Atlas provides different deployment tiers, each - with a default storage capacity and RAM size. The deployment - you select is used for all the data-bearing hosts in your - deployment tier. - type: string - providerName: - description: Cloud service provider on which Atlas provisions - the hosts. - enum: - - AWS - - GCP - - AZURE - - TENANT - - SERVERLESS - type: string - regionName: - description: Physical location of your MongoDB deployment. - The region you choose can affect network latency for clients - accessing your databases. - type: string - volumeType: - description: Disk IOPS setting for AWS storage. Set only if - you selected AWS as your cloud service provider. - enum: - - STANDARD - - PROVISIONED - type: string - required: - - providerName - type: object - replicationSpecs: - description: Configuration for deployment regions. - items: - description: ReplicationSpec represents a configuration for - deployment regions - properties: - numShards: - description: Number of shards to deploy in each specified - zone. The default value is 1. - format: int64 - type: integer - regionsConfig: - additionalProperties: - description: RegionsConfig describes the region’s priority - in elections and the number and type of MongoDB nodes - Atlas deploys to the region. - properties: - analyticsNodes: - description: The number of analytics nodes for Atlas - to deploy to the region. Analytics nodes are useful - for handling analytic data such as reporting queries - from BI Connector for Atlas. Analytics nodes are - read-only, and can never become the primary. If - you do not specify this option, no analytics nodes - are deployed to the region. - format: int64 - type: integer - electableNodes: - description: Number of electable nodes for Atlas to - deploy to the region. Electable nodes can become - the primary and can facilitate local reads. - format: int64 - type: integer - priority: - description: Election priority of the region. For - regions with only replicationSpecs[n].regionsConfig..readOnlyNodes, - set this value to 0. - format: int64 - type: integer - readOnlyNodes: - description: Number of read-only nodes for Atlas to - deploy to the region. Read-only nodes can never - become the primary, but can facilitate local-reads. - format: int64 - type: integer - type: object - description: Configuration for a region. Each regionsConfig - object describes the region's priority in elections and - the number and type of MongoDB nodes that Atlas deploys - to the region. - type: object - zoneName: - description: Name for the zone in a Global Deployment. Don't - provide this value if deploymentType is not GEOSHARDED. - type: string - type: object - type: array - tags: - description: Key-value pairs for resource tagging. - items: - description: TagSpec holds a key-value pair for resource tagging - on this deployment. - properties: - key: - maxLength: 255 - minLength: 1 - pattern: ^[a-zA-Z0-9][a-zA-Z0-9 @_.+`;`-]*$ - type: string - value: - maxLength: 255 - minLength: 1 - pattern: ^[a-zA-Z0-9][a-zA-Z0-9@_.+`;`-]*$ - type: string - required: - - key - - value - type: object - maxItems: 50 - type: array - required: - - name - - providerSettings - type: object processArgs: description: ProcessArgs allows to modify Advanced Configuration Options properties: diff --git a/helm-charts b/helm-charts index 12f59b0259..48d3f50ae8 160000 --- a/helm-charts +++ b/helm-charts @@ -1 +1 @@ -Subproject commit 12f59b02590a3f6421d244fb4a59fd5a9ae1390e +Subproject commit 48d3f50ae8b0f900053fc41521ae767374e24d35 diff --git a/pkg/api/v1/atlasdeployment_types.go b/pkg/api/v1/atlasdeployment_types.go index bdecbc513c..d99e70796e 100644 --- a/pkg/api/v1/atlasdeployment_types.go +++ b/pkg/api/v1/atlasdeployment_types.go @@ -33,6 +33,7 @@ import ( "github.com/mongodb/mongodb-atlas-kubernetes/pkg/util/compat" "github.com/mongodb/mongodb-atlas-kubernetes/pkg/util/kube" + "github.com/mongodb/mongodb-atlas-kubernetes/pkg/util/toptr" ) func init() { @@ -53,13 +54,9 @@ type AtlasDeploymentSpec struct { // Project is a reference to AtlasProject resource the deployment belongs to Project common.ResourceRefNamespaced `json:"projectRef"` - // Configuration for the normal (v1) deployment API https://www.mongodb.com/docs/atlas/reference/api/clusters/ + // Configuration for the advanced (v1.5) deployment API https://www.mongodb.com/docs/atlas/reference/api/clusters/ // +optional - DeploymentSpec *DeploymentSpec `json:"deploymentSpec,omitempty"` - - // Configuration for the advanced (v1.5) deployment API https://www.mongodb.com/docs/atlas/reference/api/clusters-advanced/ - // +optional - AdvancedDeploymentSpec *AdvancedDeploymentSpec `json:"advancedDeploymentSpec,omitempty"` + DeploymentSpec *AdvancedDeploymentSpec `json:"deploymentSpec,omitempty"` // Backup schedule for the AtlasDeployment // +optional @@ -74,23 +71,20 @@ type AtlasDeploymentSpec struct { ProcessArgs *ProcessArgs `json:"processArgs,omitempty"` } -type DeploymentSpec struct { - // Collection of settings that configures auto-scaling information for the deployment. - // If you specify the autoScaling object, you must also specify the providerSettings.autoScaling object. +type AdvancedDeploymentSpec struct { + // Applicable only for M10+ deployments. + // Flag that indicates if the deployment uses Cloud Backups for backups. // +optional - AutoScaling *AutoScalingSpec `json:"autoScaling,omitempty"` - + BackupEnabled *bool `json:"backupEnabled,omitempty"` // Configuration of BI Connector for Atlas on this deployment. // The MongoDB Connector for Business Intelligence for Atlas (BI Connector) is only available for M10 and larger deployments. // +optional - BIConnector *BiConnectorSpec `json:"biConnector,omitempty"` - + BiConnector *BiConnectorSpec `json:"biConnector,omitempty"` // Type of the deployment that you want to create. // The parameter is required if replicationSpecs are set or if Global Deployments are deployed. // +kubebuilder:validation:Enum=REPLICASET;SHARDED;GEOSHARDED // +optional - ClusterType DeploymentType `json:"clusterType,omitempty"` - + ClusterType string `json:"clusterType,omitempty"` // Capacity, in gigabytes, of the host's root volume. // Increase this number to add capacity, up to a maximum possible value of 4096 (i.e., 4 TB). // This value must be a positive integer. @@ -98,79 +92,31 @@ type DeploymentSpec struct { // +kubebuilder:validation:Minimum=0 // +kubebuilder:validation:Maximum=4096 // +optional - DiskSizeGB *int `json:"diskSizeGB,omitempty"` // TODO: may cause issues due to mongodb/go-client-mongodb-atlas#140 - + DiskSizeGB *int `json:"diskSizeGB,omitempty"` // Cloud service provider that offers Encryption at Rest. // +kubebuilder:validation:Enum=AWS;GCP;AZURE;NONE // +optional EncryptionAtRestProvider string `json:"encryptionAtRestProvider,omitempty"` - // Collection of key-value pairs that tag and categorize the deployment. // Each key and value has a maximum length of 255 characters. // +optional Labels []common.LabelSpec `json:"labels,omitempty"` - // Version of the deployment to deploy. MongoDBMajorVersion string `json:"mongoDBMajorVersion,omitempty"` - - // Name of the deployment as it appears in Atlas. + MongoDBVersion string `json:"mongoDBVersion,omitempty"` + // Name of the advanced deployment as it appears in Atlas. // After Atlas creates the deployment, you can't change its name. // Can only contain ASCII letters, numbers, and hyphens. + // +kubebuilder:validation:Required // +kubebuilder:validation:Pattern:=^[a-zA-Z0-9][a-zA-Z0-9-]*$ - Name string `json:"name"` - - // Key-value pairs for resource tagging. - // +kubebuilder:validation:MaxItems=50 - // +optional - Tags []*TagSpec `json:"tags,omitempty"` - - // Positive integer that specifies the number of shards to deploy for a sharded deployment. - // The parameter is required if replicationSpecs are configured - // +kubebuilder:validation:Minimum=1 - // +kubebuilder:validation:Maximum=50 - // +optional - NumShards *int `json:"numShards,omitempty"` - + Name string `json:"name,omitempty"` // Flag that indicates whether the deployment should be paused. Paused *bool `json:"paused,omitempty"` - // Flag that indicates the deployment uses continuous cloud backups. // +optional PitEnabled *bool `json:"pitEnabled,omitempty"` - - // Applicable only for M10+ deployments. - // Flag that indicates if the deployment uses Cloud Backups for backups. - // +optional - ProviderBackupEnabled *bool `json:"providerBackupEnabled,omitempty"` - - // Configuration for the provisioned hosts on which MongoDB runs. The available options are specific to the cloud service provider. - ProviderSettings *ProviderSettingsSpec `json:"providerSettings"` - // Configuration for deployment regions. // +optional - ReplicationSpecs []ReplicationSpec `json:"replicationSpecs,omitempty"` - // +optional - CustomZoneMapping []CustomZoneMapping `json:"customZoneMapping,omitempty"` - // +optional - ManagedNamespaces []ManagedNamespace `json:"managedNamespaces,omitempty"` -} - -type AdvancedDeploymentSpec struct { - BackupEnabled *bool `json:"backupEnabled,omitempty"` - BiConnector *BiConnectorSpec `json:"biConnector,omitempty"` - ClusterType string `json:"clusterType,omitempty"` - DiskSizeGB *int `json:"diskSizeGB,omitempty"` - EncryptionAtRestProvider string `json:"encryptionAtRestProvider,omitempty"` - Labels []common.LabelSpec `json:"labels,omitempty"` - MongoDBMajorVersion string `json:"mongoDBMajorVersion,omitempty"` - MongoDBVersion string `json:"mongoDBVersion,omitempty"` - // Name of the advanced deployment as it appears in Atlas. - // After Atlas creates the deployment, you can't change its name. - // Can only contain ASCII letters, numbers, and hyphens. - // +kubebuilder:validation:Pattern:=^[a-zA-Z0-9][a-zA-Z0-9-]*$ - Name string `json:"name,omitempty"` - Paused *bool `json:"paused,omitempty"` - PitEnabled *bool `json:"pitEnabled,omitempty"` ReplicationSpecs []*AdvancedReplicationSpec `json:"replicationSpecs,omitempty"` RootCertType string `json:"rootCertType,omitempty"` // Key-value pairs for resource tagging. @@ -290,27 +236,58 @@ type EndpointSpec struct { } type AdvancedReplicationSpec struct { - NumShards int `json:"numShards,omitempty"` - ZoneName string `json:"zoneName,omitempty"` + // Positive integer that specifies the number of shards to deploy in each specified zone. + // If you set this value to 1 and clusterType is SHARDED, MongoDB Cloud deploys a single-shard sharded cluster. + // Don't create a sharded cluster with a single shard for production environments. + // Single-shard sharded clusters don't provide the same benefits as multi-shard configurations + NumShards int `json:"numShards,omitempty"` + // Human-readable label that identifies the zone in a Global Cluster. + ZoneName string `json:"zoneName,omitempty"` + // Hardware specifications for nodes set for a given region. + // Each regionConfigs object describes the region's priority in elections and the number and type of MongoDB nodes that MongoDB Cloud deploys to the region. + // Each regionConfigs object must have either an analyticsSpecs object, electableSpecs object, or readOnlySpecs object. + // Tenant clusters only require electableSpecs. Dedicated clusters can specify any of these specifications, but must have at least one electableSpecs object within a replicationSpec. + // Every hardware specification must use the same instanceSize. RegionConfigs []*AdvancedRegionConfig `json:"regionConfigs,omitempty"` } type AdvancedRegionConfig struct { - AnalyticsSpecs *Specs `json:"analyticsSpecs,omitempty"` - ElectableSpecs *Specs `json:"electableSpecs,omitempty"` - ReadOnlySpecs *Specs `json:"readOnlySpecs,omitempty"` - AutoScaling *AdvancedAutoScalingSpec `json:"autoScaling,omitempty"` - BackingProviderName string `json:"backingProviderName,omitempty"` - Priority *int `json:"priority,omitempty"` - ProviderName string `json:"providerName,omitempty"` - RegionName string `json:"regionName,omitempty"` + AnalyticsSpecs *Specs `json:"analyticsSpecs,omitempty"` + ElectableSpecs *Specs `json:"electableSpecs,omitempty"` + ReadOnlySpecs *Specs `json:"readOnlySpecs,omitempty"` + AutoScaling *AdvancedAutoScalingSpec `json:"autoScaling,omitempty"` + // Cloud service provider on which the host for a multi-tenant deployment is provisioned. + // This setting only works when "providerName" : "TENANT" and "providerSetting.instanceSizeName" : M2 or M5. + // Otherwise it should be equal to "providerName" value + // +kubebuilder:validation:Enum=AWS;GCP;AZURE + BackingProviderName string `json:"backingProviderName,omitempty"` + // Precedence is given to this region when a primary election occurs. + // If your regionConfigs has only readOnlySpecs, analyticsSpecs, or both, set this value to 0. + // If you have multiple regionConfigs objects (your cluster is multi-region or multi-cloud), they must have priorities in descending order. + // The highest priority is 7 + Priority *int `json:"priority,omitempty"` + // +kubebuilder:validation:Enum=AWS;GCP;AZURE;TENANT;SERVERLESS + ProviderName string `json:"providerName,omitempty"` + // Physical location of your MongoDB deployment. + // The region you choose can affect network latency for clients accessing your databases. + RegionName string `json:"regionName,omitempty"` } type Specs struct { - DiskIOPS *int64 `json:"diskIOPS,omitempty"` + // Disk IOPS setting for AWS storage. + // Set only if you selected AWS as your cloud service provider. + // +optional + DiskIOPS *int64 `json:"diskIOPS,omitempty"` + // Disk IOPS setting for AWS storage. + // Set only if you selected AWS as your cloud service provider. + // +kubebuilder:validation:Enum=STANDARD;PROVISIONED EbsVolumeType string `json:"ebsVolumeType,omitempty"` - InstanceSize string `json:"instanceSize,omitempty"` - NodeCount *int `json:"nodeCount,omitempty"` + // Hardware specification for the instance sizes in this region. + // Each instance size has a default storage and memory capacity. + // The instance size you select applies to all the data-bearing hosts in your instance size + InstanceSize string `json:"instanceSize,omitempty"` + // Number of nodes of the given type for MongoDB Cloud to deploy to the region. + NodeCount *int `json:"nodeCount,omitempty"` } // AutoScalingSpec configures your deployment to automatically scale its storage @@ -504,74 +481,13 @@ type ProviderSettingsSpec struct { AutoScaling *AutoScalingSpec `json:"autoScaling,omitempty"` } -// ReplicationSpec represents a configuration for deployment regions -type ReplicationSpec struct { - // Number of shards to deploy in each specified zone. - // The default value is 1. - NumShards *int64 `json:"numShards,omitempty"` - - // Name for the zone in a Global Deployment. - // Don't provide this value if deploymentType is not GEOSHARDED. - // +optional - ZoneName string `json:"zoneName,omitempty"` - - // Configuration for a region. - // Each regionsConfig object describes the region's priority in elections and the number and type of MongoDB nodes that Atlas deploys to the region. - // +optional - RegionsConfig map[string]RegionsConfig `json:"regionsConfig,omitempty"` -} - -// RegionsConfig describes the region’s priority in elections and the number and type of MongoDB nodes Atlas deploys to the region. -type RegionsConfig struct { - // The number of analytics nodes for Atlas to deploy to the region. - // Analytics nodes are useful for handling analytic data such as reporting queries from BI Connector for Atlas. - // Analytics nodes are read-only, and can never become the primary. - // If you do not specify this option, no analytics nodes are deployed to the region. - // +optional - AnalyticsNodes *int64 `json:"analyticsNodes,omitempty"` - - // Number of electable nodes for Atlas to deploy to the region. - // Electable nodes can become the primary and can facilitate local reads. - // +optional - ElectableNodes *int64 `json:"electableNodes,omitempty"` - - // Election priority of the region. - // For regions with only replicationSpecs[n].regionsConfig..readOnlyNodes, set this value to 0. - // +optional - Priority *int64 `json:"priority,omitempty"` - - // Number of read-only nodes for Atlas to deploy to the region. - // Read-only nodes can never become the primary, but can facilitate local-reads. - // +optional - ReadOnlyNodes *int64 `json:"readOnlyNodes,omitempty"` -} - -// Check compatibility with library type. -var _ = RegionsConfig(mongodbatlas.RegionsConfig{}) - -// LegacyDeployment converts the Spec to native Atlas client format. -func (spec *AtlasDeploymentSpec) LegacyDeployment() (*mongodbatlas.Cluster, error) { - result := &mongodbatlas.Cluster{} - err := compat.JSONCopy(result, *spec.DeploymentSpec) - - if result.AutoScaling != nil { - result.AutoScaling.AutoIndexingEnabled = nil - } - - if result.ProviderSettings != nil && result.ProviderSettings.AutoScaling != nil { - result.ProviderSettings.AutoScaling.AutoIndexingEnabled = nil - } - - return result, err -} - // Deployment converts the Spec to native Atlas client format. func (spec *AtlasDeploymentSpec) Deployment() (*mongodbatlas.AdvancedCluster, error) { result := &mongodbatlas.AdvancedCluster{} - if spec.AdvancedDeploymentSpec == nil { + if spec.DeploymentSpec == nil { return result, errors.New("AdvancedDeploymentSpec is empty") } - err := compat.JSONCopy(result, *spec.AdvancedDeploymentSpec) + err := compat.JSONCopy(result, *spec.DeploymentSpec) return result, err } @@ -589,14 +505,11 @@ type AtlasDeployment struct { } func (c *AtlasDeployment) GetDeploymentName() string { - if c.IsLegacyDeployment() { - return c.Spec.DeploymentSpec.Name - } if c.IsServerless() { return c.Spec.ServerlessSpec.Name } if c.IsAdvancedDeployment() { - return c.Spec.AdvancedDeploymentSpec.Name + return c.Spec.DeploymentSpec.Name } return "" @@ -607,14 +520,9 @@ func (c *AtlasDeployment) IsServerless() bool { return c.Spec.ServerlessSpec != nil } -// IsLegacyDeployment returns true if the AtlasDeployment is configured to be an legacy deployment. -func (c *AtlasDeployment) IsLegacyDeployment() bool { - return c.Spec.DeploymentSpec != nil -} - // IsAdvancedDeployment returns true if the AtlasDeployment is configured to be an advanced deployment. func (c *AtlasDeployment) IsAdvancedDeployment() bool { - return c.Spec.AdvancedDeploymentSpec != nil + return c.Spec.DeploymentSpec != nil } func (c *AtlasDeployment) GetReplicationSetID() string { @@ -629,8 +537,8 @@ func (c *AtlasDeployment) GetReplicationSetID() string { // AtlasDeploymentList contains a list of AtlasDeployment type AtlasDeploymentList struct { - metav1.TypeMeta `json:",inline"` - metav1.ListMeta `json:"metadata,omitempty"` + metav1.TypeMeta ` json:",inline"` + metav1.ListMeta ` json:"metadata,omitempty"` Items []AtlasDeployment `json:"items"` } @@ -666,9 +574,26 @@ func NewDeployment(namespace, name, nameInAtlas string) *AtlasDeployment { Namespace: namespace, }, Spec: AtlasDeploymentSpec{ - DeploymentSpec: &DeploymentSpec{ - Name: nameInAtlas, - ProviderSettings: &ProviderSettingsSpec{InstanceSizeName: "M10"}, + DeploymentSpec: &AdvancedDeploymentSpec{ + ClusterType: "REPLICASET", + Name: nameInAtlas, + ReplicationSpecs: []*AdvancedReplicationSpec{ + { + ZoneName: "Zone 1", + RegionConfigs: []*AdvancedRegionConfig{ + { + Priority: toptr.MakePtr(7), + ElectableSpecs: &Specs{ + InstanceSize: "M10", + NodeCount: toptr.MakePtr(3), + }, + ProviderName: "AWS", + BackingProviderName: "AWS", + RegionName: "US_EAST_1", + }, + }, + }, + }, }, }, } @@ -693,37 +618,38 @@ func newServerlessInstance(namespace, name, nameInAtlas, backingProviderName, re } } -func NewAwsAdvancedDeployment(namespace, name, nameInAtlas string) *AtlasDeployment { - return newAwsAdvancedDeployment(namespace, name, nameInAtlas, "M10", "AWS", "US_EAST_1", 3) -} +func addReplicaIfNotAdded(deployment *AtlasDeployment) { + if deployment == nil { + return + } -func newAwsAdvancedDeployment(namespace, name, nameInAtlas, instanceSize, providerName, regionName string, nodeCount int) *AtlasDeployment { - priority := 7 - return &AtlasDeployment{ - ObjectMeta: metav1.ObjectMeta{ - Name: name, - Namespace: namespace, - }, - Spec: AtlasDeploymentSpec{ - AdvancedDeploymentSpec: &AdvancedDeploymentSpec{ - Name: nameInAtlas, - ClusterType: string(TypeReplicaSet), - ReplicationSpecs: []*AdvancedReplicationSpec{ - { - RegionConfigs: []*AdvancedRegionConfig{ - { - Priority: &priority, - ElectableSpecs: &Specs{ - InstanceSize: instanceSize, - NodeCount: &nodeCount, - }, - ProviderName: providerName, - RegionName: regionName, - }, - }, - }}, + if deployment.Spec.DeploymentSpec == nil { + return + } + + if len(deployment.Spec.DeploymentSpec.ReplicationSpecs) == 0 { + deployment.Spec.DeploymentSpec.ReplicationSpecs = append(deployment.Spec.DeploymentSpec.ReplicationSpecs, &AdvancedReplicationSpec{ + NumShards: 1, + ZoneName: "", + RegionConfigs: []*AdvancedRegionConfig{ + { + ElectableSpecs: &Specs{}, + BackingProviderName: "", + Priority: toptr.MakePtr(7), + ProviderName: "", + }, }, - }, + }) + } + + if len(deployment.Spec.DeploymentSpec.ReplicationSpecs[0].RegionConfigs) == 0 { + deployment.Spec.DeploymentSpec.ReplicationSpecs[0].RegionConfigs = append(deployment.Spec.DeploymentSpec.ReplicationSpecs[0].RegionConfigs, &AdvancedRegionConfig{ + ElectableSpecs: &Specs{}, + BackingProviderName: "", + Priority: toptr.MakePtr(7), + ProviderName: "", + RegionName: "", + }) } } @@ -743,18 +669,19 @@ func (c *AtlasDeployment) WithProjectName(projectName string) *AtlasDeployment { } func (c *AtlasDeployment) WithProviderName(name provider.ProviderName) *AtlasDeployment { - c.Spec.DeploymentSpec.ProviderSettings.ProviderName = name + addReplicaIfNotAdded(c) + c.Spec.DeploymentSpec.ReplicationSpecs[0].RegionConfigs[0].ProviderName = string(name) return c } func (c *AtlasDeployment) WithRegionName(name string) *AtlasDeployment { - c.Spec.DeploymentSpec.ProviderSettings.RegionName = name + addReplicaIfNotAdded(c) + c.Spec.DeploymentSpec.ReplicationSpecs[0].RegionConfigs[0].RegionName = name return c } func (c *AtlasDeployment) WithBackupScheduleRef(ref common.ResourceRefNamespaced) *AtlasDeployment { - t := true - c.Spec.DeploymentSpec.ProviderBackupEnabled = &t + c.Spec.DeploymentSpec.BackupEnabled = toptr.MakePtr(true) c.Spec.BackupScheduleRef = ref return c } @@ -765,25 +692,20 @@ func (c *AtlasDeployment) WithDiskSizeGB(size int) *AtlasDeployment { } func (c *AtlasDeployment) WithAutoscalingDisabled() *AtlasDeployment { - f := false - c.Spec.DeploymentSpec.AutoScaling = &AutoScalingSpec{ - DiskGBEnabled: &f, - Compute: &ComputeSpec{ - Enabled: &f, - ScaleDownEnabled: &f, - MinInstanceSize: "", - MaxInstanceSize: "", - }, - } + addReplicaIfNotAdded(c) + c.Spec.DeploymentSpec.ReplicationSpecs[0].RegionConfigs[0].AutoScaling = nil return c } func (c *AtlasDeployment) WithInstanceSize(name string) *AtlasDeployment { - c.Spec.DeploymentSpec.ProviderSettings.InstanceSizeName = name + addReplicaIfNotAdded(c) + c.Spec.DeploymentSpec.ReplicationSpecs[0].RegionConfigs[0].ElectableSpecs.InstanceSize = name return c } + func (c *AtlasDeployment) WithBackingProvider(name string) *AtlasDeployment { - c.Spec.DeploymentSpec.ProviderSettings.BackingProviderName = name + addReplicaIfNotAdded(c) + c.Spec.DeploymentSpec.ReplicationSpecs[0].RegionConfigs[0].BackingProviderName = name return c } @@ -792,7 +714,7 @@ func (c *AtlasDeployment) WithBackingProvider(name string) *AtlasDeployment { func (c *AtlasDeployment) Lightweight() *AtlasDeployment { c.WithInstanceSize("M2") // M2 is restricted to some set of regions only - we need to ensure them - switch c.Spec.DeploymentSpec.ProviderSettings.ProviderName { + switch provider.ProviderName(c.Spec.DeploymentSpec.ReplicationSpecs[0].RegionConfigs[0].ProviderName) { case provider.ProviderAWS: { c.WithRegionName("US_EAST_1") @@ -807,7 +729,7 @@ func (c *AtlasDeployment) Lightweight() *AtlasDeployment { } } // Changing provider to tenant as this is shared now - c.WithBackingProvider(string(c.Spec.DeploymentSpec.ProviderSettings.ProviderName)) + c.WithBackingProvider(c.Spec.DeploymentSpec.ReplicationSpecs[0].RegionConfigs[0].ProviderName) c.WithProviderName(provider.ProviderTenant) return c } @@ -816,6 +738,7 @@ func DefaultGCPDeployment(namespace, projectName string) *AtlasDeployment { return NewDeployment(namespace, "test-deployment-gcp-k8s", "test-deployment-gcp"). WithProjectName(projectName). WithProviderName(provider.ProviderGCP). + WithBackingProvider(string(provider.ProviderGCP)). WithRegionName("EASTERN_US") } @@ -823,31 +746,40 @@ func DefaultAWSDeployment(namespace, projectName string) *AtlasDeployment { return NewDeployment(namespace, "test-deployment-aws-k8s", "test-deployment-aws"). WithProjectName(projectName). WithProviderName(provider.ProviderAWS). - WithRegionName("US_WEST_2") + WithBackingProvider(string(provider.ProviderAWS)). + WithRegionName("US_EAST_1") } func DefaultAzureDeployment(namespace, projectName string) *AtlasDeployment { return NewDeployment(namespace, "test-deployment-azure-k8s", "test-deployment-azure"). WithProjectName(projectName). WithProviderName(provider.ProviderAzure). + WithBackingProvider(string(provider.ProviderAzure)). WithRegionName("EUROPE_NORTH") } func DefaultAwsAdvancedDeployment(namespace, projectName string) *AtlasDeployment { - return NewAwsAdvancedDeployment(namespace, "test-deployment-advanced-k8s", "test-deployment-advanced").WithProjectName(projectName) + return NewDeployment( + namespace, + "test-deployment-advanced-k8s", + "test-deployment-advanced", + ).WithProjectName(projectName) } func NewDefaultAWSServerlessInstance(namespace, projectName string) *AtlasDeployment { - return newServerlessInstance(namespace, "test-serverless-instance-k8s", "test-serverless-instance", "AWS", "US_EAST_1").WithProjectName(projectName) + return newServerlessInstance( + namespace, + "test-serverless-instance-k8s", + "test-serverless-instance", + "AWS", + "US_EAST_1", + ).WithProjectName(projectName) } func (c *AtlasDeployment) AtlasName() string { if c.Spec.DeploymentSpec != nil { return c.Spec.DeploymentSpec.Name } - if c.Spec.AdvancedDeploymentSpec != nil { - return c.Spec.AdvancedDeploymentSpec.Name - } if c.Spec.ServerlessSpec != nil { return c.Spec.ServerlessSpec.Name } diff --git a/pkg/api/v1/atlasdeployment_types_test.go b/pkg/api/v1/atlasdeployment_types_test.go index b84947e70e..48600fd4dd 100644 --- a/pkg/api/v1/atlasdeployment_types_test.go +++ b/pkg/api/v1/atlasdeployment_types_test.go @@ -1,16 +1,11 @@ package v1 import ( - "reflect" - "sort" "testing" - "github.com/fatih/structtag" - "github.com/stretchr/testify/assert" "go.mongodb.org/atlas/mongodbatlas" - "github.com/mongodb/mongodb-atlas-kubernetes/pkg/api/v1/provider" "github.com/mongodb/mongodb-atlas-kubernetes/pkg/util/toptr" ) @@ -57,103 +52,81 @@ func init() { excludedClusterFieldsTheirs["serverlessBackupOptions"] = true } -func TestCompatibility(t *testing.T) { - compareStruct(DeploymentSpec{}, mongodbatlas.Cluster{}, t) -} - -// TestEnums verifies that replacing the strings with "enum" in Atlas Operator works correctly and is (de)serialized -// into the correct Atlas Cluster -func TestEnums(t *testing.T) { - atlasCluster := mongodbatlas.Cluster{ - ProviderSettings: &mongodbatlas.ProviderSettings{ - ProviderName: "AWS", - }, - ClusterType: "GEOSHARDED", - } - operatorCluster := AtlasDeploymentSpec{ - DeploymentSpec: &DeploymentSpec{ - ProviderSettings: &ProviderSettingsSpec{ - ProviderName: provider.ProviderAWS, - }, - ClusterType: TypeGeoSharded, - }, - } - transformedCluster, err := operatorCluster.LegacyDeployment() - assert.NoError(t, err) - assert.Equal(t, atlasCluster, *transformedCluster) -} - -func compareStruct(ours interface{}, their interface{}, t *testing.T) { - ourFields := getAllFieldsSorted(ours, excludedClusterFieldsOurs) - theirFields := getAllFieldsSorted(their, excludedClusterFieldsTheirs) - - // Comparing the fields in sorted order first - ourStructName := reflect.ValueOf(ours).Type().Name() - theirStructName := reflect.ValueOf(their).Type().Name() - assert.Equal(t, ourFields, theirFields, "The fields for structs [ours: %s, theirs: %s] don't match!", ourStructName, theirStructName) - - // Then recurse into the fields of type struct - structFieldsTags := getAllStructFieldTags(ours, excludedClusterFieldsOurs) - for _, field := range structFieldsTags { - ourStructField := findFieldValueByTag(ours, field) - theirStructField := findFieldValueByTag(their, field) - - compareStruct(ourStructField, theirStructField, t) - } -} - -func findFieldValueByTag(theStruct interface{}, tag string) interface{} { - o := reflect.ValueOf(theStruct) - for i := 0; i < o.NumField(); i++ { - theTag := parseJSONName(o.Type().Field(i).Tag) - if theTag == tag { - v := reflect.New(o.Type().Field(i).Type.Elem()).Elem().Interface() - return v - } - } - panic("Field with tag not found") -} - -func getAllStructFieldTags(theStruct interface{}, excludedFields map[string]bool) []string { - o := reflect.ValueOf(theStruct) - var res []string - for i := 0; i < o.NumField(); i++ { - theTag := parseJSONName(o.Type().Field(i).Tag) - ft := o.Field(i).Type() - if ft.Kind() == reflect.Ptr { - ft = ft.Elem() - } - if _, ok := excludedFields[theTag]; !ok && ft.Kind() == reflect.Struct { - res = append(res, theTag) - } - } - return res -} - -func getAllFieldsSorted(theStruct interface{}, excluded map[string]bool) []string { - var res []string - o := reflect.ValueOf(theStruct) - for i := 0; i < o.NumField(); i++ { - theTag := parseJSONName(o.Type().Field(i).Tag) - if _, ok := excluded[theTag]; !ok { - res = append(res, theTag) - } - } - sort.Strings(res) - return res -} - -func parseJSONName(t reflect.StructTag) string { - tags, err := structtag.Parse(string(t)) - if err != nil { - panic(err) - } - jsonTag, err := tags.Get("json") - if err != nil { - panic(err) - } - return jsonTag.Name -} +// func TestCompatibility(t *testing.T) { +// compareStruct(AdvancedDeploymentSpec{}, mongodbatlas.Cluster{}, t) +// } + +// func compareStruct(ours interface{}, their interface{}, t *testing.T) { +// ourFields := getAllFieldsSorted(ours, excludedClusterFieldsOurs) +// theirFields := getAllFieldsSorted(their, excludedClusterFieldsTheirs) + +// // Comparing the fields in sorted order first +// ourStructName := reflect.ValueOf(ours).Type().Name() +// theirStructName := reflect.ValueOf(their).Type().Name() +// assert.Equal(t, ourFields, theirFields, "The fields for structs [ours: %s, theirs: %s] don't match!", ourStructName, theirStructName) + +// // Then recurse into the fields of type struct +// structFieldsTags := getAllStructFieldTags(ours, excludedClusterFieldsOurs) +// for _, field := range structFieldsTags { +// ourStructField := findFieldValueByTag(ours, field) +// theirStructField := findFieldValueByTag(their, field) + +// compareStruct(ourStructField, theirStructField, t) +// } +// } + +// func findFieldValueByTag(theStruct interface{}, tag string) interface{} { +// o := reflect.ValueOf(theStruct) +// for i := 0; i < o.NumField(); i++ { +// theTag := parseJSONName(o.Type().Field(i).Tag) +// if theTag == tag { +// v := reflect.New(o.Type().Field(i).Type.Elem()).Elem().Interface() +// return v +// } +// } +// panic("Field with tag not found") +// } + +// func getAllStructFieldTags(theStruct interface{}, excludedFields map[string]bool) []string { +// o := reflect.ValueOf(theStruct) +// var res []string +// for i := 0; i < o.NumField(); i++ { +// theTag := parseJSONName(o.Type().Field(i).Tag) +// ft := o.Field(i).Type() +// if ft.Kind() == reflect.Ptr { +// ft = ft.Elem() +// } +// if _, ok := excludedFields[theTag]; !ok && ft.Kind() == reflect.Struct { +// res = append(res, theTag) +// } +// } +// return res +// } + +// func getAllFieldsSorted(theStruct interface{}, excluded map[string]bool) []string { +// var res []string +// o := reflect.ValueOf(theStruct) +// for i := 0; i < o.NumField(); i++ { +// theTag := parseJSONName(o.Type().Field(i).Tag) +// if _, ok := excluded[theTag]; !ok { +// res = append(res, theTag) +// } +// } +// sort.Strings(res) +// return res +// } + +// func parseJSONName(t reflect.StructTag) string { +// tags, err := structtag.Parse(string(t)) +// if err != nil { +// panic(err) +// } +// jsonTag, err := tags.Get("json") +// if err != nil { +// panic(err) +// } +// return jsonTag.Name +// } func TestIsEqual(t *testing.T) { operatorArgs := ProcessArgs{ diff --git a/pkg/api/v1/zz_generated.deepcopy.go b/pkg/api/v1/zz_generated.deepcopy.go index 05ee899b49..e7ef38af3c 100644 --- a/pkg/api/v1/zz_generated.deepcopy.go +++ b/pkg/api/v1/zz_generated.deepcopy.go @@ -679,11 +679,6 @@ func (in *AtlasDeploymentSpec) DeepCopyInto(out *AtlasDeploymentSpec) { out.Project = in.Project if in.DeploymentSpec != nil { in, out := &in.DeploymentSpec, &out.DeploymentSpec - *out = new(DeploymentSpec) - (*in).DeepCopyInto(*out) - } - if in.AdvancedDeploymentSpec != nil { - in, out := &in.AdvancedDeploymentSpec, &out.AdvancedDeploymentSpec *out = new(AdvancedDeploymentSpec) (*in).DeepCopyInto(*out) } @@ -1459,96 +1454,6 @@ func (in *Database) DeepCopy() *Database { return out } -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *DeploymentSpec) DeepCopyInto(out *DeploymentSpec) { - *out = *in - if in.AutoScaling != nil { - in, out := &in.AutoScaling, &out.AutoScaling - *out = new(AutoScalingSpec) - (*in).DeepCopyInto(*out) - } - if in.BIConnector != nil { - in, out := &in.BIConnector, &out.BIConnector - *out = new(BiConnectorSpec) - (*in).DeepCopyInto(*out) - } - if in.DiskSizeGB != nil { - in, out := &in.DiskSizeGB, &out.DiskSizeGB - *out = new(int) - **out = **in - } - if in.Labels != nil { - in, out := &in.Labels, &out.Labels - *out = make([]common.LabelSpec, len(*in)) - copy(*out, *in) - } - if in.Tags != nil { - in, out := &in.Tags, &out.Tags - *out = make([]*TagSpec, len(*in)) - for i := range *in { - if (*in)[i] != nil { - in, out := &(*in)[i], &(*out)[i] - *out = new(TagSpec) - **out = **in - } - } - } - if in.NumShards != nil { - in, out := &in.NumShards, &out.NumShards - *out = new(int) - **out = **in - } - if in.Paused != nil { - in, out := &in.Paused, &out.Paused - *out = new(bool) - **out = **in - } - if in.PitEnabled != nil { - in, out := &in.PitEnabled, &out.PitEnabled - *out = new(bool) - **out = **in - } - if in.ProviderBackupEnabled != nil { - in, out := &in.ProviderBackupEnabled, &out.ProviderBackupEnabled - *out = new(bool) - **out = **in - } - if in.ProviderSettings != nil { - in, out := &in.ProviderSettings, &out.ProviderSettings - *out = new(ProviderSettingsSpec) - (*in).DeepCopyInto(*out) - } - if in.ReplicationSpecs != nil { - in, out := &in.ReplicationSpecs, &out.ReplicationSpecs - *out = make([]ReplicationSpec, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } - if in.CustomZoneMapping != nil { - in, out := &in.CustomZoneMapping, &out.CustomZoneMapping - *out = make([]CustomZoneMapping, len(*in)) - copy(*out, *in) - } - if in.ManagedNamespaces != nil { - in, out := &in.ManagedNamespaces, &out.ManagedNamespaces - *out = make([]ManagedNamespace, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DeploymentSpec. -func (in *DeploymentSpec) DeepCopy() *DeploymentSpec { - if in == nil { - return nil - } - out := new(DeploymentSpec) - in.DeepCopyInto(out) - return out -} - // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *DiskGB) DeepCopyInto(out *DiskGB) { *out = *in @@ -1933,68 +1838,6 @@ func (in *ProviderSettingsSpec) DeepCopy() *ProviderSettingsSpec { return out } -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *RegionsConfig) DeepCopyInto(out *RegionsConfig) { - *out = *in - if in.AnalyticsNodes != nil { - in, out := &in.AnalyticsNodes, &out.AnalyticsNodes - *out = new(int64) - **out = **in - } - if in.ElectableNodes != nil { - in, out := &in.ElectableNodes, &out.ElectableNodes - *out = new(int64) - **out = **in - } - if in.Priority != nil { - in, out := &in.Priority, &out.Priority - *out = new(int64) - **out = **in - } - if in.ReadOnlyNodes != nil { - in, out := &in.ReadOnlyNodes, &out.ReadOnlyNodes - *out = new(int64) - **out = **in - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RegionsConfig. -func (in *RegionsConfig) DeepCopy() *RegionsConfig { - if in == nil { - return nil - } - out := new(RegionsConfig) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *ReplicationSpec) DeepCopyInto(out *ReplicationSpec) { - *out = *in - if in.NumShards != nil { - in, out := &in.NumShards, &out.NumShards - *out = new(int64) - **out = **in - } - if in.RegionsConfig != nil { - in, out := &in.RegionsConfig, &out.RegionsConfig - *out = make(map[string]RegionsConfig, len(*in)) - for key, val := range *in { - (*out)[key] = *val.DeepCopy() - } - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ReplicationSpec. -func (in *ReplicationSpec) DeepCopy() *ReplicationSpec { - if in == nil { - return nil - } - out := new(ReplicationSpec) - in.DeepCopyInto(out) - return out -} - // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *Resource) DeepCopyInto(out *Resource) { *out = *in diff --git a/pkg/controller/atlasdeployment/advanced_deployment.go b/pkg/controller/atlasdeployment/advanced_deployment.go index d54599b3d3..0ee0cd81ee 100644 --- a/pkg/controller/atlasdeployment/advanced_deployment.go +++ b/pkg/controller/atlasdeployment/advanced_deployment.go @@ -25,7 +25,7 @@ import ( const FreeTier = "M0" func (r *AtlasDeploymentReconciler) ensureAdvancedDeploymentState(ctx *workflow.Context, project *mdbv1.AtlasProject, deployment *mdbv1.AtlasDeployment) (*mongodbatlas.AdvancedCluster, workflow.Result) { - advancedDeploymentSpec := deployment.Spec.AdvancedDeploymentSpec + advancedDeploymentSpec := deployment.Spec.DeploymentSpec advancedDeployment, resp, err := ctx.Client.AdvancedClusters.Get(context.Background(), project.Status.ID, advancedDeploymentSpec.Name) @@ -50,12 +50,12 @@ func (r *AtlasDeploymentReconciler) ensureAdvancedDeploymentState(ctx *workflow. } } - result := EnsureCustomZoneMapping(ctx, project.ID(), deployment.Spec.AdvancedDeploymentSpec.CustomZoneMapping, advancedDeployment.Name) + result := EnsureCustomZoneMapping(ctx, project.ID(), deployment.Spec.DeploymentSpec.CustomZoneMapping, advancedDeployment.Name) if !result.IsOk() { return advancedDeployment, result } - result = EnsureManagedNamespaces(ctx, project.ID(), deployment.Spec.AdvancedDeploymentSpec.ClusterType, deployment.Spec.AdvancedDeploymentSpec.ManagedNamespaces, advancedDeployment.Name) + result = EnsureManagedNamespaces(ctx, project.ID(), deployment.Spec.DeploymentSpec.ClusterType, deployment.Spec.DeploymentSpec.ManagedNamespaces, advancedDeployment.Name) if !result.IsOk() { return advancedDeployment, result } @@ -78,7 +78,7 @@ func (r *AtlasDeploymentReconciler) ensureAdvancedDeploymentState(ctx *workflow. } func advancedDeploymentIdle(ctx *workflow.Context, project *mdbv1.AtlasProject, deployment *mdbv1.AtlasDeployment, atlasDeploymentAsAtlas *mongodbatlas.AdvancedCluster) (*mongodbatlas.AdvancedCluster, workflow.Result) { - specDeployment, atlasDeployment, err := MergedAdvancedDeployment(*atlasDeploymentAsAtlas, *deployment.Spec.AdvancedDeploymentSpec) + specDeployment, atlasDeployment, err := MergedAdvancedDeployment(*atlasDeploymentAsAtlas, *deployment.Spec.DeploymentSpec) if err != nil { return atlasDeploymentAsAtlas, workflow.Terminate(workflow.Internal, err.Error()) } @@ -92,7 +92,7 @@ func advancedDeploymentIdle(ctx *workflow.Context, project *mdbv1.AtlasProject, // paused is different from Atlas // we need to first send a special (un)pause request before reconciling everything else specDeployment = mdbv1.AdvancedDeploymentSpec{ - Paused: deployment.Spec.AdvancedDeploymentSpec.Paused, + Paused: deployment.Spec.DeploymentSpec.Paused, } } else { // otherwise, don't send the paused field @@ -107,7 +107,11 @@ func advancedDeploymentIdle(ctx *workflow.Context, project *mdbv1.AtlasProject, return atlasDeploymentAsAtlas, workflow.Terminate(workflow.Internal, err.Error()) } - atlasDeploymentAsAtlas, _, err = ctx.Client.AdvancedClusters.Update(context.Background(), project.Status.ID, deployment.Spec.AdvancedDeploymentSpec.Name, deploymentAsAtlas) + // TODO: Potential bug with disabling autoscaling if it was previously enabled + // j, _ := json.MarshalIndent(deploymentAsAtlas, "", " ") + // fmt.Println("DEBUG AFTER REGION SYNC", string(j)) + + atlasDeploymentAsAtlas, _, err = ctx.Client.AdvancedClusters.Update(context.Background(), project.Status.ID, deployment.Spec.DeploymentSpec.Name, deploymentAsAtlas) if err != nil { return atlasDeploymentAsAtlas, workflow.Terminate(workflow.DeploymentNotUpdatedInAtlas, err.Error()) } diff --git a/pkg/controller/atlasdeployment/advanced_deployment_test.go b/pkg/controller/atlasdeployment/advanced_deployment_test.go index e155d5c41f..1a5fcb7310 100644 --- a/pkg/controller/atlasdeployment/advanced_deployment_test.go +++ b/pkg/controller/atlasdeployment/advanced_deployment_test.go @@ -24,7 +24,7 @@ func TestMergedAdvancedDeployment(t *testing.T) { t.Run("Test merging clusters removes backing provider name if empty", func(t *testing.T) { advancedCluster := mdbv1.DefaultAwsAdvancedDeployment("default", "my-project") - merged, _, err := MergedAdvancedDeployment(*defaultAtlas, *advancedCluster.Spec.AdvancedDeploymentSpec) + merged, _, err := MergedAdvancedDeployment(*defaultAtlas, *advancedCluster.Spec.DeploymentSpec) assert.NoError(t, err) assert.Empty(t, merged.ReplicationSpecs[0].RegionConfigs[0].BackingProviderName) }) @@ -35,11 +35,11 @@ func TestMergedAdvancedDeployment(t *testing.T) { atlasRegionConfig.BackingProviderName = "AWS" advancedCluster := mdbv1.DefaultAwsAdvancedDeployment("default", "my-project") - advancedCluster.Spec.AdvancedDeploymentSpec.ReplicationSpecs[0].RegionConfigs[0].ElectableSpecs.InstanceSize = "M5" - advancedCluster.Spec.AdvancedDeploymentSpec.ReplicationSpecs[0].RegionConfigs[0].ProviderName = "TENANT" - advancedCluster.Spec.AdvancedDeploymentSpec.ReplicationSpecs[0].RegionConfigs[0].BackingProviderName = "AWS" + advancedCluster.Spec.DeploymentSpec.ReplicationSpecs[0].RegionConfigs[0].ElectableSpecs.InstanceSize = "M5" + advancedCluster.Spec.DeploymentSpec.ReplicationSpecs[0].RegionConfigs[0].ProviderName = "TENANT" + advancedCluster.Spec.DeploymentSpec.ReplicationSpecs[0].RegionConfigs[0].BackingProviderName = "AWS" - merged, _, err := MergedAdvancedDeployment(*defaultAtlas, *advancedCluster.Spec.AdvancedDeploymentSpec) + merged, _, err := MergedAdvancedDeployment(*defaultAtlas, *advancedCluster.Spec.DeploymentSpec) assert.NoError(t, err) assert.Equal(t, atlasRegionConfig.BackingProviderName, merged.ReplicationSpecs[0].RegionConfigs[0].BackingProviderName) }) @@ -53,11 +53,12 @@ func TestAdvancedDeploymentsEqual(t *testing.T) { t.Run("Test ", func(t *testing.T) { advancedCluster := mdbv1.DefaultAwsAdvancedDeployment("default", "my-project") - merged, atlas, err := MergedAdvancedDeployment(*defaultAtlas, *advancedCluster.Spec.AdvancedDeploymentSpec) + merged, atlas, err := MergedAdvancedDeployment(*defaultAtlas, *advancedCluster.Spec.DeploymentSpec) assert.NoError(t, err) logger, _ := zap.NewProduction() areEqual, _ := AdvancedDeploymentsEqual(logger.Sugar(), merged, atlas) + assert.Equalf(t, merged, atlas, "Deployments should be equal") assert.True(t, areEqual, "Deployments should be equal") }) } @@ -70,7 +71,7 @@ func makeDefaultAtlasSpec() *mongodbatlas.AdvancedCluster { { NumShards: 1, ID: "123", - ZoneName: "Zone1", + ZoneName: "Zone 1", RegionConfigs: []*mongodbatlas.AdvancedRegionConfig{ { ElectableSpecs: &mongodbatlas.Specs{ diff --git a/pkg/controller/atlasdeployment/atlasdeployment_controller.go b/pkg/controller/atlasdeployment/atlasdeployment_controller.go index 3e4776cd1b..8b6584c197 100644 --- a/pkg/controller/atlasdeployment/atlasdeployment_controller.go +++ b/pkg/controller/atlasdeployment/atlasdeployment_controller.go @@ -162,14 +162,6 @@ func (r *AtlasDeploymentReconciler) Reconcile(context context.Context, req ctrl. // convertedDeployment is either serverless or advanced, deployment must be kept unchanged // convertedDeployment is always a separate copy, to avoid changes on it to go back to k8s convertedDeployment := deployment.DeepCopy() - if deployment.IsLegacyDeployment() { - if err := ConvertLegacyDeployment(&convertedDeployment.Spec); err != nil { - result = workflow.Terminate(workflow.Internal, err.Error()) - log.Errorw("failed to convert legacy deployment", "error", err) - return result.ReconcileResult(), nil - } - convertedDeployment.Spec.DeploymentSpec = nil - } if result := r.checkDeploymentIsManaged(workflowCtx, log, project, convertedDeployment); !result.IsOk() { return result.ReconcileResult(), nil @@ -224,13 +216,6 @@ func (r *AtlasDeploymentReconciler) registerConfigAndReturn( func (r *AtlasDeploymentReconciler) verifyNonTenantCase(deployment *mdbv1.AtlasDeployment) { var pSettings *mdbv1.ProviderSettingsSpec var deploymentType string - if deployment.Spec.DeploymentSpec != nil { - if deployment.Spec.DeploymentSpec.ProviderSettings == nil { - return - } - pSettings = deployment.Spec.DeploymentSpec.ProviderSettings - deploymentType = "TENANT" - } if deployment.Spec.ServerlessSpec != nil { if deployment.Spec.ServerlessSpec.ProviderSettings == nil { @@ -249,14 +234,6 @@ func (r *AtlasDeploymentReconciler) checkDeploymentIsManaged( project *mdbv1.AtlasProject, deployment *mdbv1.AtlasDeployment, ) workflow.Result { - if deployment.IsLegacyDeployment() { - result := workflow.Terminate(workflow.Internal, "ownership check expected a converted deployment, not a legacy one") - workflowCtx.SetConditionFromResult(status.DatabaseUserReadyType, result) - log.Error(result.GetMessage()) - - return result - } - owner, err := customresource.IsOwner( deployment, r.ObjectDeletionProtection, @@ -386,7 +363,7 @@ func (r *AtlasDeploymentReconciler) handleAdvancedDeployment( return result, nil } - replicaSetStatus := make([]status.ReplicaSet, 0, len(deployment.Spec.AdvancedDeploymentSpec.ReplicationSpecs)) + replicaSetStatus := make([]status.ReplicaSet, 0, len(deployment.Spec.DeploymentSpec.ReplicationSpecs)) for _, replicaSet := range c.ReplicationSpecs { replicaSetStatus = append( replicaSetStatus, @@ -676,7 +653,7 @@ func deploymentMatchesSpec(log *zap.SugaredLogger, atlasSpec *atlasTypedCluster, if atlasSpec.clusterType != Advanced { return false, nil } - return advancedDeploymentMatchesSpec(log, atlasSpec.advanced, deployment.Spec.AdvancedDeploymentSpec) + return advancedDeploymentMatchesSpec(log, atlasSpec.advanced, deployment.Spec.DeploymentSpec) } func serverlessDeploymentMatchesSpec(log *zap.SugaredLogger, atlasSpec *mongodbatlas.Cluster, operatorSpec *mdbv1.ServerlessSpec) (bool, error) { @@ -720,8 +697,8 @@ func uniqueKey(deploymentSpec *mdbv1.AtlasDeploymentSpec) error { store := make(map[string]string) var arrTags []*mdbv1.TagSpec - if deploymentSpec.AdvancedDeploymentSpec != nil { - arrTags = deploymentSpec.AdvancedDeploymentSpec.Tags + if deploymentSpec.DeploymentSpec != nil { + arrTags = deploymentSpec.DeploymentSpec.Tags } else { arrTags = deploymentSpec.ServerlessSpec.Tags } diff --git a/pkg/controller/atlasdeployment/atlasdeployment_controller_test.go b/pkg/controller/atlasdeployment/atlasdeployment_controller_test.go index 74fbb871ec..06e2b0dc39 100644 --- a/pkg/controller/atlasdeployment/atlasdeployment_controller_test.go +++ b/pkg/controller/atlasdeployment/atlasdeployment_controller_test.go @@ -92,7 +92,7 @@ func TestDeploymentManaged(t *testing.T) { }, } project := testProject(fakeNamespace) - deployment := asAdvanced(v1.NewDeployment(project.Namespace, fakeDeployment, fakeDeployment)) + deployment := v1.NewDeployment(project.Namespace, fakeDeployment, fakeDeployment) te := newTestDeploymentEnv(t, tc.protected, atlasClient, testK8sClient(), project, deployment) if tc.managedTag { customresource.SetAnnotation(te.deployment, customresource.AnnotationLastAppliedConfiguration, "") @@ -133,7 +133,7 @@ func TestProtectedAdvancedDeploymentManagedInAtlas(t *testing.T) { }, }, } - deployment := asAdvanced(v1.NewDeployment(project.Namespace, fakeDeployment, fakeDeployment)) + deployment := v1.NewDeployment(project.Namespace, fakeDeployment, fakeDeployment) te := newTestDeploymentEnv(t, protected, atlasClient, testK8sClient(), project, deployment) result := te.reconciler.checkDeploymentIsManaged(te.workflowCtx, te.log, te.project, te.deployment) @@ -147,27 +147,6 @@ func TestProtectedAdvancedDeploymentManagedInAtlas(t *testing.T) { } } -func TestLegacyIsManagedInAtlasMustFail(t *testing.T) { - t.Run("Legacy deployment must fail to check if it is managed in Atlas", func(t *testing.T) { - protected := true - project := testProject(fakeNamespace) - inAtlas := differentAdvancedDeployment(fakeNamespace) - atlasClient := mongodbatlas.Client{ - AdvancedClusters: &atlas_mock.AdvancedClustersClientMock{ - GetFunc: func(groupID string, clusterName string) (*mongodbatlas.AdvancedCluster, *mongodbatlas.Response, error) { - return inAtlas, nil, nil - }, - }, - } - deployment := v1.NewDeployment(project.Namespace, fakeDeployment, fakeDeployment) - te := newTestDeploymentEnv(t, protected, atlasClient, testK8sClient(), project, deployment) - - result := te.reconciler.checkDeploymentIsManaged(te.workflowCtx, te.log, te.project, te.deployment) - - assert.Regexp(t, regexp.MustCompile("ownership check expected a converted deployment"), result.GetMessage()) - }) -} - func TestProtectedServerlessManagedInAtlas(t *testing.T) { testCases := []struct { title string @@ -478,7 +457,7 @@ func TestCleanupBindings(t *testing.T) { schedule := testBackupSchedule("", policy) deployment := testDeployment("", schedule) require.NoError(t, r.Client.Create(context.Background(), deployment)) - schedule.Status.DeploymentIDs = []string{deployment.Spec.AdvancedDeploymentSpec.Name} + schedule.Status.DeploymentIDs = []string{deployment.Spec.DeploymentSpec.Name} require.NoError(t, r.Client.Create(context.Background(), schedule)) // test ensureBackupPolicy and cleanup @@ -507,8 +486,8 @@ func TestCleanupBindings(t *testing.T) { deployment2 := testDeployment("2", schedule) require.NoError(t, r.Client.Create(context.Background(), deployment2)) schedule.Status.DeploymentIDs = []string{ - deployment.Spec.AdvancedDeploymentSpec.Name, - deployment2.Spec.AdvancedDeploymentSpec.Name, + deployment.Spec.DeploymentSpec.Name, + deployment2.Spec.DeploymentSpec.Name, } require.NoError(t, r.Client.Create(context.Background(), schedule)) @@ -539,11 +518,11 @@ func TestCleanupBindings(t *testing.T) { deployment2 := testDeployment("2", schedule2) require.NoError(t, r.Client.Create(context.Background(), deployment2)) schedule.Status.DeploymentIDs = []string{ - deployment.Spec.AdvancedDeploymentSpec.Name, + deployment.Spec.DeploymentSpec.Name, } require.NoError(t, r.Client.Create(context.Background(), schedule)) schedule2.Status.DeploymentIDs = []string{ - deployment2.Spec.AdvancedDeploymentSpec.Name, + deployment2.Spec.DeploymentSpec.Name, } require.NoError(t, r.Client.Create(context.Background(), schedule2)) policy.Status.BackupScheduleIDs = []string{ @@ -570,15 +549,15 @@ func TestCleanupBindings(t *testing.T) { func differentAdvancedDeployment(ns string) *mongodbatlas.AdvancedCluster { project := testProject(ns) deployment := v1.NewDeployment(project.Namespace, fakeDeployment, fakeDeployment) - deployment.Spec.DeploymentSpec.ProviderSettings.InstanceSizeName = "M2" - advancedSpec := asAdvanced(deployment).Spec.AdvancedDeploymentSpec + deployment.Spec.DeploymentSpec.ReplicationSpecs[0].RegionConfigs[0].ElectableSpecs.InstanceSize = "M2" + advancedSpec := deployment.Spec.DeploymentSpec return intoAdvancedAtlasCluster(advancedSpec) } func sameAdvancedDeployment(ns string) *mongodbatlas.AdvancedCluster { project := testProject(ns) - deployment := asAdvanced(v1.NewDeployment(project.Namespace, fakeDeployment, fakeDeployment)) - advancedSpec := asAdvanced(deployment).Spec.AdvancedDeploymentSpec + deployment := v1.NewDeployment(project.Namespace, fakeDeployment, fakeDeployment) + advancedSpec := deployment.Spec.DeploymentSpec return intoAdvancedAtlasCluster(advancedSpec) } @@ -669,13 +648,13 @@ func testProject(ns string) *v1.AtlasProject { } } -func asAdvanced(deployment *v1.AtlasDeployment) *v1.AtlasDeployment { - if err := ConvertLegacyDeployment(&deployment.Spec); err != nil { - log.Fatalf("failed to convert legacy deployment: %v", err) - } - deployment.Spec.DeploymentSpec = nil - return deployment -} +// func asAdvanced(deployment *v1.AtlasDeployment) *v1.AtlasDeployment { +// if err := ConvertLegacyDeployment(&deployment.Spec); err != nil { +// log.Fatalf("failed to convert legacy deployment: %v", err) +// } +// deployment.Spec.DeploymentSpec = nil +// return deployment +// } func intoAdvancedAtlasCluster(advancedSpec *v1.AdvancedDeploymentSpec) *mongodbatlas.AdvancedCluster { ac, err := advancedSpec.ToAtlas() @@ -705,7 +684,7 @@ func testDeployment(suffix string, schedule *v1.AtlasBackupSchedule) *v1.AtlasDe return &v1.AtlasDeployment{ ObjectMeta: metav1.ObjectMeta{Name: dn.Name, Namespace: dn.Namespace}, Spec: v1.AtlasDeploymentSpec{ - AdvancedDeploymentSpec: &v1.AdvancedDeploymentSpec{ + DeploymentSpec: &v1.AdvancedDeploymentSpec{ Name: fmt.Sprintf("atlas-%s", dn.Name), }, BackupScheduleRef: common.ResourceRefNamespaced{ @@ -752,7 +731,7 @@ func testBackupPolicy() *v1.AtlasBackupPolicy { func TestUniqueKey(t *testing.T) { t.Run("Test duplicates in Advanced Deployment", func(t *testing.T) { deploymentSpec := &v1.AtlasDeploymentSpec{ - AdvancedDeploymentSpec: &v1.AdvancedDeploymentSpec{ + DeploymentSpec: &v1.AdvancedDeploymentSpec{ Tags: []*v1.TagSpec{{Key: "foo", Value: "true"}, {Key: "foo", Value: "false"}}, }, } @@ -761,7 +740,7 @@ func TestUniqueKey(t *testing.T) { }) t.Run("Test no duplicates in Advanced Deployment", func(t *testing.T) { deploymentSpec := &v1.AtlasDeploymentSpec{ - AdvancedDeploymentSpec: &v1.AdvancedDeploymentSpec{ + DeploymentSpec: &v1.AdvancedDeploymentSpec{ Tags: []*v1.TagSpec{{Key: "foo", Value: "true"}, {Key: "bar", Value: "false"}, {Key: "foobar", Value: "false"}}, }, } diff --git a/pkg/controller/atlasdeployment/backup_test.go b/pkg/controller/atlasdeployment/backup_test.go index 5658a3de56..57dc19aa85 100644 --- a/pkg/controller/atlasdeployment/backup_test.go +++ b/pkg/controller/atlasdeployment/backup_test.go @@ -25,7 +25,7 @@ const ( func Test_backupScheduleManagedByAtlas(t *testing.T) { deploment := &mdbv1.AtlasDeployment{ Spec: mdbv1.AtlasDeploymentSpec{ - AdvancedDeploymentSpec: &mdbv1.AdvancedDeploymentSpec{ + DeploymentSpec: &mdbv1.AdvancedDeploymentSpec{ Name: clusterName, }, }, diff --git a/pkg/controller/atlasdeployment/deployment.go b/pkg/controller/atlasdeployment/deployment.go deleted file mode 100644 index e87b2eecf6..0000000000 --- a/pkg/controller/atlasdeployment/deployment.go +++ /dev/null @@ -1,183 +0,0 @@ -package atlasdeployment - -import ( - "errors" - - "github.com/mongodb/mongodb-atlas-kubernetes/pkg/api/v1/provider" - - mdbv1 "github.com/mongodb/mongodb-atlas-kubernetes/pkg/api/v1" - "github.com/mongodb/mongodb-atlas-kubernetes/pkg/util/toptr" -) - -const deploymentProviderTenant provider.ProviderName = "TENANT" - -func ConvertLegacyDeployment(deploymentSpec *mdbv1.AtlasDeploymentSpec) error { - legacy := deploymentSpec.DeploymentSpec - - if legacy == nil { - return nil - } - - replicationSpecs, err := convertLegacyReplicationSpecs(legacy) - if err != nil { - return err - } - - deploymentSpec.AdvancedDeploymentSpec = &mdbv1.AdvancedDeploymentSpec{ - BackupEnabled: legacy.ProviderBackupEnabled, - BiConnector: legacy.BIConnector, - ClusterType: getDefaultClusterType(legacy.ClusterType), - DiskSizeGB: legacy.DiskSizeGB, - EncryptionAtRestProvider: legacy.EncryptionAtRestProvider, - Labels: legacy.Labels, - MongoDBMajorVersion: legacy.MongoDBMajorVersion, - Name: legacy.Name, - Tags: legacy.Tags, - Paused: legacy.Paused, - PitEnabled: legacy.PitEnabled, - ReplicationSpecs: replicationSpecs, - CustomZoneMapping: legacy.CustomZoneMapping, - ManagedNamespaces: legacy.ManagedNamespaces, - } - - return nil -} - -func convertLegacyReplicationSpecs(legacy *mdbv1.DeploymentSpec) ([]*mdbv1.AdvancedReplicationSpec, error) { - result := []*mdbv1.AdvancedReplicationSpec{} - - if legacy == nil { - return result, nil - } - - if legacy.ProviderSettings == nil { - return nil, errors.New("ProviderSettings should not be empty") - } - - if len(legacy.ReplicationSpecs) == 0 { - fillDefaultReplicationSpec(legacy) - } - - for _, legacyResplicationSpec := range legacy.ReplicationSpecs { - resplicationSpec := &mdbv1.AdvancedReplicationSpec{ - NumShards: *convertLegacyInt64(legacyResplicationSpec.NumShards), - ZoneName: legacyResplicationSpec.ZoneName, - RegionConfigs: []*mdbv1.AdvancedRegionConfig{}, - } - - for legacyRegion, legacyRegionConfig := range legacyResplicationSpec.RegionsConfig { - regionConfig := mdbv1.AdvancedRegionConfig{ - AnalyticsSpecs: &mdbv1.Specs{ - DiskIOPS: legacy.ProviderSettings.DiskIOPS, - EbsVolumeType: legacy.ProviderSettings.VolumeType, - InstanceSize: legacy.ProviderSettings.InstanceSizeName, - NodeCount: convertLegacyInt64(legacyRegionConfig.AnalyticsNodes), - }, - ElectableSpecs: &mdbv1.Specs{ - DiskIOPS: legacy.ProviderSettings.DiskIOPS, - EbsVolumeType: legacy.ProviderSettings.VolumeType, - InstanceSize: legacy.ProviderSettings.InstanceSizeName, - NodeCount: convertLegacyInt64(legacyRegionConfig.ElectableNodes), - }, - ReadOnlySpecs: &mdbv1.Specs{ - DiskIOPS: legacy.ProviderSettings.DiskIOPS, - EbsVolumeType: legacy.ProviderSettings.VolumeType, - InstanceSize: legacy.ProviderSettings.InstanceSizeName, - NodeCount: convertLegacyInt64(legacyRegionConfig.ReadOnlyNodes), - }, - AutoScaling: convertLegacyAutoScaling(legacy.ProviderSettings.ProviderName, legacy.AutoScaling, legacy.ProviderSettings.AutoScaling), - BackingProviderName: legacy.ProviderSettings.BackingProviderName, - Priority: convertLegacyInt64(legacyRegionConfig.Priority), - ProviderName: string(legacy.ProviderSettings.ProviderName), - RegionName: legacyRegion, - } - - resplicationSpec.RegionConfigs = append(resplicationSpec.RegionConfigs, ®ionConfig) - } - - result = append(result, resplicationSpec) - } - - return result, nil -} - -func convertLegacyAutoScaling(provider provider.ProviderName, legacyRoot, legacyPS *mdbv1.AutoScalingSpec) *mdbv1.AdvancedAutoScalingSpec { - if provider == deploymentProviderTenant { - return nil - } - - autoScaling := &mdbv1.AdvancedAutoScalingSpec{ - DiskGB: &mdbv1.DiskGB{ - Enabled: toptr.MakePtr(false), - }, - Compute: &mdbv1.ComputeSpec{ - Enabled: toptr.MakePtr(false), - ScaleDownEnabled: toptr.MakePtr(false), - }, - } - - if legacyRoot != nil { - autoScaling.DiskGB.Enabled = legacyRoot.DiskGBEnabled - } - - if legacyRoot != nil && legacyRoot.Compute != nil && legacyRoot.Compute.Enabled != nil { - autoScaling.Compute.Enabled = legacyRoot.Compute.Enabled - - if legacyRoot.Compute.ScaleDownEnabled != nil { - autoScaling.Compute.ScaleDownEnabled = legacyRoot.Compute.ScaleDownEnabled - } - - if legacyPS != nil && legacyPS.Compute != nil { - autoScaling.Compute.MinInstanceSize = emptyIfDisabled(legacyPS.Compute.MinInstanceSize, legacyRoot.Compute.Enabled) - autoScaling.Compute.MaxInstanceSize = emptyIfDisabled(legacyPS.Compute.MaxInstanceSize, legacyRoot.Compute.Enabled) - } - } - - return autoScaling -} - -func fillDefaultReplicationSpec(legacy *mdbv1.DeploymentSpec) { - replicationSpec := mdbv1.ReplicationSpec{ - NumShards: toptr.MakePtr[int64](1), - RegionsConfig: map[string]mdbv1.RegionsConfig{ - legacy.ProviderSettings.RegionName: { - AnalyticsNodes: toptr.MakePtr(int64(0)), - ElectableNodes: toptr.MakePtr(int64(3)), - ReadOnlyNodes: toptr.MakePtr(int64(0)), - Priority: toptr.MakePtr(int64(7)), - }, - }, - } - - if legacy.ClusterType == mdbv1.TypeGeoSharded { - replicationSpec.ZoneName = "Zone 1" - } - - legacy.ReplicationSpecs = append(legacy.ReplicationSpecs, replicationSpec) -} - -func getDefaultClusterType(legacyType mdbv1.DeploymentType) string { - clusterType := mdbv1.TypeReplicaSet - - if legacyType != "" { - clusterType = legacyType - } - - return string(clusterType) -} - -func convertLegacyInt64(input *int64) *int { - if input == nil { - return nil - } - - return toptr.MakePtr(int(*input)) -} - -func emptyIfDisabled(value string, flag *bool) string { - if flag == nil || !*flag { - return "" - } - - return value -} diff --git a/pkg/controller/atlasdeployment/deployment_test.go b/pkg/controller/atlasdeployment/deployment_test.go index 74f0b60625..5f6c9e6618 100644 --- a/pkg/controller/atlasdeployment/deployment_test.go +++ b/pkg/controller/atlasdeployment/deployment_test.go @@ -1,33 +1,28 @@ package atlasdeployment import ( - "testing" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" v1 "github.com/mongodb/mongodb-atlas-kubernetes/pkg/api/v1" "github.com/mongodb/mongodb-atlas-kubernetes/pkg/api/v1/common" - "github.com/mongodb/mongodb-atlas-kubernetes/pkg/api/v1/provider" "github.com/mongodb/mongodb-atlas-kubernetes/pkg/util/toptr" - - "github.com/stretchr/testify/assert" ) -func TestConvertLegacyDeployment(t *testing.T) { - deployment := CreateBasicDeployment("deplyment-name") +// func TestConvertLegacyDeployment(t *testing.T) { +// deployment := CreateBasicDeployment("deplyment-name") - t.Run("Legacy Deployment can be converted", func(t *testing.T) { - err := ConvertLegacyDeployment(&deployment.Spec) - assert.NoError(t, err) - }) +// t.Run("Legacy Deployment can be converted", func(t *testing.T) { +// err := ConvertLegacyDeployment(&deployment.Spec) +// assert.NoError(t, err) +// }) - deploymentMultiregion := CreateDeploymentWithMultiregion("deplyment-multiregion-name", provider.ProviderAWS) +// deploymentMultiregion := CreateDeploymentWithMultiregion("deplyment-multiregion-name", provider.ProviderAWS) - t.Run("Legacy Multiregion Deployment can be converted", func(t *testing.T) { - err := ConvertLegacyDeployment(&deploymentMultiregion.Spec) - assert.NoError(t, err) - }) -} +// t.Run("Legacy Multiregion Deployment can be converted", func(t *testing.T) { +// err := ConvertLegacyDeployment(&deploymentMultiregion.Spec) +// assert.NoError(t, err) +// }) +// } func CreateBasicDeployment(name string) *v1.AtlasDeployment { return &v1.AtlasDeployment{ @@ -38,70 +33,91 @@ func CreateBasicDeployment(name string) *v1.AtlasDeployment { Project: common.ResourceRefNamespaced{ Name: "my-project", }, - DeploymentSpec: &v1.DeploymentSpec{ + DeploymentSpec: &v1.AdvancedDeploymentSpec{ Name: "cluster-basics", - ProviderSettings: &v1.ProviderSettingsSpec{ - InstanceSizeName: "M2", - ProviderName: "TENANT", - RegionName: "US_EAST_1", - BackingProviderName: "AWS", + ReplicationSpecs: []*v1.AdvancedReplicationSpec{ + { + NumShards: 0, + ZoneName: name, + RegionConfigs: []*v1.AdvancedRegionConfig{ + { + AnalyticsSpecs: &v1.Specs{}, + ElectableSpecs: &v1.Specs{ + InstanceSize: "M2", + NodeCount: toptr.MakePtr(3), + }, + ReadOnlySpecs: &v1.Specs{}, + AutoScaling: &v1.AdvancedAutoScalingSpec{}, + BackingProviderName: "AWS", + Priority: toptr.MakePtr(7), + ProviderName: "TENANT", + RegionName: "US_EAST_1", + }, + }, + }, }, + // ProviderSettings: &v1.ProviderSettingsSpec{ + // InstanceSizeName: "M2", + // ProviderName: "TENANT", + // RegionName: "US_EAST_1", + // BackingProviderName: "AWS", + // }, }, }, } } -func CreateDeploymentWithMultiregion(name string, providerName provider.ProviderName) *v1.AtlasDeployment { - var regions []string - switch providerName { - case provider.ProviderAWS: - regions = []string{"US_EAST_1", "US_WEST_2"} - case provider.ProviderAzure: - regions = []string{"NORWAY_EAST", "GERMANY_NORTH"} - case provider.ProviderGCP: - regions = []string{"CENTRAL_US", "EASTERN_US"} - } +// func CreateDeploymentWithMultiregion(name string, providerName provider.ProviderName) *v1.AtlasDeployment { +// var regions []string +// switch providerName { +// case provider.ProviderAWS: +// regions = []string{"US_EAST_1", "US_WEST_2"} +// case provider.ProviderAzure: +// regions = []string{"NORWAY_EAST", "GERMANY_NORTH"} +// case provider.ProviderGCP: +// regions = []string{"CENTRAL_US", "EASTERN_US"} +// } - if len(regions) == 0 { - panic("unknown provider") - } +// if len(regions) == 0 { +// panic("unknown provider") +// } - return &v1.AtlasDeployment{ - ObjectMeta: metav1.ObjectMeta{ - Name: name, - }, - Spec: v1.AtlasDeploymentSpec{ - Project: common.ResourceRefNamespaced{ - Name: "my-project", - }, - DeploymentSpec: &v1.DeploymentSpec{ - Name: "deployment-multiregion", - ProviderBackupEnabled: toptr.MakePtr(true), - ClusterType: "REPLICASET", - ProviderSettings: &v1.ProviderSettingsSpec{ - InstanceSizeName: "M10", - ProviderName: providerName, - }, - ReplicationSpecs: []v1.ReplicationSpec{ - { - NumShards: toptr.MakePtr(int64(1)), - ZoneName: "US-Zone", - RegionsConfig: map[string]v1.RegionsConfig{ - regions[0]: { - AnalyticsNodes: toptr.MakePtr(int64(0)), - ElectableNodes: toptr.MakePtr(int64(1)), - Priority: toptr.MakePtr(int64(6)), - ReadOnlyNodes: toptr.MakePtr(int64(0)), - }, - regions[1]: { - AnalyticsNodes: toptr.MakePtr(int64(0)), - ElectableNodes: toptr.MakePtr(int64(2)), - Priority: toptr.MakePtr(int64(7)), - ReadOnlyNodes: toptr.MakePtr(int64(0)), - }, - }, - }, - }, - }, - }} -} +// return &v1.AtlasDeployment{ +// ObjectMeta: metav1.ObjectMeta{ +// Name: name, +// }, +// Spec: v1.AtlasDeploymentSpec{ +// Project: common.ResourceRefNamespaced{ +// Name: "my-project", +// }, +// DeploymentSpec: &v1.AdvancedDeploymentSpec{ +// Name: "deployment-multiregion", +// ProviderBackupEnabled: toptr.MakePtr(true), +// ClusterType: "REPLICASET", +// ProviderSettings: &v1.ProviderSettingsSpec{ +// InstanceSizeName: "M10", +// ProviderName: providerName, +// }, +// ReplicationSpecs: []v1.ReplicationSpec{ +// { +// NumShards: toptr.MakePtr(int64(1)), +// ZoneName: "US-Zone", +// RegionsConfig: map[string]v1.RegionsConfig{ +// regions[0]: { +// AnalyticsNodes: toptr.MakePtr(int64(0)), +// ElectableNodes: toptr.MakePtr(int64(1)), +// Priority: toptr.MakePtr(int64(6)), +// ReadOnlyNodes: toptr.MakePtr(int64(0)), +// }, +// regions[1]: { +// AnalyticsNodes: toptr.MakePtr(int64(0)), +// ElectableNodes: toptr.MakePtr(int64(2)), +// Priority: toptr.MakePtr(int64(7)), +// ReadOnlyNodes: toptr.MakePtr(int64(0)), +// }, +// }, +// }, +// }, +// }, +// }} +// } diff --git a/pkg/controller/validate/validate.go b/pkg/controller/validate/validate.go index 71a1554898..436a542112 100644 --- a/pkg/controller/validate/validate.go +++ b/pkg/controller/validate/validate.go @@ -39,12 +39,12 @@ type googleServiceAccountKey struct { func DeploymentSpec(deploymentSpec *mdbv1.AtlasDeploymentSpec, isGov bool, regionUsageRestrictions string) error { var err error - if allAreNil(deploymentSpec.AdvancedDeploymentSpec, deploymentSpec.ServerlessSpec, deploymentSpec.DeploymentSpec) { - err = errors.Join(err, errors.New("expected exactly one of spec.deploymentSpec or spec.advancedDeploymentSpec or spec.serverlessSpec to be present, but none were")) + if allAreNil(deploymentSpec.ServerlessSpec, deploymentSpec.DeploymentSpec) { + err = errors.Join(err, errors.New("expected exactly one of spec.deploymentSpec or spec.serverlessSpec to be present, but none were")) } - if moreThanOneIsNonNil(deploymentSpec.AdvancedDeploymentSpec, deploymentSpec.ServerlessSpec, deploymentSpec.DeploymentSpec) { - err = errors.Join(err, errors.New("expected exactly one of spec.deploymentSpec, spec.advancedDeploymentSpec or spec.serverlessSpec, more than one were present")) + if moreThanOneIsNonNil(deploymentSpec.ServerlessSpec, deploymentSpec.DeploymentSpec) { + err = errors.Join(err, errors.New("expected exactly one of spec.deploymentSpec or spec.serverlessSpec, more than one were present")) } if isGov { @@ -54,26 +54,17 @@ func DeploymentSpec(deploymentSpec *mdbv1.AtlasDeploymentSpec, isGov bool, regio } if deploymentSpec.DeploymentSpec != nil { - if deploymentSpec.DeploymentSpec.ProviderSettings != nil && (deploymentSpec.DeploymentSpec.ProviderSettings.InstanceSizeName == "" && deploymentSpec.DeploymentSpec.ProviderSettings.ProviderName != "SERVERLESS") { - err = errors.Join(err, errors.New("must specify instanceSizeName if provider name is not SERVERLESS")) - } - if deploymentSpec.DeploymentSpec.ProviderSettings != nil && (deploymentSpec.DeploymentSpec.ProviderSettings.InstanceSizeName != "" && deploymentSpec.DeploymentSpec.ProviderSettings.ProviderName == "SERVERLESS") { - err = errors.Join(err, errors.New("must not specify instanceSizeName if provider name is SERVERLESS")) - } - } - - if deploymentSpec.AdvancedDeploymentSpec != nil { - autoscalingErr := autoscalingForAdvancedDeployment(deploymentSpec.AdvancedDeploymentSpec.ReplicationSpecs) + autoscalingErr := autoscalingForAdvancedDeployment(deploymentSpec.DeploymentSpec.ReplicationSpecs) if autoscalingErr != nil { err = errors.Join(err, autoscalingErr) } - instanceSizeErr := instanceSizeForAdvancedDeployment(deploymentSpec.AdvancedDeploymentSpec.ReplicationSpecs) + instanceSizeErr := instanceSizeForAdvancedDeployment(deploymentSpec.DeploymentSpec.ReplicationSpecs) if instanceSizeErr != nil { err = errors.Join(err, instanceSizeErr) } - instanceSizeRangeErr := instanceSizeRangeForAdvancedDeployment(deploymentSpec.AdvancedDeploymentSpec.ReplicationSpecs) + instanceSizeRangeErr := instanceSizeRangeForAdvancedDeployment(deploymentSpec.DeploymentSpec.ReplicationSpecs) if instanceSizeRangeErr != nil { err = errors.Join(err, instanceSizeRangeErr) } @@ -86,14 +77,7 @@ func deploymentForGov(deployment *mdbv1.AtlasDeploymentSpec, regionUsageRestrict var err error if deployment.DeploymentSpec != nil { - regionErr := validCloudGovRegion(regionUsageRestrictions, deployment.DeploymentSpec.ProviderSettings.RegionName) - if regionErr != nil { - err = errors.Join(err, fmt.Errorf("deployment in atlas for government support a restricted set of regions: %w", regionErr)) - } - } - - if deployment.AdvancedDeploymentSpec != nil { - for _, replication := range deployment.AdvancedDeploymentSpec.ReplicationSpecs { + for _, replication := range deployment.DeploymentSpec.ReplicationSpecs { for _, region := range replication.RegionConfigs { regionErr := validCloudGovRegion(regionUsageRestrictions, region.RegionName) if regionErr != nil { @@ -247,12 +231,6 @@ func BackupSchedule(bSchedule *mdbv1.AtlasBackupSchedule, deployment *mdbv1.Atla } if copySetting.ShouldCopyOplogs != nil && *copySetting.ShouldCopyOplogs { - if deployment.Spec.AdvancedDeploymentSpec != nil && - (deployment.Spec.AdvancedDeploymentSpec.PitEnabled == nil || - !*deployment.Spec.AdvancedDeploymentSpec.PitEnabled) { - err = errors.Join(err, fmt.Errorf("copy setting at position %d: you must enable pit before enable copyOplogs", position)) - } - if deployment.Spec.DeploymentSpec != nil && (deployment.Spec.DeploymentSpec.PitEnabled == nil || !*deployment.Spec.DeploymentSpec.PitEnabled) { diff --git a/pkg/controller/validate/validate_test.go b/pkg/controller/validate/validate_test.go index 6de2ec0893..cc1a760c15 100644 --- a/pkg/controller/validate/validate_test.go +++ b/pkg/controller/validate/validate_test.go @@ -24,35 +24,35 @@ import ( func TestClusterValidation(t *testing.T) { t.Run("Invalid cluster specs", func(t *testing.T) { t.Run("Multiple specs specified", func(t *testing.T) { - spec := mdbv1.AtlasDeploymentSpec{AdvancedDeploymentSpec: &mdbv1.AdvancedDeploymentSpec{}, DeploymentSpec: &mdbv1.DeploymentSpec{}} + spec := mdbv1.AtlasDeploymentSpec{DeploymentSpec: &mdbv1.AdvancedDeploymentSpec{}, ServerlessSpec: &mdbv1.ServerlessSpec{}} assert.Error(t, DeploymentSpec(&spec, false, "NONE")) }) t.Run("No specs specified", func(t *testing.T) { - spec := mdbv1.AtlasDeploymentSpec{AdvancedDeploymentSpec: nil, DeploymentSpec: nil} - assert.Error(t, DeploymentSpec(&spec, false, "NONE")) - }) - t.Run("Instance size not empty when serverless", func(t *testing.T) { - spec := mdbv1.AtlasDeploymentSpec{AdvancedDeploymentSpec: nil, DeploymentSpec: &mdbv1.DeploymentSpec{ - ProviderSettings: &mdbv1.ProviderSettingsSpec{ - InstanceSizeName: "M10", - ProviderName: "SERVERLESS", - }, - }} - assert.Error(t, DeploymentSpec(&spec, false, "NONE")) - }) - t.Run("Instance size unset when not serverless", func(t *testing.T) { - spec := mdbv1.AtlasDeploymentSpec{AdvancedDeploymentSpec: nil, DeploymentSpec: &mdbv1.DeploymentSpec{ - ProviderSettings: &mdbv1.ProviderSettingsSpec{ - InstanceSizeName: "", - ProviderName: "AWS", - }, - }} + spec := mdbv1.AtlasDeploymentSpec{DeploymentSpec: nil} assert.Error(t, DeploymentSpec(&spec, false, "NONE")) }) + // t.Run("Instance size not empty when serverless", func(t *testing.T) { + // spec := mdbv1.AtlasDeploymentSpec{ServerlessSpec: nil, DeploymentSpec: &mdbv1.AdvancedDeploymentSpec{ + // ProviderSettings: &mdbv1.ProviderSettingsSpec{ + // InstanceSizeName: "M10", + // ProviderName: "SERVERLESS", + // }, + // }} + // assert.Error(t, DeploymentSpec(&spec, false, "NONE")) + // }) + // t.Run("Instance size unset when not serverless", func(t *testing.T) { + // spec := mdbv1.AtlasDeploymentSpec{AdvancedDeploymentSpec: nil, DeploymentSpec: &mdbv1.DeploymentSpec{ + // ProviderSettings: &mdbv1.ProviderSettingsSpec{ + // InstanceSizeName: "", + // ProviderName: "AWS", + // }, + // }} + // assert.Error(t, DeploymentSpec(&spec, false, "NONE")) + // }) t.Run("different instance sizes for advanced deployment", func(t *testing.T) { t.Run("different instance size in the same region", func(t *testing.T) { spec := mdbv1.AtlasDeploymentSpec{ - AdvancedDeploymentSpec: &mdbv1.AdvancedDeploymentSpec{ + DeploymentSpec: &mdbv1.AdvancedDeploymentSpec{ ReplicationSpecs: []*mdbv1.AdvancedReplicationSpec{ { RegionConfigs: []*mdbv1.AdvancedRegionConfig{ @@ -70,7 +70,7 @@ func TestClusterValidation(t *testing.T) { }) t.Run("different instance size in different regions", func(t *testing.T) { spec := mdbv1.AtlasDeploymentSpec{ - AdvancedDeploymentSpec: &mdbv1.AdvancedDeploymentSpec{ + DeploymentSpec: &mdbv1.AdvancedDeploymentSpec{ ReplicationSpecs: []*mdbv1.AdvancedReplicationSpec{ { RegionConfigs: []*mdbv1.AdvancedRegionConfig{ @@ -93,7 +93,7 @@ func TestClusterValidation(t *testing.T) { }) t.Run("different instance size in different replications", func(t *testing.T) { spec := mdbv1.AtlasDeploymentSpec{ - AdvancedDeploymentSpec: &mdbv1.AdvancedDeploymentSpec{ + DeploymentSpec: &mdbv1.AdvancedDeploymentSpec{ ReplicationSpecs: []*mdbv1.AdvancedReplicationSpec{ { RegionConfigs: []*mdbv1.AdvancedRegionConfig{ @@ -122,7 +122,7 @@ func TestClusterValidation(t *testing.T) { t.Run("different autoscaling for advanced deployment", func(t *testing.T) { t.Run("different instance size in different regions", func(t *testing.T) { spec := mdbv1.AtlasDeploymentSpec{ - AdvancedDeploymentSpec: &mdbv1.AdvancedDeploymentSpec{ + DeploymentSpec: &mdbv1.AdvancedDeploymentSpec{ ReplicationSpecs: []*mdbv1.AdvancedReplicationSpec{ { RegionConfigs: []*mdbv1.AdvancedRegionConfig{ @@ -153,7 +153,7 @@ func TestClusterValidation(t *testing.T) { }) t.Run("different autoscaling in different replications", func(t *testing.T) { spec := mdbv1.AtlasDeploymentSpec{ - AdvancedDeploymentSpec: &mdbv1.AdvancedDeploymentSpec{ + DeploymentSpec: &mdbv1.AdvancedDeploymentSpec{ ReplicationSpecs: []*mdbv1.AdvancedReplicationSpec{ { RegionConfigs: []*mdbv1.AdvancedRegionConfig{ @@ -190,28 +190,22 @@ func TestClusterValidation(t *testing.T) { }) t.Run("Valid cluster specs", func(t *testing.T) { t.Run("Advanced cluster spec specified", func(t *testing.T) { - spec := mdbv1.AtlasDeploymentSpec{AdvancedDeploymentSpec: &mdbv1.AdvancedDeploymentSpec{}, DeploymentSpec: nil} - assert.NoError(t, DeploymentSpec(&spec, false, "NONE")) - assert.Nil(t, DeploymentSpec(&spec, false, "NONE")) - }) - t.Run("Regular cluster specs specified", func(t *testing.T) { - spec := mdbv1.AtlasDeploymentSpec{AdvancedDeploymentSpec: nil, DeploymentSpec: &mdbv1.DeploymentSpec{}} - assert.NoError(t, DeploymentSpec(&spec, false, "NONE")) - assert.Nil(t, DeploymentSpec(&spec, false, "NONE")) - }) - - t.Run("Serverless Cluster", func(t *testing.T) { - spec := mdbv1.AtlasDeploymentSpec{AdvancedDeploymentSpec: nil, DeploymentSpec: &mdbv1.DeploymentSpec{ - ProviderSettings: &mdbv1.ProviderSettingsSpec{ - ProviderName: "SERVERLESS", - }, - }} + spec := mdbv1.AtlasDeploymentSpec{DeploymentSpec: &mdbv1.AdvancedDeploymentSpec{}, ServerlessSpec: nil} assert.NoError(t, DeploymentSpec(&spec, false, "NONE")) assert.Nil(t, DeploymentSpec(&spec, false, "NONE")) }) + // t.Run("Serverless Cluster", func(t *testing.T) { + // spec := mdbv1.AtlasDeploymentSpec{AdvancedDeploymentSpec: nil, DeploymentSpec: &mdbv1.AdvancedDeploymentSpec{ + // ProviderSettings: &mdbv1.ProviderSettingsSpec{ + // ProviderName: "SERVERLESS", + // }, + // }} + // assert.NoError(t, DeploymentSpec(&spec, false, "NONE")) + // assert.Nil(t, DeploymentSpec(&spec, false, "NONE")) + // }) t.Run("Advanced cluster with replication config", func(t *testing.T) { spec := mdbv1.AtlasDeploymentSpec{ - AdvancedDeploymentSpec: &mdbv1.AdvancedDeploymentSpec{ + DeploymentSpec: &mdbv1.AdvancedDeploymentSpec{ ReplicationSpecs: []*mdbv1.AdvancedReplicationSpec{ { RegionConfigs: []*mdbv1.AdvancedRegionConfig{ @@ -257,21 +251,22 @@ func TestClusterValidation(t *testing.T) { } func TestDeploymentForGov(t *testing.T) { - t.Run("should fail when deployment is configured to non-gov region", func(t *testing.T) { - deploy := mdbv1.AtlasDeploymentSpec{ - DeploymentSpec: &mdbv1.DeploymentSpec{ - ProviderSettings: &mdbv1.ProviderSettingsSpec{ - RegionName: "EU_EAST_1", - }, - }, - } - - assert.ErrorContains(t, deploymentForGov(&deploy, "GOV_REGIONS_ONLY"), "deployment in atlas for government support a restricted set of regions: EU_EAST_1 is not part of AWS for government regions") - }) + // t.Run("should fail when deployment is configured to non-gov region", func(t *testing.T) { + // deploy := mdbv1.AtlasDeploymentSpec{ + // DeploymentSpec: &mdbv1.AdvancedDeploymentSpec{ + // + // ProviderSettings: &mdbv1.ProviderSettingsSpec{ + // RegionName: "EU_EAST_1", + // }, + // }, + // } + + // assert.ErrorContains(t, deploymentForGov(&deploy, "GOV_REGIONS_ONLY"), "deployment in atlas for government support a restricted set of regions: EU_EAST_1 is not part of AWS for government regions") + // }) t.Run("should fail when advanced deployment is configured to non-gov region", func(t *testing.T) { deploy := mdbv1.AtlasDeploymentSpec{ - AdvancedDeploymentSpec: &mdbv1.AdvancedDeploymentSpec{ + DeploymentSpec: &mdbv1.AdvancedDeploymentSpec{ ReplicationSpecs: []*mdbv1.AdvancedReplicationSpec{ { RegionConfigs: []*mdbv1.AdvancedRegionConfig{ @@ -557,7 +552,7 @@ func TestBackupScheduleValidation(t *testing.T) { } deployment := &mdbv1.AtlasDeployment{ Spec: mdbv1.AtlasDeploymentSpec{ - AdvancedDeploymentSpec: &mdbv1.AdvancedDeploymentSpec{ + DeploymentSpec: &mdbv1.AdvancedDeploymentSpec{ PitEnabled: toptr.MakePtr(true), }, }, @@ -581,7 +576,7 @@ func TestBackupScheduleValidation(t *testing.T) { } deployment := &mdbv1.AtlasDeployment{ Spec: mdbv1.AtlasDeploymentSpec{ - AdvancedDeploymentSpec: &mdbv1.AdvancedDeploymentSpec{ + DeploymentSpec: &mdbv1.AdvancedDeploymentSpec{ PitEnabled: toptr.MakePtr(true), }, }, @@ -612,7 +607,7 @@ func TestBackupScheduleValidation(t *testing.T) { } deployment := &mdbv1.AtlasDeployment{ Spec: mdbv1.AtlasDeploymentSpec{ - AdvancedDeploymentSpec: &mdbv1.AdvancedDeploymentSpec{}, + DeploymentSpec: &mdbv1.AdvancedDeploymentSpec{}, }, Status: status.AtlasDeploymentStatus{ ReplicaSets: []status.ReplicaSet{ @@ -643,7 +638,7 @@ func TestBackupScheduleValidation(t *testing.T) { } deployment := &mdbv1.AtlasDeployment{ Spec: mdbv1.AtlasDeploymentSpec{ - DeploymentSpec: &mdbv1.DeploymentSpec{ + DeploymentSpec: &mdbv1.AdvancedDeploymentSpec{ PitEnabled: toptr.MakePtr(true), }, }, @@ -674,7 +669,7 @@ func TestBackupScheduleValidation(t *testing.T) { } deployment := &mdbv1.AtlasDeployment{ Spec: mdbv1.AtlasDeploymentSpec{ - DeploymentSpec: &mdbv1.DeploymentSpec{}, + DeploymentSpec: &mdbv1.AdvancedDeploymentSpec{}, }, Status: status.AtlasDeploymentStatus{ ReplicaSets: []status.ReplicaSet{ diff --git a/scripts/e2e_local.sh b/scripts/e2e_local.sh index c326f56eba..a158e4c96d 100755 --- a/scripts/e2e_local.sh +++ b/scripts/e2e_local.sh @@ -40,4 +40,4 @@ export MCLI_PUBLIC_API_KEY="${public_key}" export MCLI_PRIVATE_API_KEY="${private_key}" export MCLI_ORG_ID="${org_id}" export IMAGE_URL="${image}" #for helm chart -AKO_E2E_TEST=1 ginkgo --label-filter="${focus_key}" --timeout 120m -v test/e2e/ +AKO_E2E_TEST=1 ginkgo --label-filter="${focus_key}" --timeout 120m -vv test/e2e/ diff --git a/test/e2e/actions/deploy/deploy_operator.go b/test/e2e/actions/deploy/deploy_operator.go index 58f5dd0064..a4a16971c1 100644 --- a/test/e2e/actions/deploy/deploy_operator.go +++ b/test/e2e/actions/deploy/deploy_operator.go @@ -3,6 +3,7 @@ package deploy import ( "context" + "encoding/json" "fmt" "time" @@ -84,6 +85,9 @@ func CreateInitialDeployments(testData *model.TestDataProvider) { deployment.Namespace = testData.Resources.Namespace deployment.Spec.Project.Namespace = testData.Resources.Namespace } + j, _ := json.MarshalIndent(deployment, "", " ") + fmt.Println("DEBUG INITIAL DEPLOYMENTS", string(j)) + GinkgoWriter.Println("DEBUG INITIAL DEPLOYMENTS", string(j)) err := testData.K8SClient.Create(testData.Context, deployment) Expect(err).ShouldNot(HaveOccurred(), fmt.Sprintf("Deployment was not created: %v", deployment)) Eventually(kube.DeploymentReadyCondition(testData), time.Minute*60, time.Second*5).Should(Equal("True"), "Deployment was not created") diff --git a/test/e2e/actions/helm_related.go b/test/e2e/actions/helm_related.go index c795e83f13..fd8d59791d 100644 --- a/test/e2e/actions/helm_related.go +++ b/test/e2e/actions/helm_related.go @@ -20,7 +20,7 @@ func HelmDefaultUpgradeResources(data *model.TestDataProvider) { By("User use HELM upgrade command for changing atlas resources\n", func() { data.Resources.Project.Spec.ProjectIPAccessList[0].Comment = "updated" enabled := true - data.Resources.Deployments[0].Spec.DeploymentSpec.ProviderBackupEnabled = &enabled + data.Resources.Deployments[0].Spec.DeploymentSpec.BackupEnabled = &enabled data.Resources.Users[0].DeleteAllRoles() data.Resources.Users[0].AddBuildInAdminRole() data.Resources.Users[0].Spec.Project.Name = data.Resources.GetAtlasProjectFullKubeName() @@ -29,7 +29,7 @@ func HelmDefaultUpgradeResources(data *model.TestDataProvider) { helm.UpgradeAtlasDeploymentChartDev(data.Resources) By("Wait project creation", func() { - WaitDeployment(data, generation+1) + WaitDeployment(data, generation) ExpectWithOffset(1, data.Resources.ProjectID).ShouldNot(BeEmpty()) }) aClient := atlas.GetClientOrFail() diff --git a/test/e2e/actions/steps.go b/test/e2e/actions/steps.go index a5db3a1f05..de9dee9c5d 100644 --- a/test/e2e/actions/steps.go +++ b/test/e2e/actions/steps.go @@ -16,7 +16,6 @@ import ( v1 "github.com/mongodb/mongodb-atlas-kubernetes/pkg/api/v1" "github.com/mongodb/mongodb-atlas-kubernetes/pkg/api/v1/status" - "github.com/mongodb/mongodb-atlas-kubernetes/pkg/controller/atlasdeployment" kube "github.com/mongodb/mongodb-atlas-kubernetes/test/e2e/actions/kube" "github.com/mongodb/mongodb-atlas-kubernetes/test/e2e/api/atlas" appclient "github.com/mongodb/mongodb-atlas-kubernetes/test/e2e/appclient" @@ -74,12 +73,12 @@ func WaitDeploymentWithoutGenerationCheckV2(data *model.TestDataProvider) { deployment := data.InitialDeployments[0] switch { - case deployment.Spec.AdvancedDeploymentSpec != nil: - atlasClient, err := atlas.AClient() - Expect(err).To(BeNil()) - advancedDeployment, err := atlasClient.GetDeployment(input.ProjectID, deployment.Spec.AdvancedDeploymentSpec.Name) - Expect(err).To(BeNil()) - Expect(advancedDeployment.StateName).To(Equal("IDLE")) + // case deployment.Spec.AdvancedDeploymentSpec != nil: + // atlasClient, err := atlas.AClient() + // Expect(err).To(BeNil()) + // advancedDeployment, err := atlasClient.GetDeployment(input.ProjectID, deployment.Spec.AdvancedDeploymentSpec.Name) + // Expect(err).To(BeNil()) + // Expect(advancedDeployment.StateName).To(Equal("IDLE")) case deployment.Spec.ServerlessSpec != nil: atlasClient, err := atlas.AClient() Expect(err).To(BeNil()) @@ -103,34 +102,36 @@ func WaitDeploymentWithoutGenerationCheck(data *model.TestDataProvider) { g.Expect(err).ToNot(HaveOccurred()) return deploymentStatus }, - "60m", "1m", - ).Should(Equal("True"), "Kubernetes resource: Deployment status `Ready` should be 'True'") + // "60m", "5m", + ).WithTimeout(30*time.Minute).WithPolling(1*time.Minute).Should(Equal("True"), "Kubernetes resource: Deployment status `Ready` should be 'True'") + + Eventually(func(g Gomega) { + deploymentState, err := k8s.GetK8sDeploymentStateName(data.Context, data.K8SClient, + input.Namespace, input.Deployments[0].ObjectMeta.GetName()) + g.Expect(err).ToNot(HaveOccurred()) + g.Expect(deploymentState).Should(Equal("IDLE"), "Kubernetes resource: Deployment status should be IDLE") + }).WithTimeout(30 * time.Minute).WithPolling(1 * time.Minute).Should(Succeed()) deploymentState, err := k8s.GetK8sDeploymentStateName(data.Context, data.K8SClient, input.Namespace, input.Deployments[0].ObjectMeta.GetName()) ExpectWithOffset(1, err).ToNot(HaveOccurred()) ExpectWithOffset(1, deploymentState).Should(Equal("IDLE"), "Kubernetes resource: Deployment status should be IDLE") - deployment := input.Deployments[0] - switch { - case deployment.Spec.AdvancedDeploymentSpec != nil: - atlasClient, err := atlas.AClient() - Expect(err).To(BeNil()) - advancedDeployment, err := atlasClient.GetDeployment(input.ProjectID, deployment.Spec.AdvancedDeploymentSpec.Name) - Expect(err).To(BeNil()) - Expect(advancedDeployment.StateName).To(Equal("IDLE")) - case deployment.Spec.ServerlessSpec != nil: - atlasClient, err := atlas.AClient() - Expect(err).To(BeNil()) - serverlessInstance, err := atlasClient.GetServerlessInstance(input.ProjectID, deployment.Spec.ServerlessSpec.Name) - Expect(err).To(BeNil()) - Expect(serverlessInstance.StateName).To(Equal("IDLE")) - default: - aClient := atlas.GetClientOrFail() - deployment, err := aClient.GetDeployment(input.ProjectID, input.Deployments[0].Spec.GetDeploymentName()) - Expect(err).To(BeNil()) - Expect(deployment.StateName).Should(Equal("IDLE")) - } + // WHY all this if this can be checked directly above??? + // deployment := input.Deployments[0] + // switch { + // case deployment.Spec.ServerlessSpec != nil: + // atlasClient, err := atlas.AClient() + // Expect(err).To(BeNil()) + // serverlessInstance, err := atlasClient.GetServerlessInstance(input.ProjectID, deployment.Spec.ServerlessSpec.Name) + // Expect(err).To(BeNil()) + // Expect(serverlessInstance.StateName).To(Equal("IDLE")) + // default: + // aClient := atlas.GetClientOrFail() + // deployment, err := aClient.GetDeployment(input.ProjectID, input.Deployments[0].Spec.GetDeploymentName()) + // Expect(err).To(BeNil()) + // Expect(deployment.StateName).Should(Equal("IDLE")) + // } } func WaitProjectWithoutGenerationCheck(data *model.TestDataProvider) { @@ -187,51 +188,8 @@ func CheckUserExistInAtlas(data *model.TestDataProvider) func() bool { } } -func CompareDeploymentsSpec(requested model.DeploymentSpec, created mongodbatlas.Cluster) { - ExpectWithOffset(1, created).To(MatchFields(IgnoreExtras, Fields{ - "Name": Equal(requested.DeploymentSpec.Name), - "ProviderSettings": PointTo(MatchFields(IgnoreExtras, Fields{ - "InstanceSizeName": Equal(requested.DeploymentSpec.ProviderSettings.InstanceSizeName), - "ProviderName": Equal(string(requested.DeploymentSpec.ProviderSettings.ProviderName)), - })), - "ConnectionStrings": PointTo(MatchFields(IgnoreExtras, Fields{ - "Standard": Not(BeEmpty()), - "StandardSrv": Not(BeEmpty()), - })), - }), "Deployment should be the same as requested by the user") - - if len(requested.DeploymentSpec.ReplicationSpecs) > 0 { - for i, replica := range requested.DeploymentSpec.ReplicationSpecs { - for key, region := range replica.RegionsConfig { - // different type - ExpectWithOffset(1, created.ReplicationSpecs[i].RegionsConfig[key].AnalyticsNodes).Should(PointTo(Equal(*region.AnalyticsNodes)), "Replica Spec: AnalyticsNodes is not the same") - ExpectWithOffset(1, created.ReplicationSpecs[i].RegionsConfig[key].ElectableNodes).Should(PointTo(Equal(*region.ElectableNodes)), "Replica Spec: ElectableNodes is not the same") - ExpectWithOffset(1, created.ReplicationSpecs[i].RegionsConfig[key].Priority).Should(PointTo(Equal(*region.Priority)), "Replica Spec: Priority is not the same") - ExpectWithOffset(1, created.ReplicationSpecs[i].RegionsConfig[key].ReadOnlyNodes).Should(PointTo(Equal(*region.ReadOnlyNodes)), "Replica Spec: ReadOnlyNodes is not the same") - } - } - } else { - ExpectWithOffset(1, requested.DeploymentSpec.ProviderSettings).To(PointTo(MatchFields(IgnoreExtras, Fields{ - "RegionName": Equal(created.ProviderSettings.RegionName), - })), "Deployment should be the same as requested by the user: Region Name") - } - if requested.DeploymentSpec.ProviderSettings.ProviderName == "TENANT" { - ExpectWithOffset(1, requested.DeploymentSpec.ProviderSettings).To(PointTo(MatchFields(IgnoreExtras, Fields{ - "BackingProviderName": Equal(created.ProviderSettings.BackingProviderName), - })), "Deployment should be the same as requested by the user: Backing Provider Name") - } -} - func CompareAdvancedDeploymentsSpec(requested model.DeploymentSpec, created mongodbatlas.AdvancedCluster) { - advancedSpec := requested.AdvancedDeploymentSpec - - if advancedSpec == nil { - converted := v1.AtlasDeploymentSpec(requested) - err := atlasdeployment.ConvertLegacyDeployment(&converted) - Expect(err).ShouldNot(HaveOccurred()) - converted.DeploymentSpec = nil - advancedSpec = converted.AdvancedDeploymentSpec - } + advancedSpec := requested.DeploymentSpec Expect(created.MongoDBVersion).ToNot(BeEmpty()) Expect(created.MongoDBVersion).ToNot(BeEmpty()) diff --git a/test/e2e/atlas_gov_test.go b/test/e2e/atlas_gov_test.go index b036516476..30d7d16908 100644 --- a/test/e2e/atlas_gov_test.go +++ b/test/e2e/atlas_gov_test.go @@ -419,7 +419,7 @@ var _ = Describe("Atlas for Government", Label("atlas-gov"), func() { Name: projectName, Namespace: testData.Resources.Namespace, }, - AdvancedDeploymentSpec: &mdbv1.AdvancedDeploymentSpec{ + DeploymentSpec: &mdbv1.AdvancedDeploymentSpec{ Name: clusterName, BackupEnabled: toptr.MakePtr(true), BiConnector: &mdbv1.BiConnectorSpec{ diff --git a/test/e2e/backup_config_test.go b/test/e2e/backup_config_test.go index 416636aa13..29c9f3ab4a 100644 --- a/test/e2e/backup_config_test.go +++ b/test/e2e/backup_config_test.go @@ -84,7 +84,7 @@ var _ = Describe("Deployment Backup Configuration", Label("backup-config"), func func backupConfigFlow(data *model.TestDataProvider, bucket string) { By("Enable backup for deployment", func() { Expect(data.K8SClient.Get(data.Context, client.ObjectKeyFromObject(data.InitialDeployments[0]), data.InitialDeployments[0])).To(Succeed()) - data.InitialDeployments[0].Spec.AdvancedDeploymentSpec.BackupEnabled = toptr.MakePtr(true) + data.InitialDeployments[0].Spec.DeploymentSpec.BackupEnabled = toptr.MakePtr(true) Expect(data.K8SClient.Update(data.Context, data.InitialDeployments[0])).To(Succeed()) Eventually(func(g Gomega) bool { diff --git a/test/e2e/configuration_test.go b/test/e2e/configuration_test.go index 1eb4f29086..b0cb97a176 100644 --- a/test/e2e/configuration_test.go +++ b/test/e2e/configuration_test.go @@ -140,7 +140,7 @@ var _ = Describe("Configuration namespaced. Deploy deployment", Label("deploymen actions.DeleteFirstUser, }, ).WithProject(data.DefaultProject()). - WithInitialDeployments(data.CreateBasicFreeDeployment("basic-free-deployment")). + WithInitialDeployments(data.CreateFreeAdvancedDeployment("basic-free-deployment")). WithUsers(data.BasicUser("user", "user1", data.WithSecretRef("dbuser-secret"), data.WithAdminRole())), ), Entry("Free - Users can use M0, global", Label("ns-global-key-m0"), @@ -152,7 +152,7 @@ var _ = Describe("Configuration namespaced. Deploy deployment", Label("deploymen actions.DeleteFirstUser, }, ).WithProject(data.DefaultProject()). - WithInitialDeployments(data.CreateBasicFreeDeployment("basic-free-deployment")). + WithInitialDeployments(data.CreateFreeAdvancedDeployment("basic-free-deployment")). WithUsers(data.BasicUser("user", "user1", data.WithSecretRef("dbuser-secret"), data.WithAdminRole())), ), ) diff --git a/test/e2e/data/atlasdeployment_advanced_helm.yaml b/test/e2e/data/atlasdeployment_advanced_helm.yaml index 047f6fd3b3..5389bcd553 100644 --- a/test/e2e/data/atlasdeployment_advanced_helm.yaml +++ b/test/e2e/data/atlasdeployment_advanced_helm.yaml @@ -5,13 +5,17 @@ metadata: spec: projectRef: name: my-project - advancedDeploymentSpec: + deploymentSpec: clusterType: REPLICASET name: advanced-deployment replicationSpecs: - - regionConfigs: + - zoneName: Zone1 + numShards: 1 + regionConfigs: - electableSpecs: instanceSize: M5 + nodeCount: 1 providerName: TENANT backingProviderName: AWS regionName: US_EAST_1 + priority: 7 diff --git a/test/e2e/data/atlasdeployment_advanced_multi_region_helm.yaml b/test/e2e/data/atlasdeployment_advanced_multi_region_helm.yaml index 57653df6f1..5e4cbf3f9e 100644 --- a/test/e2e/data/atlasdeployment_advanced_multi_region_helm.yaml +++ b/test/e2e/data/atlasdeployment_advanced_multi_region_helm.yaml @@ -5,7 +5,7 @@ metadata: spec: projectRef: name: my-project - advancedDeploymentSpec: + deploymentSpec: clusterType: GEOSHARDED name: advanced-deployment replicationSpecs: diff --git a/test/e2e/data/atlasdeployment_backup.yaml b/test/e2e/data/atlasdeployment_backup.yaml index 9bab3f836b..3c99619fcd 100644 --- a/test/e2e/data/atlasdeployment_backup.yaml +++ b/test/e2e/data/atlasdeployment_backup.yaml @@ -7,8 +7,15 @@ spec: name: my-project deploymentSpec: name: deployment-backup - providerBackupEnabled: true - providerSettings: - instanceSizeName: M10 - providerName: AWS - regionName: US_EAST_1 + backupEnabled: true + clusterType: REPLICASET + replicationSpecs: + - zoneName: Zone 1 + regionConfigs: + - electableSpecs: + instanceSize: M20 + nodeCount: 1 + providerName: AWS + backingProviderName: AWS + regionName: US_EAST_1 + priority: 7 diff --git a/test/e2e/data/atlasdeployment_backup_update.yaml b/test/e2e/data/atlasdeployment_backup_update.yaml index 5c789a1c22..833830f9d8 100644 --- a/test/e2e/data/atlasdeployment_backup_update.yaml +++ b/test/e2e/data/atlasdeployment_backup_update.yaml @@ -7,8 +7,15 @@ spec: name: my-project deploymentSpec: name: deployment-backup - providerBackupEnabled: false - providerSettings: - instanceSizeName: M20 - providerName: AWS - regionName: US_EAST_1 + backupEnabled: false + clusterType: REPLICASET + replicationSpecs: + - zoneName: Zone 1 + regionConfigs: + - electableSpecs: + instanceSize: M20 + nodeCount: 1 + providerName: AWS + backingProviderName: AWS + regionName: US_EAST_1 + priority: 7 diff --git a/test/e2e/data/atlasdeployment_backup_update_remove_backup.yaml b/test/e2e/data/atlasdeployment_backup_update_remove_backup.yaml index 3a70b07189..0dc19eb9ce 100644 --- a/test/e2e/data/atlasdeployment_backup_update_remove_backup.yaml +++ b/test/e2e/data/atlasdeployment_backup_update_remove_backup.yaml @@ -7,8 +7,15 @@ spec: name: my-project deploymentSpec: name: deployment-backup - providerBackupEnabled: false - providerSettings: - instanceSizeName: M10 - providerName: AWS - regionName: US_EAST_1 + backupEnabled: false + clusterType: REPLICASET + replicationSpecs: + - zoneName: Zone 1 + regionConfigs: + - electableSpecs: + instanceSize: M10 + nodeCount: 1 + providerName: AWS + backingProviderName: AWS + regionName: US_EAST_1 + priority: 7 diff --git a/test/e2e/data/atlasdeployment_basic.yaml b/test/e2e/data/atlasdeployment_basic.yaml index 238f11e6ac..3b9377daa6 100644 --- a/test/e2e/data/atlasdeployment_basic.yaml +++ b/test/e2e/data/atlasdeployment_basic.yaml @@ -7,8 +7,13 @@ spec: name: my-project deploymentSpec: name: deployment-basic - providerSettings: - instanceSizeName: M2 - providerName: TENANT - regionName: US_EAST_1 - backingProviderName: AWS + replicationSpecs: + - zoneName: Zone 1 + regionConfigs: + - electableSpecs: + instanceSize: M2 + nodeCount: 1 + providerName: TENANT + backingProviderName: AWS + regionName: US_EAST_1 + priority: 7 diff --git a/test/e2e/data/atlasdeployment_basic_free.yaml b/test/e2e/data/atlasdeployment_basic_free.yaml index 284fb4f9ac..0af11b4f08 100644 --- a/test/e2e/data/atlasdeployment_basic_free.yaml +++ b/test/e2e/data/atlasdeployment_basic_free.yaml @@ -7,8 +7,13 @@ spec: name: my-project deploymentSpec: name: deployment-basic - providerSettings: - instanceSizeName: M0 - providerName: TENANT - regionName: US_EAST_1 - backingProviderName: AWS + replicationSpecs: + - zoneName: Zone 1 + regionConfigs: + - electableSpecs: + instanceSize: M0 + nodeCount: 1 + providerName: TENANT + backingProviderName: "AWS" + regionName: US_EAST_1 + priority: 7 diff --git a/test/e2e/data/atlasdeployment_basic_helm.yaml b/test/e2e/data/atlasdeployment_basic_helm.yaml index 157d4b27db..8ef299e841 100644 --- a/test/e2e/data/atlasdeployment_basic_helm.yaml +++ b/test/e2e/data/atlasdeployment_basic_helm.yaml @@ -7,7 +7,14 @@ spec: name: my-project deploymentSpec: name: atlas-deployment-basic-helm - providerSettings: - instanceSizeName: M10 - providerName: AWS - regionName: US_EAST_1 + clusterType: REPLICASET + replicationSpecs: + - zoneName: Zone 1 + regionConfigs: + - electableSpecs: + instanceSize: M0 + nodeCount: 1 + providerName: TENANT + backingProviderName: "AWS" + regionName: US_EAST_1 + priority: 7 diff --git a/test/e2e/data/atlasdeployment_basic_update.yaml b/test/e2e/data/atlasdeployment_basic_update.yaml index 8de14a9c4c..78c020bee3 100644 --- a/test/e2e/data/atlasdeployment_basic_update.yaml +++ b/test/e2e/data/atlasdeployment_basic_update.yaml @@ -7,8 +7,13 @@ spec: name: my-project deploymentSpec: name: deployment-basic - providerSettings: - instanceSizeName: M5 - providerName: TENANT - regionName: US_EAST_1 - backingProviderName: AWS + replicationSpecs: + - zoneName: Zone 1 + regionConfigs: + - electableSpecs: + instanceSize: M5 + nodeCount: 1 + providerName: TENANT + backingProviderName: "AWS" + regionName: US_EAST_1 + priority: 7 diff --git a/test/e2e/data/atlasdeployment_basic_with_keep_resource_policy.yaml b/test/e2e/data/atlasdeployment_basic_with_keep_resource_policy.yaml index 2024fbead3..4e7d8e7e8e 100644 --- a/test/e2e/data/atlasdeployment_basic_with_keep_resource_policy.yaml +++ b/test/e2e/data/atlasdeployment_basic_with_keep_resource_policy.yaml @@ -9,8 +9,13 @@ spec: name: my-project deploymentSpec: name: cluster-basic - providerSettings: - instanceSizeName: M2 - providerName: TENANT - regionName: US_EAST_1 - backingProviderName: AWS + replicationSpecs: + - zoneName: Zone 1 + regionConfigs: + - electableSpecs: + instanceSize: M2 + nodeCount: 1 + providerName: TENANT + backingProviderName: "AWS" + regionName: US_EAST_1 + priority: 7 diff --git a/test/e2e/data/atlasdeployment_multiregion_aws.yaml b/test/e2e/data/atlasdeployment_multiregion_aws.yaml index b9bc941dcb..1c5211a586 100644 --- a/test/e2e/data/atlasdeployment_multiregion_aws.yaml +++ b/test/e2e/data/atlasdeployment_multiregion_aws.yaml @@ -9,20 +9,24 @@ spec: name: deployment-multiregion-aws providerBackupEnabled: true clusterType: REPLICASET - providerSettings: - instanceSizeName: M10 - providerName: AWS replicationSpecs: - - numShards: 1 - zoneName: US-Zone + - zoneName: US-Zone + numShards: 1 regionsConfig: - US_EAST_1: - analyticsNodes: 0 - electableNodes: 1 + - regionName: US_EAST_1 + providerName: AWS + backingProviderName: AWS priority: 6 - readOnlyNodes: 0 - US_WEST_2: - analyticsNodes: 0 - electableNodes: 2 + electableSpecs: + - instanceSize: M10 + nodeCount: 1 + - regionName: US_WEST_2 + providerName: AWS + backingProviderName: AWS priority: 7 - readOnlyNodes: 0 + electableSpecs: + - instanceSize: M10 + nodeCount: 2 + providerSettings: + instanceSizeName: M10 + providerName: AWS diff --git a/test/e2e/data/atlasdeployment_multiregion_aws_update.yaml b/test/e2e/data/atlasdeployment_multiregion_aws_update.yaml index 1171cf3fa7..97c89efea1 100644 --- a/test/e2e/data/atlasdeployment_multiregion_aws_update.yaml +++ b/test/e2e/data/atlasdeployment_multiregion_aws_update.yaml @@ -9,20 +9,20 @@ spec: name: deployment-multiregion-aws providerBackupEnabled: false clusterType: REPLICASET - providerSettings: - instanceSizeName: M20 - providerName: AWS replicationSpecs: - - numShards: 1 - zoneName: US-Zone + - zoneName: US-Zone regionsConfig: - US_EAST_1: - analyticsNodes: 0 - electableNodes: 1 + - regionName: US_EAST_1 + electableSpecs: + instanceSize: M20 + nodeCount: 1 + providerName: AWS + backingProviderName: AWS priority: 6 - readOnlyNodes: 0 - US_WEST_2: - analyticsNodes: 0 - electableNodes: 2 + - regionName: US_WEST_2 + electableSpecs: + instanceSize: M20 + nodeCount: 2 + providerName: AWS + backingProviderName: AWS priority: 7 - readOnlyNodes: 0 diff --git a/test/e2e/data/atlasdeployment_multiregion_azure.yaml b/test/e2e/data/atlasdeployment_multiregion_azure.yaml index 8f457a6527..48f72dd23d 100644 --- a/test/e2e/data/atlasdeployment_multiregion_azure.yaml +++ b/test/e2e/data/atlasdeployment_multiregion_azure.yaml @@ -9,20 +9,22 @@ spec: name: deployment-multiregion-azure providerBackupEnabled: true clusterType: REPLICASET - providerSettings: - instanceSizeName: M10 - providerName: AZURE replicationSpecs: - - numShards: 1 - zoneName: Europe - regionsConfig: - NORWAY_EAST: - analyticsNodes: 0 - electableNodes: 1 + - zoneName: Europe + numShards: 1 + regionConfigs: + - regionName: NORWAY_EAST + providerName: AZURE + backingProviderName: AZURE priority: 6 - readOnlyNodes: 0 - GERMANY_NORTH: - analyticsNodes: 0 - electableNodes: 2 + electableSpecs: + nodeCount: 1 + instanceSize: M10 + + - regionName: GERMANY_NORTH + providerName: AZURE + backingProviderName: AZURE priority: 7 - readOnlyNodes: 0 + electableSpecs: + nodeCount: 2 + instanceSize: M10 diff --git a/test/e2e/data/atlasdeployment_multiregion_azure_update.yaml b/test/e2e/data/atlasdeployment_multiregion_azure_update.yaml index 8443e4dfd8..70f8ff472c 100644 --- a/test/e2e/data/atlasdeployment_multiregion_azure_update.yaml +++ b/test/e2e/data/atlasdeployment_multiregion_azure_update.yaml @@ -9,20 +9,21 @@ spec: name: deployment-multiregion-azure providerBackupEnabled: true clusterType: REPLICASET - providerSettings: - instanceSizeName: M20 - providerName: AZURE replicationSpecs: - - numShards: 1 - zoneName: Europe + - zoneName: Europe + numShards: 1 regionsConfig: - NORWAY_EAST: - analyticsNodes: 0 - electableNodes: 1 + - regionName: NORWAY_EAST + providerName: AZURE + backingProviderName: AZURE priority: 6 - readOnlyNodes: 0 - GERMANY_NORTH: - analyticsNodes: 0 - electableNodes: 2 + electableSpecs: + instanceSize: M20 + nodeCount: 1 + - regionName: GERMANY_NORTH + providerName: AZURE + backingProviderName: AZURE priority: 7 - readOnlyNodes: 0 + electableSpecs: + instanceSize: M20 + nodeCount: 2 diff --git a/test/e2e/data/atlasdeployment_multiregion_gcp.yaml b/test/e2e/data/atlasdeployment_multiregion_gcp.yaml index ace578927f..247d65fc0a 100644 --- a/test/e2e/data/atlasdeployment_multiregion_gcp.yaml +++ b/test/e2e/data/atlasdeployment_multiregion_gcp.yaml @@ -9,20 +9,21 @@ spec: name: deployment-multiregion-gcp providerBackupEnabled: true clusterType: REPLICASET - providerSettings: - instanceSizeName: M10 - providerName: GCP replicationSpecs: - - numShards: 1 - zoneName: US-Zone - regionsConfig: - CENTRAL_US: - analyticsNodes: 0 - electableNodes: 1 + - zoneName: US-Zone + numShards: 1 + regionConfigs: + - regionName: CENTRAL_US + providerName: GCP + backingProviderName: GCP priority: 6 - readOnlyNodes: 0 - EASTERN_US: - analyticsNodes: 0 - electableNodes: 2 + electableSpecs: + - instanceSize: M10 + nodeCount: 1 + - regionName: EASTERN_US + providerName: GCP + backingProviderName: GCP priority: 7 - readOnlyNodes: 0 + electableSpecs: + - instanceSize: M10 + nodeCount: 2 diff --git a/test/e2e/data/atlasdeployment_multiregion_multicloud_gcp_aws.yaml b/test/e2e/data/atlasdeployment_multiregion_multicloud_gcp_aws.yaml new file mode 100644 index 0000000000..eb22d57b25 --- /dev/null +++ b/test/e2e/data/atlasdeployment_multiregion_multicloud_gcp_aws.yaml @@ -0,0 +1,29 @@ +apiVersion: atlas.mongodb.com/v1 +kind: AtlasDeployment +metadata: + name: atlas-deployment-multiregion-gcp +spec: + projectRef: + name: my-project + deploymentSpec: + name: deployment-multiregion-gcp + providerBackupEnabled: true + clusterType: REPLICASET + replicationSpecs: + - zoneName: US-Zone + numShards: 1 + regionsConfig: + - regionName: CENTRAL_US + providerName: GCP + backingProviderName: GCP + priority: 6 + electableSpecs: + instanceSize: M10 + nodeCount: 1 + - regionName: EASTERN_US + providerName: GCP + backingProviderName: GCP + priority: 7 + electableSpecs: + instanceSize: M10 + nodeCount: 2 diff --git a/test/e2e/data/atlasdeployment_standard.yaml b/test/e2e/data/atlasdeployment_standard.yaml index 27c416b416..54112d9c87 100644 --- a/test/e2e/data/atlasdeployment_standard.yaml +++ b/test/e2e/data/atlasdeployment_standard.yaml @@ -7,7 +7,14 @@ spec: name: my-project deploymentSpec: name: deployment-standard - providerSettings: - instanceSizeName: M10 - providerName: AWS - regionName: US_EAST_1 + replicationSpecs: + - zoneName: Zone 1 + numShards: 1 + regionConfigs: + - regionName: US_EAST_1 + providerName: AWS + backingProviderName: AWS + priority: 7 + electableSpecs: + instanceSize: M10 + nodeCount: 1 diff --git a/test/e2e/data/deployments.go b/test/e2e/data/deployments.go index 32d32caeff..9fb1542b2e 100644 --- a/test/e2e/data/deployments.go +++ b/test/e2e/data/deployments.go @@ -40,7 +40,7 @@ func CreateAdvancedGeoshardedDeployment(name string) *v1.AtlasDeployment { Project: common.ResourceRefNamespaced{ Name: ProjectName, }, - AdvancedDeploymentSpec: &v1.AdvancedDeploymentSpec{ + DeploymentSpec: &v1.AdvancedDeploymentSpec{ ClusterType: "GEOSHARDED", Name: name, ReplicationSpecs: []*v1.AdvancedReplicationSpec{ @@ -80,41 +80,6 @@ func CreateAdvancedGeoshardedDeployment(name string) *v1.AtlasDeployment { } } -func CreateRegularGeoshardedDeployment(name string) *v1.AtlasDeployment { - return &v1.AtlasDeployment{ - ObjectMeta: metav1.ObjectMeta{ - Name: name, - }, - Spec: v1.AtlasDeploymentSpec{ - Project: common.ResourceRefNamespaced{ - Name: ProjectName, - }, - DeploymentSpec: &v1.DeploymentSpec{ - Name: name, - ProviderSettings: &v1.ProviderSettingsSpec{ - InstanceSizeName: InstanceSizeM30, - ProviderName: "AWS", - }, - ClusterType: "GEOSHARDED", - ReplicationSpecs: []v1.ReplicationSpec{ - { - NumShards: toptr.MakePtr(int64(1)), - ZoneName: "Zone 1", - RegionsConfig: map[string]v1.RegionsConfig{ - "US_EAST_1": { - AnalyticsNodes: toptr.MakePtr(int64(0)), - ElectableNodes: toptr.MakePtr(int64(3)), - Priority: toptr.MakePtr(int64(7)), - ReadOnlyNodes: toptr.MakePtr(int64(0)), - }, - }, - }, - }, - }, - }, - } -} - func CreateServerlessDeployment(name string, providerName string, regionName string) *v1.AtlasDeployment { return &v1.AtlasDeployment{ ObjectMeta: metav1.ObjectMeta{ @@ -145,13 +110,25 @@ func CreateBasicDeployment(name string) *v1.AtlasDeployment { Project: common.ResourceRefNamespaced{ Name: ProjectName, }, - DeploymentSpec: &v1.DeploymentSpec{ - Name: "cluster-basics", - ProviderSettings: &v1.ProviderSettingsSpec{ - InstanceSizeName: InstanceSizeM2, - ProviderName: "TENANT", - RegionName: "US_EAST_1", - BackingProviderName: "AWS", + DeploymentSpec: &v1.AdvancedDeploymentSpec{ + ClusterType: "REPLICASET", + Name: "cluster-basics", + ReplicationSpecs: []*v1.AdvancedReplicationSpec{ + { + ZoneName: "test zone 1", + RegionConfigs: []*v1.AdvancedRegionConfig{ + { + ElectableSpecs: &v1.Specs{ + InstanceSize: "M2", + NodeCount: toptr.MakePtr(1), + }, + BackingProviderName: "AWS", + Priority: toptr.MakePtr(7), + ProviderName: "TENANT", + RegionName: "US_EAST_1", + }, + }, + }, }, }, }, @@ -167,13 +144,26 @@ func CreateDeploymentWithBackup(name string) *v1.AtlasDeployment { Project: common.ResourceRefNamespaced{ Name: ProjectName, }, - DeploymentSpec: &v1.DeploymentSpec{ - Name: "deployment-backup", - ProviderBackupEnabled: toptr.MakePtr(true), - ProviderSettings: &v1.ProviderSettingsSpec{ - InstanceSizeName: InstanceSizeM10, - ProviderName: "AWS", - RegionName: "US_EAST_1", + DeploymentSpec: &v1.AdvancedDeploymentSpec{ + ClusterType: "REPLICASET", + Name: "deployment-backup", + BackupEnabled: toptr.MakePtr(true), + ReplicationSpecs: []*v1.AdvancedReplicationSpec{ + { + ZoneName: "Zone 1", + RegionConfigs: []*v1.AdvancedRegionConfig{ + { + ElectableSpecs: &v1.Specs{ + InstanceSize: InstanceSizeM10, + NodeCount: toptr.MakePtr(3), + }, + Priority: toptr.MakePtr(7), + ProviderName: "AWS", + BackingProviderName: "AWS", + RegionName: "US_EAST_1", + }, + }, + }, }, }, }, @@ -186,13 +176,25 @@ func NewDeploymentWithBackupSpec() v1.AtlasDeploymentSpec { Project: common.ResourceRefNamespaced{ Name: ProjectName, }, - DeploymentSpec: &v1.DeploymentSpec{ - Name: "deployment-backup", - ProviderBackupEnabled: toptr.MakePtr(false), - ProviderSettings: &v1.ProviderSettingsSpec{ - InstanceSizeName: InstanceSizeM20, - ProviderName: "AWS", - RegionName: "US_EAST_1", + DeploymentSpec: &v1.AdvancedDeploymentSpec{ + Name: "deployment-backup", + BackupEnabled: toptr.MakePtr(false), + ReplicationSpecs: []*v1.AdvancedReplicationSpec{ + { + ZoneName: "Zone 1", + RegionConfigs: []*v1.AdvancedRegionConfig{ + { + ElectableSpecs: &v1.Specs{ + InstanceSize: InstanceSizeM20, + NodeCount: toptr.MakePtr(3), + }, + Priority: toptr.MakePtr(7), + ProviderName: "AWS", + BackingProviderName: "AWS", + RegionName: "US_EAST_1", + }, + }, + }, }, }, } @@ -233,56 +235,39 @@ func CreateDeploymentWithMultiregion(name string, providerName provider.Provider Project: common.ResourceRefNamespaced{ Name: ProjectName, }, - DeploymentSpec: &v1.DeploymentSpec{ - Name: "deployment-multiregion", - ProviderBackupEnabled: toptr.MakePtr(true), - ClusterType: "REPLICASET", - ProviderSettings: &v1.ProviderSettingsSpec{ - InstanceSizeName: InstanceSizeM10, - ProviderName: providerName, - }, - ReplicationSpecs: []v1.ReplicationSpec{ + DeploymentSpec: &v1.AdvancedDeploymentSpec{ + Name: "deployment-multiregion", + BackupEnabled: toptr.MakePtr(true), + ClusterType: "REPLICASET", + ReplicationSpecs: []*v1.AdvancedReplicationSpec{ { - NumShards: toptr.MakePtr(int64(1)), + NumShards: 1, ZoneName: "US-Zone", - RegionsConfig: map[string]v1.RegionsConfig{ - regions[0]: { - AnalyticsNodes: toptr.MakePtr(int64(0)), - ElectableNodes: toptr.MakePtr(int64(1)), - Priority: toptr.MakePtr(int64(6)), - ReadOnlyNodes: toptr.MakePtr(int64(0)), + RegionConfigs: []*v1.AdvancedRegionConfig{ + { + ElectableSpecs: &v1.Specs{ + InstanceSize: InstanceSizeM10, + NodeCount: toptr.MakePtr(2), + }, + AutoScaling: &v1.AdvancedAutoScalingSpec{}, + Priority: toptr.MakePtr(7), + ProviderName: string(providerName), + RegionName: regions[0], }, - regions[1]: { - AnalyticsNodes: toptr.MakePtr(int64(0)), - ElectableNodes: toptr.MakePtr(int64(2)), - Priority: toptr.MakePtr(int64(7)), - ReadOnlyNodes: toptr.MakePtr(int64(0)), + { + ElectableSpecs: &v1.Specs{ + InstanceSize: InstanceSizeM10, + NodeCount: toptr.MakePtr(1), + }, + AutoScaling: &v1.AdvancedAutoScalingSpec{}, + Priority: toptr.MakePtr(6), + ProviderName: string(providerName), + RegionName: regions[1], }, }, }, }, }, - }} -} - -func CreateBasicFreeDeployment(name string) *v1.AtlasDeployment { - return &v1.AtlasDeployment{ - ObjectMeta: metav1.ObjectMeta{ - Name: name, - }, - Spec: v1.AtlasDeploymentSpec{ - Project: common.ResourceRefNamespaced{ - Name: ProjectName, - }, - DeploymentSpec: &v1.DeploymentSpec{ - Name: name, - ProviderSettings: &v1.ProviderSettingsSpec{ - InstanceSizeName: InstanceSizeM0, - ProviderName: "TENANT", - RegionName: "US_EAST_1", - BackingProviderName: "AWS", - }, - }, }, } } @@ -296,19 +281,11 @@ func CreateFreeAdvancedDeployment(name string) *v1.AtlasDeployment { Project: common.ResourceRefNamespaced{ Name: ProjectName, }, - AdvancedDeploymentSpec: &v1.AdvancedDeploymentSpec{ - Name: name, - BackupEnabled: toptr.MakePtr(false), - BiConnector: &v1.BiConnectorSpec{ - Enabled: toptr.MakePtr(false), - ReadPreference: "secondary", - }, - ClusterType: string(v1.TypeReplicaSet), - EncryptionAtRestProvider: "NONE", - PitEnabled: toptr.MakePtr(false), - Paused: toptr.MakePtr(false), - RootCertType: "ISRGROOTX1", - VersionReleaseSystem: "LTS", + DeploymentSpec: &v1.AdvancedDeploymentSpec{ + Name: name, + ClusterType: string(v1.TypeReplicaSet), + RootCertType: "ISRGROOTX1", + VersionReleaseSystem: "LTS", ReplicationSpecs: []*v1.AdvancedReplicationSpec{ { NumShards: 1, @@ -345,7 +322,7 @@ func CreateAdvancedDeployment(name string) *v1.AtlasDeployment { Project: common.ResourceRefNamespaced{ Name: ProjectName, }, - AdvancedDeploymentSpec: &v1.AdvancedDeploymentSpec{ + DeploymentSpec: &v1.AdvancedDeploymentSpec{ Name: name, BackupEnabled: toptr.MakePtr(false), BiConnector: &v1.BiConnectorSpec{ diff --git a/test/e2e/free_tier_test.go b/test/e2e/free_tier_test.go index 32f8ac9ef2..c60a14e42d 100644 --- a/test/e2e/free_tier_test.go +++ b/test/e2e/free_tier_test.go @@ -45,7 +45,7 @@ var _ = Describe("Free tier", Label("free-tier"), func() { model.NewEmptyAtlasKeyType().UseDefaultFullAccess(), 40000, []func(*model.TestDataProvider){}, - ).WithProject(data.DefaultProject()).WithInitialDeployments(data.CreateBasicFreeDeployment("free-tier")), + ).WithProject(data.DefaultProject()).WithInitialDeployments(data.CreateFreeAdvancedDeployment("free-tier")), ), Entry("Test free tier advanced deployment", model.DataProvider( diff --git a/test/e2e/global_deployment_test.go b/test/e2e/global_deployment_test.go index 58797f143a..9fbb645dc6 100644 --- a/test/e2e/global_deployment_test.go +++ b/test/e2e/global_deployment_test.go @@ -41,27 +41,6 @@ var _ = Describe("UserLogin", Label("global-deployment"), func() { actions.ProjectCreationFlow(test) globalClusterFlow(test, mapping, ns) }, - Entry("Test[gc-regular-deployment]: Deployment with global config", Label("gc-regular-deployment"), - model.DataProvider( - "gc-regular-deployment", - model.NewEmptyAtlasKeyType().UseDefaultFullAccess(), - 40000, - []func(*model.TestDataProvider){}, - ).WithProject(data.DefaultProject()).WithInitialDeployments(data.CreateRegularGeoshardedDeployment("gc-regular-deployment")), - []v1.CustomZoneMapping{ - { - Zone: "Zone 1", - Location: "AO", - }, - }, - []v1.ManagedNamespace{ - { - Collection: "somecollection", - Db: "somedb", - CustomShardKey: "somekey", - }, - }, - ), Entry("Test[gc-advanced-deployment]: Advanced", Label("gc-advanced-deployment"), model.DataProvider( "gc-advanced-deployment", @@ -115,9 +94,6 @@ func globalClusterFlow(userData *model.TestDataProvider, mapping []v1.CustomZone if userData.InitialDeployments[0].Spec.DeploymentSpec != nil { userData.InitialDeployments[0].Spec.DeploymentSpec.ManagedNamespaces = managedNamespace userData.InitialDeployments[0].Spec.DeploymentSpec.CustomZoneMapping = mapping - } else { - userData.InitialDeployments[0].Spec.AdvancedDeploymentSpec.ManagedNamespaces = managedNamespace - userData.InitialDeployments[0].Spec.AdvancedDeploymentSpec.CustomZoneMapping = mapping } Expect(userData.K8SClient.Update(userData.Context, userData.InitialDeployments[0])).To(Succeed()) @@ -161,9 +137,6 @@ func globalClusterFlow(userData *model.TestDataProvider, mapping []v1.CustomZone if userData.InitialDeployments[0].Spec.DeploymentSpec != nil { userData.InitialDeployments[0].Spec.DeploymentSpec.ManagedNamespaces = nil userData.InitialDeployments[0].Spec.DeploymentSpec.CustomZoneMapping = nil - } else { - userData.InitialDeployments[0].Spec.AdvancedDeploymentSpec.ManagedNamespaces = nil - userData.InitialDeployments[0].Spec.AdvancedDeploymentSpec.CustomZoneMapping = nil } Expect(userData.K8SClient.Update(userData.Context, userData.InitialDeployments[0])).To(Succeed()) Eventually(func(g Gomega) bool { diff --git a/test/e2e/helm_chart_test.go b/test/e2e/helm_chart_test.go index f62a10c16d..3a733ab825 100644 --- a/test/e2e/helm_chart_test.go +++ b/test/e2e/helm_chart_test.go @@ -85,8 +85,6 @@ var _ = Describe("HELM charts", Ordered, func() { data = test GinkgoWriter.Println(data.Resources.KeyName) switch deploymentType { - case "advanced": - data.Resources.Deployments[0].Spec.AdvancedDeploymentSpec.Name = data.Resources.KeyName case "serverless": data.Resources.Deployments[0].Spec.ServerlessSpec.Name = data.Resources.KeyName default: @@ -133,7 +131,7 @@ var _ = Describe("HELM charts", Ordered, func() { ), "default", ), - Entry("Advanced deployment by helm chart", Label("helm-advanced"), + Entry("Deployment by helm chart", Label("helm-advanced"), model.DataProviderWithResources( "helm-advanced", model.AProject{}, @@ -151,7 +149,7 @@ var _ = Describe("HELM charts", Ordered, func() { ), "advanced", ), - Entry("Advanced multiregion deployment by helm chart", Label("helm-advanced-multiregion"), + Entry("Deployment multiregion by helm chart", Label("helm-advanced-multiregion"), model.DataProviderWithResources( "helm-advanced-multiregion", model.AProject{}, @@ -252,7 +250,7 @@ var _ = Describe("HELM charts", Ordered, func() { }) By("User update new released operator", func() { backup := true - data.Resources.Deployments[0].Spec.DeploymentSpec.ProviderBackupEnabled = &backup + data.Resources.Deployments[0].Spec.DeploymentSpec.BackupEnabled = &backup actions.HelmUpgradeChartVersions(&data) actions.CheckUsersCanUseOldApp(&data) }) @@ -264,7 +262,7 @@ var _ = Describe("HELM charts", Ordered, func() { }) func waitDeploymentWithChecks(data *model.TestDataProvider) { - By("Wait creation until is done", func() { + By("Wait for a Deployment to be created", func() { actions.WaitProjectWithoutGenerationCheck(data) resource, err := kube.GetProjectResource(data) Expect(err).Should(BeNil()) @@ -275,10 +273,6 @@ func waitDeploymentWithChecks(data *model.TestDataProvider) { By("Check attributes", func() { deployment := data.Resources.Deployments[0] switch { - case deployment.Spec.AdvancedDeploymentSpec != nil: - advancedDeployment, err := atlasClient.GetDeployment(data.Resources.ProjectID, deployment.Spec.AdvancedDeploymentSpec.Name) - Expect(err).To(BeNil()) - actions.CompareAdvancedDeploymentsSpec(deployment.Spec, *advancedDeployment) case deployment.Spec.ServerlessSpec != nil: serverlessInstance, err := atlasClient.GetServerlessInstance(data.Resources.ProjectID, deployment.Spec.ServerlessSpec.Name) Expect(err).To(BeNil()) diff --git a/test/e2e/model/deployment.go b/test/e2e/model/deployment.go index 410d937b55..3151f86e96 100644 --- a/test/e2e/model/deployment.go +++ b/test/e2e/model/deployment.go @@ -18,9 +18,6 @@ type AtlasDeployment struct { type DeploymentSpec v1.AtlasDeploymentSpec func (spec DeploymentSpec) GetDeploymentName() string { - if spec.AdvancedDeploymentSpec != nil { - return spec.AdvancedDeploymentSpec.Name - } if spec.ServerlessSpec != nil { return spec.ServerlessSpec.Name } diff --git a/test/int/backup_protected_test.go b/test/int/backup_protected_test.go index b562c7ab8f..a2a7c5f2f3 100644 --- a/test/int/backup_protected_test.go +++ b/test/int/backup_protected_test.go @@ -146,7 +146,7 @@ var _ = Describe("AtlasBackupSchedule Deletion Protected", By("Creating a deployment with backups enabled (default)", func() { testDeployment = mdbv1.DefaultAWSDeployment(testNamespace.Name, testProject.Name) - testDeployment.Spec.DeploymentSpec.ProviderBackupEnabled = toptr.MakePtr(true) + testDeployment.Spec.DeploymentSpec.BackupEnabled = toptr.MakePtr(true) Expect(k8sClient.Create(context.Background(), testDeployment)).To(Succeed()) }) diff --git a/test/int/deployment_test.go b/test/int/deployment_test.go index eb69343620..b255e1c3e2 100644 --- a/test/int/deployment_test.go +++ b/test/int/deployment_test.go @@ -145,33 +145,19 @@ var _ = Describe("AtlasDeployment", Label("int", "AtlasDeployment", "deployment- checkAtlasState := func(additionalChecks ...func(c *mongodbatlas.AdvancedCluster)) { By("Verifying Deployment state in Atlas", func() { - legacyDeployment := createdDeployment.Spec.DeploymentSpec - - if legacyDeployment != nil { - err := atlasdeployment.ConvertLegacyDeployment(&createdDeployment.Spec) - Expect(err).ToNot(HaveOccurred()) - - createdDeployment.Spec.DeploymentSpec = nil - } atlasDeploymentAsAtlas, _, err := atlasClient.AdvancedClusters.Get(context.Background(), createdProject.Status.ID, createdDeployment.GetDeploymentName()) Expect(err).ToNot(HaveOccurred()) - mergedDeployment, atlasDeployment, err := atlasdeployment.MergedAdvancedDeployment(*atlasDeploymentAsAtlas, *createdDeployment.Spec.AdvancedDeploymentSpec) + mergedDeployment, atlasDeployment, err := atlasdeployment.MergedAdvancedDeployment(*atlasDeploymentAsAtlas, *createdDeployment.Spec.DeploymentSpec) Expect(err).ToNot(HaveOccurred()) _, diff := atlasdeployment.AdvancedDeploymentsEqual(zap.S(), mergedDeployment, atlasDeployment) Expect(diff).To(BeEmpty()) - createdDeployment.Spec.DeploymentSpec = legacyDeployment - for _, check := range additionalChecks { check(atlasDeploymentAsAtlas) } - - if legacyDeployment != nil { - createdDeployment.Spec.AdvancedDeploymentSpec = nil - } }) } @@ -180,7 +166,7 @@ var _ = Describe("AtlasDeployment", Label("int", "AtlasDeployment", "deployment- atlasDeploymentAsAtlas, _, err := atlasClient.AdvancedClusters.Get(context.Background(), createdProject.Status.ID, createdDeployment.GetDeploymentName()) Expect(err).ToNot(HaveOccurred()) - mergedDeployment, atlasDeployment, err := atlasdeployment.MergedAdvancedDeployment(*atlasDeploymentAsAtlas, *createdDeployment.Spec.AdvancedDeploymentSpec) + mergedDeployment, atlasDeployment, err := atlasdeployment.MergedAdvancedDeployment(*atlasDeploymentAsAtlas, *createdDeployment.Spec.DeploymentSpec) Expect(err).ToNot(HaveOccurred()) _, diff := atlasdeployment.AdvancedDeploymentsEqual(zap.S(), mergedDeployment, atlasDeployment) @@ -298,7 +284,7 @@ var _ = Describe("AtlasDeployment", Label("int", "AtlasDeployment", "deployment- By("Updating ReplicationSpecs", func() { numShards := 2 - createdDeployment.Spec.DeploymentSpec.ReplicationSpecs[0].NumShards = toptr.MakePtr(int64(numShards)) + createdDeployment.Spec.DeploymentSpec.ReplicationSpecs[0].NumShards = numShards createdDeployment.Spec.DeploymentSpec.ClusterType = "SHARDED" performUpdate(40 * time.Minute) @@ -313,7 +299,7 @@ var _ = Describe("AtlasDeployment", Label("int", "AtlasDeployment", "deployment- }) }) - Describe("Create deployment & increase DiskSizeGB", func() { + Describe("Create deployment & increase InstanceSize", func() { It("Should Succeed", func() { expectedDeployment := mdbv1.DefaultAWSDeployment(namespace.Name, createdProject.Name) @@ -329,7 +315,9 @@ var _ = Describe("AtlasDeployment", Label("int", "AtlasDeployment", "deployment- }) By("Increasing InstanceSize", func() { - createdDeployment.Spec.DeploymentSpec.ProviderSettings.InstanceSizeName = "M30" + createdDeployment.Spec.DeploymentSpec.ReplicationSpecs[0].RegionConfigs[0].ElectableSpecs.InstanceSize = "M30" + createdDeployment.Spec.DeploymentSpec.ReplicationSpecs[0].RegionConfigs[0].ReadOnlySpecs.InstanceSize = "M30" + createdDeployment.Spec.DeploymentSpec.ReplicationSpecs[0].RegionConfigs[0].AnalyticsSpecs.InstanceSize = "M30" performUpdate(40 * time.Minute) doDeploymentStatusChecks() checkAtlasState() @@ -351,26 +339,55 @@ var _ = Describe("AtlasDeployment", Label("int", "AtlasDeployment", "deployment- By("Change deployment to GEOSHARDED", func() { createdDeployment.Spec.DeploymentSpec.ClusterType = "GEOSHARDED" - createdDeployment.Spec.DeploymentSpec.ReplicationSpecs = []mdbv1.ReplicationSpec{ + createdDeployment.Spec.DeploymentSpec.ReplicationSpecs = []*mdbv1.AdvancedReplicationSpec{ { - NumShards: int64ptr(1), + NumShards: 1, ZoneName: "Zone 1", - RegionsConfig: map[string]mdbv1.RegionsConfig{ - "US_EAST_1": { - AnalyticsNodes: int64ptr(1), - ElectableNodes: int64ptr(2), - Priority: int64ptr(7), - ReadOnlyNodes: int64ptr(0), + RegionConfigs: []*mdbv1.AdvancedRegionConfig{ + { + AutoScaling: &mdbv1.AdvancedAutoScalingSpec{ + DiskGB: &mdbv1.DiskGB{ + Enabled: toptr.MakePtr(false), + }, + Compute: &mdbv1.ComputeSpec{ + Enabled: toptr.MakePtr(false), + ScaleDownEnabled: toptr.MakePtr(false), + }, + }, + ElectableSpecs: &mdbv1.Specs{ + InstanceSize: "M10", + NodeCount: toptr.MakePtr(2), + }, + AnalyticsSpecs: &mdbv1.Specs{ + InstanceSize: "M10", + NodeCount: toptr.MakePtr(1), + }, + Priority: toptr.MakePtr(7), + ProviderName: "AWS", + RegionName: "US_EAST_1", }, - "US_WEST_1": { - AnalyticsNodes: int64ptr(0), - ElectableNodes: int64ptr(1), - Priority: int64ptr(6), - ReadOnlyNodes: int64ptr(0), + { + AutoScaling: &mdbv1.AdvancedAutoScalingSpec{ + DiskGB: &mdbv1.DiskGB{ + Enabled: toptr.MakePtr(false), + }, + Compute: &mdbv1.ComputeSpec{ + Enabled: toptr.MakePtr(false), + ScaleDownEnabled: toptr.MakePtr(false), + }, + }, + ElectableSpecs: &mdbv1.Specs{ + InstanceSize: "M10", + NodeCount: toptr.MakePtr(1), + }, + Priority: toptr.MakePtr(6), + ProviderName: "AWS", + RegionName: "US_WEST_1", }, }, }, } + performUpdate(90 * time.Minute) doDeploymentStatusChecks() checkAtlasState() @@ -381,42 +398,62 @@ var _ = Describe("AtlasDeployment", Label("int", "AtlasDeployment", "deployment- Describe("Create/Update the deployment (more complex scenario)", func() { It("Should be created", func() { createdDeployment = mdbv1.DefaultAWSDeployment(namespace.Name, createdProject.Name) - createdDeployment.Spec.DeploymentSpec.ClusterType = mdbv1.TypeReplicaSet - createdDeployment.Spec.DeploymentSpec.AutoScaling = &mdbv1.AutoScalingSpec{ - Compute: &mdbv1.ComputeSpec{ - Enabled: boolptr(true), - ScaleDownEnabled: boolptr(true), - }, - DiskGBEnabled: boolptr(false), - } - createdDeployment.Spec.DeploymentSpec.ProviderSettings.AutoScaling = &mdbv1.AutoScalingSpec{ - Compute: &mdbv1.ComputeSpec{ - MaxInstanceSize: "M20", - MinInstanceSize: "M10", - }, - } - createdDeployment.Spec.DeploymentSpec.ProviderSettings.InstanceSizeName = "M10" + createdDeployment.Spec.DeploymentSpec.ClusterType = string(mdbv1.TypeReplicaSet) createdDeployment.Spec.DeploymentSpec.Labels = []common.LabelSpec{{Key: "createdBy", Value: "Atlas Operator"}} - createdDeployment.Spec.DeploymentSpec.ReplicationSpecs = []mdbv1.ReplicationSpec{{ - NumShards: int64ptr(1), + createdDeployment.Spec.DeploymentSpec.ReplicationSpecs[0] = &mdbv1.AdvancedReplicationSpec{ + NumShards: 1, ZoneName: "Zone 1", - // One interesting thing: if the regionsConfig is not empty - Atlas nullifies the 'providerSettings.regionName' field - RegionsConfig: map[string]mdbv1.RegionsConfig{ - "US_EAST_1": {AnalyticsNodes: int64ptr(0), ElectableNodes: int64ptr(1), Priority: int64ptr(6), ReadOnlyNodes: int64ptr(0)}, - "US_WEST_2": {AnalyticsNodes: int64ptr(0), ElectableNodes: int64ptr(2), Priority: int64ptr(7), ReadOnlyNodes: int64ptr(0)}, + RegionConfigs: []*mdbv1.AdvancedRegionConfig{ + { + AutoScaling: &mdbv1.AdvancedAutoScalingSpec{ + DiskGB: &mdbv1.DiskGB{ + Enabled: toptr.MakePtr(true), + }, + Compute: &mdbv1.ComputeSpec{ + Enabled: toptr.MakePtr(true), + ScaleDownEnabled: toptr.MakePtr(true), + MinInstanceSize: "M10", + MaxInstanceSize: "M20", + }, + }, + ElectableSpecs: &mdbv1.Specs{ + InstanceSize: "M10", + NodeCount: toptr.MakePtr(2), + }, + Priority: toptr.MakePtr(7), + ProviderName: "AWS", + RegionName: "US_EAST_1", + }, + { + AutoScaling: &mdbv1.AdvancedAutoScalingSpec{ + DiskGB: &mdbv1.DiskGB{ + Enabled: toptr.MakePtr(true), + }, + Compute: &mdbv1.ComputeSpec{ + Enabled: toptr.MakePtr(true), + ScaleDownEnabled: toptr.MakePtr(true), + MinInstanceSize: "M10", + MaxInstanceSize: "M20", + }, + }, + ElectableSpecs: &mdbv1.Specs{ + InstanceSize: "M10", + NodeCount: toptr.MakePtr(1), + }, + Priority: toptr.MakePtr(6), + ProviderName: "AWS", + RegionName: "US_WEST_2", + }, }, - }} - createdDeployment.Spec.DeploymentSpec.DiskSizeGB = intptr(10) + } - replicationSpecsCheckFunc := func(c *mongodbatlas.AdvancedCluster) { - err := atlasdeployment.ConvertLegacyDeployment(&createdDeployment.Spec) - Expect(err).ToNot(HaveOccurred()) + createdDeployment.Spec.DeploymentSpec.DiskSizeGB = toptr.MakePtr(10) - mergedDeployment, _, err := atlasdeployment.MergedAdvancedDeployment(*c, *createdDeployment.Spec.AdvancedDeploymentSpec) + replicationSpecsCheckFunc := func(c *mongodbatlas.AdvancedCluster) { + mergedDeployment, _, err := atlasdeployment.MergedAdvancedDeployment(*c, *createdDeployment.Spec.DeploymentSpec) Expect(err).ToNot(HaveOccurred()) expectedReplicationSpecs := mergedDeployment.ReplicationSpecs - createdDeployment.Spec.AdvancedDeploymentSpec = nil // The ID field is added by Atlas - we don't have it in our specs Expect(c.ReplicationSpecs[0].ID).NotTo(BeNil()) @@ -436,14 +473,48 @@ var _ = Describe("AtlasDeployment", Label("int", "AtlasDeployment", "deployment- }) By("Updating the deployment (multiple operations)", func() { - delete(createdDeployment.Spec.DeploymentSpec.ReplicationSpecs[0].RegionsConfig, "US_WEST_2") - createdDeployment.Spec.DeploymentSpec.ReplicationSpecs[0].RegionsConfig["US_WEST_1"] = mdbv1.RegionsConfig{AnalyticsNodes: int64ptr(0), ElectableNodes: int64ptr(2), Priority: int64ptr(6), ReadOnlyNodes: int64ptr(0)} - config := createdDeployment.Spec.DeploymentSpec.ReplicationSpecs[0].RegionsConfig["US_EAST_1"] - // Note, that Atlas has strict requirements to priorities - they must start with 7 and be in descending order over the regions - config.Priority = int64ptr(7) - createdDeployment.Spec.DeploymentSpec.ReplicationSpecs[0].RegionsConfig["US_EAST_1"] = config - - createdDeployment.Spec.DeploymentSpec.ProviderSettings.AutoScaling.Compute.MaxInstanceSize = "M30" + createdDeployment.Spec.DeploymentSpec.ReplicationSpecs[0].RegionConfigs = []*mdbv1.AdvancedRegionConfig{ + { + AutoScaling: &mdbv1.AdvancedAutoScalingSpec{ + DiskGB: &mdbv1.DiskGB{ + Enabled: toptr.MakePtr(true), + }, + Compute: &mdbv1.ComputeSpec{ + Enabled: toptr.MakePtr(true), + ScaleDownEnabled: toptr.MakePtr(true), + MinInstanceSize: "M10", + MaxInstanceSize: "M30", + }, + }, + ElectableSpecs: &mdbv1.Specs{ + InstanceSize: "M10", + NodeCount: toptr.MakePtr(2), + }, + Priority: toptr.MakePtr(7), + ProviderName: "AWS", + RegionName: "US_EAST_1", + }, + { + ElectableSpecs: &mdbv1.Specs{ + InstanceSize: "M10", + NodeCount: toptr.MakePtr(1), + }, + Priority: toptr.MakePtr(6), + ProviderName: "AWS", + RegionName: "US_WEST_1", + AutoScaling: &mdbv1.AdvancedAutoScalingSpec{ + DiskGB: &mdbv1.DiskGB{ + Enabled: toptr.MakePtr(true), + }, + Compute: &mdbv1.ComputeSpec{ + Enabled: toptr.MakePtr(true), + ScaleDownEnabled: toptr.MakePtr(true), + MinInstanceSize: "M10", + MaxInstanceSize: "M30", + }, + }, + }, + } legacySpec := createdDeployment.Spec.DeploymentSpec @@ -461,17 +532,20 @@ var _ = Describe("AtlasDeployment", Label("int", "AtlasDeployment", "deployment- }) By("Disable deployment and disk AutoScaling", func() { - createdDeployment.Spec.DeploymentSpec.AutoScaling = &mdbv1.AutoScalingSpec{ + createdDeployment.Spec.DeploymentSpec.ReplicationSpecs[0].RegionConfigs[0].AutoScaling = &mdbv1.AdvancedAutoScalingSpec{ + DiskGB: &mdbv1.DiskGB{ + Enabled: toptr.MakePtr(false), + }, Compute: &mdbv1.ComputeSpec{ - Enabled: boolptr(false), - ScaleDownEnabled: boolptr(false), + Enabled: toptr.MakePtr(false), }, - DiskGBEnabled: boolptr(false), } - createdDeployment.Spec.DeploymentSpec.ProviderSettings.AutoScaling = &mdbv1.AutoScalingSpec{ + createdDeployment.Spec.DeploymentSpec.ReplicationSpecs[0].RegionConfigs[1].AutoScaling = &mdbv1.AdvancedAutoScalingSpec{ + DiskGB: &mdbv1.DiskGB{ + Enabled: toptr.MakePtr(false), + }, Compute: &mdbv1.ComputeSpec{ - MinInstanceSize: "", - MaxInstanceSize: "", + Enabled: toptr.MakePtr(false), }, } @@ -488,7 +562,9 @@ var _ = Describe("AtlasDeployment", Label("int", "AtlasDeployment", "deployment- autoScalingInput := c.ReplicationSpecs[0].RegionConfigs[0].AutoScaling autoScalingSpec := deployment.ReplicationSpecs[0].RegionConfigs[0].AutoScaling - Expect(autoScalingInput.Compute).To(Equal(autoScalingSpec.Compute)) + Expect(autoScalingInput.Compute.Enabled).To(Equal(autoScalingSpec.Compute.Enabled)) + Expect(autoScalingInput.Compute.MaxInstanceSize).To(Equal(autoScalingSpec.Compute.MaxInstanceSize)) + Expect(autoScalingInput.Compute.MinInstanceSize).To(Equal(autoScalingSpec.Compute.MinInstanceSize)) }) }) }) @@ -496,7 +572,7 @@ var _ = Describe("AtlasDeployment", Label("int", "AtlasDeployment", "deployment- Describe("Create/Update the cluster", func() { It("Should fail, then be fixed (GCP)", func() { - createdDeployment = mdbv1.DefaultGCPDeployment(namespace.Name, createdProject.Name).WithAtlasName("") + createdDeployment = mdbv1.DefaultGCPDeployment(namespace.Name, createdProject.Name).WithAtlasName("----") By(fmt.Sprintf("Trying to create the Deployment %s with invalid parameters", kube.ObjectKeyFromObject(createdDeployment)), func() { err := k8sClient.Create(context.Background(), createdDeployment) @@ -513,11 +589,14 @@ var _ = Describe("AtlasDeployment", Label("int", "AtlasDeployment", "deployment- }) }) - It("Should Success (AWS) with enabled autoscaling", func() { + It("Should succeed (AWS) with enabled autoscaling for Disk size", func() { createdDeployment = mdbv1.DefaultAWSDeployment(namespace.Name, createdProject.Name) - createdDeployment.Spec.DeploymentSpec.DiskSizeGB = intptr(20) - createdDeployment.Spec.DeploymentSpec.AutoScaling = &mdbv1.AutoScalingSpec{ - DiskGBEnabled: boolptr(true), + + createdDeployment.Spec.DeploymentSpec.DiskSizeGB = toptr.MakePtr[int](20) + createdDeployment.Spec.DeploymentSpec.ReplicationSpecs[0].RegionConfigs[0].AutoScaling = &mdbv1.AdvancedAutoScalingSpec{ + DiskGB: &mdbv1.DiskGB{ + Enabled: toptr.MakePtr(true), + }, } By(fmt.Sprintf("Creating the Deployment %s with autoscaling", kube.ObjectKeyFromObject(createdDeployment)), func() { @@ -529,7 +608,7 @@ var _ = Describe("AtlasDeployment", Label("int", "AtlasDeployment", "deployment- By("Decreasing the Deployment disk size should not take effect", func() { // prevDiskSize := *createdDeployment.Spec.DeploymentSpec.DiskSizeGB - createdDeployment.Spec.DeploymentSpec.DiskSizeGB = intptr(14) + createdDeployment.Spec.DeploymentSpec.DiskSizeGB = toptr.MakePtr(14) performUpdate(30 * time.Minute) doDeploymentStatusChecks() @@ -537,14 +616,14 @@ var _ = Describe("AtlasDeployment", Label("int", "AtlasDeployment", "deployment- // Expect(*c.DiskSizeGB).To(BeEquivalentTo(prevDiskSize)) // todo: find out if this should still work for advanced clusters // check whether https://github.com/mongodb/go-client-mongodb-atlas/issues/140 is fixed - Expect(c.DiskSizeGB).To(BeAssignableToTypeOf(float64ptr(0)), "DiskSizeGB is no longer a *float64, please check the spec!") + Expect(c.DiskSizeGB).To(BeAssignableToTypeOf(toptr.MakePtr[float64](0)), "DiskSizeGB is no longer a *float64, please check the spec!") }) }) }) It("Should Succeed (AWS)", func() { createdDeployment = mdbv1.DefaultAWSDeployment(namespace.Name, createdProject.Name) - createdDeployment.Spec.DeploymentSpec.DiskSizeGB = intptr(20) + createdDeployment.Spec.DeploymentSpec.DiskSizeGB = toptr.MakePtr(20) createdDeployment = createdDeployment.WithAutoscalingDisabled() By(fmt.Sprintf("Creating the Deployment %s", kube.ObjectKeyFromObject(createdDeployment)), func() { @@ -556,14 +635,14 @@ var _ = Describe("AtlasDeployment", Label("int", "AtlasDeployment", "deployment- By("Updating the Deployment labels", func() { createdDeployment.Spec.DeploymentSpec.Labels = []common.LabelSpec{{Key: "int-test", Value: "true"}} - performUpdate(20 * time.Minute) + performUpdate(30 * time.Minute) doDeploymentStatusChecks() checkAtlasState() }) By("Updating the Deployment tags", func() { createdDeployment.Spec.DeploymentSpec.Tags = []*mdbv1.TagSpec{{Key: "test-1", Value: "value-1"}, {Key: "test-2", Value: "value-2"}} - performUpdate(20 * time.Minute) + performUpdate(30 * time.Minute) doDeploymentStatusChecks() checkAtlasState(func(c *mongodbatlas.AdvancedCluster) { for i, tag := range createdDeployment.Spec.DeploymentSpec.Tags { @@ -575,7 +654,7 @@ var _ = Describe("AtlasDeployment", Label("int", "AtlasDeployment", "deployment- By("Updating the order of Deployment tags", func() { createdDeployment.Spec.DeploymentSpec.Tags = []*mdbv1.TagSpec{{Key: "test-2", Value: "value-2"}, {Key: "test-1", Value: "value-1"}} - performUpdate(20 * time.Minute) + performUpdate(30 * time.Minute) doDeploymentStatusChecks() checkAtlasState(func(c *mongodbatlas.AdvancedCluster) { for i, tag := range createdDeployment.Spec.DeploymentSpec.Tags { @@ -596,33 +675,34 @@ var _ = Describe("AtlasDeployment", Label("int", "AtlasDeployment", "deployment- lastGeneration++ // Removing tags for next tests createdDeployment.Spec.DeploymentSpec.Tags = []*mdbv1.TagSpec{} - performUpdate(20 * time.Minute) + performUpdate(30 * time.Minute) }) By("Updating the Deployment backups settings", func() { - createdDeployment.Spec.DeploymentSpec.ProviderBackupEnabled = boolptr(true) - performUpdate(20 * time.Minute) + createdDeployment.Spec.DeploymentSpec.BackupEnabled = toptr.MakePtr(true) + // createdDeployment.Spec.DeploymentSpec.ProviderBackupEnabled = toptr.MakePtr(true) + performUpdate(30 * time.Minute) doDeploymentStatusChecks() checkAtlasState(func(c *mongodbatlas.AdvancedCluster) { - Expect(c.BackupEnabled).To(Equal(createdDeployment.Spec.DeploymentSpec.ProviderBackupEnabled)) + Expect(c.BackupEnabled).To(Equal(createdDeployment.Spec.DeploymentSpec.BackupEnabled)) }) }) By("Decreasing the Deployment disk size", func() { - createdDeployment.Spec.DeploymentSpec.DiskSizeGB = intptr(15) - performUpdate(20 * time.Minute) + createdDeployment.Spec.DeploymentSpec.DiskSizeGB = toptr.MakePtr(15) + performUpdate(30 * time.Minute) doDeploymentStatusChecks() checkAtlasState(func(c *mongodbatlas.AdvancedCluster) { Expect(*c.DiskSizeGB).To(BeEquivalentTo(*createdDeployment.Spec.DeploymentSpec.DiskSizeGB)) // check whether https://github.com/mongodb/go-client-mongodb-atlas/issues/140 is fixed - Expect(c.DiskSizeGB).To(BeAssignableToTypeOf(float64ptr(0)), "DiskSizeGB is no longer a *float64, please check the spec!") + Expect(c.DiskSizeGB).To(BeAssignableToTypeOf(toptr.MakePtr[float64](0)), "DiskSizeGB is no longer a *float64, please check the spec!") }) }) By("Pausing the deployment", func() { - createdDeployment.Spec.DeploymentSpec.Paused = boolptr(true) - performUpdate(20 * time.Minute) + createdDeployment.Spec.DeploymentSpec.Paused = toptr.MakePtr(true) + performUpdate(30 * time.Minute) doDeploymentStatusChecks() checkAtlasState(func(c *mongodbatlas.AdvancedCluster) { Expect(c.Paused).To(Equal(createdDeployment.Spec.DeploymentSpec.Paused)) @@ -630,7 +710,7 @@ var _ = Describe("AtlasDeployment", Label("int", "AtlasDeployment", "deployment- }) By("Updating the Deployment configuration while paused (should fail)", func() { - createdDeployment.Spec.DeploymentSpec.ProviderBackupEnabled = boolptr(false) + createdDeployment.Spec.DeploymentSpec.BackupEnabled = toptr.MakePtr(false) Expect(k8sClient.Update(context.Background(), createdDeployment)).To(Succeed()) Eventually(func() bool { return testutil.CheckCondition( @@ -650,8 +730,8 @@ var _ = Describe("AtlasDeployment", Label("int", "AtlasDeployment", "deployment- }) By("Unpausing the deployment", func() { - createdDeployment.Spec.DeploymentSpec.Paused = boolptr(false) - performUpdate(20 * time.Minute) + createdDeployment.Spec.DeploymentSpec.Paused = toptr.MakePtr(false) + performUpdate(30 * time.Minute) doDeploymentStatusChecks() checkAtlasState(func(c *mongodbatlas.AdvancedCluster) { Expect(c.Paused).To(Equal(createdDeployment.Spec.DeploymentSpec.Paused)) @@ -661,13 +741,15 @@ var _ = Describe("AtlasDeployment", Label("int", "AtlasDeployment", "deployment- By("Checking that modifications were applied after unpausing", func() { doDeploymentStatusChecks() checkAtlasState(func(c *mongodbatlas.AdvancedCluster) { - Expect(c.BackupEnabled).To(Equal(createdDeployment.Spec.DeploymentSpec.ProviderBackupEnabled)) + Expect(c.BackupEnabled).To(Equal(createdDeployment.Spec.DeploymentSpec.BackupEnabled)) }) }) By("Setting incorrect instance size (should fail)", func() { - oldSizeName := createdDeployment.Spec.DeploymentSpec.ProviderSettings.InstanceSizeName - createdDeployment.Spec.DeploymentSpec.ProviderSettings.InstanceSizeName = "M42" + oldSizeName := createdDeployment.Spec.DeploymentSpec.ReplicationSpecs[0].RegionConfigs[0].ElectableSpecs.InstanceSize + createdDeployment.Spec.DeploymentSpec.ReplicationSpecs[0].RegionConfigs[0].ElectableSpecs.InstanceSize = "M42" + createdDeployment.Spec.DeploymentSpec.ReplicationSpecs[0].RegionConfigs[0].AnalyticsSpecs.InstanceSize = "M42" + createdDeployment.Spec.DeploymentSpec.ReplicationSpecs[0].RegionConfigs[0].ReadOnlySpecs.InstanceSize = "M42" Expect(k8sClient.Update(context.Background(), createdDeployment)).To(Succeed()) Eventually(func() bool { return testutil.CheckCondition( @@ -684,8 +766,10 @@ var _ = Describe("AtlasDeployment", Label("int", "AtlasDeployment", "deployment- lastGeneration++ By("Fixing the Deployment", func() { - createdDeployment.Spec.DeploymentSpec.ProviderSettings.InstanceSizeName = oldSizeName - performUpdate(20 * time.Minute) + createdDeployment.Spec.DeploymentSpec.ReplicationSpecs[0].RegionConfigs[0].ElectableSpecs.InstanceSize = oldSizeName + createdDeployment.Spec.DeploymentSpec.ReplicationSpecs[0].RegionConfigs[0].AnalyticsSpecs.InstanceSize = oldSizeName + createdDeployment.Spec.DeploymentSpec.ReplicationSpecs[0].RegionConfigs[0].ReadOnlySpecs.InstanceSize = oldSizeName + performUpdate(30 * time.Minute) doDeploymentStatusChecks() checkAtlasState() }) @@ -840,9 +924,9 @@ var _ = Describe("AtlasDeployment", Label("int", "AtlasDeployment", "deployment- }) By(fmt.Sprintf("Updating the InstanceSize of Advanced Deployment %s", kube.ObjectKeyFromObject(createdDeployment)), func() { - createdDeployment.Spec.AdvancedDeploymentSpec.ReplicationSpecs[0].RegionConfigs[0].ElectableSpecs.InstanceSize = "M20" - createdDeployment.Spec.AdvancedDeploymentSpec.ReplicationSpecs[0].RegionConfigs[0].ReadOnlySpecs.InstanceSize = "M20" - createdDeployment.Spec.AdvancedDeploymentSpec.ReplicationSpecs[0].RegionConfigs[0].AnalyticsSpecs.InstanceSize = "M20" + createdDeployment.Spec.DeploymentSpec.ReplicationSpecs[0].RegionConfigs[0].ElectableSpecs.InstanceSize = "M20" + createdDeployment.Spec.DeploymentSpec.ReplicationSpecs[0].RegionConfigs[0].ReadOnlySpecs.InstanceSize = "M20" + createdDeployment.Spec.DeploymentSpec.ReplicationSpecs[0].RegionConfigs[0].AnalyticsSpecs.InstanceSize = "M20" Expect(k8sClient.Update(context.Background(), createdDeployment)).ToNot(HaveOccurred()) Eventually(func(g Gomega) bool { @@ -856,7 +940,7 @@ var _ = Describe("AtlasDeployment", Label("int", "AtlasDeployment", "deployment- }) By(fmt.Sprintf("Enable AutoScaling for the Advanced Deployment %s", kube.ObjectKeyFromObject(createdDeployment)), func() { - regionConfig := createdDeployment.Spec.AdvancedDeploymentSpec.ReplicationSpecs[0].RegionConfigs[0] + regionConfig := createdDeployment.Spec.DeploymentSpec.ReplicationSpecs[0].RegionConfigs[0] regionConfig.ElectableSpecs.InstanceSize = "M10" regionConfig.ReadOnlySpecs.InstanceSize = "M10" regionConfig.AnalyticsSpecs.InstanceSize = "M10" @@ -884,7 +968,7 @@ var _ = Describe("AtlasDeployment", Label("int", "AtlasDeployment", "deployment- }) By(fmt.Sprintf("Update Instance Size Margins with AutoScaling for Deployment %s", kube.ObjectKeyFromObject(createdDeployment)), func() { - regionConfig := createdDeployment.Spec.AdvancedDeploymentSpec.ReplicationSpecs[0].RegionConfigs[0] + regionConfig := createdDeployment.Spec.DeploymentSpec.ReplicationSpecs[0].RegionConfigs[0] regionConfig.AutoScaling.Compute.MinInstanceSize = "M20" regionConfig.ElectableSpecs.InstanceSize = "M20" regionConfig.ReadOnlySpecs.InstanceSize = "M20" @@ -905,7 +989,7 @@ var _ = Describe("AtlasDeployment", Label("int", "AtlasDeployment", "deployment- It("Should Succeed", func() { createdDeployment = mdbv1.DefaultAwsAdvancedDeployment(namespace.Name, createdProject.Name) - createdDeployment.Spec.AdvancedDeploymentSpec.ReplicationSpecs = []*mdbv1.AdvancedReplicationSpec{ + createdDeployment.Spec.DeploymentSpec.ReplicationSpecs = []*mdbv1.AdvancedReplicationSpec{ { NumShards: 1, ZoneName: "US_EAST_1", @@ -915,19 +999,19 @@ var _ = Describe("AtlasDeployment", Label("int", "AtlasDeployment", "deployment- DiskIOPS: nil, EbsVolumeType: "", InstanceSize: "M10", - NodeCount: intptr(1), + NodeCount: toptr.MakePtr(1), }, ElectableSpecs: &mdbv1.Specs{ DiskIOPS: nil, EbsVolumeType: "", InstanceSize: "M10", - NodeCount: intptr(3), + NodeCount: toptr.MakePtr(3), }, ReadOnlySpecs: &mdbv1.Specs{ DiskIOPS: nil, EbsVolumeType: "", InstanceSize: "M10", - NodeCount: intptr(1), + NodeCount: toptr.MakePtr(1), }, AutoScaling: &mdbv1.AdvancedAutoScalingSpec{ DiskGB: &mdbv1.DiskGB{ @@ -941,7 +1025,7 @@ var _ = Describe("AtlasDeployment", Label("int", "AtlasDeployment", "deployment- }, }, BackingProviderName: "AWS", - Priority: intptr(7), + Priority: toptr.MakePtr(7), ProviderName: "AWS", RegionName: "US_EAST_1", }, @@ -963,7 +1047,7 @@ var _ = Describe("AtlasDeployment", Label("int", "AtlasDeployment", "deployment- err := compat.JSONCopy(&previousDeployment, createdDeployment) Expect(err).NotTo(HaveOccurred()) - createdDeployment.Spec.AdvancedDeploymentSpec.ReplicationSpecs[0]. + createdDeployment.Spec.DeploymentSpec.ReplicationSpecs[0]. RegionConfigs[0]. AutoScaling. Compute. @@ -990,16 +1074,16 @@ var _ = Describe("AtlasDeployment", Label("int", "AtlasDeployment", "deployment- err := compat.JSONCopy(&previousDeployment, createdDeployment) Expect(err).NotTo(HaveOccurred()) - createdDeployment.Spec.AdvancedDeploymentSpec.ReplicationSpecs[0]. + createdDeployment.Spec.DeploymentSpec.ReplicationSpecs[0]. RegionConfigs[0]. ElectableSpecs.InstanceSize = "M20" - createdDeployment.Spec.AdvancedDeploymentSpec.ReplicationSpecs[0]. + createdDeployment.Spec.DeploymentSpec.ReplicationSpecs[0]. RegionConfigs[0]. ReadOnlySpecs.InstanceSize = "M20" - createdDeployment.Spec.AdvancedDeploymentSpec.ReplicationSpecs[0]. + createdDeployment.Spec.DeploymentSpec.ReplicationSpecs[0]. RegionConfigs[0]. AnalyticsSpecs.InstanceSize = "M20" - createdDeployment.Spec.AdvancedDeploymentSpec.ReplicationSpecs[0]. + createdDeployment.Spec.DeploymentSpec.ReplicationSpecs[0]. RegionConfigs[0]. AutoScaling. Compute. @@ -1026,7 +1110,7 @@ var _ = Describe("AtlasDeployment", Label("int", "AtlasDeployment", "deployment- It("Should Succeed", func() { createdDeployment = mdbv1.DefaultAWSDeployment(namespace.Name, createdProject.Name) createdDeployment.Spec.ProcessArgs = &mdbv1.ProcessArgs{ - JavascriptEnabled: boolptr(true), + JavascriptEnabled: toptr.MakePtr(true), DefaultReadConcern: "available", } @@ -1038,7 +1122,7 @@ var _ = Describe("AtlasDeployment", Label("int", "AtlasDeployment", "deployment- }) By("Updating Advanced Deployment Options", func() { - createdDeployment.Spec.ProcessArgs.JavascriptEnabled = boolptr(false) + createdDeployment.Spec.ProcessArgs.JavascriptEnabled = toptr.MakePtr(false) performUpdate(40 * time.Minute) doDeploymentStatusChecks() checkAdvancedDeploymentOptions(createdDeployment.Spec.ProcessArgs) @@ -1172,7 +1256,6 @@ var _ = Describe("AtlasDeployment", Ordered, Label("int", "AtlasDeployment", "de }) It("Should succeed", func() { - fmt.Println("hey!") By(fmt.Sprintf("Creating deployment with backups enabled: %s", kube.ObjectKeyFromObject(createdDeployment)), func() { Expect(k8sClient.Create(context.Background(), createdDeployment)).NotTo(HaveOccurred()) @@ -1232,11 +1315,11 @@ var _ = Describe("AtlasDeployment", Ordered, Label("int", "AtlasDeployment", "de It("Should succeed", func() { By("Creating deployment with backups enabled", func() { createdDeployment = mdbv1.DefaultAwsAdvancedDeployment(namespace.Name, createdProject.Name) - createdDeployment.Spec.AdvancedDeploymentSpec.BackupEnabled = toptr.MakePtr(true) - Expect(k8sClient.Create(context.Background(), createdDeployment)).Should(Succeed()) + createdDeployment.Spec.DeploymentSpec.BackupEnabled = toptr.MakePtr(true) + Expect(k8sClient.Create(context.Background(), createdDeployment)).NotTo(HaveOccurred()) Eventually(func(g Gomega) { - deployment, _, err := atlasClient.AdvancedClusters.Get(context.Background(), createdProject.ID(), createdDeployment.Spec.AdvancedDeploymentSpec.Name) + deployment, _, err := atlasClient.AdvancedClusters.Get(context.Background(), createdProject.ID(), createdDeployment.Spec.DeploymentSpec.Name) g.Expect(err).Should(BeNil()) g.Expect(deployment.StateName).Should(Equal("IDLE")) g.Expect(*deployment.BackupEnabled).Should(BeTrue()) @@ -1319,8 +1402,8 @@ var _ = Describe("AtlasDeployment", Ordered, Label("int", "AtlasDeployment", "de By("Creating a second deployment with backups enabled using same snapshot distribution configuration", func() { secondDeployment = mdbv1.DefaultAwsAdvancedDeployment(namespace.Name, createdProject.Name) secondDeployment.WithName("deployment-advanced-k8s-2") - secondDeployment.Spec.AdvancedDeploymentSpec.Name = "deployment-advanced-2" - secondDeployment.Spec.AdvancedDeploymentSpec.BackupEnabled = toptr.MakePtr(true) + secondDeployment.Spec.DeploymentSpec.Name = "deployment-advanced-2" + secondDeployment.Spec.DeploymentSpec.BackupEnabled = toptr.MakePtr(true) secondDeployment.Spec.BackupScheduleRef = common.ResourceRefNamespaced{ Name: bScheduleName, Namespace: namespace.Name, @@ -1328,7 +1411,7 @@ var _ = Describe("AtlasDeployment", Ordered, Label("int", "AtlasDeployment", "de Expect(k8sClient.Create(context.Background(), secondDeployment)).Should(Succeed()) Eventually(func(g Gomega) { - deployment, _, err := atlasClient.AdvancedClusters.Get(context.Background(), createdProject.ID(), secondDeployment.Spec.AdvancedDeploymentSpec.Name) + deployment, _, err := atlasClient.AdvancedClusters.Get(context.Background(), createdProject.ID(), secondDeployment.Spec.DeploymentSpec.Name) g.Expect(err).Should(BeNil()) g.Expect(deployment.StateName).Should(Equal("IDLE")) g.Expect(*deployment.BackupEnabled).Should(BeTrue()) @@ -1459,22 +1542,6 @@ func deleteServerlessInstance(projectID string, deploymentName string) error { return err } -func int64ptr(i int64) *int64 { - return &i -} - -func intptr(i int) *int { - return &i -} - -func float64ptr(f float64) *float64 { - return &f -} - -func boolptr(b bool) *bool { - return &b -} - func createConnectionSecret() *corev1.Secret { connectionSecret := corev1.Secret{ ObjectMeta: metav1.ObjectMeta{ From d9be7d64dc07bdc547dcf8e17576a339b907c9ac Mon Sep 17 00:00:00 2001 From: Igor Karpukhin Date: Mon, 30 Oct 2023 10:44:15 +0100 Subject: [PATCH 2/8] Fixed roles --- config/rbac/clusterwide/role.yaml | 2 +- config/rbac/namespaced/role.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/config/rbac/clusterwide/role.yaml b/config/rbac/clusterwide/role.yaml index f2defc2155..ff9827f50c 100644 --- a/config/rbac/clusterwide/role.yaml +++ b/config/rbac/clusterwide/role.yaml @@ -167,7 +167,7 @@ rules: - apiGroups: - atlas.mongodb.com resources: - - atlasfederatedauths + - atlasfederatedauths verbs: - create - delete diff --git a/config/rbac/namespaced/role.yaml b/config/rbac/namespaced/role.yaml index ac6db90443..ed3d1745fc 100644 --- a/config/rbac/namespaced/role.yaml +++ b/config/rbac/namespaced/role.yaml @@ -168,7 +168,7 @@ rules: - apiGroups: - atlas.mongodb.com resources: - - atlasfederatedauths + - atlasfederatedauths verbs: - create - delete From 0c197647710a323bd7e4f6b2215a0bf047b9fc19 Mon Sep 17 00:00:00 2001 From: Igor Karpukhin Date: Mon, 30 Oct 2023 14:50:00 +0100 Subject: [PATCH 3/8] Removed comments --- .../atlasdeployment/advanced_deployment.go | 2 - .../atlasdeployment_controller_test.go | 8 -- .../atlasdeployment/deployment_test.go | 77 ------------------- pkg/controller/validate/validate_test.go | 49 +++++------- test/e2e/actions/deploy/deploy_operator.go | 3 - test/e2e/actions/steps.go | 22 ------ 6 files changed, 19 insertions(+), 142 deletions(-) diff --git a/pkg/controller/atlasdeployment/advanced_deployment.go b/pkg/controller/atlasdeployment/advanced_deployment.go index 0ee0cd81ee..e59f698836 100644 --- a/pkg/controller/atlasdeployment/advanced_deployment.go +++ b/pkg/controller/atlasdeployment/advanced_deployment.go @@ -108,8 +108,6 @@ func advancedDeploymentIdle(ctx *workflow.Context, project *mdbv1.AtlasProject, } // TODO: Potential bug with disabling autoscaling if it was previously enabled - // j, _ := json.MarshalIndent(deploymentAsAtlas, "", " ") - // fmt.Println("DEBUG AFTER REGION SYNC", string(j)) atlasDeploymentAsAtlas, _, err = ctx.Client.AdvancedClusters.Update(context.Background(), project.Status.ID, deployment.Spec.DeploymentSpec.Name, deploymentAsAtlas) if err != nil { diff --git a/pkg/controller/atlasdeployment/atlasdeployment_controller_test.go b/pkg/controller/atlasdeployment/atlasdeployment_controller_test.go index 06e2b0dc39..84a255c40e 100644 --- a/pkg/controller/atlasdeployment/atlasdeployment_controller_test.go +++ b/pkg/controller/atlasdeployment/atlasdeployment_controller_test.go @@ -648,14 +648,6 @@ func testProject(ns string) *v1.AtlasProject { } } -// func asAdvanced(deployment *v1.AtlasDeployment) *v1.AtlasDeployment { -// if err := ConvertLegacyDeployment(&deployment.Spec); err != nil { -// log.Fatalf("failed to convert legacy deployment: %v", err) -// } -// deployment.Spec.DeploymentSpec = nil -// return deployment -// } - func intoAdvancedAtlasCluster(advancedSpec *v1.AdvancedDeploymentSpec) *mongodbatlas.AdvancedCluster { ac, err := advancedSpec.ToAtlas() if err != nil { diff --git a/pkg/controller/atlasdeployment/deployment_test.go b/pkg/controller/atlasdeployment/deployment_test.go index 5f6c9e6618..4d0514bc74 100644 --- a/pkg/controller/atlasdeployment/deployment_test.go +++ b/pkg/controller/atlasdeployment/deployment_test.go @@ -8,22 +8,6 @@ import ( "github.com/mongodb/mongodb-atlas-kubernetes/pkg/util/toptr" ) -// func TestConvertLegacyDeployment(t *testing.T) { -// deployment := CreateBasicDeployment("deplyment-name") - -// t.Run("Legacy Deployment can be converted", func(t *testing.T) { -// err := ConvertLegacyDeployment(&deployment.Spec) -// assert.NoError(t, err) -// }) - -// deploymentMultiregion := CreateDeploymentWithMultiregion("deplyment-multiregion-name", provider.ProviderAWS) - -// t.Run("Legacy Multiregion Deployment can be converted", func(t *testing.T) { -// err := ConvertLegacyDeployment(&deploymentMultiregion.Spec) -// assert.NoError(t, err) -// }) -// } - func CreateBasicDeployment(name string) *v1.AtlasDeployment { return &v1.AtlasDeployment{ ObjectMeta: metav1.ObjectMeta{ @@ -56,68 +40,7 @@ func CreateBasicDeployment(name string) *v1.AtlasDeployment { }, }, }, - // ProviderSettings: &v1.ProviderSettingsSpec{ - // InstanceSizeName: "M2", - // ProviderName: "TENANT", - // RegionName: "US_EAST_1", - // BackingProviderName: "AWS", - // }, }, }, } } - -// func CreateDeploymentWithMultiregion(name string, providerName provider.ProviderName) *v1.AtlasDeployment { -// var regions []string -// switch providerName { -// case provider.ProviderAWS: -// regions = []string{"US_EAST_1", "US_WEST_2"} -// case provider.ProviderAzure: -// regions = []string{"NORWAY_EAST", "GERMANY_NORTH"} -// case provider.ProviderGCP: -// regions = []string{"CENTRAL_US", "EASTERN_US"} -// } - -// if len(regions) == 0 { -// panic("unknown provider") -// } - -// return &v1.AtlasDeployment{ -// ObjectMeta: metav1.ObjectMeta{ -// Name: name, -// }, -// Spec: v1.AtlasDeploymentSpec{ -// Project: common.ResourceRefNamespaced{ -// Name: "my-project", -// }, -// DeploymentSpec: &v1.AdvancedDeploymentSpec{ -// Name: "deployment-multiregion", -// ProviderBackupEnabled: toptr.MakePtr(true), -// ClusterType: "REPLICASET", -// ProviderSettings: &v1.ProviderSettingsSpec{ -// InstanceSizeName: "M10", -// ProviderName: providerName, -// }, -// ReplicationSpecs: []v1.ReplicationSpec{ -// { -// NumShards: toptr.MakePtr(int64(1)), -// ZoneName: "US-Zone", -// RegionsConfig: map[string]v1.RegionsConfig{ -// regions[0]: { -// AnalyticsNodes: toptr.MakePtr(int64(0)), -// ElectableNodes: toptr.MakePtr(int64(1)), -// Priority: toptr.MakePtr(int64(6)), -// ReadOnlyNodes: toptr.MakePtr(int64(0)), -// }, -// regions[1]: { -// AnalyticsNodes: toptr.MakePtr(int64(0)), -// ElectableNodes: toptr.MakePtr(int64(2)), -// Priority: toptr.MakePtr(int64(7)), -// ReadOnlyNodes: toptr.MakePtr(int64(0)), -// }, -// }, -// }, -// }, -// }, -// }} -// } diff --git a/pkg/controller/validate/validate_test.go b/pkg/controller/validate/validate_test.go index cc1a760c15..41e69df7a1 100644 --- a/pkg/controller/validate/validate_test.go +++ b/pkg/controller/validate/validate_test.go @@ -31,24 +31,6 @@ func TestClusterValidation(t *testing.T) { spec := mdbv1.AtlasDeploymentSpec{DeploymentSpec: nil} assert.Error(t, DeploymentSpec(&spec, false, "NONE")) }) - // t.Run("Instance size not empty when serverless", func(t *testing.T) { - // spec := mdbv1.AtlasDeploymentSpec{ServerlessSpec: nil, DeploymentSpec: &mdbv1.AdvancedDeploymentSpec{ - // ProviderSettings: &mdbv1.ProviderSettingsSpec{ - // InstanceSizeName: "M10", - // ProviderName: "SERVERLESS", - // }, - // }} - // assert.Error(t, DeploymentSpec(&spec, false, "NONE")) - // }) - // t.Run("Instance size unset when not serverless", func(t *testing.T) { - // spec := mdbv1.AtlasDeploymentSpec{AdvancedDeploymentSpec: nil, DeploymentSpec: &mdbv1.DeploymentSpec{ - // ProviderSettings: &mdbv1.ProviderSettingsSpec{ - // InstanceSizeName: "", - // ProviderName: "AWS", - // }, - // }} - // assert.Error(t, DeploymentSpec(&spec, false, "NONE")) - // }) t.Run("different instance sizes for advanced deployment", func(t *testing.T) { t.Run("different instance size in the same region", func(t *testing.T) { spec := mdbv1.AtlasDeploymentSpec{ @@ -251,18 +233,25 @@ func TestClusterValidation(t *testing.T) { } func TestDeploymentForGov(t *testing.T) { - // t.Run("should fail when deployment is configured to non-gov region", func(t *testing.T) { - // deploy := mdbv1.AtlasDeploymentSpec{ - // DeploymentSpec: &mdbv1.AdvancedDeploymentSpec{ - // - // ProviderSettings: &mdbv1.ProviderSettingsSpec{ - // RegionName: "EU_EAST_1", - // }, - // }, - // } - - // assert.ErrorContains(t, deploymentForGov(&deploy, "GOV_REGIONS_ONLY"), "deployment in atlas for government support a restricted set of regions: EU_EAST_1 is not part of AWS for government regions") - // }) + t.Run("should fail when deployment is configured to non-gov region", func(t *testing.T) { + deploy := mdbv1.AtlasDeploymentSpec{ + DeploymentSpec: &mdbv1.AdvancedDeploymentSpec{ + ReplicationSpecs: []*mdbv1.AdvancedReplicationSpec{ + { + ZoneName: "Zone EU", + NumShards: 1, + RegionConfigs: []*mdbv1.AdvancedRegionConfig{ + { + RegionName: "EU_EAST_1", + }, + }, + }, + }, + }, + } + + assert.ErrorContains(t, deploymentForGov(&deploy, "GOV_REGIONS_ONLY"), "deployment in atlas for government support a restricted set of regions: EU_EAST_1 is not part of AWS for government regions") + }) t.Run("should fail when advanced deployment is configured to non-gov region", func(t *testing.T) { deploy := mdbv1.AtlasDeploymentSpec{ diff --git a/test/e2e/actions/deploy/deploy_operator.go b/test/e2e/actions/deploy/deploy_operator.go index a4a16971c1..cc77055e66 100644 --- a/test/e2e/actions/deploy/deploy_operator.go +++ b/test/e2e/actions/deploy/deploy_operator.go @@ -85,9 +85,6 @@ func CreateInitialDeployments(testData *model.TestDataProvider) { deployment.Namespace = testData.Resources.Namespace deployment.Spec.Project.Namespace = testData.Resources.Namespace } - j, _ := json.MarshalIndent(deployment, "", " ") - fmt.Println("DEBUG INITIAL DEPLOYMENTS", string(j)) - GinkgoWriter.Println("DEBUG INITIAL DEPLOYMENTS", string(j)) err := testData.K8SClient.Create(testData.Context, deployment) Expect(err).ShouldNot(HaveOccurred(), fmt.Sprintf("Deployment was not created: %v", deployment)) Eventually(kube.DeploymentReadyCondition(testData), time.Minute*60, time.Second*5).Should(Equal("True"), "Deployment was not created") diff --git a/test/e2e/actions/steps.go b/test/e2e/actions/steps.go index de9dee9c5d..26d2355b2e 100644 --- a/test/e2e/actions/steps.go +++ b/test/e2e/actions/steps.go @@ -73,12 +73,6 @@ func WaitDeploymentWithoutGenerationCheckV2(data *model.TestDataProvider) { deployment := data.InitialDeployments[0] switch { - // case deployment.Spec.AdvancedDeploymentSpec != nil: - // atlasClient, err := atlas.AClient() - // Expect(err).To(BeNil()) - // advancedDeployment, err := atlasClient.GetDeployment(input.ProjectID, deployment.Spec.AdvancedDeploymentSpec.Name) - // Expect(err).To(BeNil()) - // Expect(advancedDeployment.StateName).To(Equal("IDLE")) case deployment.Spec.ServerlessSpec != nil: atlasClient, err := atlas.AClient() Expect(err).To(BeNil()) @@ -116,22 +110,6 @@ func WaitDeploymentWithoutGenerationCheck(data *model.TestDataProvider) { input.Namespace, input.Deployments[0].ObjectMeta.GetName()) ExpectWithOffset(1, err).ToNot(HaveOccurred()) ExpectWithOffset(1, deploymentState).Should(Equal("IDLE"), "Kubernetes resource: Deployment status should be IDLE") - - // WHY all this if this can be checked directly above??? - // deployment := input.Deployments[0] - // switch { - // case deployment.Spec.ServerlessSpec != nil: - // atlasClient, err := atlas.AClient() - // Expect(err).To(BeNil()) - // serverlessInstance, err := atlasClient.GetServerlessInstance(input.ProjectID, deployment.Spec.ServerlessSpec.Name) - // Expect(err).To(BeNil()) - // Expect(serverlessInstance.StateName).To(Equal("IDLE")) - // default: - // aClient := atlas.GetClientOrFail() - // deployment, err := aClient.GetDeployment(input.ProjectID, input.Deployments[0].Spec.GetDeploymentName()) - // Expect(err).To(BeNil()) - // Expect(deployment.StateName).Should(Equal("IDLE")) - // } } func WaitProjectWithoutGenerationCheck(data *model.TestDataProvider) { From 9000220c1b36e6b93be2fce259345a0ebd1859a4 Mon Sep 17 00:00:00 2001 From: Igor Karpukhin Date: Mon, 30 Oct 2023 15:10:03 +0100 Subject: [PATCH 4/8] Fixed linter --- pkg/api/v1/atlasdeployment_types_test.go | 76 ---------------------- test/e2e/actions/deploy/deploy_operator.go | 1 - 2 files changed, 77 deletions(-) diff --git a/pkg/api/v1/atlasdeployment_types_test.go b/pkg/api/v1/atlasdeployment_types_test.go index 48600fd4dd..99a0de2098 100644 --- a/pkg/api/v1/atlasdeployment_types_test.go +++ b/pkg/api/v1/atlasdeployment_types_test.go @@ -52,82 +52,6 @@ func init() { excludedClusterFieldsTheirs["serverlessBackupOptions"] = true } -// func TestCompatibility(t *testing.T) { -// compareStruct(AdvancedDeploymentSpec{}, mongodbatlas.Cluster{}, t) -// } - -// func compareStruct(ours interface{}, their interface{}, t *testing.T) { -// ourFields := getAllFieldsSorted(ours, excludedClusterFieldsOurs) -// theirFields := getAllFieldsSorted(their, excludedClusterFieldsTheirs) - -// // Comparing the fields in sorted order first -// ourStructName := reflect.ValueOf(ours).Type().Name() -// theirStructName := reflect.ValueOf(their).Type().Name() -// assert.Equal(t, ourFields, theirFields, "The fields for structs [ours: %s, theirs: %s] don't match!", ourStructName, theirStructName) - -// // Then recurse into the fields of type struct -// structFieldsTags := getAllStructFieldTags(ours, excludedClusterFieldsOurs) -// for _, field := range structFieldsTags { -// ourStructField := findFieldValueByTag(ours, field) -// theirStructField := findFieldValueByTag(their, field) - -// compareStruct(ourStructField, theirStructField, t) -// } -// } - -// func findFieldValueByTag(theStruct interface{}, tag string) interface{} { -// o := reflect.ValueOf(theStruct) -// for i := 0; i < o.NumField(); i++ { -// theTag := parseJSONName(o.Type().Field(i).Tag) -// if theTag == tag { -// v := reflect.New(o.Type().Field(i).Type.Elem()).Elem().Interface() -// return v -// } -// } -// panic("Field with tag not found") -// } - -// func getAllStructFieldTags(theStruct interface{}, excludedFields map[string]bool) []string { -// o := reflect.ValueOf(theStruct) -// var res []string -// for i := 0; i < o.NumField(); i++ { -// theTag := parseJSONName(o.Type().Field(i).Tag) -// ft := o.Field(i).Type() -// if ft.Kind() == reflect.Ptr { -// ft = ft.Elem() -// } -// if _, ok := excludedFields[theTag]; !ok && ft.Kind() == reflect.Struct { -// res = append(res, theTag) -// } -// } -// return res -// } - -// func getAllFieldsSorted(theStruct interface{}, excluded map[string]bool) []string { -// var res []string -// o := reflect.ValueOf(theStruct) -// for i := 0; i < o.NumField(); i++ { -// theTag := parseJSONName(o.Type().Field(i).Tag) -// if _, ok := excluded[theTag]; !ok { -// res = append(res, theTag) -// } -// } -// sort.Strings(res) -// return res -// } - -// func parseJSONName(t reflect.StructTag) string { -// tags, err := structtag.Parse(string(t)) -// if err != nil { -// panic(err) -// } -// jsonTag, err := tags.Get("json") -// if err != nil { -// panic(err) -// } -// return jsonTag.Name -// } - func TestIsEqual(t *testing.T) { operatorArgs := ProcessArgs{ JavascriptEnabled: toptr.MakePtr(true), diff --git a/test/e2e/actions/deploy/deploy_operator.go b/test/e2e/actions/deploy/deploy_operator.go index cc77055e66..58f5dd0064 100644 --- a/test/e2e/actions/deploy/deploy_operator.go +++ b/test/e2e/actions/deploy/deploy_operator.go @@ -3,7 +3,6 @@ package deploy import ( "context" - "encoding/json" "fmt" "time" From 62c3eed10edc736ce60bb190b3c7d551d3c9f4b7 Mon Sep 17 00:00:00 2001 From: Igor Karpukhin Date: Mon, 30 Oct 2023 15:20:02 +0100 Subject: [PATCH 5/8] Removed unused code --- pkg/controller/validate/validate_test.go | 9 --------- test/e2e/actions/steps.go | 1 - 2 files changed, 10 deletions(-) diff --git a/pkg/controller/validate/validate_test.go b/pkg/controller/validate/validate_test.go index 41e69df7a1..a0c8bb7ea6 100644 --- a/pkg/controller/validate/validate_test.go +++ b/pkg/controller/validate/validate_test.go @@ -176,15 +176,6 @@ func TestClusterValidation(t *testing.T) { assert.NoError(t, DeploymentSpec(&spec, false, "NONE")) assert.Nil(t, DeploymentSpec(&spec, false, "NONE")) }) - // t.Run("Serverless Cluster", func(t *testing.T) { - // spec := mdbv1.AtlasDeploymentSpec{AdvancedDeploymentSpec: nil, DeploymentSpec: &mdbv1.AdvancedDeploymentSpec{ - // ProviderSettings: &mdbv1.ProviderSettingsSpec{ - // ProviderName: "SERVERLESS", - // }, - // }} - // assert.NoError(t, DeploymentSpec(&spec, false, "NONE")) - // assert.Nil(t, DeploymentSpec(&spec, false, "NONE")) - // }) t.Run("Advanced cluster with replication config", func(t *testing.T) { spec := mdbv1.AtlasDeploymentSpec{ DeploymentSpec: &mdbv1.AdvancedDeploymentSpec{ diff --git a/test/e2e/actions/steps.go b/test/e2e/actions/steps.go index 26d2355b2e..2a5a78ea9a 100644 --- a/test/e2e/actions/steps.go +++ b/test/e2e/actions/steps.go @@ -96,7 +96,6 @@ func WaitDeploymentWithoutGenerationCheck(data *model.TestDataProvider) { g.Expect(err).ToNot(HaveOccurred()) return deploymentStatus }, - // "60m", "5m", ).WithTimeout(30*time.Minute).WithPolling(1*time.Minute).Should(Equal("True"), "Kubernetes resource: Deployment status `Ready` should be 'True'") Eventually(func(g Gomega) { From 33e6a6638116955bad26294bc286b9739c9e34a5 Mon Sep 17 00:00:00 2001 From: Igor Karpukhin Date: Tue, 31 Oct 2023 17:02:39 +0100 Subject: [PATCH 6/8] Updated helm-charts --- helm-charts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/helm-charts b/helm-charts index 48d3f50ae8..b63edbeac9 160000 --- a/helm-charts +++ b/helm-charts @@ -1 +1 @@ -Subproject commit 48d3f50ae8b0f900053fc41521ae767374e24d35 +Subproject commit b63edbeac9e6bc581b00b0670de8b30edaafde2a From 5cd0f6e836758d99d09ca8987d4d527c0b08cd04 Mon Sep 17 00:00:00 2001 From: Igor Karpukhin Date: Tue, 31 Oct 2023 19:12:37 +0100 Subject: [PATCH 7/8] Updated helm-charts --- helm-charts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/helm-charts b/helm-charts index b63edbeac9..48d3f50ae8 160000 --- a/helm-charts +++ b/helm-charts @@ -1 +1 @@ -Subproject commit b63edbeac9e6bc581b00b0670de8b30edaafde2a +Subproject commit 48d3f50ae8b0f900053fc41521ae767374e24d35 From 28a9815db6d6bb01ff8f4c73bd9bf0d1dffa5e85 Mon Sep 17 00:00:00 2001 From: Igor Karpukhin Date: Tue, 31 Oct 2023 19:20:00 +0100 Subject: [PATCH 8/8] revert changes in Deploy folder --- .../atlas.mongodb.com_atlasdeployments.yaml | 511 +++++++++++++----- 1 file changed, 370 insertions(+), 141 deletions(-) diff --git a/deploy/crds/atlas.mongodb.com_atlasdeployments.yaml b/deploy/crds/atlas.mongodb.com_atlasdeployments.yaml index 14f6e0d76d..e3c50ede7a 100644 --- a/deploy/crds/atlas.mongodb.com_atlasdeployments.yaml +++ b/deploy/crds/atlas.mongodb.com_atlasdeployments.yaml @@ -37,30 +37,15 @@ spec: Only one of DeploymentSpec, AdvancedDeploymentSpec and ServerlessSpec should be defined properties: - backupRef: - description: Backup schedule for the AtlasDeployment - properties: - name: - description: Name is the name of the Kubernetes Resource - type: string - namespace: - description: Namespace is the namespace of the Kubernetes Resource - type: string - required: - - name - type: object - deploymentSpec: + advancedDeploymentSpec: description: Configuration for the advanced (v1.5) deployment API - https://www.mongodb.com/docs/atlas/reference/api/clusters/ + https://www.mongodb.com/docs/atlas/reference/api/clusters-advanced/ properties: backupEnabled: - description: Applicable only for M10+ deployments. Flag that indicates - if the deployment uses Cloud Backups for backups. type: boolean biConnector: - description: Configuration of BI Connector for Atlas on this deployment. - The MongoDB Connector for Business Intelligence for Atlas (BI - Connector) is only available for M10 and larger deployments. + description: BiConnectorSpec specifies BI Connector for Atlas + configuration on this deployment properties: enabled: description: Flag that indicates whether or not BI Connector @@ -74,13 +59,6 @@ spec: type: string type: object clusterType: - description: Type of the deployment that you want to create. The - parameter is required if replicationSpecs are set or if Global - Deployments are deployed. - enum: - - REPLICASET - - SHARDED - - GEOSHARDED type: string customZoneMapping: items: @@ -95,26 +73,10 @@ spec: type: object type: array diskSizeGB: - description: Capacity, in gigabytes, of the host's root volume. - Increase this number to add capacity, up to a maximum possible - value of 4096 (i.e., 4 TB). This value must be a positive integer. - The parameter is required if replicationSpecs are configured. - maximum: 4096 - minimum: 0 type: integer encryptionAtRestProvider: - description: Cloud service provider that offers Encryption at - Rest. - enum: - - AWS - - GCP - - AZURE - - NONE type: string labels: - description: Collection of key-value pairs that tag and categorize - the deployment. Each key and value has a maximum length of 255 - characters. items: description: LabelSpec contains key-value pairs that tag and categorize the Cluster/DBUser @@ -154,7 +116,6 @@ spec: type: object type: array mongoDBMajorVersion: - description: Version of the deployment to deploy. type: string mongoDBVersion: type: string @@ -165,66 +126,27 @@ spec: pattern: ^[a-zA-Z0-9][a-zA-Z0-9-]*$ type: string paused: - description: Flag that indicates whether the deployment should - be paused. type: boolean pitEnabled: - description: Flag that indicates the deployment uses continuous - cloud backups. type: boolean replicationSpecs: - description: Configuration for deployment regions. items: properties: numShards: - description: Positive integer that specifies the number - of shards to deploy in each specified zone. If you set - this value to 1 and clusterType is SHARDED, MongoDB Cloud - deploys a single-shard sharded cluster. Don't create a - sharded cluster with a single shard for production environments. - Single-shard sharded clusters don't provide the same benefits - as multi-shard configurations type: integer regionConfigs: - description: Hardware specifications for nodes set for a - given region. Each regionConfigs object describes the - region's priority in elections and the number and type - of MongoDB nodes that MongoDB Cloud deploys to the region. - Each regionConfigs object must have either an analyticsSpecs - object, electableSpecs object, or readOnlySpecs object. - Tenant clusters only require electableSpecs. Dedicated - clusters can specify any of these specifications, but - must have at least one electableSpecs object within a - replicationSpec. Every hardware specification must use - the same instanceSize. items: properties: analyticsSpecs: properties: diskIOPS: - description: Disk IOPS setting for AWS storage. - Set only if you selected AWS as your cloud service - provider. format: int64 type: integer ebsVolumeType: - description: Disk IOPS setting for AWS storage. - Set only if you selected AWS as your cloud service - provider. - enum: - - STANDARD - - PROVISIONED type: string instanceSize: - description: Hardware specification for the instance - sizes in this region. Each instance size has - a default storage and memory capacity. The instance - size you select applies to all the data-bearing - hosts in your instance size type: string nodeCount: - description: Number of nodes of the given type - for MongoDB Cloud to deploy to the region. type: integer type: object autoScaling: @@ -270,99 +192,40 @@ spec: type: object type: object backingProviderName: - description: 'Cloud service provider on which the - host for a multi-tenant deployment is provisioned. - This setting only works when "providerName" : "TENANT" - and "providerSetting.instanceSizeName" : M2 or M5. - Otherwise it should be equal to "providerName" value' - enum: - - AWS - - GCP - - AZURE type: string electableSpecs: properties: diskIOPS: - description: Disk IOPS setting for AWS storage. - Set only if you selected AWS as your cloud service - provider. format: int64 type: integer ebsVolumeType: - description: Disk IOPS setting for AWS storage. - Set only if you selected AWS as your cloud service - provider. - enum: - - STANDARD - - PROVISIONED type: string instanceSize: - description: Hardware specification for the instance - sizes in this region. Each instance size has - a default storage and memory capacity. The instance - size you select applies to all the data-bearing - hosts in your instance size type: string nodeCount: - description: Number of nodes of the given type - for MongoDB Cloud to deploy to the region. type: integer type: object priority: - description: Precedence is given to this region when - a primary election occurs. If your regionConfigs - has only readOnlySpecs, analyticsSpecs, or both, - set this value to 0. If you have multiple regionConfigs - objects (your cluster is multi-region or multi-cloud), - they must have priorities in descending order. The - highest priority is 7 type: integer providerName: - enum: - - AWS - - GCP - - AZURE - - TENANT - - SERVERLESS type: string readOnlySpecs: properties: diskIOPS: - description: Disk IOPS setting for AWS storage. - Set only if you selected AWS as your cloud service - provider. format: int64 type: integer ebsVolumeType: - description: Disk IOPS setting for AWS storage. - Set only if you selected AWS as your cloud service - provider. - enum: - - STANDARD - - PROVISIONED type: string instanceSize: - description: Hardware specification for the instance - sizes in this region. Each instance size has - a default storage and memory capacity. The instance - size you select applies to all the data-bearing - hosts in your instance size type: string nodeCount: - description: Number of nodes of the given type - for MongoDB Cloud to deploy to the region. type: integer type: object regionName: - description: Physical location of your MongoDB deployment. - The region you choose can affect network latency - for clients accessing your databases. type: string type: object type: array zoneName: - description: Human-readable label that identifies the zone - in a Global Cluster. type: string type: object type: array @@ -393,6 +256,372 @@ spec: versionReleaseSystem: type: string type: object + backupRef: + description: Backup schedule for the AtlasDeployment + properties: + name: + description: Name is the name of the Kubernetes Resource + type: string + namespace: + description: Namespace is the namespace of the Kubernetes Resource + type: string + required: + - name + type: object + deploymentSpec: + description: Configuration for the normal (v1) deployment API https://www.mongodb.com/docs/atlas/reference/api/clusters/ + properties: + autoScaling: + description: Collection of settings that configures auto-scaling + information for the deployment. If you specify the autoScaling + object, you must also specify the providerSettings.autoScaling + object. + properties: + autoIndexingEnabled: + description: 'Deprecated: This flag is not supported anymore. + Flag that indicates whether autopilot mode for Performance + Advisor is enabled. The default is false.' + type: boolean + compute: + description: Collection of settings that configure how a deployment + might scale its deployment tier and whether the deployment + can scale down. + properties: + enabled: + description: Flag that indicates whether deployment tier + auto-scaling is enabled. The default is false. + type: boolean + maxInstanceSize: + description: 'Maximum instance size to which your deployment + can automatically scale (such as M40). Atlas requires + this parameter if "autoScaling.compute.enabled" : true.' + type: string + minInstanceSize: + description: 'Minimum instance size to which your deployment + can automatically scale (such as M10). Atlas requires + this parameter if "autoScaling.compute.scaleDownEnabled" + : true.' + type: string + scaleDownEnabled: + description: 'Flag that indicates whether the deployment + tier may scale down. Atlas requires this parameter if + "autoScaling.compute.enabled" : true.' + type: boolean + type: object + diskGBEnabled: + description: Flag that indicates whether disk auto-scaling + is enabled. The default is true. + type: boolean + type: object + biConnector: + description: Configuration of BI Connector for Atlas on this deployment. + The MongoDB Connector for Business Intelligence for Atlas (BI + Connector) is only available for M10 and larger deployments. + properties: + enabled: + description: Flag that indicates whether or not BI Connector + for Atlas is enabled on the deployment. + type: boolean + readPreference: + description: Source from which the BI Connector for Atlas + reads data. Each BI Connector for Atlas read preference + contains a distinct combination of readPreference and readPreferenceTags + options. + type: string + type: object + clusterType: + description: Type of the deployment that you want to create. The + parameter is required if replicationSpecs are set or if Global + Deployments are deployed. + enum: + - REPLICASET + - SHARDED + - GEOSHARDED + type: string + customZoneMapping: + items: + properties: + location: + type: string + zone: + type: string + required: + - location + - zone + type: object + type: array + diskSizeGB: + description: Capacity, in gigabytes, of the host's root volume. + Increase this number to add capacity, up to a maximum possible + value of 4096 (i.e., 4 TB). This value must be a positive integer. + The parameter is required if replicationSpecs are configured. + maximum: 4096 + minimum: 0 + type: integer + encryptionAtRestProvider: + description: Cloud service provider that offers Encryption at + Rest. + enum: + - AWS + - GCP + - AZURE + - NONE + type: string + labels: + description: Collection of key-value pairs that tag and categorize + the deployment. Each key and value has a maximum length of 255 + characters. + items: + description: LabelSpec contains key-value pairs that tag and + categorize the Cluster/DBUser + properties: + key: + maxLength: 255 + type: string + value: + type: string + required: + - key + - value + type: object + type: array + managedNamespaces: + items: + description: ManagedNamespace represents the information about + managed namespace configuration. + properties: + collection: + type: string + customShardKey: + type: string + db: + type: string + isCustomShardKeyHashed: + type: boolean + isShardKeyUnique: + type: boolean + numInitialChunks: + type: integer + presplitHashedZones: + type: boolean + required: + - collection + - db + type: object + type: array + mongoDBMajorVersion: + description: Version of the deployment to deploy. + type: string + name: + description: Name of the deployment as it appears in Atlas. After + Atlas creates the deployment, you can't change its name. Can + only contain ASCII letters, numbers, and hyphens. + pattern: ^[a-zA-Z0-9][a-zA-Z0-9-]*$ + type: string + numShards: + description: Positive integer that specifies the number of shards + to deploy for a sharded deployment. The parameter is required + if replicationSpecs are configured + maximum: 50 + minimum: 1 + type: integer + paused: + description: Flag that indicates whether the deployment should + be paused. + type: boolean + pitEnabled: + description: Flag that indicates the deployment uses continuous + cloud backups. + type: boolean + providerBackupEnabled: + description: Applicable only for M10+ deployments. Flag that indicates + if the deployment uses Cloud Backups for backups. + type: boolean + providerSettings: + description: Configuration for the provisioned hosts on which + MongoDB runs. The available options are specific to the cloud + service provider. + properties: + autoScaling: + description: Range of instance sizes to which your deployment + can scale. + properties: + autoIndexingEnabled: + description: 'Deprecated: This flag is not supported anymore. + Flag that indicates whether autopilot mode for Performance + Advisor is enabled. The default is false.' + type: boolean + compute: + description: Collection of settings that configure how + a deployment might scale its deployment tier and whether + the deployment can scale down. + properties: + enabled: + description: Flag that indicates whether deployment + tier auto-scaling is enabled. The default is false. + type: boolean + maxInstanceSize: + description: 'Maximum instance size to which your + deployment can automatically scale (such as M40). + Atlas requires this parameter if "autoScaling.compute.enabled" + : true.' + type: string + minInstanceSize: + description: 'Minimum instance size to which your + deployment can automatically scale (such as M10). + Atlas requires this parameter if "autoScaling.compute.scaleDownEnabled" + : true.' + type: string + scaleDownEnabled: + description: 'Flag that indicates whether the deployment + tier may scale down. Atlas requires this parameter + if "autoScaling.compute.enabled" : true.' + type: boolean + type: object + diskGBEnabled: + description: Flag that indicates whether disk auto-scaling + is enabled. The default is true. + type: boolean + type: object + backingProviderName: + description: 'Cloud service provider on which the host for + a multi-tenant deployment is provisioned. This setting only + works when "providerSetting.providerName" : "TENANT" and + "providerSetting.instanceSizeName" : M2 or M5.' + enum: + - AWS + - GCP + - AZURE + type: string + diskIOPS: + description: Disk IOPS setting for AWS storage. Set only if + you selected AWS as your cloud service provider. + format: int64 + type: integer + diskTypeName: + description: Type of disk if you selected Azure as your cloud + service provider. + type: string + encryptEBSVolume: + description: Flag that indicates whether the Amazon EBS encryption + feature encrypts the host's root volume for both data at + rest within the volume and for data moving between the volume + and the deployment. + type: boolean + instanceSizeName: + description: Atlas provides different deployment tiers, each + with a default storage capacity and RAM size. The deployment + you select is used for all the data-bearing hosts in your + deployment tier. + type: string + providerName: + description: Cloud service provider on which Atlas provisions + the hosts. + enum: + - AWS + - GCP + - AZURE + - TENANT + - SERVERLESS + type: string + regionName: + description: Physical location of your MongoDB deployment. + The region you choose can affect network latency for clients + accessing your databases. + type: string + volumeType: + description: Disk IOPS setting for AWS storage. Set only if + you selected AWS as your cloud service provider. + enum: + - STANDARD + - PROVISIONED + type: string + required: + - providerName + type: object + replicationSpecs: + description: Configuration for deployment regions. + items: + description: ReplicationSpec represents a configuration for + deployment regions + properties: + numShards: + description: Number of shards to deploy in each specified + zone. The default value is 1. + format: int64 + type: integer + regionsConfig: + additionalProperties: + description: RegionsConfig describes the region’s priority + in elections and the number and type of MongoDB nodes + Atlas deploys to the region. + properties: + analyticsNodes: + description: The number of analytics nodes for Atlas + to deploy to the region. Analytics nodes are useful + for handling analytic data such as reporting queries + from BI Connector for Atlas. Analytics nodes are + read-only, and can never become the primary. If + you do not specify this option, no analytics nodes + are deployed to the region. + format: int64 + type: integer + electableNodes: + description: Number of electable nodes for Atlas to + deploy to the region. Electable nodes can become + the primary and can facilitate local reads. + format: int64 + type: integer + priority: + description: Election priority of the region. For + regions with only replicationSpecs[n].regionsConfig..readOnlyNodes, + set this value to 0. + format: int64 + type: integer + readOnlyNodes: + description: Number of read-only nodes for Atlas to + deploy to the region. Read-only nodes can never + become the primary, but can facilitate local-reads. + format: int64 + type: integer + type: object + description: Configuration for a region. Each regionsConfig + object describes the region's priority in elections and + the number and type of MongoDB nodes that Atlas deploys + to the region. + type: object + zoneName: + description: Name for the zone in a Global Deployment. Don't + provide this value if deploymentType is not GEOSHARDED. + type: string + type: object + type: array + tags: + description: Key-value pairs for resource tagging. + items: + description: TagSpec holds a key-value pair for resource tagging + on this deployment. + properties: + key: + maxLength: 255 + minLength: 1 + pattern: ^[a-zA-Z0-9][a-zA-Z0-9 @_.+`;`-]*$ + type: string + value: + maxLength: 255 + minLength: 1 + pattern: ^[a-zA-Z0-9][a-zA-Z0-9@_.+`;`-]*$ + type: string + required: + - key + - value + type: object + maxItems: 50 + type: array + required: + - name + - providerSettings + type: object processArgs: description: ProcessArgs allows to modify Advanced Configuration Options properties: