From 7d6f3b6059aa0a60663ca50f5454110b3920984d Mon Sep 17 00:00:00 2001 From: Tanmay Jain Date: Mon, 13 May 2024 15:22:49 +0530 Subject: [PATCH 1/2] changing 0 rack-id to correct rack id in rackConfig --- api/v1/aerospikecluster_mutating_webhook.go | 9 +++++++++ controllers/configmap.go | 6 ++++++ 2 files changed, 15 insertions(+) diff --git a/api/v1/aerospikecluster_mutating_webhook.go b/api/v1/aerospikecluster_mutating_webhook.go index 3f3f65d87..c500810ee 100644 --- a/api/v1/aerospikecluster_mutating_webhook.go +++ b/api/v1/aerospikecluster_mutating_webhook.go @@ -403,6 +403,13 @@ func setDefaultNsConf(asLog logr.Logger, configSpec AerospikeConfigSpec, if rackID != nil { // Add rack-id only in rack specific config, not in global config defaultConfs := map[string]interface{}{"rack-id": *rackID} + + // Delete rack-id from namespace in rack specific config if set to 0 + // This could happen in operator below 3.3.0 + if id, ok := nsMap["rack-id"]; ok && id == float64(0) && *rackID != 0 { + delete(nsMap, "rack-id") + } + if err := setDefaultsInConfigMap( asLog, nsMap, defaultConfs, ); err != nil { @@ -411,6 +418,8 @@ func setDefaultNsConf(asLog logr.Logger, configSpec AerospikeConfigSpec, err, ) } + } else { + delete(nsMap, "rack-id") } } else { // User may have added this key or may have patched object with new smaller rackEnabledNamespace list diff --git a/controllers/configmap.go b/controllers/configmap.go index 1514a63ba..b47960596 100644 --- a/controllers/configmap.go +++ b/controllers/configmap.go @@ -8,6 +8,7 @@ import ( "fmt" "io/fs" "path/filepath" + "regexp" "strings" "text/template" @@ -106,6 +107,11 @@ func (r *SingleClusterReconciler) createConfigMapData(rack *asdbv1.Rack) ( confData[aerospikeTemplateConfFileName] = confTemp + re := regexp.MustCompile(`rack-id.*\d+`) + if rackStr := re.FindString(confTemp); rackStr != "" { + confTemp = strings.ReplaceAll(confTemp, rackStr, "rack-id 0") + } + // Add conf hash confHash, err := utils.GetHash(confTemp) if err != nil { From 1fb98797336ffbf7f618da64b27561b5c627f9db Mon Sep 17 00:00:00 2001 From: Tanmay Jain Date: Mon, 13 May 2024 15:29:50 +0530 Subject: [PATCH 2/2] adding comment --- controllers/configmap.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/controllers/configmap.go b/controllers/configmap.go index b47960596..cb5b1f0da 100644 --- a/controllers/configmap.go +++ b/controllers/configmap.go @@ -107,6 +107,9 @@ func (r *SingleClusterReconciler) createConfigMapData(rack *asdbv1.Rack) ( confData[aerospikeTemplateConfFileName] = confTemp + // This field value is rectified in 3.3.0. + // Ignore rack-id change from hash computation so that on upgrade clusters are + // not rolling restarted. re := regexp.MustCompile(`rack-id.*\d+`) if rackStr := re.FindString(confTemp); rackStr != "" { confTemp = strings.ReplaceAll(confTemp, rackStr, "rack-id 0")