github.com/verrazzano/verrazzano@v1.7.0/pkg/k8s/node/node.go (about) 1 // Copyright (c) 2022, 2023, Oracle and/or its affiliates. 2 // Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. 3 4 package node 5 6 import ( 7 "context" 8 v1 "k8s.io/api/core/v1" 9 "sigs.k8s.io/controller-runtime/pkg/client" 10 ) 11 12 const ( 13 controlPlaneTaint = "node-role.kubernetes.io/control-plane" 14 masterTaint = "node-role.kubernetes.io/master" 15 loadBalancerTaint = "node.kubernetes.io/exclude-from-external-load-balancers" 16 ) 17 18 // GetK8sNodeList returns a list of Kubernetes nodes. 19 func GetK8sNodeList(k8sClient client.Client) (*v1.NodeList, error) { 20 nodeList := &v1.NodeList{} 21 err := k8sClient.List( 22 context.TODO(), 23 nodeList, 24 &client.ListOptions{}, 25 ) 26 return nodeList, err 27 } 28 29 // SetControlPlaneScheduling will mark control plane nodes for scheduling by removing taints. 30 func SetControlPlaneScheduling(ctx context.Context, k8sClient client.Client) error { 31 nodes, err := GetK8sNodeList(k8sClient) 32 if err != nil { 33 return err 34 } 35 for i := range nodes.Items { 36 node := &nodes.Items[i] 37 var taints []v1.Taint 38 for _, taint := range node.Spec.Taints { 39 if !isControlPlaneNoScheduleTaint(taint) { 40 taints = append(taints, taint) 41 } 42 } 43 node.Spec.Taints = taints 44 delete(node.Labels, loadBalancerTaint) 45 if err := k8sClient.Update(ctx, node); err != nil { 46 return err 47 } 48 } 49 return nil 50 } 51 52 func isControlPlaneNoScheduleTaint(taint v1.Taint) bool { 53 return taint.Key == controlPlaneTaint || taint.Key == masterTaint 54 }