Skip to content

Commit

Permalink
chore: podAntiAffinity control by annotation
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaozhuang committed Dec 26, 2024
1 parent 42ea5f4 commit 8974004
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions pkg/webhook/pod_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ const (
podLabelsPodName = "statefulset.kubernetes.io/pod-name"
podLabelsRedisType = "redis_setup_type"
)
const annotationKeyEnablePodAntiAffinity = "redis.opstreelabs/enable-pod-anti-affinity"

func (v *PodAntiAffiniytMutate) Handle(ctx context.Context, req admission.Request) admission.Response {
logger := v.logger.WithValues("Request.Namespace", req.Namespace, "Request.Name", req.Name)
Expand All @@ -66,6 +67,15 @@ func (v *PodAntiAffiniytMutate) Handle(ctx context.Context, req admission.Reques
if !v.isRedisClusterPod(pod) {
return admission.Allowed("")
}

Check warning on line 69 in pkg/webhook/pod_webhook.go

View check run for this annotation

Codecov / codecov/patch

pkg/webhook/pod_webhook.go#L67-L69

Added lines #L67 - L69 were not covered by tests
// check if the pod anti-affinity is enabled
annotations := pod.GetAnnotations()
if annotations == nil {
return admission.Allowed("")
}
if enable, ok := annotations[annotationKeyEnablePodAntiAffinity]; !ok || enable != "true" {
logger.V(1).Info("pod anti-affinity is not enabled")
return admission.Allowed("")
}

Check warning on line 78 in pkg/webhook/pod_webhook.go

View check run for this annotation

Codecov / codecov/patch

pkg/webhook/pod_webhook.go#L71-L78

Added lines #L71 - L78 were not covered by tests

old := pod.DeepCopy()

Expand Down

0 comments on commit 8974004

Please sign in to comment.