Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLOUDP-237545: Ignore tenant readonly fields for Kubernetes generation #2771

Merged
merged 6 commits into from Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
}
roothorp marked this conversation as resolved.
Show resolved Hide resolved

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)
}
})
}
}