Skip to content

Commit

Permalink
Compaction job shouldn't add annotation `cluster-autoscaler.kubernete…
Browse files Browse the repository at this point in the history
…s.io/safe-to-evict: false` to compaction pod. (#850)
  • Loading branch information
ishan16696 authored Aug 4, 2024
1 parent 4d64aa8 commit 59c3ed3
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion controllers/compaction/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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
}

0 comments on commit 59c3ed3

Please sign in to comment.