From 73dc8f72d8d3d41a6d7d92d1aa415676a83f9a81 Mon Sep 17 00:00:00 2001 From: Ciprian Hacman Date: Fri, 6 Oct 2023 16:09:40 +0300 Subject: [PATCH] Use droplet ID for node names in DO --- docs/releases/1.29-NOTES.md | 2 +- k8s/crds/kops.k8s.io_clusters.yaml | 8 ++++++++ k8s/crds/kops.k8s.io_instancegroups.yaml | 4 ++++ nodeup/pkg/model/kubelet.go | 1 + pkg/apis/kops/componentconfig.go | 2 ++ pkg/apis/kops/v1alpha2/componentconfig.go | 2 ++ .../kops/v1alpha2/zz_generated.conversion.go | 2 ++ pkg/apis/kops/v1alpha3/componentconfig.go | 2 ++ .../kops/v1alpha3/zz_generated.conversion.go | 2 ++ upup/pkg/fi/cloudup/do/verifier.go | 2 +- upup/pkg/fi/nodeup/command.go | 16 +++++++--------- 11 files changed, 32 insertions(+), 11 deletions(-) diff --git a/docs/releases/1.29-NOTES.md b/docs/releases/1.29-NOTES.md index 8c06fccc778c5..915f23a0c5560 100644 --- a/docs/releases/1.29-NOTES.md +++ b/docs/releases/1.29-NOTES.md @@ -14,7 +14,7 @@ This is a document to gather the release notes prior to the release. ## DigitalOcean -* Node names have changed from the droplet's private IP to the droplet hostname +* Node names have changed from the droplet's private IP to the droplet's ID # Breaking changes diff --git a/k8s/crds/kops.k8s.io_clusters.yaml b/k8s/crds/kops.k8s.io_clusters.yaml index 784263873b4df..47cd46e5b2767 100644 --- a/k8s/crds/kops.k8s.io_clusters.yaml +++ b/k8s/crds/kops.k8s.io_clusters.yaml @@ -3932,6 +3932,10 @@ spec: kubelet defaults. (DEPRECATED: This parameter should be set via the config file specified by the Kubelet''s --config flag.' type: boolean + providerID: + description: ProviderID specifies the unique ID of the instance + that an external provider can use to identify a specific node. + type: string readOnlyPort: description: ReadOnlyPort is the port used by the kubelet api for read-only access (default 10255) @@ -4370,6 +4374,10 @@ spec: kubelet defaults. (DEPRECATED: This parameter should be set via the config file specified by the Kubelet''s --config flag.' type: boolean + providerID: + description: ProviderID specifies the unique ID of the instance + that an external provider can use to identify a specific node. + type: string readOnlyPort: description: ReadOnlyPort is the port used by the kubelet api for read-only access (default 10255) diff --git a/k8s/crds/kops.k8s.io_instancegroups.yaml b/k8s/crds/kops.k8s.io_instancegroups.yaml index 9ef52b9308779..deaceec19c6d5 100644 --- a/k8s/crds/kops.k8s.io_instancegroups.yaml +++ b/k8s/crds/kops.k8s.io_instancegroups.yaml @@ -682,6 +682,10 @@ spec: kubelet defaults. (DEPRECATED: This parameter should be set via the config file specified by the Kubelet''s --config flag.' type: boolean + providerID: + description: ProviderID specifies the unique ID of the instance + that an external provider can use to identify a specific node. + type: string readOnlyPort: description: ReadOnlyPort is the port used by the kubelet api for read-only access (default 10255) diff --git a/nodeup/pkg/model/kubelet.go b/nodeup/pkg/model/kubelet.go index 18b048fbe137e..719cff335043c 100644 --- a/nodeup/pkg/model/kubelet.go +++ b/nodeup/pkg/model/kubelet.go @@ -221,6 +221,7 @@ func buildKubeletComponentConfig(kubeletConfig *kops.KubeletConfigSpec) (*nodeta componentConfig.ShutdownGracePeriodCriticalPods = *kubeletConfig.ShutdownGracePeriodCriticalPods } componentConfig.MemorySwap.SwapBehavior = kubeletConfig.MemorySwapBehavior + componentConfig.ProviderID = kubeletConfig.ProviderID s := runtime.NewScheme() if err := kubelet.AddToScheme(s); err != nil { diff --git a/pkg/apis/kops/componentconfig.go b/pkg/apis/kops/componentconfig.go index 9bf3826529670..1572c441dafc1 100644 --- a/pkg/apis/kops/componentconfig.go +++ b/pkg/apis/kops/componentconfig.go @@ -236,6 +236,8 @@ type KubeletConfigSpec struct { // MemorySwapBehavior defines how swap is used by container workloads. // Supported values: LimitedSwap, "UnlimitedSwap. MemorySwapBehavior string `json:"memorySwapBehavior,omitempty"` + // ProviderID specifies the unique ID of the instance that an external provider can use to identify a specific node. + ProviderID string `json:"providerID,omitempty"` } // KubeProxyConfig defines the configuration for a proxy diff --git a/pkg/apis/kops/v1alpha2/componentconfig.go b/pkg/apis/kops/v1alpha2/componentconfig.go index 3a25ef84281ca..d130522ae34e2 100644 --- a/pkg/apis/kops/v1alpha2/componentconfig.go +++ b/pkg/apis/kops/v1alpha2/componentconfig.go @@ -236,6 +236,8 @@ type KubeletConfigSpec struct { // MemorySwapBehavior defines how swap is used by container workloads. // Supported values: LimitedSwap, "UnlimitedSwap. MemorySwapBehavior string `json:"memorySwapBehavior,omitempty"` + // ProviderID specifies the unique ID of the instance that an external provider can use to identify a specific node. + ProviderID string `json:"providerID,omitempty"` } // KubeProxyConfig defines the configuration for a proxy diff --git a/pkg/apis/kops/v1alpha2/zz_generated.conversion.go b/pkg/apis/kops/v1alpha2/zz_generated.conversion.go index 24e64c6be48d8..417786b1aebfd 100644 --- a/pkg/apis/kops/v1alpha2/zz_generated.conversion.go +++ b/pkg/apis/kops/v1alpha2/zz_generated.conversion.go @@ -5478,6 +5478,7 @@ func autoConvert_v1alpha2_KubeletConfigSpec_To_kops_KubeletConfigSpec(in *Kubele out.ShutdownGracePeriod = in.ShutdownGracePeriod out.ShutdownGracePeriodCriticalPods = in.ShutdownGracePeriodCriticalPods out.MemorySwapBehavior = in.MemorySwapBehavior + out.ProviderID = in.ProviderID return nil } @@ -5580,6 +5581,7 @@ func autoConvert_kops_KubeletConfigSpec_To_v1alpha2_KubeletConfigSpec(in *kops.K out.ShutdownGracePeriod = in.ShutdownGracePeriod out.ShutdownGracePeriodCriticalPods = in.ShutdownGracePeriodCriticalPods out.MemorySwapBehavior = in.MemorySwapBehavior + out.ProviderID = in.ProviderID return nil } diff --git a/pkg/apis/kops/v1alpha3/componentconfig.go b/pkg/apis/kops/v1alpha3/componentconfig.go index b51fd207fa7a6..7ccd298f71038 100644 --- a/pkg/apis/kops/v1alpha3/componentconfig.go +++ b/pkg/apis/kops/v1alpha3/componentconfig.go @@ -234,6 +234,8 @@ type KubeletConfigSpec struct { // MemorySwapBehavior defines how swap is used by container workloads. // Supported values: LimitedSwap, "UnlimitedSwap. MemorySwapBehavior string `json:"memorySwapBehavior,omitempty"` + // ProviderID specifies the unique ID of the instance that an external provider can use to identify a specific node. + ProviderID string `json:"providerID,omitempty"` } // KubeProxyConfig defines the configuration for a proxy diff --git a/pkg/apis/kops/v1alpha3/zz_generated.conversion.go b/pkg/apis/kops/v1alpha3/zz_generated.conversion.go index 5167e7b88833d..f0adc3a7ce7fc 100644 --- a/pkg/apis/kops/v1alpha3/zz_generated.conversion.go +++ b/pkg/apis/kops/v1alpha3/zz_generated.conversion.go @@ -5869,6 +5869,7 @@ func autoConvert_v1alpha3_KubeletConfigSpec_To_kops_KubeletConfigSpec(in *Kubele out.ShutdownGracePeriod = in.ShutdownGracePeriod out.ShutdownGracePeriodCriticalPods = in.ShutdownGracePeriodCriticalPods out.MemorySwapBehavior = in.MemorySwapBehavior + out.ProviderID = in.ProviderID return nil } @@ -5971,6 +5972,7 @@ func autoConvert_kops_KubeletConfigSpec_To_v1alpha3_KubeletConfigSpec(in *kops.K out.ShutdownGracePeriod = in.ShutdownGracePeriod out.ShutdownGracePeriodCriticalPods = in.ShutdownGracePeriodCriticalPods out.MemorySwapBehavior = in.MemorySwapBehavior + out.ProviderID = in.ProviderID return nil } diff --git a/upup/pkg/fi/cloudup/do/verifier.go b/upup/pkg/fi/cloudup/do/verifier.go index 84ff15f177558..d384c25f4e8b2 100644 --- a/upup/pkg/fi/cloudup/do/verifier.go +++ b/upup/pkg/fi/cloudup/do/verifier.go @@ -103,7 +103,7 @@ func (o digitalOceanVerifier) VerifyToken(ctx context.Context, rawRequest *http. } result := &bootstrap.VerifyResult{ - NodeName: droplet.Name, + NodeName: strconv.Itoa(droplet.ID), CertificateNames: addresses, ChallengeEndpoint: challengeEndpoints[0], } diff --git a/upup/pkg/fi/nodeup/command.go b/upup/pkg/fi/nodeup/command.go index e3c81118123bc..278fe066341dc 100644 --- a/upup/pkg/fi/nodeup/command.go +++ b/upup/pkg/fi/nodeup/command.go @@ -20,7 +20,6 @@ import ( "context" "crypto/sha256" "encoding/base64" - "errors" "fmt" "io" "net" @@ -426,6 +425,10 @@ func evaluateSpec(nodeupConfig *nodeup.Config, cloudProvider api.CloudProviderID nodeupConfig.KubeletConfig.HostnameOverride = hostnameOverride + if cloudProvider == api.CloudProviderDO { + nodeupConfig.KubeletConfig.ProviderID = "digitalocean://" + hostnameOverride + } + if nodeupConfig.KubeProxy != nil { nodeupConfig.KubeProxy.HostnameOverride = hostnameOverride nodeupConfig.KubeProxy.BindAddress, err = evaluateBindAddress(nodeupConfig.KubeProxy.BindAddress) @@ -460,17 +463,12 @@ func evaluateHostnameOverride(cloudProvider api.CloudProviderID) (string, error) bareHostname := strings.Split(fullyQualified, ".")[0] return bareHostname, nil case api.CloudProviderDO: - vBytes, err := vfs.Context.ReadFile("metadata://digitalocean/hostname") + dropletIDBytes, err := vfs.Context.ReadFile("metadata://digitalocean/id") if err != nil { - return "", fmt.Errorf("error reading droplet hostname from DigitalOcean metadata: %v", err) - } - - hostname := string(vBytes) - if hostname == "" { - return "", errors.New("hostname for digitalocean droplet was empty") + return "", fmt.Errorf("error reading droplet ID from DigitalOcean metadata: %v", err) } - return hostname, nil + return string(dropletIDBytes), nil } return "", nil