Merge pull request #65981 from oracle/for/upstream/master/jah/reduce-log-spam

Only attempt to register cloud nodes on update with the cloud taint
pull/564/head
Kubernetes Prow Robot 2019-01-26 06:20:28 -08:00 committed by GitHub
commit 6cfd7beb86
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 22 additions and 9 deletions

View File

@ -22,9 +22,7 @@ import (
"fmt"
"time"
"k8s.io/klog"
"k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
@ -37,6 +35,7 @@ import (
"k8s.io/client-go/tools/record"
clientretry "k8s.io/client-go/util/retry"
cloudprovider "k8s.io/cloud-provider"
"k8s.io/klog"
kubeletapis "k8s.io/kubernetes/pkg/kubelet/apis"
schedulerapi "k8s.io/kubernetes/pkg/scheduler/api"
nodeutil "k8s.io/kubernetes/pkg/util/node"
@ -199,14 +198,22 @@ func (cnc *CloudNodeController) updateNodeAddress(node *v1.Node, instances cloud
}
func (cnc *CloudNodeController) UpdateCloudNode(_, newObj interface{}) {
if _, ok := newObj.(*v1.Node); !ok {
node, ok := newObj.(*v1.Node)
if !ok {
utilruntime.HandleError(fmt.Errorf("unexpected object type: %v", newObj))
return
}
cnc.AddCloudNode(newObj)
cloudTaint := getCloudTaint(node.Spec.Taints)
if cloudTaint == nil {
// The node has already been initialized so nothing to do.
return
}
cnc.initializeNode(node)
}
// This processes nodes that were added into the cluster, and cloud initialize them if appropriate
// AddCloudNode handles initializing new nodes registered with the cloud taint.
func (cnc *CloudNodeController) AddCloudNode(obj interface{}) {
node := obj.(*v1.Node)
@ -216,6 +223,12 @@ func (cnc *CloudNodeController) AddCloudNode(obj interface{}) {
return
}
cnc.initializeNode(node)
}
// This processes nodes that were added into the cluster, and cloud initialize them if appropriate
func (cnc *CloudNodeController) initializeNode(node *v1.Node) {
instances, ok := cnc.cloud.Instances()
if !ok {
utilruntime.HandleError(fmt.Errorf("failed to get instances from cloud provider"))
@ -290,7 +303,7 @@ func (cnc *CloudNodeController) AddCloudNode(obj interface{}) {
}
}
curNode.Spec.Taints = excludeTaintFromList(curNode.Spec.Taints, *cloudTaint)
curNode.Spec.Taints = excludeCloudTaint(curNode.Spec.Taints)
_, err = cnc.kubeClient.CoreV1().Nodes().Update(curNode)
if err != nil {
@ -318,10 +331,10 @@ func getCloudTaint(taints []v1.Taint) *v1.Taint {
return nil
}
func excludeTaintFromList(taints []v1.Taint, toExclude v1.Taint) []v1.Taint {
func excludeCloudTaint(taints []v1.Taint) []v1.Taint {
newTaints := []v1.Taint{}
for _, taint := range taints {
if toExclude.MatchTaint(&taint) {
if taint.Key == schedulerapi.TaintExternalCloudProvider {
continue
}
newTaints = append(newTaints, taint)