diff --git a/Jenkinsfile b/Jenkinsfile index 05763504c..db2d6d55e 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -23,6 +23,8 @@ pipeline { BUNDLE_IMG="${OPERATOR_BUNDLE_IMAGE_CANDIDATE_NAME}" AEROSPIKE_CUSTOM_INIT_REGISTRY="568976754000.dkr.ecr.ap-south-1.amazonaws.com" + AEROSPIKE_CUSTOM_INIT_REGISTRY_NAMESPACE="aerospike" + AEROSPIKE_CUSTOM_INIT_NAME_TAG="aerospike-kubernetes-init:2.2.1" } stages { @@ -90,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}" + 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/aerospikecluster_types.go b/api/v1/aerospikecluster_types.go index 26a727faa..6bceddd99 100644 --- a/api/v1/aerospikecluster_types.go +++ b/api/v1/aerospikecluster_types.go @@ -321,6 +321,10 @@ type AerospikeInitContainerSpec struct { //nolint:govet // for readability // ImageRegistry is the name of image registry for aerospike-init container image // ImageRegistry, e.g. docker.io, redhat.access.com ImageRegistry string `json:"imageRegistry,omitempty"` + // ImageRegistryNamespace is the name of namespace in registry for aerospike-init container image + ImageRegistryNamespace *string `json:"imageRegistryNamespace,omitempty"` + // ImageNameAndTag is the name:tag of aerospike-init container image + ImageNameAndTag string `json:"imageNameAndTag,omitempty"` // SecurityContext that will be added to aerospike-init container created by operator. SecurityContext *corev1.SecurityContext `json:"securityContext,omitempty"` // Define resources requests and limits for Aerospike init Container. diff --git a/api/v1/utils.go b/api/v1/utils.go index ce14db874..f69f92a04 100644 --- a/api/v1/utils.go +++ b/api/v1/utils.go @@ -71,9 +71,11 @@ const ( AerospikeServerContainerName = "aerospike-server" AerospikeInitContainerName = "aerospike-init" AerospikeInitContainerRegistryEnvVar = "AEROSPIKE_KUBERNETES_INIT_REGISTRY" + AerospikeInitContainerRegistryNamespaceEnvVar = "AEROSPIKE_KUBERNETES_INIT_REGISTRY_NAMESPACE" + AerospikeInitContainerNameTagEnvVar = "AEROSPIKE_KUBERNETES_INIT_NAME_TAG" AerospikeInitContainerDefaultRegistry = "docker.io" AerospikeInitContainerDefaultRegistryNamespace = "aerospike" - AerospikeInitContainerDefaultRepoAndTag = "aerospike-kubernetes-init:2.2.1" + AerospikeInitContainerDefaultNameAndTag = "aerospike-kubernetes-init:2.2.1" AerospikeAppLabel = "app" AerospikeAppLabelValue = "aerospike-cluster" AerospikeCustomResourceLabel = "aerospike.com/cr" @@ -121,33 +123,73 @@ func GetWorkDirectory(aerospikeConfigSpec AerospikeConfigSpec) string { return DefaultWorkDirectory } -func getInitContainerImage(registry string) string { +func getInitContainerImage(registry, namespace, repoAndTag string) string { return fmt.Sprintf( "%s/%s/%s", strings.TrimSuffix(registry, "/"), - strings.TrimSuffix(AerospikeInitContainerDefaultRegistryNamespace, "/"), - AerospikeInitContainerDefaultRepoAndTag, + strings.TrimSuffix(namespace, "/"), + repoAndTag, ) } func GetAerospikeInitContainerImage(aeroCluster *AerospikeCluster) string { + registry := getInitContainerImageValue(aeroCluster, AerospikeInitContainerRegistryEnvVar, + AerospikeInitContainerDefaultRegistry) + namespace := getInitContainerImageRegistryNamespace(aeroCluster) + repoAndTag := getInitContainerImageValue(aeroCluster, AerospikeInitContainerNameTagEnvVar, + AerospikeInitContainerDefaultNameAndTag) + + return getInitContainerImage(registry, namespace, repoAndTag) +} + +func getInitContainerImageRegistryNamespace(aeroCluster *AerospikeCluster) string { // Given in CR - registry := "" + var namespace *string + if aeroCluster.Spec.PodSpec.AerospikeInitContainerSpec != nil { + namespace = aeroCluster.Spec.PodSpec.AerospikeInitContainerSpec.ImageRegistryNamespace + } + + if namespace == nil { + // Given in EnvVar + envRegistryNamespace, found := os.LookupEnv(AerospikeInitContainerRegistryNamespaceEnvVar) + if found { + namespace = &envRegistryNamespace + } + } + + if namespace == nil { + return AerospikeInitContainerDefaultRegistryNamespace + } + + return *namespace +} + +func getInitContainerImageValue(aeroCluster *AerospikeCluster, envVar, defaultValue string) string { + var value string + + // Check in CR based on the valueType if aeroCluster.Spec.PodSpec.AerospikeInitContainerSpec != nil { - registry = aeroCluster.Spec.PodSpec.AerospikeInitContainerSpec.ImageRegistry + switch envVar { + case AerospikeInitContainerRegistryEnvVar: + value = aeroCluster.Spec.PodSpec.AerospikeInitContainerSpec.ImageRegistry + case AerospikeInitContainerNameTagEnvVar: + value = aeroCluster.Spec.PodSpec.AerospikeInitContainerSpec.ImageNameAndTag + } } - if registry != "" { - return getInitContainerImage(registry) + // Check in EnvVar if not found in CR + if value == "" { + envVal, found := os.LookupEnv(envVar) + if found { + value = envVal + } } - // Given in EnvVar - registry, found := os.LookupEnv(AerospikeInitContainerRegistryEnvVar) - if found { - return getInitContainerImage(registry) + // Return default values if still not found + if value == "" { + return defaultValue } - // Use default - return getInitContainerImage(AerospikeInitContainerDefaultRegistry) + return value } func ClusterNamespacedName(aeroCluster *AerospikeCluster) string { diff --git a/api/v1/zz_generated.deepcopy.go b/api/v1/zz_generated.deepcopy.go index 8a1a8f646..0a81b1f54 100644 --- a/api/v1/zz_generated.deepcopy.go +++ b/api/v1/zz_generated.deepcopy.go @@ -365,6 +365,11 @@ func (in *AerospikeContainerSpec) DeepCopy() *AerospikeContainerSpec { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *AerospikeInitContainerSpec) DeepCopyInto(out *AerospikeInitContainerSpec) { *out = *in + if in.ImageRegistryNamespace != nil { + in, out := &in.ImageRegistryNamespace, &out.ImageRegistryNamespace + *out = new(string) + **out = **in + } if in.SecurityContext != nil { in, out := &in.SecurityContext, &out.SecurityContext *out = new(corev1.SecurityContext) diff --git a/config/crd/bases/asdb.aerospike.com_aerospikeclusters.yaml b/config/crd/bases/asdb.aerospike.com_aerospikeclusters.yaml index d2928d104..4ad9433e5 100644 --- a/config/crd/bases/asdb.aerospike.com_aerospikeclusters.yaml +++ b/config/crd/bases/asdb.aerospike.com_aerospikeclusters.yaml @@ -636,11 +636,19 @@ spec: AerospikeInitContainerSpec configures the aerospike-init container created by the operator. properties: + imageNameAndTag: + description: ImageNameAndTag is the name:tag of aerospike-init + container image + type: string imageRegistry: description: |- ImageRegistry is the name of image registry for aerospike-init container image ImageRegistry, e.g. docker.io, redhat.access.com type: string + imageRegistryNamespace: + description: ImageRegistryNamespace is the name of namespace + in registry for aerospike-init container image + type: string resources: description: |- Define resources requests and limits for Aerospike init Container. @@ -9174,11 +9182,19 @@ spec: AerospikeInitContainerSpec configures the aerospike-init container created by the operator. properties: + imageNameAndTag: + description: ImageNameAndTag is the name:tag of aerospike-init + container image + type: string imageRegistry: description: |- ImageRegistry is the name of image registry for aerospike-init container image ImageRegistry, e.g. docker.io, redhat.access.com type: string + imageRegistryNamespace: + description: ImageRegistryNamespace is the name of namespace + in registry for aerospike-init container image + type: string resources: description: |- Define resources requests and limits for Aerospike init Container. diff --git a/config/manager/manager.yaml b/config/manager/manager.yaml index 9577e5084..d5dc95a08 100644 --- a/config/manager/manager.yaml +++ b/config/manager/manager.yaml @@ -61,6 +61,12 @@ spec: - name: AEROSPIKE_KUBERNETES_INIT_REGISTRY # this is the registry used to pull aerospike-init image value: docker.io + - name: AEROSPIKE_KUBERNETES_INIT_REGISTRY_NAMESPACE + # this is the namespace in registry used to pull aerospike-init image + value: aerospike + - 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 terminationGracePeriodSeconds: 10 diff --git a/helm-charts/aerospike-kubernetes-operator/crds/customresourcedefinition_aerospikeclusters.asdb.aerospike.com.yaml b/helm-charts/aerospike-kubernetes-operator/crds/customresourcedefinition_aerospikeclusters.asdb.aerospike.com.yaml index d2928d104..4ad9433e5 100644 --- a/helm-charts/aerospike-kubernetes-operator/crds/customresourcedefinition_aerospikeclusters.asdb.aerospike.com.yaml +++ b/helm-charts/aerospike-kubernetes-operator/crds/customresourcedefinition_aerospikeclusters.asdb.aerospike.com.yaml @@ -636,11 +636,19 @@ spec: AerospikeInitContainerSpec configures the aerospike-init container created by the operator. properties: + imageNameAndTag: + description: ImageNameAndTag is the name:tag of aerospike-init + container image + type: string imageRegistry: description: |- ImageRegistry is the name of image registry for aerospike-init container image ImageRegistry, e.g. docker.io, redhat.access.com type: string + imageRegistryNamespace: + description: ImageRegistryNamespace is the name of namespace + in registry for aerospike-init container image + type: string resources: description: |- Define resources requests and limits for Aerospike init Container. @@ -9174,11 +9182,19 @@ spec: AerospikeInitContainerSpec configures the aerospike-init container created by the operator. properties: + imageNameAndTag: + description: ImageNameAndTag is the name:tag of aerospike-init + container image + type: string imageRegistry: description: |- ImageRegistry is the name of image registry for aerospike-init container image ImageRegistry, e.g. docker.io, redhat.access.com type: string + imageRegistryNamespace: + description: ImageRegistryNamespace is the name of namespace + in registry for aerospike-init container image + type: string resources: description: |- Define resources requests and limits for Aerospike init Container. 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 7a5741d66..a28a2e440 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 @@ -57,6 +57,10 @@ spec: value: {{ .Values.watchNamespaces | quote }} - name: AEROSPIKE_KUBERNETES_INIT_REGISTRY value: {{ .Values.aerospikeKubernetesInitRegistry }} + - name: AEROSPIKE_KUBERNETES_INIT_REGISTRY_NAMESPACE + value: {{ .Values.aerospikeKubernetesInitRegistryNamespace }} + - name: AEROSPIKE_KUBERNETES_INIT_NAME_TAG + value: {{ .Values.aerospikeKubernetesInitNameTag }} {{- if .Values.extraEnv }} {{- range $key, $value := .Values.extraEnv }} - name: "{{ $key }}" diff --git a/helm-charts/aerospike-kubernetes-operator/values.yaml b/helm-charts/aerospike-kubernetes-operator/values.yaml index abcc33c9d..b5d878131 100644 --- a/helm-charts/aerospike-kubernetes-operator/values.yaml +++ b/helm-charts/aerospike-kubernetes-operator/values.yaml @@ -33,6 +33,12 @@ watchNamespaces: "default,aerospike" # Registry used to pull aerospike-init image aerospikeKubernetesInitRegistry: "docker.io" +# Namespace in registry used to pull aerospike-init image +aerospikeKubernetesInitRegistryNamespace: "aerospike" + +# Name and tag of aerospike-init image +aerospikeKubernetesInitNameTag: "aerospike-kubernetes-init:2.2.1" + ## Resources - limits / requests resources: limits: diff --git a/internal/controller/cluster/rack.go b/internal/controller/cluster/rack.go index 538d5d7a2..35e762744 100644 --- a/internal/controller/cluster/rack.go +++ b/internal/controller/cluster/rack.go @@ -1110,15 +1110,6 @@ func (r *SingleClusterReconciler) rollingRestartRack( } } - if len(failedPods) != 0 && r.isAnyPodInImageFailedState(podList, ignorablePodNames) { - return found, common.ReconcileError( - fmt.Errorf( - "cannot Rolling restart AerospikeCluster. " + - "A pod is already in failed state due to image related issues", - ), - ) - } - err = r.updateSTS(found, rackState) if err != nil { return found, common.ReconcileError( diff --git a/test/backup/test_utils.go b/test/backup/test_utils.go index 307780fb1..6efd74d65 100644 --- a/test/backup/test_utils.go +++ b/test/backup/test_utils.go @@ -33,7 +33,7 @@ var testCtx = context.TODO() var backupServiceName, backupServiceNamespace string -var pkgLog = ctrl.Log.WithName("backup") +var pkgLog = ctrl.Log.WithName("aerospikebackup") var aerospikeNsNm = types.NamespacedName{ Name: "aerocluster", diff --git a/test/backup_service/test_utils.go b/test/backup_service/test_utils.go index 1b27d563a..72142a4a3 100644 --- a/test/backup_service/test_utils.go +++ b/test/backup_service/test_utils.go @@ -34,7 +34,7 @@ const ( var testCtx = context.TODO() -var pkgLog = ctrl.Log.WithName("backupservice") +var pkgLog = ctrl.Log.WithName("aerospikebackupservice") func NewBackupService() (*asdbv1beta1.AerospikeBackupService, error) { configBytes, err := getBackupServiceConfBytes() diff --git a/test/cluster/batch_restart_pods_test.go b/test/cluster/batch_restart_pods_test.go index 27803a1fb..aa708b340 100644 --- a/test/cluster/batch_restart_pods_test.go +++ b/test/cluster/batch_restart_pods_test.go @@ -250,7 +250,7 @@ func BatchRollingRestart(ctx goctx.Context, clusterNamespacedName types.Namespac aeroCluster, err := getCluster(k8sClient, ctx, clusterNamespacedName) Expect(err).ToNot(HaveOccurred()) - aeroCluster.Spec.PodSpec.AerospikeContainerSpec.Resources = schedulableResource("1Gi") + aeroCluster.Spec.PodSpec.AerospikeContainerSpec.Resources = schedulableResource("200m") err = updateCluster(k8sClient, ctx, aeroCluster) Expect(err).ToNot(HaveOccurred()) @@ -279,7 +279,7 @@ func BatchRollingRestart(ctx goctx.Context, clusterNamespacedName types.Namespac Expect(err).ToNot(HaveOccurred()) // schedule batch of pods - err = rollingRestartTest(k8sClient, ctx, clusterNamespacedName, percent("100%"), "1Gi") + err = rollingRestartTest(k8sClient, ctx, clusterNamespacedName, percent("100%"), "200m") Expect(err).ToNot(HaveOccurred()) By("Using RollingUpdateBatchSize Count greater than pods in rack") @@ -288,7 +288,7 @@ func BatchRollingRestart(ctx goctx.Context, clusterNamespacedName types.Namespac Expect(err).ToNot(HaveOccurred()) // Schedule batch of pods - err = rollingRestartTest(k8sClient, ctx, clusterNamespacedName, count(10), "2Gi") + err = rollingRestartTest(k8sClient, ctx, clusterNamespacedName, count(10), "300m") Expect(err).ToNot(HaveOccurred()) }) @@ -299,7 +299,7 @@ func BatchRollingRestart(ctx goctx.Context, clusterNamespacedName types.Namespac err := batchRollingRestartTest(k8sClient, ctx, clusterNamespacedName, percent("90%")) Expect(err).ToNot(HaveOccurred()) - err = rollingRestartTest(k8sClient, ctx, clusterNamespacedName, percent("90%"), "1Gi") + err = rollingRestartTest(k8sClient, ctx, clusterNamespacedName, percent("90%"), "200m") Expect(err).ToNot(HaveOccurred()) By("Update RollingUpdateBatchSize Count") @@ -307,7 +307,7 @@ func BatchRollingRestart(ctx goctx.Context, clusterNamespacedName types.Namespac err = batchRollingRestartTest(k8sClient, ctx, clusterNamespacedName, count(3)) Expect(err).ToNot(HaveOccurred()) - err = rollingRestartTest(k8sClient, ctx, clusterNamespacedName, count(3), "2Gi") + err = rollingRestartTest(k8sClient, ctx, clusterNamespacedName, count(3), "300m") Expect(err).ToNot(HaveOccurred()) }) @@ -319,7 +319,7 @@ func BatchRollingRestart(ctx goctx.Context, clusterNamespacedName types.Namespac Expect(err).ToNot(HaveOccurred()) aeroCluster.Spec.RackConfig.RollingUpdateBatchSize = count(3) - aeroCluster.Spec.PodSpec.AerospikeContainerSpec.Resources = schedulableResource("1Gi") + aeroCluster.Spec.PodSpec.AerospikeContainerSpec.Resources = schedulableResource("200m") err = k8sClient.Update(ctx, aeroCluster) Expect(err).ToNot(HaveOccurred()) @@ -339,7 +339,7 @@ func BatchRollingRestart(ctx goctx.Context, clusterNamespacedName types.Namespac By("Again Update RollingUpdateBatchSize Count") - err = rollingRestartTest(k8sClient, ctx, clusterNamespacedName, count(3), "1Gi") + err = rollingRestartTest(k8sClient, ctx, clusterNamespacedName, count(3), "200m") Expect(err).ToNot(HaveOccurred()) }) } diff --git a/test/cluster/cluster_helper.go b/test/cluster/cluster_helper.go index 3eaa477bd..b15e86834 100644 --- a/test/cluster/cluster_helper.go +++ b/test/cluster/cluster_helper.go @@ -47,7 +47,7 @@ const ( var ( storageClass = "ssd" namespace = "test" - pkgLog = ctrl.Log.WithName("cluster") + pkgLog = ctrl.Log.WithName("aerospikecluster") ) const aerospikeConfigSecret string = "aerospike-config-secret" //nolint:gosec // for testing diff --git a/test/cluster/podspec_test.go b/test/cluster/podspec_test.go index 10a687d15..2a5226540 100644 --- a/test/cluster/podspec_test.go +++ b/test/cluster/podspec_test.go @@ -5,7 +5,7 @@ import ( "fmt" "os" "reflect" - "strings" + "time" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" @@ -16,8 +16,10 @@ import ( ) var ( - customInitRegistryEnvVar = "CUSTOM_INIT_REGISTRY" - imagePullSecretNameEnvVar = "IMAGE_PULL_SECRET_NAME" //nolint:gosec // for testing + customInitRegistryEnvVar = "CUSTOM_INIT_REGISTRY" + customInitRegistryNamespaceEnvVar = "CUSTOM_INIT_REGISTRY_NAMESPACE" + customInitNameAndTagEnvVar = "CUSTOM_INIT_NAME_TAG" + imagePullSecretNameEnvVar = "IMAGE_PULL_SECRET_NAME" //nolint:gosec // for testing ) var _ = Describe( @@ -427,9 +429,13 @@ var _ = Describe( } }) - It("Should be able to set/update aerospike-init custom registry", 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" customRegistry := getEnvVar(customInitRegistryEnvVar) + customRegistryNamespace := getEnvVar(customInitRegistryNamespaceEnvVar) + customInitNameAndTag := getEnvVar(customInitNameAndTagEnvVar) imagePullSecret := getEnvVar(imagePullSecretNameEnvVar) By("Updating imagePullSecret") @@ -445,26 +451,62 @@ var _ = Describe( err = updateCluster(k8sClient, ctx, aeroCluster) Expect(err).ToNot(HaveOccurred()) - By("Using registry in CR") + By("Using registry, namespace and name in CR") aeroCluster, err = getCluster(k8sClient, ctx, clusterNamespacedName) Expect(err).ToNot(HaveOccurred()) aeroCluster.Spec.PodSpec.AerospikeInitContainerSpec.ImageRegistry = customRegistry + aeroCluster.Spec.PodSpec.AerospikeInitContainerSpec.ImageRegistryNamespace = &customRegistryNamespace + aeroCluster.Spec.PodSpec.AerospikeInitContainerSpec.ImageNameAndTag = customInitNameAndTag err = updateCluster(k8sClient, ctx, aeroCluster) Expect(err).ToNot(HaveOccurred()) - validateImageRegistry(k8sClient, ctx, aeroCluster, customRegistry) + validateInitImage(k8sClient, aeroCluster, customRegistry, + customRegistryNamespace, customInitNameAndTag) - By("Using envVar registry") + By("Using envVar registry, namespace and name") aeroCluster, err = getCluster(k8sClient, ctx, clusterNamespacedName) Expect(err).ToNot(HaveOccurred()) // Empty imageRegistry, should use operator envVar docker.io aeroCluster.Spec.PodSpec.AerospikeInitContainerSpec.ImageRegistry = "" + aeroCluster.Spec.PodSpec.AerospikeInitContainerSpec.ImageRegistryNamespace = nil + aeroCluster.Spec.PodSpec.AerospikeInitContainerSpec.ImageNameAndTag = "" err = updateCluster(k8sClient, ctx, aeroCluster) Expect(err).ToNot(HaveOccurred()) - validateImageRegistry(k8sClient, ctx, aeroCluster, operatorEnvVarRegistry) + validateInitImage(k8sClient, aeroCluster, operatorEnvVarRegistry, + operatorEnvVarRegistryNamespace, operatorEnvVarNameAndTag) + }) + + It("Should be able to recover cluster after setting correct aerospike-init custom registry/namespace", func() { + operatorEnvVarRegistry := "docker.io" + operatorEnvVarRegistryNamespace := "aerospike" + operatorEnvVarNameAndTag := "aerospike-kubernetes-init:2.2.1" + incorrectCustomRegistryNamespace := "incorrectnamespace" + + By("Using incorrect registry namespace in CR") + aeroCluster, err := getCluster(k8sClient, ctx, clusterNamespacedName) + Expect(err).ToNot(HaveOccurred()) + + aeroCluster.Spec.PodSpec.AerospikeInitContainerSpec.ImageRegistryNamespace = &incorrectCustomRegistryNamespace + err = updateClusterWithTO(k8sClient, ctx, aeroCluster, time.Minute*1) + Expect(err).Should(HaveOccurred()) + + validateInitImage(k8sClient, aeroCluster, operatorEnvVarRegistry, + incorrectCustomRegistryNamespace, operatorEnvVarNameAndTag) + + By("Using correct registry namespace in CR") + aeroCluster, err = getCluster(k8sClient, ctx, clusterNamespacedName) + Expect(err).ToNot(HaveOccurred()) + + // Nil ImageRegistryNamespace, should use operator envVar aerospike + aeroCluster.Spec.PodSpec.AerospikeInitContainerSpec.ImageRegistryNamespace = nil + err = updateCluster(k8sClient, ctx, aeroCluster) + Expect(err).ToNot(HaveOccurred()) + + validateInitImage(k8sClient, aeroCluster, operatorEnvVarRegistry, + operatorEnvVarRegistryNamespace, operatorEnvVarNameAndTag) }) }) Context( @@ -521,7 +563,6 @@ var _ = Describe( ) }, ) - }, ) @@ -532,15 +573,16 @@ func getEnvVar(envVar string) string { return envVarVal } -func validateImageRegistry( - k8sClient client.Client, _ goctx.Context, aeroCluster *asdbv1.AerospikeCluster, registry string, -) { +func validateInitImage(k8sClient client.Client, aeroCluster *asdbv1.AerospikeCluster, + registry, namespace, nameAndTag string) { stsList, err := getSTSList(aeroCluster, k8sClient) Expect(err).ToNot(HaveOccurred()) + expectedImage := fmt.Sprintf("%s/%s/%s", registry, namespace, nameAndTag) + for stsIndex := range stsList.Items { image := stsList.Items[stsIndex].Spec.Template.Spec.InitContainers[0].Image - hasPrefix := strings.HasPrefix(image, registry) - Expect(hasPrefix).To(BeTrue(), fmt.Sprintf("expected registry %s, found image %s", registry, image)) + Expect(image == expectedImage).To(BeTrue(), fmt.Sprintf("expected init image %s, found image %s", + expectedImage, image)) } } diff --git a/test/restore/test_utils.go b/test/restore/test_utils.go index 04fdbaf81..1dc5ca04d 100644 --- a/test/restore/test_utils.go +++ b/test/restore/test_utils.go @@ -30,7 +30,7 @@ var backupServiceName, backupServiceNamespace string var backupDataPath string -var pkgLog = ctrl.Log.WithName("restore") +var pkgLog = ctrl.Log.WithName("aerospikerestore") var backupNsNm = types.NamespacedName{ Name: "sample-backup", diff --git a/test/test.sh b/test/test.sh index 9f437577d..0fcfe528f 100755 --- a/test/test.sh +++ b/test/test.sh @@ -11,7 +11,7 @@ set -e # test.sh -c aerospike/aerospike-kubernetes-operator-bundle:1.1.0 -f ".*RackManagement.*" -a "--connect-through-network-type=hostInternal" # test.sh -c <IMAGE> -f "<GINKGO-FOCUS-REGEXP>" -a "<PASS-THROUGHS>" -while getopts "b:c:f:a:r:p:" opt +while getopts "b:c:f:a:r:p:n:t:" opt do case "$opt" in b ) BUNDLE="$OPTARG" ;; @@ -20,6 +20,8 @@ do a ) ARGS="$OPTARG" ;; r ) REGISTRY="$OPTARG" ;; p ) CRED_PATH="$OPTARG" ;; + n ) REGISTRY_NAMESPACE="$OPTARG" ;; + t ) INIT_IMAGE_NAME_TAG="$OPTARG" ;; esac done @@ -27,6 +29,8 @@ done # Defaults 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_TAG=${INIT_IMAGE_NAME_TAG:-aerospike-kubernetes-init:2.2.1} DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" @@ -60,6 +64,8 @@ echo "| Starting tests.... |" echo "---------------------" export CUSTOM_INIT_REGISTRY="$REGISTRY" +export CUSTOM_INIT_REGISTRY_NAMESPACE="$REGISTRY_NAMESPACE" +export CUSTOM_INIT_NAME_TAG="$INIT_IMAGE_NAME_TAG" export IMAGE_PULL_SECRET_NAME="$IMAGE_PULL_SECRET" make all-test FOCUS="$FOCUS" ARGS="$ARGS"