From 385c3d22a864fcf3c41e838b3599f9ec88e921d6 Mon Sep 17 00:00:00 2001 From: Abhisek Dwivedi Date: Mon, 6 Jan 2025 18:38:01 +0530 Subject: [PATCH] KO-364: Handle special bool fields (#333) * Updating the enable-benchmarks-* fields to align with changes in server version 6.1, as they are no longer treated as special boolean fields. Co-authored-by: Tanmay Jain --- ...rnetes-operator.clusterserviceversion.yaml | 2 +- config/samples/kustomization.yaml | 3 + go.mod | 2 +- go.sum | 4 +- internal/controller/cluster/configmap.go | 16 +++ test/cluster/cluster_test.go | 105 ++++++++++++++++++ 6 files changed, 128 insertions(+), 4 deletions(-) diff --git a/config/manifests/bases/aerospike-kubernetes-operator.clusterserviceversion.yaml b/config/manifests/bases/aerospike-kubernetes-operator.clusterserviceversion.yaml index 28f873703..92c3a3780 100644 --- a/config/manifests/bases/aerospike-kubernetes-operator.clusterserviceversion.yaml +++ b/config/manifests/bases/aerospike-kubernetes-operator.clusterserviceversion.yaml @@ -3,7 +3,7 @@ kind: ClusterServiceVersion metadata: annotations: alm-examples: '[]' - capabilities: Seamless Upgrades + capabilities: Deep Insights categories: Database containerImage: controller:latest createdAt: dateplaceholder diff --git a/config/samples/kustomization.yaml b/config/samples/kustomization.yaml index 31dd1f191..80d1b8964 100644 --- a/config/samples/kustomization.yaml +++ b/config/samples/kustomization.yaml @@ -1,4 +1,7 @@ ## Append samples you want in your CSV to this file as resources ## resources: - dim_nostorage_cluster_skip_validation_cr.yaml + - aerospikebackupservice.yaml + - aerospikebackup.yaml + - aerospikerestore.yaml # +kubebuilder:scaffold:manifestskustomizesamples diff --git a/go.mod b/go.mod index c9f70306c..89f44d26d 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.22 require ( github.com/aerospike/aerospike-backup-service v0.0.0-20240822110128-dc2b4811b9d3 github.com/aerospike/aerospike-client-go/v7 v7.6.1 - github.com/aerospike/aerospike-management-lib v1.5.0 + github.com/aerospike/aerospike-management-lib v1.5.1-0.20250106091653-f0c86baa6cd7 github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d github.com/deckarep/golang-set/v2 v2.3.1 github.com/evanphx/json-patch v4.12.0+incompatible diff --git a/go.sum b/go.sum index 7376c7ff9..6eeb9c242 100644 --- a/go.sum +++ b/go.sum @@ -2,8 +2,8 @@ github.com/aerospike/aerospike-backup-service v0.0.0-20240822110128-dc2b4811b9d3 github.com/aerospike/aerospike-backup-service v0.0.0-20240822110128-dc2b4811b9d3/go.mod h1:PFWhqxcMsEEyoOZtQ70b+X8xWbbemDYuitT24EPBizk= github.com/aerospike/aerospike-client-go/v7 v7.6.1 h1:VZK6S9YKq2w6ptTk3kXXjTxG2U9M9Y7Oi3YQ+3T7wQQ= github.com/aerospike/aerospike-client-go/v7 v7.6.1/go.mod h1:uCbSYMpjlRcH/9f26VSF/luzDDXrcDaV8c6/WIcKtT4= -github.com/aerospike/aerospike-management-lib v1.5.0 h1:uAEaBU+PkzbtwsSrPVokLIUeJaDrFSMtwqeCKba3xIs= -github.com/aerospike/aerospike-management-lib v1.5.0/go.mod h1:hsEptY/AmTmHoJnItJNmfJ4yCMG8LIB8YPnIpIyvGXI= +github.com/aerospike/aerospike-management-lib v1.5.1-0.20250106091653-f0c86baa6cd7 h1:lhccxfqnvqdSNnpxdM4xjUnp8AzHsUKKqJPXRKIgfsw= +github.com/aerospike/aerospike-management-lib v1.5.1-0.20250106091653-f0c86baa6cd7/go.mod h1:hsEptY/AmTmHoJnItJNmfJ4yCMG8LIB8YPnIpIyvGXI= github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio= github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs= github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d h1:Byv0BzEl3/e6D5CLfI0j/7hiIEtvGVFPCZ7Ei2oq8iQ= diff --git a/internal/controller/cluster/configmap.go b/internal/controller/cluster/configmap.go index 6e218388c..e17715fac 100644 --- a/internal/controller/cluster/configmap.go +++ b/internal/controller/cluster/configmap.go @@ -119,6 +119,22 @@ func (r *SingleClusterReconciler) createConfigMapData(rack *asdbv1.Rack) ( confTemp = strings.ReplaceAll(confTemp, rackStr, "rack-id 0") } + // [Backward Compatibility Fix] + // Historically, all benchmark configurations were represented as single literal fields in the configuration. + // The presence of these fields indicated that the corresponding benchmark was enabled. + // However, AER-6767(https://aerospike.atlassian.net/browse/AER-6767) restricted a two-literal benchmark + // configuration format (e.g., "enable-benchmarks-read true"). + // Handling this change leads to hash mismatches during AKO upgrades, leading to unnecessary warm restarts. + // Solution: For hash calculations, replace the new benchmark configuration format with the old format + // to maintain compatibility and prevent these issues. + // Example: Convert "enable-benchmarks-read true" to "enable-benchmarks-read". + for _, benchmarkConfig := range asconfig.BenchmarkConfigs { + re := regexp.MustCompile(fmt.Sprintf(`%s.*true`, benchmarkConfig)) + if benchmarkStr := re.FindString(confTemp); benchmarkStr != "" { + confTemp = strings.ReplaceAll(confTemp, benchmarkStr, benchmarkConfig) + } + } + // Add conf hash confHash, err := utils.GetHash(confTemp) if err != nil { diff --git a/test/cluster/cluster_test.go b/test/cluster/cluster_test.go index c660a241b..cee876f93 100644 --- a/test/cluster/cluster_test.go +++ b/test/cluster/cluster_test.go @@ -16,6 +16,7 @@ import ( asdbv1 "github.com/aerospike/aerospike-kubernetes-operator/api/v1" "github.com/aerospike/aerospike-kubernetes-operator/pkg/utils" "github.com/aerospike/aerospike-kubernetes-operator/test" + lib "github.com/aerospike/aerospike-management-lib" ) var _ = Describe( @@ -85,6 +86,11 @@ var _ = Describe( PauseReconcileTest(ctx) }, ) + Context( + "ValidateAerospikeBenchmarkConfigs", func() { + ValidateAerospikeBenchmarkConfigs(ctx) + }, + ) }, ) @@ -193,6 +199,105 @@ func setPauseFlag(ctx goctx.Context, clusterNamespacedName types.NamespacedName, return k8sClient.Update(ctx, aeroCluster) } +// Historically, all benchmark configurations were represented as single literal fields in the configuration. +// The presence of these fields indicated that the corresponding benchmark was enabled. +// However, AER-6767(https://aerospike.atlassian.net/browse/AER-6767) restricted a two-literal benchmark +// configuration format (e.g., "enable-benchmarks-read true") +// Here validating that benchmark configurations are working as expected with all server versions. +func ValidateAerospikeBenchmarkConfigs(ctx goctx.Context) { + Context( + "ValidateAerospikeBenchmarkConfigs", func() { + clusterNamespacedName := getNamespacedName( + "deploy-cluster-benchmark", namespace, + ) + + AfterEach( + func() { + aeroCluster, err := getCluster( + k8sClient, ctx, clusterNamespacedName, + ) + Expect(err).ToNot(HaveOccurred()) + + _ = deleteCluster(k8sClient, ctx, aeroCluster) + }, + ) + + It( + "benchmarking should work in all aerospike server version", func() { + By("Deploying cluster which does not have the fix for AER-6767") + + imageBeforeFix := fmt.Sprintf("%s:%s", baseImage, "7.1.0.2") + aeroCluster := createAerospikeClusterPost640(clusterNamespacedName, 2, imageBeforeFix) + namespaceConfig := + aeroCluster.Spec.AerospikeConfig.Value["namespaces"].([]interface{})[0].(map[string]interface{}) + namespaceConfig["enable-benchmarks-read"] = false + aeroCluster.Spec.AerospikeConfig.Value["namespaces"].([]interface{})[0] = namespaceConfig + err := deployCluster(k8sClient, ctx, aeroCluster) + Expect(err).ToNot(HaveOccurred()) + + By("Validating benchmarking is disabled") + + aeroCluster, err = getCluster(k8sClient, ctx, clusterNamespacedName) + Expect(err).ToNot(HaveOccurred()) + + pod := aeroCluster.Status.Pods["deploy-cluster-benchmark-0-0"] + nsConfs, err := getAerospikeConfigFromNode(logger, k8sClient, ctx, clusterNamespacedName, "namespaces", &pod) + Expect(err).ToNot(HaveOccurred()) + Expect(nsConfs["test"].(lib.Stats)["enable-benchmarks-read"]).To(Equal(false)) + + By("Updating cluster to enable benchmarking") + + namespaceConfig = + aeroCluster.Spec.AerospikeConfig.Value["namespaces"].([]interface{})[0].(map[string]interface{}) + namespaceConfig["enable-benchmarks-read"] = true + aeroCluster.Spec.AerospikeConfig.Value["namespaces"].([]interface{})[0] = namespaceConfig + + err = updateCluster(k8sClient, ctx, aeroCluster) + Expect(err).ToNot(HaveOccurred()) + + nsConfs, err = getAerospikeConfigFromNode(logger, k8sClient, ctx, clusterNamespacedName, "namespaces", &pod) + Expect(err).ToNot(HaveOccurred()) + Expect(nsConfs["test"].(lib.Stats)["enable-benchmarks-read"]).To(Equal(true)) + + By("Updating cluster server to version which has the fix for AER-6767") + + imageAfterFix := fmt.Sprintf("%s:%s", baseImage, "7.1.0.10") + + aeroCluster, err = getCluster(k8sClient, ctx, clusterNamespacedName) + Expect(err).ToNot(HaveOccurred()) + + aeroCluster.Spec.Image = imageAfterFix + + err = updateCluster(k8sClient, ctx, aeroCluster) + Expect(err).ToNot(HaveOccurred()) + + aeroCluster, err = getCluster(k8sClient, ctx, clusterNamespacedName) + Expect(err).ToNot(HaveOccurred()) + + nsConfs, err = getAerospikeConfigFromNode(logger, k8sClient, ctx, clusterNamespacedName, "namespaces", &pod) + Expect(err).ToNot(HaveOccurred()) + Expect(nsConfs["test"].(lib.Stats)["enable-benchmarks-read"]).To(Equal(true)) + + By("Updating cluster to disable benchmarking") + + namespaceConfig = + aeroCluster.Spec.AerospikeConfig.Value["namespaces"].([]interface{})[0].(map[string]interface{}) + + namespaceConfig["enable-benchmarks-read"] = false + aeroCluster.Spec.AerospikeConfig.Value["namespaces"].([]interface{})[0] = namespaceConfig + + err = updateCluster(k8sClient, ctx, aeroCluster) + Expect(err).ToNot(HaveOccurred()) + + nsConfs, err = getAerospikeConfigFromNode(logger, k8sClient, ctx, clusterNamespacedName, "namespaces", &pod) + Expect(err).ToNot(HaveOccurred()) + Expect(nsConfs["test"].(lib.Stats)["enable-benchmarks-read"]).To(Equal(false)) + }, + ) + }, + ) +} + func UpdateClusterPre600(ctx goctx.Context) { Context( "UpdateClusterPre600", func() {