Skip to content

Commit

Permalink
CLOUDP-237545: Ignore tenant readonly fields for Kubernetes generation (
Browse files Browse the repository at this point in the history
#2771)

Co-authored-by: Sergiusz Urbaniak <sergiusz.urbaniak@gmail.com>
  • Loading branch information
roothorp and s-urbaniak committed Mar 19, 2024
1 parent 31b153a commit b6d1f93
Show file tree
Hide file tree
Showing 2 changed files with 128 additions and 0 deletions.
26 changes: 26 additions & 0 deletions internal/kubernetes/operator/deployment/deployment.go
Expand Up @@ -171,9 +171,35 @@ func BuildAtlasAdvancedDeployment(deploymentStore store.OperatorClusterStore, va
advancedSpec.ManagedNamespaces = managedNamespaces
}

if hasTenantRegionConfig(atlasDeployment) {
atlasDeployment.Spec.DeploymentSpec.BiConnector = nil
atlasDeployment.Spec.DeploymentSpec.EncryptionAtRestProvider = ""
atlasDeployment.Spec.DeploymentSpec.DiskSizeGB = nil
atlasDeployment.Spec.DeploymentSpec.MongoDBMajorVersion = ""
atlasDeployment.Spec.DeploymentSpec.PitEnabled = nil
atlasDeployment.Spec.DeploymentSpec.BackupEnabled = nil
}

return deploymentResult, nil
}

func hasTenantRegionConfig(out *akov2.AtlasDeployment) bool {
if out.Spec.DeploymentSpec == nil {
return false
}
for _, spec := range out.Spec.DeploymentSpec.ReplicationSpecs {
if spec == nil {
continue
}
for _, c := range spec.RegionConfigs {
if c != nil && c.ProviderName == "TENANT" {
return true
}
}
}
return false
}

func buildGlobalDeployment(atlasRepSpec []atlasv2.ReplicationSpec, globalDeploymentProvider store.GlobalClusterDescriber, projectID, clusterID string) ([]akov2.CustomZoneMapping, []akov2.ManagedNamespace, error) {
globalCluster, err := globalDeploymentProvider.GlobalCluster(projectID, clusterID)
if err != nil {
Expand Down
102 changes: 102 additions & 0 deletions internal/kubernetes/operator/deployment/deployment_test.go
Expand Up @@ -520,3 +520,105 @@ func TestBuildServerlessDeployments(t *testing.T) {
}
})
}

func TestCleanTenantFields(t *testing.T) {
for _, tt := range []struct {
name string
spec akov2.AtlasDeploymentSpec
expect bool
}{
{
name: "nil deploymentspec",
spec: akov2.AtlasDeploymentSpec{
DeploymentSpec: nil,
},
expect: false,
},
{
name: "nil replicationspec",
spec: akov2.AtlasDeploymentSpec{
DeploymentSpec: &akov2.AdvancedDeploymentSpec{
ReplicationSpecs: []*akov2.AdvancedReplicationSpec{
nil,
},
},
},
expect: false,
},
{
name: "nil regionconfig",
spec: akov2.AtlasDeploymentSpec{
DeploymentSpec: &akov2.AdvancedDeploymentSpec{
ReplicationSpecs: []*akov2.AdvancedReplicationSpec{
{
RegionConfigs: []*akov2.AdvancedRegionConfig{
nil,
},
},
},
},
},
expect: false,
},
{
name: "multiple non-tenant regionconfigs",
spec: akov2.AtlasDeploymentSpec{
DeploymentSpec: &akov2.AdvancedDeploymentSpec{
ReplicationSpecs: []*akov2.AdvancedReplicationSpec{
{
RegionConfigs: []*akov2.AdvancedRegionConfig{
{
ProviderName: "AWS",
},
{
ProviderName: "GCP",
},
{
ProviderName: "AZURE",
},
{
ProviderName: "AWS",
},
},
},
},
},
},
expect: false,
},
{
name: "multiple non-tenant regionconfigs and one tenant",
spec: akov2.AtlasDeploymentSpec{
DeploymentSpec: &akov2.AdvancedDeploymentSpec{
ReplicationSpecs: []*akov2.AdvancedReplicationSpec{
{
RegionConfigs: []*akov2.AdvancedRegionConfig{
{
ProviderName: "AWS",
},
{
ProviderName: "GCP",
},
{
ProviderName: "AZURE",
},
{
ProviderName: "TENANT",
},
},
},
},
},
},
expect: true,
},
} {
t.Run(tt.name, func(t *testing.T) {
if got := hasTenantRegionConfig(&akov2.AtlasDeployment{
Spec: tt.spec,
}); got != tt.expect {
t.Errorf("expect hasTenantRegionConfig to be %t, got %t", tt.expect, got)
}
})
}
}

0 comments on commit b6d1f93

Please sign in to comment.