Skip to content

Commit 6cfd7be

Browse files
authored
Merge pull request kubernetes#65981 from oracle/for/upstream/master/jah/reduce-log-spam
Only attempt to register cloud nodes on update with the cloud taint
2 parents b5f2147 + 9b3ab29 commit 6cfd7be

File tree

1 file changed

+22
-9
lines changed

1 file changed

+22
-9
lines changed

pkg/controller/cloud/node_controller.go

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@ import (
2222
"fmt"
2323
"time"
2424

25-
"k8s.io/klog"
26-
27-
"k8s.io/api/core/v1"
25+
v1 "k8s.io/api/core/v1"
2826
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2927
"k8s.io/apimachinery/pkg/types"
3028
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
@@ -37,6 +35,7 @@ import (
3735
"k8s.io/client-go/tools/record"
3836
clientretry "k8s.io/client-go/util/retry"
3937
cloudprovider "k8s.io/cloud-provider"
38+
"k8s.io/klog"
4039
kubeletapis "k8s.io/kubernetes/pkg/kubelet/apis"
4140
schedulerapi "k8s.io/kubernetes/pkg/scheduler/api"
4241
nodeutil "k8s.io/kubernetes/pkg/util/node"
@@ -199,14 +198,22 @@ func (cnc *CloudNodeController) updateNodeAddress(node *v1.Node, instances cloud
199198
}
200199

201200
func (cnc *CloudNodeController) UpdateCloudNode(_, newObj interface{}) {
202-
if _, ok := newObj.(*v1.Node); !ok {
201+
node, ok := newObj.(*v1.Node)
202+
if !ok {
203203
utilruntime.HandleError(fmt.Errorf("unexpected object type: %v", newObj))
204204
return
205205
}
206-
cnc.AddCloudNode(newObj)
206+
207+
cloudTaint := getCloudTaint(node.Spec.Taints)
208+
if cloudTaint == nil {
209+
// The node has already been initialized so nothing to do.
210+
return
211+
}
212+
213+
cnc.initializeNode(node)
207214
}
208215

209-
// This processes nodes that were added into the cluster, and cloud initialize them if appropriate
216+
// AddCloudNode handles initializing new nodes registered with the cloud taint.
210217
func (cnc *CloudNodeController) AddCloudNode(obj interface{}) {
211218
node := obj.(*v1.Node)
212219

@@ -216,6 +223,12 @@ func (cnc *CloudNodeController) AddCloudNode(obj interface{}) {
216223
return
217224
}
218225

226+
cnc.initializeNode(node)
227+
}
228+
229+
// This processes nodes that were added into the cluster, and cloud initialize them if appropriate
230+
func (cnc *CloudNodeController) initializeNode(node *v1.Node) {
231+
219232
instances, ok := cnc.cloud.Instances()
220233
if !ok {
221234
utilruntime.HandleError(fmt.Errorf("failed to get instances from cloud provider"))
@@ -290,7 +303,7 @@ func (cnc *CloudNodeController) AddCloudNode(obj interface{}) {
290303
}
291304
}
292305

293-
curNode.Spec.Taints = excludeTaintFromList(curNode.Spec.Taints, *cloudTaint)
306+
curNode.Spec.Taints = excludeCloudTaint(curNode.Spec.Taints)
294307

295308
_, err = cnc.kubeClient.CoreV1().Nodes().Update(curNode)
296309
if err != nil {
@@ -318,10 +331,10 @@ func getCloudTaint(taints []v1.Taint) *v1.Taint {
318331
return nil
319332
}
320333

321-
func excludeTaintFromList(taints []v1.Taint, toExclude v1.Taint) []v1.Taint {
334+
func excludeCloudTaint(taints []v1.Taint) []v1.Taint {
322335
newTaints := []v1.Taint{}
323336
for _, taint := range taints {
324-
if toExclude.MatchTaint(&taint) {
337+
if taint.Key == schedulerapi.TaintExternalCloudProvider {
325338
continue
326339
}
327340
newTaints = append(newTaints, taint)

0 commit comments

Comments
 (0)