Skip to content

Commit b9f340d

Browse files
author
Kubernetes Submit Queue
authored
Merge pull request kubernetes#45349 from gmarek/taint_immunity
Automatic merge from submit-queue (batch tested with PRs 45218, 45349) Make Daemons tolerate NoExecute taints correctly Fix kubernetes#45348 @kubernetes/sig-scheduling-pr-reviews
2 parents 8f9216a + f371c14 commit b9f340d

File tree

3 files changed

+33
-5
lines changed

3 files changed

+33
-5
lines changed

pkg/api/v1/helper/helpers.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -203,10 +203,10 @@ func NodeSelectorRequirementsAsSelector(nsm []v1.NodeSelectorRequirement) (label
203203
return selector, nil
204204
}
205205

206-
// AddOrUpdateTolerationInPod tries to add a toleration to the pod's toleration list.
206+
// AddOrUpdateTolerationInPodSpec tries to add a toleration to the toleration list in PodSpec.
207207
// Returns true if something was updated, false otherwise.
208-
func AddOrUpdateTolerationInPod(pod *v1.Pod, toleration *v1.Toleration) bool {
209-
podTolerations := pod.Spec.Tolerations
208+
func AddOrUpdateTolerationInPodSpec(spec *v1.PodSpec, toleration *v1.Toleration) bool {
209+
podTolerations := spec.Tolerations
210210

211211
var newTolerations []v1.Toleration
212212
updated := false
@@ -227,10 +227,16 @@ func AddOrUpdateTolerationInPod(pod *v1.Pod, toleration *v1.Toleration) bool {
227227
newTolerations = append(newTolerations, *toleration)
228228
}
229229

230-
pod.Spec.Tolerations = newTolerations
230+
spec.Tolerations = newTolerations
231231
return true
232232
}
233233

234+
// AddOrUpdateTolerationInPod tries to add a toleration to the pod's toleration list.
235+
// Returns true if something was updated, false otherwise.
236+
func AddOrUpdateTolerationInPod(pod *v1.Pod, toleration *v1.Toleration) bool {
237+
return AddOrUpdateTolerationInPodSpec(&pod.Spec, toleration)
238+
}
239+
234240
// TolerationsTolerateTaint checks if taint is tolerated by any of the tolerations.
235241
func TolerationsTolerateTaint(tolerations []v1.Toleration, taint *v1.Taint) bool {
236242
for i := range tolerations {

pkg/controller/daemon/util/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ go_library(
1515
deps = [
1616
"//pkg/api:go_default_library",
1717
"//pkg/api/v1:go_default_library",
18+
"//pkg/api/v1/helper:go_default_library",
1819
"//pkg/api/v1/pod:go_default_library",
1920
"//pkg/apis/extensions/v1beta1:go_default_library",
2021
"//pkg/util/labels:go_default_library",

pkg/controller/daemon/util/daemonset_util.go

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,37 @@ import (
2222
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2323
"k8s.io/kubernetes/pkg/api"
2424
"k8s.io/kubernetes/pkg/api/v1"
25+
v1helper "k8s.io/kubernetes/pkg/api/v1/helper"
2526
podutil "k8s.io/kubernetes/pkg/api/v1/pod"
2627
extensions "k8s.io/kubernetes/pkg/apis/extensions/v1beta1"
2728
labelsutil "k8s.io/kubernetes/pkg/util/labels"
2829
)
2930

3031
// GetPodTemplateWithHash returns copy of provided template with additional
31-
// label which contains hash of provided template
32+
// label which contains hash of provided template and sets default daemon tolerations.
3233
func GetPodTemplateWithGeneration(template v1.PodTemplateSpec, generation int64) v1.PodTemplateSpec {
3334
obj, _ := api.Scheme.DeepCopy(template)
3435
newTemplate := obj.(v1.PodTemplateSpec)
36+
// DaemonSet pods shouldn't be deleted by NodeController in case of node problems.
37+
// Add infinite toleration for taint notReady:NoExecute here
38+
// to survive taint-based eviction enforced by NodeController
39+
// when node turns not ready.
40+
v1helper.AddOrUpdateTolerationInPodSpec(&newTemplate.Spec, &v1.Toleration{
41+
Key: metav1.TaintNodeNotReady,
42+
Operator: v1.TolerationOpExists,
43+
Effect: v1.TaintEffectNoExecute,
44+
})
45+
46+
// DaemonSet pods shouldn't be deleted by NodeController in case of node problems.
47+
// Add infinite toleration for taint unreachable:NoExecute here
48+
// to survive taint-based eviction enforced by NodeController
49+
// when node turns unreachable.
50+
v1helper.AddOrUpdateTolerationInPodSpec(&newTemplate.Spec, &v1.Toleration{
51+
Key: metav1.TaintNodeUnreachable,
52+
Operator: v1.TolerationOpExists,
53+
Effect: v1.TaintEffectNoExecute,
54+
})
55+
3556
templateGenerationStr := fmt.Sprint(generation)
3657
newTemplate.ObjectMeta.Labels = labelsutil.CloneAndAddLabel(
3758
template.ObjectMeta.Labels,

0 commit comments

Comments
 (0)