Skip to content

Commit

Permalink
Addressing comments
Browse files Browse the repository at this point in the history
  • Loading branch information
tanmayja committed Sep 10, 2024
1 parent daba298 commit 1458518
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 44 deletions.
4 changes: 2 additions & 2 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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}"

}
}
Expand Down
40 changes: 12 additions & 28 deletions api/v1/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
}
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion config/manager/manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
2 changes: 1 addition & 1 deletion test/cluster/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,7 @@ func DeployClusterForDiffStorageTest(
}

repFact := nHosts
//nolint:wsl //Comments are for test-case description

Context(
"Positive", func() {

Check failure on line 663 in test/cluster/cluster_test.go

View workflow job for this annotation

GitHub Actions / lint

block should not start with a whitespace (wsl)
// Cluster with n nodes, enterprise can be more than 8
Expand Down
16 changes: 8 additions & 8 deletions test/cluster/podspec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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())

Expand All @@ -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)
})

Expand All @@ -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")
Expand All @@ -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)
})
})
Expand Down Expand Up @@ -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())
Expand Down
6 changes: 3 additions & 3 deletions test/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 )"
Expand Down Expand Up @@ -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"

0 comments on commit 1458518

Please sign in to comment.