From 3f24d465644427ff3b7ba742ee6a86f34afc75d7 Mon Sep 17 00:00:00 2001 From: Klaus Ma Date: Mon, 13 Mar 2017 22:37:41 +0800 Subject: [PATCH 1/2] Removed err from return value of AddOrUpdateTolerationInPod. --- pkg/api/helpers.go | 6 +++--- pkg/api/v1/helpers.go | 10 +++++----- pkg/controller/daemon/daemoncontroller.go | 10 ++-------- .../admission/defaulttolerationseconds/admission.go | 12 ++---------- 4 files changed, 12 insertions(+), 26 deletions(-) diff --git a/pkg/api/helpers.go b/pkg/api/helpers.go index 4705e11fed5..bc8687863d5 100644 --- a/pkg/api/helpers.go +++ b/pkg/api/helpers.go @@ -467,7 +467,7 @@ const ( // AddOrUpdateTolerationInPod tries to add a toleration to the pod's toleration list. // 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 var newTolerations []Toleration @@ -475,7 +475,7 @@ func AddOrUpdateTolerationInPod(pod *Pod, toleration *Toleration) (bool, error) for i := range podTolerations { if toleration.MatchToleration(&podTolerations[i]) { if Semantic.DeepEqual(toleration, podTolerations[i]) { - return false, nil + return false } newTolerations = append(newTolerations, *toleration) updated = true @@ -490,7 +490,7 @@ func AddOrUpdateTolerationInPod(pod *Pod, toleration *Toleration) (bool, error) } pod.Spec.Tolerations = newTolerations - return true, nil + return true } // MatchToleration checks if the toleration matches tolerationToMatch. Tolerations are unique by , diff --git a/pkg/api/v1/helpers.go b/pkg/api/v1/helpers.go index 83495de0b4d..0308031e172 100644 --- a/pkg/api/v1/helpers.go +++ b/pkg/api/v1/helpers.go @@ -276,9 +276,9 @@ const ( AffinityAnnotationKey string = "scheduler.alpha.kubernetes.io/affinity" ) -// Tries to add a toleration to annotations list. Returns true if something was updated -// false otherwise. -func AddOrUpdateTolerationInPod(pod *Pod, toleration *Toleration) (bool, error) { +// AddOrUpdateTolerationInPod tries to add a toleration to the pod's toleration list. +// Returns true if something was updated, false otherwise. +func AddOrUpdateTolerationInPod(pod *Pod, toleration *Toleration) bool { podTolerations := pod.Spec.Tolerations var newTolerations []Toleration @@ -286,7 +286,7 @@ func AddOrUpdateTolerationInPod(pod *Pod, toleration *Toleration) (bool, error) for i := range podTolerations { if toleration.MatchToleration(&podTolerations[i]) { if api.Semantic.DeepEqual(toleration, podTolerations[i]) { - return false, nil + return false } newTolerations = append(newTolerations, *toleration) updated = true @@ -301,7 +301,7 @@ func AddOrUpdateTolerationInPod(pod *Pod, toleration *Toleration) (bool, error) } pod.Spec.Tolerations = newTolerations - return true, nil + return true } // MatchToleration checks if the toleration matches tolerationToMatch. Tolerations are unique by , diff --git a/pkg/controller/daemon/daemoncontroller.go b/pkg/controller/daemon/daemoncontroller.go index a3a0ae761f9..e2a463a88fb 100644 --- a/pkg/controller/daemon/daemoncontroller.go +++ b/pkg/controller/daemon/daemoncontroller.go @@ -844,27 +844,21 @@ func (dsc *DaemonSetsController) nodeShouldRunDaemonPod(node *v1.Node, ds *exten // Add infinite toleration for taint notReady:NoExecute here // to survive taint-based eviction enforced by NodeController // when node turns not ready. - _, err = v1.AddOrUpdateTolerationInPod(newPod, &v1.Toleration{ + v1.AddOrUpdateTolerationInPod(newPod, &v1.Toleration{ Key: metav1.TaintNodeNotReady, Operator: v1.TolerationOpExists, Effect: v1.TaintEffectNoExecute, }) - if err != nil { - return false, false, false, err - } // 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. - _, err = v1.AddOrUpdateTolerationInPod(newPod, &v1.Toleration{ + v1.AddOrUpdateTolerationInPod(newPod, &v1.Toleration{ Key: metav1.TaintNodeUnreachable, Operator: v1.TolerationOpExists, Effect: v1.TaintEffectNoExecute, }) - if err != nil { - return false, false, false, err - } pods := []*v1.Pod{} diff --git a/plugin/pkg/admission/defaulttolerationseconds/admission.go b/plugin/pkg/admission/defaulttolerationseconds/admission.go index b0f5a8c903a..ec0060121b1 100644 --- a/plugin/pkg/admission/defaulttolerationseconds/admission.go +++ b/plugin/pkg/admission/defaulttolerationseconds/admission.go @@ -97,29 +97,21 @@ func (p *plugin) Admit(attributes admission.Attributes) (err error) { } if !toleratesNodeNotReady { - _, err := api.AddOrUpdateTolerationInPod(pod, &api.Toleration{ + api.AddOrUpdateTolerationInPod(pod, &api.Toleration{ Key: metav1.TaintNodeNotReady, Operator: api.TolerationOpExists, Effect: api.TaintEffectNoExecute, 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 { - _, err := api.AddOrUpdateTolerationInPod(pod, &api.Toleration{ + api.AddOrUpdateTolerationInPod(pod, &api.Toleration{ Key: metav1.TaintNodeUnreachable, Operator: api.TolerationOpExists, Effect: api.TaintEffectNoExecute, 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 } From 98a52fd6b5fd50f45554c4c8f86350d62826fc26 Mon Sep 17 00:00:00 2001 From: Klaus Ma Date: Mon, 13 Mar 2017 22:40:56 +0800 Subject: [PATCH 2/2] generated client-go. --- staging/src/k8s.io/client-go/pkg/api/helpers.go | 6 +++--- staging/src/k8s.io/client-go/pkg/api/v1/helpers.go | 10 +++++----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/staging/src/k8s.io/client-go/pkg/api/helpers.go b/staging/src/k8s.io/client-go/pkg/api/helpers.go index 4705e11fed5..bc8687863d5 100644 --- a/staging/src/k8s.io/client-go/pkg/api/helpers.go +++ b/staging/src/k8s.io/client-go/pkg/api/helpers.go @@ -467,7 +467,7 @@ const ( // AddOrUpdateTolerationInPod tries to add a toleration to the pod's toleration list. // 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 var newTolerations []Toleration @@ -475,7 +475,7 @@ func AddOrUpdateTolerationInPod(pod *Pod, toleration *Toleration) (bool, error) for i := range podTolerations { if toleration.MatchToleration(&podTolerations[i]) { if Semantic.DeepEqual(toleration, podTolerations[i]) { - return false, nil + return false } newTolerations = append(newTolerations, *toleration) updated = true @@ -490,7 +490,7 @@ func AddOrUpdateTolerationInPod(pod *Pod, toleration *Toleration) (bool, error) } pod.Spec.Tolerations = newTolerations - return true, nil + return true } // MatchToleration checks if the toleration matches tolerationToMatch. Tolerations are unique by , diff --git a/staging/src/k8s.io/client-go/pkg/api/v1/helpers.go b/staging/src/k8s.io/client-go/pkg/api/v1/helpers.go index 01f4ef4706b..340ba63a4df 100644 --- a/staging/src/k8s.io/client-go/pkg/api/v1/helpers.go +++ b/staging/src/k8s.io/client-go/pkg/api/v1/helpers.go @@ -276,9 +276,9 @@ const ( AffinityAnnotationKey string = "scheduler.alpha.kubernetes.io/affinity" ) -// Tries to add a toleration to annotations list. Returns true if something was updated -// false otherwise. -func AddOrUpdateTolerationInPod(pod *Pod, toleration *Toleration) (bool, error) { +// AddOrUpdateTolerationInPod tries to add a toleration to the pod's toleration list. +// Returns true if something was updated, false otherwise. +func AddOrUpdateTolerationInPod(pod *Pod, toleration *Toleration) bool { podTolerations := pod.Spec.Tolerations var newTolerations []Toleration @@ -286,7 +286,7 @@ func AddOrUpdateTolerationInPod(pod *Pod, toleration *Toleration) (bool, error) for i := range podTolerations { if toleration.MatchToleration(&podTolerations[i]) { if api.Semantic.DeepEqual(toleration, podTolerations[i]) { - return false, nil + return false } newTolerations = append(newTolerations, *toleration) updated = true @@ -301,7 +301,7 @@ func AddOrUpdateTolerationInPod(pod *Pod, toleration *Toleration) (bool, error) } pod.Spec.Tolerations = newTolerations - return true, nil + return true } // MatchToleration checks if the toleration matches tolerationToMatch. Tolerations are unique by ,