mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-12 21:36:24 +00:00
Incorporate feedback from review
Signed-off-by: Davanum Srinivas <davanum@gmail.com>
This commit is contained in:
parent
52b1c77730
commit
3fa898bbc6
@ -40,7 +40,6 @@ import (
|
|||||||
apierrors "k8s.io/apimachinery/pkg/api/errors"
|
apierrors "k8s.io/apimachinery/pkg/api/errors"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
"k8s.io/apimachinery/pkg/fields"
|
"k8s.io/apimachinery/pkg/fields"
|
||||||
"k8s.io/apimachinery/pkg/labels"
|
|
||||||
"k8s.io/apimachinery/pkg/runtime"
|
"k8s.io/apimachinery/pkg/runtime"
|
||||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||||
"k8s.io/apimachinery/pkg/util/sets"
|
"k8s.io/apimachinery/pkg/util/sets"
|
||||||
@ -130,7 +129,7 @@ const (
|
|||||||
// SnapshotDeleteTimeout is how long for snapshot to delete snapshotContent.
|
// SnapshotDeleteTimeout is how long for snapshot to delete snapshotContent.
|
||||||
SnapshotDeleteTimeout = 5 * time.Minute
|
SnapshotDeleteTimeout = 5 * time.Minute
|
||||||
|
|
||||||
// ControlPlaneLabel is valid for kubeadm based clusters like kops ONLY
|
// ControlPlaneLabel is valid label for kubeadm based clusters like kops ONLY
|
||||||
ControlPlaneLabel = "node-role.kubernetes.io/control-plane"
|
ControlPlaneLabel = "node-role.kubernetes.io/control-plane"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -711,11 +710,29 @@ func getControlPlaneAddresses(ctx context.Context, c clientset.Interface) ([]str
|
|||||||
|
|
||||||
// GetControlPlaneNodes returns a list of control plane nodes
|
// GetControlPlaneNodes returns a list of control plane nodes
|
||||||
func GetControlPlaneNodes(ctx context.Context, c clientset.Interface) *v1.NodeList {
|
func GetControlPlaneNodes(ctx context.Context, c clientset.Interface) *v1.NodeList {
|
||||||
selector := labels.Set{ControlPlaneLabel: ""}.AsSelector()
|
allNodes, err := c.CoreV1().Nodes().List(ctx, metav1.ListOptions{})
|
||||||
cpNodes, err := c.CoreV1().Nodes().
|
ExpectNoError(err, "error reading all nodes")
|
||||||
List(ctx, metav1.ListOptions{LabelSelector: selector.String()})
|
|
||||||
ExpectNoError(err, "error reading control-plane nodes")
|
var cpNodes v1.NodeList
|
||||||
return cpNodes
|
|
||||||
|
for _, node := range allNodes.Items {
|
||||||
|
// Check for the control plane label
|
||||||
|
if _, hasLabel := node.Labels[ControlPlaneLabel]; hasLabel {
|
||||||
|
cpNodes.Items = append(cpNodes.Items, node)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check for the specific taint
|
||||||
|
for _, taint := range node.Spec.Taints {
|
||||||
|
// NOTE the taint key is the same as the control plane label
|
||||||
|
if taint.Key == ControlPlaneLabel && taint.Effect == v1.TaintEffectNoSchedule {
|
||||||
|
cpNodes.Items = append(cpNodes.Items, node)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return &cpNodes
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetControlPlaneAddresses returns all IP addresses on which the kubelet can reach the control plane.
|
// GetControlPlaneAddresses returns all IP addresses on which the kubelet can reach the control plane.
|
||||||
|
Loading…
Reference in New Issue
Block a user