Commit e3e44b77 authored by Kubernetes Submit Queue's avatar Kubernetes Submit Queue Committed by GitHub

Merge pull request #42964 from k82cn/update_defalt_toleration_sec

Automatic merge from submit-queue (batch tested with PRs 44084, 42964) Updated AddOrUpdateTolerationInPod to return bool only. Updated AddOrUpdateTolerationInPod to return bool only, as there's no case to generate error (the error was used for annotation, it'll not return error after moving to field); and also update admission & daemonset accordingly.
parents 586e6d03 98a52fd6
...@@ -494,7 +494,7 @@ func GetTolerationsFromPodAnnotations(annotations map[string]string) ([]Tolerati ...@@ -494,7 +494,7 @@ func GetTolerationsFromPodAnnotations(annotations map[string]string) ([]Tolerati
// AddOrUpdateTolerationInPod tries to add a toleration to the pod's toleration list. // AddOrUpdateTolerationInPod tries to add a toleration to the pod's toleration list.
// Returns true if something was updated, false otherwise. // Returns true if something was updated, false otherwise.
func AddOrUpdateTolerationInPod(pod *Pod, toleration *Toleration) (bool, error) { func AddOrUpdateTolerationInPod(pod *Pod, toleration *Toleration) bool {
podTolerations := pod.Spec.Tolerations podTolerations := pod.Spec.Tolerations
var newTolerations []Toleration var newTolerations []Toleration
...@@ -502,7 +502,7 @@ func AddOrUpdateTolerationInPod(pod *Pod, toleration *Toleration) (bool, error) ...@@ -502,7 +502,7 @@ func AddOrUpdateTolerationInPod(pod *Pod, toleration *Toleration) (bool, error)
for i := range podTolerations { for i := range podTolerations {
if toleration.MatchToleration(&podTolerations[i]) { if toleration.MatchToleration(&podTolerations[i]) {
if Semantic.DeepEqual(toleration, podTolerations[i]) { if Semantic.DeepEqual(toleration, podTolerations[i]) {
return false, nil return false
} }
newTolerations = append(newTolerations, *toleration) newTolerations = append(newTolerations, *toleration)
updated = true updated = true
...@@ -517,7 +517,7 @@ func AddOrUpdateTolerationInPod(pod *Pod, toleration *Toleration) (bool, error) ...@@ -517,7 +517,7 @@ func AddOrUpdateTolerationInPod(pod *Pod, toleration *Toleration) (bool, error)
} }
pod.Spec.Tolerations = newTolerations pod.Spec.Tolerations = newTolerations
return true, nil return true
} }
// MatchToleration checks if the toleration matches tolerationToMatch. Tolerations are unique by <key,effect,operator,value>, // MatchToleration checks if the toleration matches tolerationToMatch. Tolerations are unique by <key,effect,operator,value>,
......
...@@ -276,9 +276,9 @@ const ( ...@@ -276,9 +276,9 @@ const (
AffinityAnnotationKey string = "scheduler.alpha.kubernetes.io/affinity" AffinityAnnotationKey string = "scheduler.alpha.kubernetes.io/affinity"
) )
// Tries to add a toleration to annotations list. Returns true if something was updated // AddOrUpdateTolerationInPod tries to add a toleration to the pod's toleration list.
// false otherwise. // Returns true if something was updated, false otherwise.
func AddOrUpdateTolerationInPod(pod *Pod, toleration *Toleration) (bool, error) { func AddOrUpdateTolerationInPod(pod *Pod, toleration *Toleration) bool {
podTolerations := pod.Spec.Tolerations podTolerations := pod.Spec.Tolerations
var newTolerations []Toleration var newTolerations []Toleration
...@@ -286,7 +286,7 @@ func AddOrUpdateTolerationInPod(pod *Pod, toleration *Toleration) (bool, error) ...@@ -286,7 +286,7 @@ func AddOrUpdateTolerationInPod(pod *Pod, toleration *Toleration) (bool, error)
for i := range podTolerations { for i := range podTolerations {
if toleration.MatchToleration(&podTolerations[i]) { if toleration.MatchToleration(&podTolerations[i]) {
if api.Semantic.DeepEqual(toleration, podTolerations[i]) { if api.Semantic.DeepEqual(toleration, podTolerations[i]) {
return false, nil return false
} }
newTolerations = append(newTolerations, *toleration) newTolerations = append(newTolerations, *toleration)
updated = true updated = true
...@@ -301,7 +301,7 @@ func AddOrUpdateTolerationInPod(pod *Pod, toleration *Toleration) (bool, error) ...@@ -301,7 +301,7 @@ func AddOrUpdateTolerationInPod(pod *Pod, toleration *Toleration) (bool, error)
} }
pod.Spec.Tolerations = newTolerations pod.Spec.Tolerations = newTolerations
return true, nil return true
} }
// MatchToleration checks if the toleration matches tolerationToMatch. Tolerations are unique by <key,effect,operator,value>, // MatchToleration checks if the toleration matches tolerationToMatch. Tolerations are unique by <key,effect,operator,value>,
......
...@@ -858,27 +858,21 @@ func (dsc *DaemonSetsController) nodeShouldRunDaemonPod(node *v1.Node, ds *exten ...@@ -858,27 +858,21 @@ func (dsc *DaemonSetsController) nodeShouldRunDaemonPod(node *v1.Node, ds *exten
// Add infinite toleration for taint notReady:NoExecute here // Add infinite toleration for taint notReady:NoExecute here
// to survive taint-based eviction enforced by NodeController // to survive taint-based eviction enforced by NodeController
// when node turns not ready. // when node turns not ready.
_, err = v1.AddOrUpdateTolerationInPod(newPod, &v1.Toleration{ v1.AddOrUpdateTolerationInPod(newPod, &v1.Toleration{
Key: metav1.TaintNodeNotReady, Key: metav1.TaintNodeNotReady,
Operator: v1.TolerationOpExists, Operator: v1.TolerationOpExists,
Effect: v1.TaintEffectNoExecute, Effect: v1.TaintEffectNoExecute,
}) })
if err != nil {
return false, false, false, err
}
// DaemonSet pods shouldn't be deleted by NodeController in case of node problems. // DaemonSet pods shouldn't be deleted by NodeController in case of node problems.
// Add infinite toleration for taint unreachable:NoExecute here // Add infinite toleration for taint unreachable:NoExecute here
// to survive taint-based eviction enforced by NodeController // to survive taint-based eviction enforced by NodeController
// when node turns unreachable. // when node turns unreachable.
_, err = v1.AddOrUpdateTolerationInPod(newPod, &v1.Toleration{ v1.AddOrUpdateTolerationInPod(newPod, &v1.Toleration{
Key: metav1.TaintNodeUnreachable, Key: metav1.TaintNodeUnreachable,
Operator: v1.TolerationOpExists, Operator: v1.TolerationOpExists,
Effect: v1.TaintEffectNoExecute, Effect: v1.TaintEffectNoExecute,
}) })
if err != nil {
return false, false, false, err
}
pods := []*v1.Pod{} pods := []*v1.Pod{}
......
...@@ -97,29 +97,21 @@ func (p *plugin) Admit(attributes admission.Attributes) (err error) { ...@@ -97,29 +97,21 @@ func (p *plugin) Admit(attributes admission.Attributes) (err error) {
} }
if !toleratesNodeNotReady { if !toleratesNodeNotReady {
_, err := api.AddOrUpdateTolerationInPod(pod, &api.Toleration{ api.AddOrUpdateTolerationInPod(pod, &api.Toleration{
Key: metav1.TaintNodeNotReady, Key: metav1.TaintNodeNotReady,
Operator: api.TolerationOpExists, Operator: api.TolerationOpExists,
Effect: api.TaintEffectNoExecute, Effect: api.TaintEffectNoExecute,
TolerationSeconds: defaultNotReadyTolerationSeconds, TolerationSeconds: defaultNotReadyTolerationSeconds,
}) })
if err != nil {
return admission.NewForbidden(attributes,
fmt.Errorf("failed to add default tolerations for taints `notReady:NoExecute` and `unreachable:NoExecute`, err: %v", err))
}
} }
if !toleratesNodeUnreachable { if !toleratesNodeUnreachable {
_, err := api.AddOrUpdateTolerationInPod(pod, &api.Toleration{ api.AddOrUpdateTolerationInPod(pod, &api.Toleration{
Key: metav1.TaintNodeUnreachable, Key: metav1.TaintNodeUnreachable,
Operator: api.TolerationOpExists, Operator: api.TolerationOpExists,
Effect: api.TaintEffectNoExecute, Effect: api.TaintEffectNoExecute,
TolerationSeconds: defaultUnreachableTolerationSeconds, TolerationSeconds: defaultUnreachableTolerationSeconds,
}) })
if err != nil {
return admission.NewForbidden(attributes,
fmt.Errorf("failed to add default tolerations for taints `notReady:NoExecute` and `unreachable:NoExecute`, err: %v", err))
}
} }
return nil return nil
} }
...@@ -494,7 +494,7 @@ func GetTolerationsFromPodAnnotations(annotations map[string]string) ([]Tolerati ...@@ -494,7 +494,7 @@ func GetTolerationsFromPodAnnotations(annotations map[string]string) ([]Tolerati
// AddOrUpdateTolerationInPod tries to add a toleration to the pod's toleration list. // AddOrUpdateTolerationInPod tries to add a toleration to the pod's toleration list.
// Returns true if something was updated, false otherwise. // Returns true if something was updated, false otherwise.
func AddOrUpdateTolerationInPod(pod *Pod, toleration *Toleration) (bool, error) { func AddOrUpdateTolerationInPod(pod *Pod, toleration *Toleration) bool {
podTolerations := pod.Spec.Tolerations podTolerations := pod.Spec.Tolerations
var newTolerations []Toleration var newTolerations []Toleration
...@@ -502,7 +502,7 @@ func AddOrUpdateTolerationInPod(pod *Pod, toleration *Toleration) (bool, error) ...@@ -502,7 +502,7 @@ func AddOrUpdateTolerationInPod(pod *Pod, toleration *Toleration) (bool, error)
for i := range podTolerations { for i := range podTolerations {
if toleration.MatchToleration(&podTolerations[i]) { if toleration.MatchToleration(&podTolerations[i]) {
if Semantic.DeepEqual(toleration, podTolerations[i]) { if Semantic.DeepEqual(toleration, podTolerations[i]) {
return false, nil return false
} }
newTolerations = append(newTolerations, *toleration) newTolerations = append(newTolerations, *toleration)
updated = true updated = true
...@@ -517,7 +517,7 @@ func AddOrUpdateTolerationInPod(pod *Pod, toleration *Toleration) (bool, error) ...@@ -517,7 +517,7 @@ func AddOrUpdateTolerationInPod(pod *Pod, toleration *Toleration) (bool, error)
} }
pod.Spec.Tolerations = newTolerations pod.Spec.Tolerations = newTolerations
return true, nil return true
} }
// MatchToleration checks if the toleration matches tolerationToMatch. Tolerations are unique by <key,effect,operator,value>, // MatchToleration checks if the toleration matches tolerationToMatch. Tolerations are unique by <key,effect,operator,value>,
......
...@@ -276,9 +276,9 @@ const ( ...@@ -276,9 +276,9 @@ const (
AffinityAnnotationKey string = "scheduler.alpha.kubernetes.io/affinity" AffinityAnnotationKey string = "scheduler.alpha.kubernetes.io/affinity"
) )
// Tries to add a toleration to annotations list. Returns true if something was updated // AddOrUpdateTolerationInPod tries to add a toleration to the pod's toleration list.
// false otherwise. // Returns true if something was updated, false otherwise.
func AddOrUpdateTolerationInPod(pod *Pod, toleration *Toleration) (bool, error) { func AddOrUpdateTolerationInPod(pod *Pod, toleration *Toleration) bool {
podTolerations := pod.Spec.Tolerations podTolerations := pod.Spec.Tolerations
var newTolerations []Toleration var newTolerations []Toleration
...@@ -286,7 +286,7 @@ func AddOrUpdateTolerationInPod(pod *Pod, toleration *Toleration) (bool, error) ...@@ -286,7 +286,7 @@ func AddOrUpdateTolerationInPod(pod *Pod, toleration *Toleration) (bool, error)
for i := range podTolerations { for i := range podTolerations {
if toleration.MatchToleration(&podTolerations[i]) { if toleration.MatchToleration(&podTolerations[i]) {
if api.Semantic.DeepEqual(toleration, podTolerations[i]) { if api.Semantic.DeepEqual(toleration, podTolerations[i]) {
return false, nil return false
} }
newTolerations = append(newTolerations, *toleration) newTolerations = append(newTolerations, *toleration)
updated = true updated = true
...@@ -301,7 +301,7 @@ func AddOrUpdateTolerationInPod(pod *Pod, toleration *Toleration) (bool, error) ...@@ -301,7 +301,7 @@ func AddOrUpdateTolerationInPod(pod *Pod, toleration *Toleration) (bool, error)
} }
pod.Spec.Tolerations = newTolerations pod.Spec.Tolerations = newTolerations
return true, nil return true
} }
// MatchToleration checks if the toleration matches tolerationToMatch. Tolerations are unique by <key,effect,operator,value>, // MatchToleration checks if the toleration matches tolerationToMatch. Tolerations are unique by <key,effect,operator,value>,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment