Skip to content

Commit

Permalink
Use droplet ID for node names in DO
Browse files Browse the repository at this point in the history
  • Loading branch information
hakman committed Oct 6, 2023
1 parent 7a37a36 commit 73dc8f7
Show file tree
Hide file tree
Showing 11 changed files with 32 additions and 11 deletions.
2 changes: 1 addition & 1 deletion docs/releases/1.29-NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 8 additions & 0 deletions k8s/crds/kops.k8s.io_clusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions k8s/crds/kops.k8s.io_instancegroups.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions nodeup/pkg/model/kubelet.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions pkg/apis/kops/componentconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions pkg/apis/kops/v1alpha2/componentconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions pkg/apis/kops/v1alpha2/zz_generated.conversion.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions pkg/apis/kops/v1alpha3/componentconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions pkg/apis/kops/v1alpha3/zz_generated.conversion.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion upup/pkg/fi/cloudup/do/verifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -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],
}
Expand Down
16 changes: 7 additions & 9 deletions upup/pkg/fi/nodeup/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"context"
"crypto/sha256"
"encoding/base64"
"errors"
"fmt"
"io"
"net"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 73dc8f7

Please sign in to comment.