From 59c3ed328187979c51748a659c555393d8058397 Mon Sep 17 00:00:00 2001 From: Ishan Tyagi <42602577+ishan16696@users.noreply.github.com> Date: Sun, 4 Aug 2024 21:37:18 +0530 Subject: [PATCH] Compaction job shouldn't add annotation `cluster-autoscaler.kubernetes.io/safe-to-evict: false` to compaction pod. (#850) --- controllers/compaction/reconciler.go | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/controllers/compaction/reconciler.go b/controllers/compaction/reconciler.go index de44655c8..feb0baf2d 100644 --- a/controllers/compaction/reconciler.go +++ b/controllers/compaction/reconciler.go @@ -47,6 +47,10 @@ import ( const ( // DefaultETCDQuota is the default etcd quota. DefaultETCDQuota = 8 * 1024 * 1024 * 1024 // 8Gi + + // SafeToEvictKey - annotation that ignores constraints to evict a pod like not being replicated, being on + // kube-system namespace or having a local storage if set to "false". + SafeToEvictKey = "cluster-autoscaler.kubernetes.io/safe-to-evict" ) // Reconciler reconciles compaction jobs for Etcd resources. @@ -293,7 +297,7 @@ func (r *Reconciler) createCompactionJob(ctx context.Context, logger logr.Logger BackoffLimit: pointer.Int32(0), Template: v1.PodTemplateSpec{ ObjectMeta: metav1.ObjectMeta{ - Annotations: etcd.Spec.Annotations, + Annotations: getEtcdCompactionAnnotations(etcd.Spec.Annotations), Labels: getLabels(etcd), }, Spec: v1.PodSpec{ @@ -494,3 +498,16 @@ func getCompactionJobArgs(etcd *druidv1alpha1.Etcd, metricsScrapeWaitDuration st return command } + +func getEtcdCompactionAnnotations(etcdAnnotations map[string]string) map[string]string { + etcdCompactionAnnotations := make(map[string]string) + + for key, value := range etcdAnnotations { + // Do not add annotation: `cluster-autoscaler.kubernetes.io/safe-to-evict: "false"` to compaction job's pod template. + if key == SafeToEvictKey && value == "false" { + continue + } + etcdCompactionAnnotations[key] = value + } + return etcdCompactionAnnotations +}