mirror of
				https://github.com/optim-enterprises-bv/kubernetes.git
				synced 2025-11-03 19:58:17 +00:00 
			
		
		
		
	Only attempt to register cloud nodes on update with the cloud taint
This commit is contained in:
		
				
					committed by
					
						
						Josh Horwitz
					
				
			
			
				
	
			
			
			
						parent
						
							c6a6c65e32
						
					
				
				
					commit
					9b3ab29cc9
				
			@@ -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)
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user