Skip to content

Commit

Permalink
add karpenter annotations instead of using pod disruption budget (#1019)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tofel authored Jul 9, 2024
1 parent 049fbaf commit 0bcb9f4
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 17 deletions.
1 change: 1 addition & 0 deletions k8s-test-runner/chart/templates/job.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ spec:
{{- toYaml . | nindent 8 }}
{{- end }}
karpenter.sh/do-not-evict: "true"
karpenter.sh/do-not-disrupt: "true"
cluster-autoscaler.kubernetes.io/safe-to-evict: "false"
spec:
serviceAccountName: {{ $.Values.rbac.serviceAccountName }}
Expand Down
19 changes: 2 additions & 17 deletions k8s/environment/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,30 +281,14 @@ func (m *Environment) initApp() error {
Labels: nsLabels,
Namespace: ptr.Ptr(m.Cfg.Namespace),
})

k8s.NewKubeNamespace(m.root, ptr.Ptr("namespace"), &k8s.KubeNamespaceProps{
Metadata: &k8s.ObjectMeta{
Name: ptr.Ptr(m.Cfg.Namespace),
Labels: nsLabels,
Annotations: &defaultNamespaceAnnotations,
},
})
if m.Cfg.PreventPodEviction {
zero := float64(0)
k8s.NewKubePodDisruptionBudget(m.root, ptr.Ptr("pdb"), &k8s.KubePodDisruptionBudgetProps{
Metadata: &k8s.ObjectMeta{
Name: ptr.Ptr("clenv-pdb"),
Namespace: ptr.Ptr(m.Cfg.Namespace),
},
Spec: &k8s.PodDisruptionBudgetSpec{
MaxUnavailable: k8s.IntOrString_FromNumber(&zero),
Selector: &k8s.LabelSelector{
MatchLabels: &map[string]*string{
pkg.NamespaceLabelKey: ptr.Ptr(m.Cfg.Namespace),
},
},
},
})
}
m.CurrentManifest = *m.App.SynthYaml()
// loop retry applying the initial manifest with the namespace and other basics
ctx, cancel := context.WithTimeout(testcontext.Get(m.Cfg.Test), m.Cfg.ReadyCheckData.Timeout)
Expand Down Expand Up @@ -1093,6 +1077,7 @@ func markNotSafeToEvict(preventPodEviction bool, m map[string]string) map[string
}
if preventPodEviction {
m["karpenter.sh/do-not-evict"] = "true"
m["karpenter.sh/do-not-disrupt"] = "true"
m["cluster-autoscaler.kubernetes.io/safe-to-evict"] = "false"
}

Expand Down

0 comments on commit 0bcb9f4

Please sign in to comment.