Skip to content

Commit

Permalink
check dynamic config enable flag bsed on init image tag
Browse files Browse the repository at this point in the history
  • Loading branch information
tanmayja committed May 14, 2024
1 parent bff9a81 commit c61475a
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 3 deletions.
2 changes: 2 additions & 0 deletions api/v1/aerospikecluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -873,6 +873,8 @@ type AerospikeInstanceSummary struct { //nolint:govet // for readability
type AerospikePodStatus struct { //nolint:govet // for readability
// Image is the Aerospike image this pod is running.
Image string `json:"image"`
// InitImage is the init image this pod's init container is running.
InitImage string `json:"initImage,omitempty"`
// PodIP in the K8s network.
PodIP string `json:"podIP"`
// HostInternalIP of the K8s host this pod is scheduled on.
Expand Down
63 changes: 63 additions & 0 deletions api/v1/aerospikecluster_validating_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ func (c *AerospikeCluster) ValidateUpdate(oldObj runtime.Object) (admission.Warn
return nil, err
}

// Validate MaxUnavailable for PodDisruptionBudget
if err := c.validateEnableDynamicConfigUpdate(); err != nil {
return nil, err
}

outgoingVersion, err := GetImageVersion(old.Spec.Image)
if err != nil {
return nil, err
Expand Down Expand Up @@ -2301,3 +2306,61 @@ func (c *AerospikeCluster) validateMaxUnavailable() error {

return nil
}

func (c *AerospikeCluster) validateEnableDynamicConfigUpdate() error {
if !GetBool(c.Spec.EnableDynamicConfigUpdate) {
return nil
}

if len(c.Status.Pods) == 0 {
return nil
}

minInitVersion, err := getMinRunningInitVersion(c.Status.Pods)
if err != nil {
return err
}

val, err := lib.CompareVersions(minInitVersion, minInitVersion4DynamicConf)
if err != nil {
return fmt.Errorf("failed to check image version: %v", err)
}

if val < 0 {
return fmt.Errorf("cannot enable enableDynamicConfigUpdate flag, init container are running version less than %s",
minInitVersion4DynamicConf)
}

return nil
}

func getMinRunningInitVersion(pods map[string]AerospikePodStatus) (string, error) {
minVersion := ""

for idx := range pods {
if pods[idx].InitImage != "" {
version, err := GetImageVersion(pods[idx].InitImage)
if err != nil {
return "", err
}

if minVersion == "" {
minVersion = version
continue
}

val, err := lib.CompareVersions(version, minVersion)
if err != nil {
return "", fmt.Errorf("failed to check image version: %v", err)
}

if val < 0 {
minVersion = version
}
} else {
return baseInitVersion, nil
}
}

return minVersion, nil
}
10 changes: 7 additions & 3 deletions api/v1/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ const (
InfoPortName = "info"
)

const baseVersion = "4.9.0.3"
const (
baseVersion = "4.9.0.3"
baseInitVersion = "2.0.0"
minInitVersion4DynamicConf = "2.2.0"
)

const (
// Namespace keys.
Expand Down Expand Up @@ -62,8 +66,8 @@ const (
AerospikeInitContainerName = "aerospike-init"
AerospikeInitContainerRegistryEnvVar = "AEROSPIKE_KUBERNETES_INIT_REGISTRY"
AerospikeInitContainerDefaultRegistry = "docker.io"
AerospikeInitContainerDefaultRegistryNamespace = "sud82"
AerospikeInitContainerDefaultRepoAndTag = "aerospike-kubernetes-init-nightly:2.1.0-dev1"
AerospikeInitContainerDefaultRegistryNamespace = "tanmayj10"
AerospikeInitContainerDefaultRepoAndTag = "aerospike-kubernetes-init-nightly:2.2.0"
AerospikeAppLabel = "app"
AerospikeAppLabelValue = "aerospike-cluster"
AerospikeCustomResourceLabel = "aerospike.com/cr"
Expand Down
4 changes: 4 additions & 0 deletions config/crd/bases/asdb.aerospike.com_aerospikeclusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14291,6 +14291,10 @@ spec:
image:
description: Image is the Aerospike image this pod is running.
type: string
initImage:
description: InitImage is the init image this pod's init container
is running.
type: string
initializedVolumes:
description: InitializedVolumes is the list of volume names
that have already been initialized.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14291,6 +14291,10 @@ spec:
image:
description: Image is the Aerospike image this pod is running.
type: string
initImage:
description: InitImage is the init image this pod's init container
is running.
type: string
initializedVolumes:
description: InitializedVolumes is the list of volume names
that have already been initialized.
Expand Down

0 comments on commit c61475a

Please sign in to comment.