mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-29 14:37:00 +00:00
kubeadm: only apply the new "control-plane" label during init/join
- Update the markcontrolplane phase used by init and join to only label the nodes with the new control plane label. - Cleanup TODOs about the old label. - Remove outdated comment about selfhosting in staticpod/utils.go. Selfhosting has not been supported in kubeadm for a while and the comment also mentions the "master" label. - Update unit tests.
This commit is contained in:
parent
c0871b4433
commit
a3d5e55982
@ -19,31 +19,23 @@ package markcontrolplane
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"k8s.io/api/core/v1"
|
||||
v1 "k8s.io/api/core/v1"
|
||||
clientset "k8s.io/client-go/kubernetes"
|
||||
|
||||
"k8s.io/kubernetes/cmd/kubeadm/app/constants"
|
||||
"k8s.io/kubernetes/cmd/kubeadm/app/util/apiclient"
|
||||
)
|
||||
|
||||
// labelsToAdd holds a list of labels that are applied on kubeadm managed control plane nodes
|
||||
var labelsToAdd = []string{
|
||||
// TODO: remove this label:
|
||||
// https://github.com/kubernetes/kubeadm/issues/2200
|
||||
constants.LabelNodeRoleOldControlPlane,
|
||||
constants.LabelNodeRoleControlPlane,
|
||||
constants.LabelExcludeFromExternalLB,
|
||||
}
|
||||
|
||||
// MarkControlPlane taints the control-plane and sets the control-plane label
|
||||
func MarkControlPlane(client clientset.Interface, controlPlaneName string, taints []v1.Taint) error {
|
||||
// TODO: remove this "deprecated" amend and pass "labelsToAdd" directly:
|
||||
// https://github.com/kubernetes/kubeadm/issues/2200
|
||||
labels := make([]string, len(labelsToAdd))
|
||||
copy(labels, labelsToAdd)
|
||||
labels[0] = constants.LabelNodeRoleOldControlPlane + "(deprecated)"
|
||||
|
||||
fmt.Printf("[mark-control-plane] Marking the node %s as control-plane by adding the labels: %v\n",
|
||||
controlPlaneName, labels)
|
||||
controlPlaneName, labelsToAdd)
|
||||
|
||||
if len(taints) > 0 {
|
||||
taintStrs := []string{}
|
||||
|
@ -49,26 +49,25 @@ func TestMarkControlPlane(t *testing.T) {
|
||||
existingLabels: []string{""},
|
||||
existingTaints: nil,
|
||||
newTaints: []v1.Taint{kubeadmconstants.OldControlPlaneTaint},
|
||||
expectedPatch: `{"metadata":{"labels":{"node-role.kubernetes.io/control-plane":"","node-role.kubernetes.io/master":"","node.kubernetes.io/exclude-from-external-load-balancers":""}},"spec":{"taints":[{"effect":"NoSchedule","key":"node-role.kubernetes.io/master"}]}}`,
|
||||
expectedPatch: `{"metadata":{"labels":{"node-role.kubernetes.io/control-plane":"","node.kubernetes.io/exclude-from-external-load-balancers":""}},"spec":{"taints":[{"effect":"NoSchedule","key":"node-role.kubernetes.io/master"}]}}`,
|
||||
},
|
||||
{
|
||||
name: "control-plane label and taint missing but taint not wanted",
|
||||
existingLabels: []string{""},
|
||||
existingTaints: nil,
|
||||
newTaints: nil,
|
||||
expectedPatch: `{"metadata":{"labels":{"node-role.kubernetes.io/control-plane":"","node-role.kubernetes.io/master":"","node.kubernetes.io/exclude-from-external-load-balancers":""}}}`,
|
||||
expectedPatch: `{"metadata":{"labels":{"node-role.kubernetes.io/control-plane":"","node.kubernetes.io/exclude-from-external-load-balancers":""}}}`,
|
||||
},
|
||||
{
|
||||
name: "control-plane label missing",
|
||||
existingLabels: []string{""},
|
||||
existingTaints: []v1.Taint{kubeadmconstants.OldControlPlaneTaint},
|
||||
newTaints: []v1.Taint{kubeadmconstants.OldControlPlaneTaint},
|
||||
expectedPatch: `{"metadata":{"labels":{"node-role.kubernetes.io/control-plane":"","node-role.kubernetes.io/master":"","node.kubernetes.io/exclude-from-external-load-balancers":""}}}`,
|
||||
expectedPatch: `{"metadata":{"labels":{"node-role.kubernetes.io/control-plane":"","node.kubernetes.io/exclude-from-external-load-balancers":""}}}`,
|
||||
},
|
||||
{
|
||||
name: "control-plane taint missing",
|
||||
existingLabels: []string{
|
||||
kubeadmconstants.LabelNodeRoleOldControlPlane,
|
||||
kubeadmconstants.LabelNodeRoleControlPlane,
|
||||
kubeadmconstants.LabelExcludeFromExternalLB,
|
||||
},
|
||||
@ -79,7 +78,6 @@ func TestMarkControlPlane(t *testing.T) {
|
||||
{
|
||||
name: "nothing missing",
|
||||
existingLabels: []string{
|
||||
kubeadmconstants.LabelNodeRoleOldControlPlane,
|
||||
kubeadmconstants.LabelNodeRoleControlPlane,
|
||||
kubeadmconstants.LabelExcludeFromExternalLB,
|
||||
},
|
||||
@ -90,7 +88,6 @@ func TestMarkControlPlane(t *testing.T) {
|
||||
{
|
||||
name: "has taint and no new taints wanted",
|
||||
existingLabels: []string{
|
||||
kubeadmconstants.LabelNodeRoleOldControlPlane,
|
||||
kubeadmconstants.LabelNodeRoleControlPlane,
|
||||
kubeadmconstants.LabelExcludeFromExternalLB,
|
||||
},
|
||||
|
@ -288,13 +288,6 @@ func createHTTPProbe(host, path string, port int, scheme v1.URIScheme, initialDe
|
||||
|
||||
// GetAPIServerProbeAddress returns the probe address for the API server
|
||||
func GetAPIServerProbeAddress(endpoint *kubeadmapi.APIEndpoint) string {
|
||||
// In the case of a self-hosted deployment, the initial host on which kubeadm --init is run,
|
||||
// will generate a DaemonSet with a nodeSelector such that all nodes with the label
|
||||
// node-role.kubernetes.io/master='' will have the API server deployed to it. Since the init
|
||||
// is run only once on an initial host, the API advertise address will be invalid for any
|
||||
// future hosts that do not have the same address. Furthermore, since liveness and readiness
|
||||
// probes do not support the Downward API we cannot dynamically set the advertise address to
|
||||
// the node's IP. The only option then is to use localhost.
|
||||
if endpoint != nil && endpoint.AdvertiseAddress != "" {
|
||||
return getProbeAddress(endpoint.AdvertiseAddress)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user