@@ -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.
3233func 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