mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-25 12:43:23 +00:00
Merge pull request #45349 from gmarek/taint_immunity
Automatic merge from submit-queue (batch tested with PRs 45218, 45349) Make Daemons tolerate NoExecute taints correctly Fix #45348 @kubernetes/sig-scheduling-pr-reviews
This commit is contained in:
commit
b9f340d922
@ -203,10 +203,10 @@ func NodeSelectorRequirementsAsSelector(nsm []v1.NodeSelectorRequirement) (label
|
|||||||
return selector, nil
|
return selector, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddOrUpdateTolerationInPod tries to add a toleration to the pod's toleration list.
|
// AddOrUpdateTolerationInPodSpec tries to add a toleration to the toleration list in PodSpec.
|
||||||
// Returns true if something was updated, false otherwise.
|
// Returns true if something was updated, false otherwise.
|
||||||
func AddOrUpdateTolerationInPod(pod *v1.Pod, toleration *v1.Toleration) bool {
|
func AddOrUpdateTolerationInPodSpec(spec *v1.PodSpec, toleration *v1.Toleration) bool {
|
||||||
podTolerations := pod.Spec.Tolerations
|
podTolerations := spec.Tolerations
|
||||||
|
|
||||||
var newTolerations []v1.Toleration
|
var newTolerations []v1.Toleration
|
||||||
updated := false
|
updated := false
|
||||||
@ -227,10 +227,16 @@ func AddOrUpdateTolerationInPod(pod *v1.Pod, toleration *v1.Toleration) bool {
|
|||||||
newTolerations = append(newTolerations, *toleration)
|
newTolerations = append(newTolerations, *toleration)
|
||||||
}
|
}
|
||||||
|
|
||||||
pod.Spec.Tolerations = newTolerations
|
spec.Tolerations = newTolerations
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AddOrUpdateTolerationInPod tries to add a toleration to the pod's toleration list.
|
||||||
|
// Returns true if something was updated, false otherwise.
|
||||||
|
func AddOrUpdateTolerationInPod(pod *v1.Pod, toleration *v1.Toleration) bool {
|
||||||
|
return AddOrUpdateTolerationInPodSpec(&pod.Spec, toleration)
|
||||||
|
}
|
||||||
|
|
||||||
// TolerationsTolerateTaint checks if taint is tolerated by any of the tolerations.
|
// TolerationsTolerateTaint checks if taint is tolerated by any of the tolerations.
|
||||||
func TolerationsTolerateTaint(tolerations []v1.Toleration, taint *v1.Taint) bool {
|
func TolerationsTolerateTaint(tolerations []v1.Toleration, taint *v1.Taint) bool {
|
||||||
for i := range tolerations {
|
for i := range tolerations {
|
||||||
|
@ -15,6 +15,7 @@ go_library(
|
|||||||
deps = [
|
deps = [
|
||||||
"//pkg/api:go_default_library",
|
"//pkg/api:go_default_library",
|
||||||
"//pkg/api/v1:go_default_library",
|
"//pkg/api/v1:go_default_library",
|
||||||
|
"//pkg/api/v1/helper:go_default_library",
|
||||||
"//pkg/api/v1/pod:go_default_library",
|
"//pkg/api/v1/pod:go_default_library",
|
||||||
"//pkg/apis/extensions/v1beta1:go_default_library",
|
"//pkg/apis/extensions/v1beta1:go_default_library",
|
||||||
"//pkg/util/labels:go_default_library",
|
"//pkg/util/labels:go_default_library",
|
||||||
|
@ -22,16 +22,37 @@ import (
|
|||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
"k8s.io/kubernetes/pkg/api"
|
"k8s.io/kubernetes/pkg/api"
|
||||||
"k8s.io/kubernetes/pkg/api/v1"
|
"k8s.io/kubernetes/pkg/api/v1"
|
||||||
|
v1helper "k8s.io/kubernetes/pkg/api/v1/helper"
|
||||||
podutil "k8s.io/kubernetes/pkg/api/v1/pod"
|
podutil "k8s.io/kubernetes/pkg/api/v1/pod"
|
||||||
extensions "k8s.io/kubernetes/pkg/apis/extensions/v1beta1"
|
extensions "k8s.io/kubernetes/pkg/apis/extensions/v1beta1"
|
||||||
labelsutil "k8s.io/kubernetes/pkg/util/labels"
|
labelsutil "k8s.io/kubernetes/pkg/util/labels"
|
||||||
)
|
)
|
||||||
|
|
||||||
// GetPodTemplateWithHash returns copy of provided template with additional
|
// GetPodTemplateWithHash returns copy of provided template with additional
|
||||||
// label which contains hash of provided template
|
// label which contains hash of provided template and sets default daemon tolerations.
|
||||||
func GetPodTemplateWithGeneration(template v1.PodTemplateSpec, generation int64) v1.PodTemplateSpec {
|
func GetPodTemplateWithGeneration(template v1.PodTemplateSpec, generation int64) v1.PodTemplateSpec {
|
||||||
obj, _ := api.Scheme.DeepCopy(template)
|
obj, _ := api.Scheme.DeepCopy(template)
|
||||||
newTemplate := obj.(v1.PodTemplateSpec)
|
newTemplate := obj.(v1.PodTemplateSpec)
|
||||||
|
// DaemonSet pods shouldn't be deleted by NodeController in case of node problems.
|
||||||
|
// Add infinite toleration for taint notReady:NoExecute here
|
||||||
|
// to survive taint-based eviction enforced by NodeController
|
||||||
|
// when node turns not ready.
|
||||||
|
v1helper.AddOrUpdateTolerationInPodSpec(&newTemplate.Spec, &v1.Toleration{
|
||||||
|
Key: metav1.TaintNodeNotReady,
|
||||||
|
Operator: v1.TolerationOpExists,
|
||||||
|
Effect: v1.TaintEffectNoExecute,
|
||||||
|
})
|
||||||
|
|
||||||
|
// DaemonSet pods shouldn't be deleted by NodeController in case of node problems.
|
||||||
|
// Add infinite toleration for taint unreachable:NoExecute here
|
||||||
|
// to survive taint-based eviction enforced by NodeController
|
||||||
|
// when node turns unreachable.
|
||||||
|
v1helper.AddOrUpdateTolerationInPodSpec(&newTemplate.Spec, &v1.Toleration{
|
||||||
|
Key: metav1.TaintNodeUnreachable,
|
||||||
|
Operator: v1.TolerationOpExists,
|
||||||
|
Effect: v1.TaintEffectNoExecute,
|
||||||
|
})
|
||||||
|
|
||||||
templateGenerationStr := fmt.Sprint(generation)
|
templateGenerationStr := fmt.Sprint(generation)
|
||||||
newTemplate.ObjectMeta.Labels = labelsutil.CloneAndAddLabel(
|
newTemplate.ObjectMeta.Labels = labelsutil.CloneAndAddLabel(
|
||||||
template.ObjectMeta.Labels,
|
template.ObjectMeta.Labels,
|
||||||
|
Loading…
Reference in New Issue
Block a user