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 6 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_NAMETAG="aerospike"
abhishekdwivedi3060 marked this conversation as resolved.
Show resolved Hide resolved
}

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_NAMETAG}"

}
}
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
84 changes: 71 additions & 13 deletions api/v1/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,11 @@ 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"
AerospikeInitContainerDefaultRegistry = "docker.io"
AerospikeInitContainerDefaultRegistryNamespace = "aerospike"
AerospikeInitContainerDefaultRepoAndTag = "aerospike-kubernetes-init:2.2.1"
abhishekdwivedi3060 marked this conversation as resolved.
Show resolved Hide resolved
Expand Down Expand Up @@ -121,33 +125,87 @@ 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, AerospikeInitContainerRegistry)
namespace := getInitContainerImageRegistryNamespace(aeroCluster)
repoAndTag := getInitContainerImageValue(aeroCluster, AerospikeInitContainerNameAndTag)

return getInitContainerImage(registry, namespace, repoAndTag)
}

func getInitContainerImageRegistryNamespace(aeroCluster *AerospikeCluster) string {
// Given in CR
registry := ""
var namespace *string
if aeroCluster.Spec.PodSpec.AerospikeInitContainerSpec != nil {
registry = aeroCluster.Spec.PodSpec.AerospikeInitContainerSpec.ImageRegistry
namespace = aeroCluster.Spec.PodSpec.AerospikeInitContainerSpec.ImageRegistryNamespace
}

if namespace == nil {
// Given in EnvVar
envRegistryNamespace, found := os.LookupEnv(AerospikeInitContainerRegistryNamespaceEnvVar)
if found {
namespace = &envRegistryNamespace
}
}

if registry != "" {
return getInitContainerImage(registry)
if namespace == nil {
return AerospikeInitContainerDefaultRegistryNamespace
}

// Given in EnvVar
registry, found := os.LookupEnv(AerospikeInitContainerRegistryEnvVar)
if found {
return getInitContainerImage(registry)
return *namespace
}

func getInitContainerImageValue(aeroCluster *AerospikeCluster, valueType string) string {
abhishekdwivedi3060 marked this conversation as resolved.
Show resolved Hide resolved
var value string

// Check in CR based on the valueType
if aeroCluster.Spec.PodSpec.AerospikeInitContainerSpec != nil {
switch valueType {
case AerospikeInitContainerRegistry:
value = aeroCluster.Spec.PodSpec.AerospikeInitContainerSpec.ImageRegistry
case AerospikeInitContainerNameAndTag:
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)
}

if found {
value = envVar
}
}

// Return default values if still not found
if value == "" {
switch valueType {
case AerospikeInitContainerRegistry:
return AerospikeInitContainerDefaultRegistry
case AerospikeInitContainerNameAndTag:
return AerospikeInitContainerDefaultRepoAndTag
}
}

// 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_NAMETAG
abhishekdwivedi3060 marked this conversation as resolved.
Show resolved Hide resolved
# this is the name and tag of aerospike-init image
value: aerospike-kubernetes-init:2.2.1
abhishekdwivedi3060 marked this conversation as resolved.
Show resolved Hide resolved
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_NAMETAG
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
Loading
Loading