Skip to content

Commit a773e3b

Browse files
author
xiaozhuang
committed
chore: podAntiAffinity control by annotation
Signed-off-by: xiaozhuang <xiaozhuang@minimaxi.com>
1 parent 42ea5f4 commit a773e3b

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

pkg/webhook/pod_webhook.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ const (
5252
podLabelsPodName = "statefulset.kubernetes.io/pod-name"
5353
podLabelsRedisType = "redis_setup_type"
5454
)
55+
const annotationKeyEnablePodAntiAffinity = "redis.opstreelabs/enable-pod-anti-affinity"
5556

5657
func (v *PodAntiAffiniytMutate) Handle(ctx context.Context, req admission.Request) admission.Response {
5758
logger := v.logger.WithValues("Request.Namespace", req.Namespace, "Request.Name", req.Name)
@@ -66,6 +67,15 @@ func (v *PodAntiAffiniytMutate) Handle(ctx context.Context, req admission.Reques
6667
if !v.isRedisClusterPod(pod) {
6768
return admission.Allowed("")
6869
}
70+
// check if the pod anti-affinity is enabled
71+
annotations := pod.GetAnnotations()
72+
if annotations == nil {
73+
return admission.Allowed("")
74+
}
75+
if enable, ok := annotations[annotationKeyEnablePodAntiAffinity]; !ok || enable != "true" {
76+
logger.V(1).Info("pod anti-affinity is not enabled")
77+
return admission.Allowed("")
78+
}
6979

7080
old := pod.DeepCopy()
7181

0 commit comments

Comments
 (0)