Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[KO-338] Making the aerospike-init image namespace configurable #308

Merged
merged 10 commits into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"
abhishekdwivedi3060 marked this conversation as resolved.
Show resolved Hide resolved
AEROSPIKE_CUSTOM_INIT_NAME_TAG="aerospike-kubernetes-init:2.2.1"
}

stages {
Expand Down Expand Up @@ -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}"

}
}
Expand Down
4 changes: 4 additions & 0 deletions api/v1/aerospikecluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
abhishekdwivedi3060 marked this conversation as resolved.
Show resolved Hide resolved
// 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.
Expand Down
70 changes: 56 additions & 14 deletions api/v1/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down
5 changes: 5 additions & 0 deletions api/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions config/crd/bases/asdb.aerospike.com_aerospikeclusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
6 changes: 6 additions & 0 deletions config/manager/manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}"
Expand Down
6 changes: 6 additions & 0 deletions helm-charts/aerospike-kubernetes-operator/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
9 changes: 0 additions & 9 deletions internal/controller/cluster/rack.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion test/backup/test_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion test/backup_service/test_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
14 changes: 7 additions & 7 deletions test/cluster/batch_restart_pods_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())

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

Expand All @@ -299,15 +299,15 @@ 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")

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())
})

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

Expand All @@ -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())
})
}
Expand Down
2 changes: 1 addition & 1 deletion test/cluster/cluster_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading
Loading