From 0a4f2ae6a28c9ff5cec6e772d07558607fd01a93 Mon Sep 17 00:00:00 2001 From: Sergiusz Urbaniak <sergiusz.urbaniak@gmail.com> Date: Wed, 20 Mar 2024 07:51:31 +0100 Subject: [PATCH 1/5] unindent UnknownBackupPolicyFrequencyTypesPruner --- internal/kubernetes/operator/features/crds.go | 4 +- .../kubernetes/operator/features/patcher.go | 44 +++++++++---------- .../operator/features/patcher_test.go | 4 +- 3 files changed, 24 insertions(+), 28 deletions(-) diff --git a/internal/kubernetes/operator/features/crds.go b/internal/kubernetes/operator/features/crds.go index 24c03ac157..939f48ce96 100644 --- a/internal/kubernetes/operator/features/crds.go +++ b/internal/kubernetes/operator/features/crds.go @@ -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()}, @@ -64,7 +64,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()}, diff --git a/internal/kubernetes/operator/features/patcher.go b/internal/kubernetes/operator/features/patcher.go index b1e8c2a4e3..42df38bb7e 100644 --- a/internal/kubernetes/operator/features/patcher.go +++ b/internal/kubernetes/operator/features/patcher.go @@ -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 } diff --git a/internal/kubernetes/operator/features/patcher_test.go b/internal/kubernetes/operator/features/patcher_test.go index 052c4fe796..47d5047d42 100644 --- a/internal/kubernetes/operator/features/patcher_test.go +++ b/internal/kubernetes/operator/features/patcher_test.go @@ -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() } From e1ffc45e843c1fd780c8a253fbb3893ff895783d Mon Sep 17 00:00:00 2001 From: Sergiusz Urbaniak <sergiusz.urbaniak@gmail.com> Date: Wed, 20 Mar 2024 07:55:15 +0100 Subject: [PATCH 2/5] add AKO 2.2.0 --- internal/kubernetes/operator/features/crds.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/internal/kubernetes/operator/features/crds.go b/internal/kubernetes/operator/features/crds.go index 939f48ce96..11c2d10a79 100644 --- a/internal/kubernetes/operator/features/crds.go +++ b/internal/kubernetes/operator/features/crds.go @@ -27,7 +27,7 @@ import ( ) const ( - LatestOperatorMajorVersion = "2.0.0" + LatestOperatorMajorVersion = "2.2.0" maxDepth = 100 ResourceVersion = "mongodb.com/atlas-resource-version" ResourceAtlasProject = "atlasprojects" @@ -69,6 +69,16 @@ var ( 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()}, + }, } ) From 28065b8eb955e221028b5d5f0573d2f3bd08ef85 Mon Sep 17 00:00:00 2001 From: Sergiusz Urbaniak <sergiusz.urbaniak@gmail.com> Date: Wed, 20 Mar 2024 10:56:19 +0100 Subject: [PATCH 3/5] make gen-docs --- docs/command/atlas-kubernetes-config-generate.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/command/atlas-kubernetes-config-generate.txt b/docs/command/atlas-kubernetes-config-generate.txt index 20e14130b8..7ce4d3cad9 100644 --- a/docs/command/atlas-kubernetes-config-generate.txt +++ b/docs/command/atlas-kubernetes-config-generate.txt @@ -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 From 3fc3fcc2503abc4c6c343abba48091b8971b3e9b Mon Sep 17 00:00:00 2001 From: Sergiusz Urbaniak <sergiusz.urbaniak@gmail.com> Date: Wed, 20 Mar 2024 13:21:46 +0100 Subject: [PATCH 4/5] test/e2e add yearly backup frequency types --- test/e2e/atlas/kubernetes_config_apply_test.go | 6 ++++++ test/e2e/atlas/kubernetes_config_generate_test.go | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/test/e2e/atlas/kubernetes_config_apply_test.go b/test/e2e/atlas/kubernetes_config_apply_test.go index eee1ee8bb2..0bb57265c3 100644 --- a/test/e2e/atlas/kubernetes_config_apply_test.go +++ b/test/e2e/atlas/kubernetes_config_apply_test.go @@ -395,6 +395,12 @@ func referenceExportedBackupPolicy() *akov2.AtlasBackupPolicy { RetentionUnit: "months", RetentionValue: 12, }, + { + FrequencyType: "yearly", + FrequencyInterval: 12, + RetentionUnit: "years", + RetentionValue: 1, + }, }, }, } diff --git a/test/e2e/atlas/kubernetes_config_generate_test.go b/test/e2e/atlas/kubernetes_config_generate_test.go index faf6cf698c..a5a27f1af8 100644 --- a/test/e2e/atlas/kubernetes_config_generate_test.go +++ b/test/e2e/atlas/kubernetes_config_generate_test.go @@ -1215,6 +1215,12 @@ func referenceBackupPolicy(namespace, projectName, clusterName string, labels ma RetentionUnit: "months", RetentionValue: 12, }, + { + FrequencyType: "yearly", + FrequencyInterval: 12, + RetentionUnit: "years", + RetentionValue: 1, + }, }, }, } From 83dac75cd1d7d0ecd64386f5b04afddaddfbcf04 Mon Sep 17 00:00:00 2001 From: Sergiusz Urbaniak <sergiusz.urbaniak@gmail.com> Date: Wed, 20 Mar 2024 14:25:45 +0100 Subject: [PATCH 5/5] test/e2e/kubernetes_config_generate: ignore tenant readonly fields for shared clusters --- test/e2e/atlas/kubernetes_config_generate_test.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/test/e2e/atlas/kubernetes_config_generate_test.go b/test/e2e/atlas/kubernetes_config_generate_test.go index a5a27f1af8..2e124c9975 100644 --- a/test/e2e/atlas/kubernetes_config_generate_test.go +++ b/test/e2e/atlas/kubernetes_config_generate_test.go @@ -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 }