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 3 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
27 changes: 27 additions & 0 deletions internal/kubernetes/operator/deployment/deployment.go
Expand Up @@ -171,9 +171,36 @@ func BuildAtlasAdvancedDeployment(deploymentStore store.OperatorClusterStore, va
advancedSpec.ManagedNamespaces = managedNamespaces
}

cleanTenantFields(&atlasDeployment.Spec)

return deploymentResult, nil
}

func cleanTenantFields(out *akov2.AtlasDeploymentSpec) {
isTenant := false

if out.DeploymentSpec == nil {
return
}
for _, spec := range out.DeploymentSpec.ReplicationSpecs {
for _, c := range spec.RegionConfigs {
if c.ProviderName == "TENANT" {
isTenant = true
break
}
}
}

if isTenant {
out.DeploymentSpec.BiConnector = nil
out.DeploymentSpec.EncryptionAtRestProvider = ""
out.DeploymentSpec.DiskSizeGB = nil
out.DeploymentSpec.MongoDBMajorVersion = ""
out.DeploymentSpec.PitEnabled = nil
out.DeploymentSpec.BackupEnabled = nil
}
}
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
48 changes: 48 additions & 0 deletions internal/kubernetes/operator/deployment/deployment_test.go
Expand Up @@ -520,3 +520,51 @@ func TestBuildServerlessDeployments(t *testing.T) {
}
})
}

func TestCleanTenantFields(t *testing.T) {
spec := akov2.AtlasDeploymentSpec{
DeploymentSpec: &akov2.AdvancedDeploymentSpec{
BackupEnabled: pointer.Get(true),
BiConnector: &akov2.BiConnectorSpec{
Enabled: pointer.Get(true),
ReadPreference: "SECONDARY",
},
EncryptionAtRestProvider: "AWS",
PitEnabled: pointer.Get(true),
MongoDBMajorVersion: "5.1",
ReplicationSpecs: []*akov2.AdvancedReplicationSpec{
{
RegionConfigs: []*akov2.AdvancedRegionConfig{
{
ProviderName: "TENANT",
},
},
},
},
},
}
roothorp marked this conversation as resolved.
Show resolved Hide resolved

cleanTenantFields(&spec)

expected := akov2.AtlasDeploymentSpec{
DeploymentSpec: &akov2.AdvancedDeploymentSpec{
BackupEnabled: nil,
BiConnector: nil,
EncryptionAtRestProvider: "",
PitEnabled: nil,
MongoDBMajorVersion: "",
ReplicationSpecs: []*akov2.AdvancedReplicationSpec{
{
RegionConfigs: []*akov2.AdvancedRegionConfig{
{
ProviderName: "TENANT",
},
},
},
},
},
}
if !reflect.DeepEqual(spec, expected) {
t.Fatalf("Cleaning tenant readonly fields mismatch.\r\nexpected: %v\r\ngot: %v\r\n", expected, spec)
}
}