diff --git a/Jenkinsfile b/Jenkinsfile index 12e9c2eb..db2d6d55 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -24,7 +24,7 @@ pipeline { AEROSPIKE_CUSTOM_INIT_REGISTRY="568976754000.dkr.ecr.ap-south-1.amazonaws.com" AEROSPIKE_CUSTOM_INIT_REGISTRY_NAMESPACE="aerospike" - AEROSPIKE_CUSTOM_INIT_NAMETAG="aerospike" + AEROSPIKE_CUSTOM_INIT_NAME_TAG="aerospike-kubernetes-init:2.2.1" } stages { @@ -92,7 +92,7 @@ pipeline { dir("${env.GO_REPO}") { sh "rsync -aK ${env.WORKSPACE}/../../aerospike-kubernetes-operator-resources/secrets/ config/samples/secrets" sh "set +x; docker login --username AWS 568976754000.dkr.ecr.ap-south-1.amazonaws.com -p \$(aws ecr get-login-password --region ap-south-1); set -x" - sh "./test/test.sh -b ${OPERATOR_BUNDLE_IMAGE_CANDIDATE_NAME} -c ${OPERATOR_CATALOG_IMAGE_CANDIDATE_NAME} -r ${AEROSPIKE_CUSTOM_INIT_REGISTRY} -n ${AEROSPIKE_CUSTOM_INIT_REGISTRY_NAMESPACE} -t ${AEROSPIKE_CUSTOM_INIT_NAMETAG}" + sh "./test/test.sh -b ${OPERATOR_BUNDLE_IMAGE_CANDIDATE_NAME} -c ${OPERATOR_CATALOG_IMAGE_CANDIDATE_NAME} -r ${AEROSPIKE_CUSTOM_INIT_REGISTRY} -n ${AEROSPIKE_CUSTOM_INIT_REGISTRY_NAMESPACE} -t ${AEROSPIKE_CUSTOM_INIT_NAME_TAG}" } } diff --git a/api/v1/utils.go b/api/v1/utils.go index a5a35cc8..e07febf1 100644 --- a/api/v1/utils.go +++ b/api/v1/utils.go @@ -70,11 +70,9 @@ const ( const ( AerospikeServerContainerName = "aerospike-server" AerospikeInitContainerName = "aerospike-init" - AerospikeInitContainerNameAndTag = "nameAndTag" - AerospikeInitContainerRegistry = "registry" AerospikeInitContainerRegistryEnvVar = "AEROSPIKE_KUBERNETES_INIT_REGISTRY" AerospikeInitContainerRegistryNamespaceEnvVar = "AEROSPIKE_KUBERNETES_INIT_REGISTRY_NAMESPACE" - AerospikeInitContainerNameTagEnvVar = "AEROSPIKE_KUBERNETES_INIT_NAMETAG" + AerospikeInitContainerNameTagEnvVar = "AEROSPIKE_KUBERNETES_INIT_NAME_TAG" AerospikeInitContainerDefaultRegistry = "docker.io" AerospikeInitContainerDefaultRegistryNamespace = "aerospike" AerospikeInitContainerDefaultRepoAndTag = "aerospike-kubernetes-init:2.2.1" @@ -134,9 +132,11 @@ func getInitContainerImage(registry, namespace, repoAndTag string) string { } func GetAerospikeInitContainerImage(aeroCluster *AerospikeCluster) string { - registry := getInitContainerImageValue(aeroCluster, AerospikeInitContainerRegistry) + registry := getInitContainerImageValue(aeroCluster, AerospikeInitContainerRegistryEnvVar, + AerospikeInitContainerDefaultRegistry) namespace := getInitContainerImageRegistryNamespace(aeroCluster) - repoAndTag := getInitContainerImageValue(aeroCluster, AerospikeInitContainerNameAndTag) + repoAndTag := getInitContainerImageValue(aeroCluster, AerospikeInitContainerNameTagEnvVar, + AerospikeInitContainerDefaultRepoAndTag) return getInitContainerImage(registry, namespace, repoAndTag) } @@ -163,46 +163,30 @@ func getInitContainerImageRegistryNamespace(aeroCluster *AerospikeCluster) strin return *namespace } -func getInitContainerImageValue(aeroCluster *AerospikeCluster, valueType string) string { +func getInitContainerImageValue(aeroCluster *AerospikeCluster, envVar, defaultValue string) string { var value string // Check in CR based on the valueType if aeroCluster.Spec.PodSpec.AerospikeInitContainerSpec != nil { - switch valueType { - case AerospikeInitContainerRegistry: + switch envVar { + case AerospikeInitContainerRegistryEnvVar: value = aeroCluster.Spec.PodSpec.AerospikeInitContainerSpec.ImageRegistry - case AerospikeInitContainerNameAndTag: + case AerospikeInitContainerNameTagEnvVar: value = aeroCluster.Spec.PodSpec.AerospikeInitContainerSpec.ImageNameAndTag } } // Check in EnvVar if not found in CR if value == "" { - var ( - envVar string - found bool - ) - - switch valueType { - case AerospikeInitContainerRegistry: - envVar, found = os.LookupEnv(AerospikeInitContainerRegistryEnvVar) - case AerospikeInitContainerNameAndTag: - envVar, found = os.LookupEnv(AerospikeInitContainerNameTagEnvVar) - } - + envVal, found := os.LookupEnv(envVar) if found { - value = envVar + value = envVal } } // Return default values if still not found if value == "" { - switch valueType { - case AerospikeInitContainerRegistry: - return AerospikeInitContainerDefaultRegistry - case AerospikeInitContainerNameAndTag: - return AerospikeInitContainerDefaultRepoAndTag - } + return defaultValue } return value diff --git a/config/manager/manager.yaml b/config/manager/manager.yaml index a8dcebc7..d5dc95a0 100644 --- a/config/manager/manager.yaml +++ b/config/manager/manager.yaml @@ -64,7 +64,7 @@ spec: - name: AEROSPIKE_KUBERNETES_INIT_REGISTRY_NAMESPACE # this is the namespace in registry used to pull aerospike-init image value: aerospike - - name: AEROSPIKE_KUBERNETES_INIT_NAMETAG + - name: AEROSPIKE_KUBERNETES_INIT_NAME_TAG # this is the name and tag of aerospike-init image value: aerospike-kubernetes-init:2.2.1 serviceAccountName: controller-manager diff --git a/helm-charts/aerospike-kubernetes-operator/templates/aerospike-operator-controller-manager-deployment.yaml b/helm-charts/aerospike-kubernetes-operator/templates/aerospike-operator-controller-manager-deployment.yaml index 9cbed370..a28a2e44 100644 --- a/helm-charts/aerospike-kubernetes-operator/templates/aerospike-operator-controller-manager-deployment.yaml +++ b/helm-charts/aerospike-kubernetes-operator/templates/aerospike-operator-controller-manager-deployment.yaml @@ -59,7 +59,7 @@ spec: value: {{ .Values.aerospikeKubernetesInitRegistry }} - name: AEROSPIKE_KUBERNETES_INIT_REGISTRY_NAMESPACE value: {{ .Values.aerospikeKubernetesInitRegistryNamespace }} - - name: AEROSPIKE_KUBERNETES_INIT_NAMETAG + - name: AEROSPIKE_KUBERNETES_INIT_NAME_TAG value: {{ .Values.aerospikeKubernetesInitNameTag }} {{- if .Values.extraEnv }} {{- range $key, $value := .Values.extraEnv }} diff --git a/test/cluster/cluster_test.go b/test/cluster/cluster_test.go index c660a241..c1f726b5 100644 --- a/test/cluster/cluster_test.go +++ b/test/cluster/cluster_test.go @@ -658,7 +658,7 @@ func DeployClusterForDiffStorageTest( } repFact := nHosts - //nolint:wsl //Comments are for test-case description + Context( "Positive", func() { // Cluster with n nodes, enterprise can be more than 8 diff --git a/test/cluster/podspec_test.go b/test/cluster/podspec_test.go index d3120fb2..2a522654 100644 --- a/test/cluster/podspec_test.go +++ b/test/cluster/podspec_test.go @@ -18,7 +18,7 @@ import ( var ( customInitRegistryEnvVar = "CUSTOM_INIT_REGISTRY" customInitRegistryNamespaceEnvVar = "CUSTOM_INIT_REGISTRY_NAMESPACE" - customInitNameAndTagEnvVar = "CUSTOM_INIT_NAMETAG" + customInitNameAndTagEnvVar = "CUSTOM_INIT_NAME_TAG" imagePullSecretNameEnvVar = "IMAGE_PULL_SECRET_NAME" //nolint:gosec // for testing ) @@ -429,7 +429,7 @@ var _ = Describe( } }) - It("Should be able to set/update aerospike-init custom registry and namespace", func() { + It("Should be able to set/update aerospike-init custom registry, namespace and name", func() { operatorEnvVarRegistry := "docker.io" operatorEnvVarRegistryNamespace := "aerospike" operatorEnvVarNameAndTag := "aerospike-kubernetes-init:2.2.1" @@ -461,10 +461,10 @@ var _ = Describe( err = updateCluster(k8sClient, ctx, aeroCluster) Expect(err).ToNot(HaveOccurred()) - validateImageRegistryNamespace(k8sClient, ctx, aeroCluster, customRegistry, + validateInitImage(k8sClient, aeroCluster, customRegistry, customRegistryNamespace, customInitNameAndTag) - By("Using envVar registry and namespace") + By("Using envVar registry, namespace and name") aeroCluster, err = getCluster(k8sClient, ctx, clusterNamespacedName) Expect(err).ToNot(HaveOccurred()) @@ -475,7 +475,7 @@ var _ = Describe( err = updateCluster(k8sClient, ctx, aeroCluster) Expect(err).ToNot(HaveOccurred()) - validateImageRegistryNamespace(k8sClient, ctx, aeroCluster, operatorEnvVarRegistry, + validateInitImage(k8sClient, aeroCluster, operatorEnvVarRegistry, operatorEnvVarRegistryNamespace, operatorEnvVarNameAndTag) }) @@ -493,7 +493,7 @@ var _ = Describe( err = updateClusterWithTO(k8sClient, ctx, aeroCluster, time.Minute*1) Expect(err).Should(HaveOccurred()) - validateImageRegistryNamespace(k8sClient, ctx, aeroCluster, operatorEnvVarRegistry, + validateInitImage(k8sClient, aeroCluster, operatorEnvVarRegistry, incorrectCustomRegistryNamespace, operatorEnvVarNameAndTag) By("Using correct registry namespace in CR") @@ -505,7 +505,7 @@ var _ = Describe( err = updateCluster(k8sClient, ctx, aeroCluster) Expect(err).ToNot(HaveOccurred()) - validateImageRegistryNamespace(k8sClient, ctx, aeroCluster, operatorEnvVarRegistry, + validateInitImage(k8sClient, aeroCluster, operatorEnvVarRegistry, operatorEnvVarRegistryNamespace, operatorEnvVarNameAndTag) }) }) @@ -573,7 +573,7 @@ func getEnvVar(envVar string) string { return envVarVal } -func validateImageRegistryNamespace(k8sClient client.Client, _ goctx.Context, aeroCluster *asdbv1.AerospikeCluster, +func validateInitImage(k8sClient client.Client, aeroCluster *asdbv1.AerospikeCluster, registry, namespace, nameAndTag string) { stsList, err := getSTSList(aeroCluster, k8sClient) Expect(err).ToNot(HaveOccurred()) diff --git a/test/test.sh b/test/test.sh index a8adbc4e..0fcfe528 100755 --- a/test/test.sh +++ b/test/test.sh @@ -21,7 +21,7 @@ do r ) REGISTRY="$OPTARG" ;; p ) CRED_PATH="$OPTARG" ;; n ) REGISTRY_NAMESPACE="$OPTARG" ;; - t ) INIT_IMAGE_NAME_AND_TAG="$OPTARG" ;; + t ) INIT_IMAGE_NAME_TAG="$OPTARG" ;; esac done @@ -30,7 +30,7 @@ done CRED_PATH=${CRED_PATH:-$HOME/.docker/config.json} REGISTRY=${REGISTRY:-568976754000.dkr.ecr.ap-south-1.amazonaws.com} REGISTRY_NAMESPACE=${REGISTRY_NAMESPACE:-aerospike} -INIT_IMAGE_NAME_AND_TAG=${INIT_IMAGE_NAME_AND_TAG:-aerospike-kubernetes-init:2.2.1} +INIT_IMAGE_NAME_TAG=${INIT_IMAGE_NAME_TAG:-aerospike-kubernetes-init:2.2.1} DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" @@ -65,7 +65,7 @@ echo "---------------------" export CUSTOM_INIT_REGISTRY="$REGISTRY" export CUSTOM_INIT_REGISTRY_NAMESPACE="$REGISTRY_NAMESPACE" -export CUSTOM_INIT_NAMETAG="$INIT_IMAGE_NAME_AND_TAG" +export CUSTOM_INIT_NAME_TAG="$INIT_IMAGE_NAME_TAG" export IMAGE_PULL_SECRET_NAME="$IMAGE_PULL_SECRET" make all-test FOCUS="$FOCUS" ARGS="$ARGS"