From 22fba6591dec555f40d0437606f2d7bd461823a9 Mon Sep 17 00:00:00 2001 From: Antonio Ojea Date: Wed, 5 Jun 2024 11:56:11 +0000 Subject: [PATCH] node-ip unspecified addresses initialize Node with cloud provider external The node.status.addresses logic grew organically and with weird semantics, this commit try to document existing semantics when the kubelet uses an external cloud provider and recover the same behavior existing pre-1.29. The node.status.addresses can be populated by the kubelet at startup or delegated to the external cloud provider. If the --node-ip flag is set to an IP in the node, the kubelet will add an annotation to the Node object that will be respected by the external cloud providers, no new IP addresses will be added for the same address type. If the IP set in the --node-ip flag is `0.0.0.0` or `::`, the kubelet will initialize the node with the default address of the corresponding IP family of the unspecified address, and the cloud-provider will override it later. --- cmd/kubelet/app/options/options.go | 2 +- pkg/kubelet/nodestatus/setters.go | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/cmd/kubelet/app/options/options.go b/cmd/kubelet/app/options/options.go index b87cd735659..fea488e00ab 100644 --- a/cmd/kubelet/app/options/options.go +++ b/cmd/kubelet/app/options/options.go @@ -292,7 +292,7 @@ func (f *KubeletFlags) AddFlags(mainfs *pflag.FlagSet) { fs.StringVar(&f.HostnameOverride, "hostname-override", f.HostnameOverride, "If non-empty, will use this string as identification instead of the actual hostname. If --cloud-provider is set, the cloud provider determines the name of the node (consult cloud provider documentation to determine if and how the hostname is used).") - fs.StringVar(&f.NodeIP, "node-ip", f.NodeIP, "IP address (or comma-separated dual-stack IP addresses) of the node. If unset, kubelet will use the node's default IPv4 address, if any, or its default IPv6 address if it has no IPv4 addresses. You can pass '::' to make it prefer the default IPv6 address rather than the default IPv4 address.") + fs.StringVar(&f.NodeIP, "node-ip", f.NodeIP, "IP address (or comma-separated dual-stack IP addresses) of the node. If unset, kubelet will use the node's default IPv4 address, if any, or its default IPv6 address if it has no IPv4 addresses. You can pass '::' to make it prefer the default IPv6 address rather than the default IPv4 address. If cloud-provider is set to external, this flag will help to bootstrap the node with the corresponding IP.") fs.StringVar(&f.CertDirectory, "cert-dir", f.CertDirectory, "The directory where the TLS certs are located. "+ "If --tls-cert-file and --tls-private-key-file are provided, this flag will be ignored.") diff --git a/pkg/kubelet/nodestatus/setters.go b/pkg/kubelet/nodestatus/setters.go index 19bb6ce7295..6e97651413f 100644 --- a/pkg/kubelet/nodestatus/setters.go +++ b/pkg/kubelet/nodestatus/setters.go @@ -129,12 +129,15 @@ func NodeAddress(nodeIPs []net.IP, // typically Kubelet.nodeIPs if len(node.Status.Addresses) > 0 { return nil } - // If nodeIPs are not specified wait for the external cloud-provider to set the node addresses. + // If nodeIPs are not set wait for the external cloud-provider to set the node addresses. + // If the nodeIP is the unspecified address 0.0.0.0 or ::, then use the IP of the default gateway of + // the corresponding IP family to bootstrap the node until the out-of-tree provider overrides it later. + // xref: https://github.com/kubernetes/kubernetes/issues/125348 // Otherwise uses them on the assumption that the installer/administrator has the previous knowledge // required to ensure the external cloud provider will use the same addresses to avoid the issues explained // in https://github.com/kubernetes/kubernetes/issues/120720. // We are already hinting the external cloud provider via the annotation AnnotationAlphaProvidedIPAddr. - if !nodeIPSpecified { + if nodeIP == nil { node.Status.Addresses = []v1.NodeAddress{ {Type: v1.NodeHostName, Address: hostname}, }