Skip to content

Commit

Permalink
Added isClusterReadinessEnabled field in status
Browse files Browse the repository at this point in the history
  • Loading branch information
abhishekdwivedi3060 committed May 14, 2024
1 parent 02d3945 commit bff9a81
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 17 deletions.
6 changes: 6 additions & 0 deletions api/v1/aerospikecluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,12 @@ type AerospikeClusterStatusSpec struct { //nolint:govet // for readability
// In case of inconsistent state during dynamic config update, operator falls back to rolling restart.
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Enable Dynamic Config Update"
EnableDynamicConfigUpdate *bool `json:"enableDynamicConfigUpdate,omitempty"`

// IsClusterReadinessEnabled determines if the cluster is readiness enabled i.e. readiness probe is
// present in all pods.
// This field is used to determine if PodDisruptionBudget should be created for the Aerospike cluster or not.
// +optional
IsClusterReadinessEnabled bool `json:"isClusterReadinessEnabled"`
// Define resources requests and limits for Aerospike Server Container.
// Please contact aerospike for proper sizing exercise
// Only Memory and Cpu resources can be given
Expand Down
6 changes: 6 additions & 0 deletions config/crd/bases/asdb.aerospike.com_aerospikeclusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9618,6 +9618,12 @@ spec:
image:
description: Aerospike server image
type: string
isClusterReadinessEnabled:
description: IsClusterReadinessEnabled determines if the cluster is
readiness enabled i.e. readiness probe is present in all pods. This
field is used to determine if PodDisruptionBudget should be created
for the Aerospike cluster or not.
type: boolean
k8sNodeBlockList:
description: K8sNodeBlockList is a list of Kubernetes nodes which
are not used for Aerospike pods.
Expand Down
26 changes: 9 additions & 17 deletions controllers/poddistruptionbudget.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,24 +63,16 @@ func (r *SingleClusterReconciler) deletePDB() error {
}

func (r *SingleClusterReconciler) createOrUpdatePDB() error {
podList, err := r.getClusterPodList()
if err != nil {
return err
}

for podIdx := range podList.Items {
pod := &podList.Items[podIdx]

for containerIdx := range pod.Spec.Containers {
if pod.Spec.Containers[containerIdx].Name != asdbv1.AerospikeServerContainerName {
continue
}
if !r.IsStatusEmpty() {
clusterReadinessEnabled, err := r.getClusterReadinessStatus()
if err != nil {
return fmt.Errorf("failed to get cluster readiness status: %v", err)
}

if pod.Spec.Containers[containerIdx].ReadinessProbe == nil {
r.Log.Info("Pod found without ReadinessProbe, skipping PodDisruptionBudget. Refer Aerospike "+
"documentation for more details.", "name", pod.Name)
return nil
}
if !clusterReadinessEnabled {
r.Log.Info("Pod Readiness is not enabled throughout cluster. Skipping PodDisruptionBudget." +
" Refer Aerospike documentation for more details.")
return nil
}
}

Expand Down
30 changes: 30 additions & 0 deletions controllers/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,13 @@ func (r *SingleClusterReconciler) updateStatus() error {
newAeroCluster.Status.AerospikeClusterStatusSpec = *specToStatus
newAeroCluster.Status.Phase = asdbv1.AerospikeClusterCompleted

clusterReadinessEnable, err := r.getClusterReadinessStatus()
if err != nil {
return fmt.Errorf("failed to get cluster readiness status: %v", err)
}

newAeroCluster.Status.IsClusterReadinessEnabled = clusterReadinessEnable

err = r.patchStatus(newAeroCluster)
if err != nil {
return fmt.Errorf("error updating status: %w", err)
Expand All @@ -442,6 +449,29 @@ func (r *SingleClusterReconciler) setStatusPhase(phase asdbv1.AerospikeClusterPh
return nil
}

func (r *SingleClusterReconciler) getClusterReadinessStatus() (bool, error) {
podList, err := r.getClusterPodList()
if err != nil {
return false, err
}

for podIdx := range podList.Items {
pod := &podList.Items[podIdx]

for containerIdx := range pod.Spec.Containers {
if pod.Spec.Containers[containerIdx].Name != asdbv1.AerospikeServerContainerName {
continue
}

if pod.Spec.Containers[containerIdx].ReadinessProbe == nil {
return false, nil
}
}
}

return true, nil
}

func (r *SingleClusterReconciler) updateAccessControlStatus() error {
if r.aeroCluster.Spec.AerospikeAccessControl == nil {
return nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9618,6 +9618,12 @@ spec:
image:
description: Aerospike server image
type: string
isClusterReadinessEnabled:
description: IsClusterReadinessEnabled determines if the cluster is
readiness enabled i.e. readiness probe is present in all pods. This
field is used to determine if PodDisruptionBudget should be created
for the Aerospike cluster or not.
type: boolean
k8sNodeBlockList:
description: K8sNodeBlockList is a list of Kubernetes nodes which
are not used for Aerospike pods.
Expand Down

0 comments on commit bff9a81

Please sign in to comment.