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-238726: AKO: Add Release 2.2.0 #2789

Merged
merged 5 commits into from
Mar 20, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/command/atlas-kubernetes-config-generate.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ Options
* - --operatorVersion
- string
- false
- Version of Atlas Kubernetes Operator to generate resources for. This value defaults to "2.0.0".
- Version of Atlas Kubernetes Operator to generate resources for. This value defaults to "2.2.0".
* - --orgId
- string
- false
Expand Down
16 changes: 13 additions & 3 deletions internal/kubernetes/operator/features/crds.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
)

const (
LatestOperatorMajorVersion = "2.0.0"
LatestOperatorMajorVersion = "2.2.0"
maxDepth = 100
ResourceVersion = "mongodb.com/atlas-resource-version"
ResourceAtlasProject = "atlasprojects"
Expand All @@ -54,7 +54,7 @@ var (
resource{ResourceAtlasProject, NopPatcher()},
resource{ResourceAtlasDeployment, NopPatcher()},
resource{ResourceAtlasBackupSchedule, NopPatcher()},
resource{ResourceAtlasBackupPolicy, UnknownBackupPolicyFrequencyTypesPruner()},
resource{ResourceAtlasBackupPolicy, PatcherFunc(UnknownBackupPolicyFrequencyTypesPruner)},
resource{ResourceAtlasTeam, NopPatcher()},
resource{ResourceAtlasDataFederation, NopPatcher()},
resource{ResourceAtlasFederatedAuth, NopPatcher()},
Expand All @@ -64,7 +64,17 @@ var (
resource{ResourceAtlasProject, NopPatcher()},
resource{ResourceAtlasDeployment, NopPatcher()},
resource{ResourceAtlasBackupSchedule, NopPatcher()},
resource{ResourceAtlasBackupPolicy, UnknownBackupPolicyFrequencyTypesPruner()},
resource{ResourceAtlasBackupPolicy, PatcherFunc(UnknownBackupPolicyFrequencyTypesPruner)},
resource{ResourceAtlasTeam, NopPatcher()},
resource{ResourceAtlasDataFederation, NopPatcher()},
resource{ResourceAtlasFederatedAuth, NopPatcher()},
},
"2.2.0": {
resource{ResourceAtlasDatabaseUser, NopPatcher()},
resource{ResourceAtlasProject, NopPatcher()},
resource{ResourceAtlasDeployment, NopPatcher()},
resource{ResourceAtlasBackupSchedule, NopPatcher()},
resource{ResourceAtlasBackupPolicy, NopPatcher()},
resource{ResourceAtlasTeam, NopPatcher()},
resource{ResourceAtlasDataFederation, NopPatcher()},
resource{ResourceAtlasFederatedAuth, NopPatcher()},
Expand Down
44 changes: 21 additions & 23 deletions internal/kubernetes/operator/features/patcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,32 +45,30 @@ func NopPatcher() Patcher {
// UnknownBackupPolicyFrequencyTypesPruner removes backup policy items from a backup policy
// with unknown frequency types.
// It inspects the CRD definition to determine supported frequency types.
func UnknownBackupPolicyFrequencyTypesPruner() Patcher {
return PatcherFunc(func(crdSpec *v1.JSONSchemaProps, obj runtime.Object) error {
// we are not defensive here as this function assumes the invariant
// of a stable CRD definition for a given version of Kubernetes Atlas Operator.
frequencyTypePropsEnum := crdSpec.Properties["items"].Items.Schema.Properties["frequencyType"].Enum
func UnknownBackupPolicyFrequencyTypesPruner(crdSpec *v1.JSONSchemaProps, obj runtime.Object) error {
// we are not defensive here as this function assumes the invariant
// of a stable CRD definition for a given version of Kubernetes Atlas Operator.
frequencyTypePropsEnum := crdSpec.Properties["items"].Items.Schema.Properties["frequencyType"].Enum

knownFrequencyTypes := make(map[string]struct{})
for i := range frequencyTypePropsEnum {
knownFrequencyType := strings.Trim(string(frequencyTypePropsEnum[i].Raw), `"`)
knownFrequencyTypes[knownFrequencyType] = struct{}{}
}
knownFrequencyTypes := make(map[string]struct{})
for i := range frequencyTypePropsEnum {
knownFrequencyType := strings.Trim(string(frequencyTypePropsEnum[i].Raw), `"`)
knownFrequencyTypes[knownFrequencyType] = struct{}{}
}

policy, ok := obj.(*akov2.AtlasBackupPolicy)
if !ok || policy == nil {
return fmt.Errorf("invalid object: %T: %v", obj, obj)
}
policy, ok := obj.(*akov2.AtlasBackupPolicy)
if !ok || policy == nil {
return fmt.Errorf("invalid object: %T: %v", obj, obj)
}

prunedItems := make([]akov2.AtlasBackupPolicyItem, 0, len(policy.Spec.Items))
for i := range policy.Spec.Items {
frequencyType := policy.Spec.Items[i].FrequencyType
if _, ok := knownFrequencyTypes[frequencyType]; ok {
prunedItems = append(prunedItems, policy.Spec.Items[i])
}
prunedItems := make([]akov2.AtlasBackupPolicyItem, 0, len(policy.Spec.Items))
for i := range policy.Spec.Items {
frequencyType := policy.Spec.Items[i].FrequencyType
if _, ok := knownFrequencyTypes[frequencyType]; ok {
prunedItems = append(prunedItems, policy.Spec.Items[i])
}
policy.Spec.Items = prunedItems
}
policy.Spec.Items = prunedItems

return nil
})
return nil
s-urbaniak marked this conversation as resolved.
Show resolved Hide resolved
}
4 changes: 1 addition & 3 deletions internal/kubernetes/operator/features/patcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,8 @@ func TestUnkownBackupPolicyFrequencyTypesPruner(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
patcher := UnknownBackupPolicyFrequencyTypesPruner()

gotErr := ""
if err := patcher.Patch(tt.crdSpec, tt.atlasBackupPolicy); err != nil {
if err := UnknownBackupPolicyFrequencyTypesPruner(tt.crdSpec, tt.atlasBackupPolicy); err != nil {
gotErr = err.Error()
}

Expand Down
6 changes: 6 additions & 0 deletions test/e2e/atlas/kubernetes_config_apply_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,12 @@ func referenceExportedBackupPolicy() *akov2.AtlasBackupPolicy {
RetentionUnit: "months",
RetentionValue: 12,
},
{
FrequencyType: "yearly",
FrequencyInterval: 12,
RetentionUnit: "years",
RetentionValue: 1,
},
},
},
}
Expand Down
11 changes: 10 additions & 1 deletion test/e2e/atlas/kubernetes_config_generate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1093,7 +1093,10 @@ func referenceSharedCluster(name, region, namespace, projectName string, labels
cluster.Spec.DeploymentSpec.ReplicationSpecs[0].RegionConfigs[0].BackingProviderName = string(akov2provider.ProviderAWS)
cluster.Spec.DeploymentSpec.ReplicationSpecs[0].RegionConfigs[0].ProviderName = string(akov2provider.ProviderTenant)

cluster.Spec.DeploymentSpec.PitEnabled = pointer.Get(false)
cluster.Spec.DeploymentSpec.BackupEnabled = nil
cluster.Spec.DeploymentSpec.BiConnector = nil
cluster.Spec.DeploymentSpec.EncryptionAtRestProvider = ""
cluster.Spec.DeploymentSpec.PitEnabled = nil
cluster.Spec.BackupScheduleRef = akov2common.ResourceRefNamespaced{}
return cluster
}
Expand Down Expand Up @@ -1215,6 +1218,12 @@ func referenceBackupPolicy(namespace, projectName, clusterName string, labels ma
RetentionUnit: "months",
RetentionValue: 12,
},
{
FrequencyType: "yearly",
FrequencyInterval: 12,
RetentionUnit: "years",
RetentionValue: 1,
},
},
},
}
Expand Down
Loading