Skip to content

Commit

Permalink
Merge pull request #7803 from bittopaz/ali-hostname-override
Browse files Browse the repository at this point in the history
Alicloud: add hostname override
  • Loading branch information
k8s-ci-robot authored Oct 19, 2019
2 parents ca312dd + 002ddbb commit 006d27e
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 1 deletion.
1 change: 1 addition & 0 deletions pkg/model/components/kubelet.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ func (b *KubeletOptionsBuilder) BuildOptions(o interface{}) error {

if cloudProvider == kops.CloudProviderALI {
clusterSpec.Kubelet.CloudProvider = "alicloud"
clusterSpec.Kubelet.HostnameOverride = "@alicloud"
}

if clusterSpec.ExternalCloudControllerManager != nil {
Expand Down
6 changes: 6 additions & 0 deletions pkg/model/components/kubeproxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,5 +88,11 @@ func (b *KubeProxyOptionsBuilder) BuildOptions(o interface{}) error {
}
}

if cloudProvider == kops.CloudProviderALI {
if config.HostnameOverride == "" {
config.HostnameOverride = "@alicloud"
}
}

return nil
}
22 changes: 22 additions & 0 deletions upup/pkg/fi/nodeup/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,28 @@ func evaluateHostnameOverride(hostnameOverride string) (string, error) {
return hostname, nil
}

if k == "@alicloud" {
// @alicloud means to use the "{az}.{instance-id}" of a instance as the hostname override
azBytes, err := vfs.Context.ReadFile("metadata://alicloud/zone-id")
if err != nil {
return "", fmt.Errorf("error reading zone-id from Alicloud metadata: %v", err)
}
az := string(azBytes)

instanceIDBytes, err := vfs.Context.ReadFile("metadata://alicloud/instance-id")
if err != nil {
return "", fmt.Errorf("error reading instance-id from Alicloud metadata: %v", err)
}
instanceID := string(instanceIDBytes)

hostname := fmt.Sprintf("%s.%s", az, instanceID)
if hostname == "" {
return "", errors.New("private IP for digitalocean droplet was empty")
}

return hostname, nil
}

return hostnameOverride, nil
}

Expand Down
4 changes: 3 additions & 1 deletion util/pkg/vfs/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,9 @@ func (c *VFSContext) ReadFile(location string, options ...VFSOption) ([]byte, er
case "digitalocean":
httpURL := "http://169.254.169.254/metadata/v1" + u.Path
return c.readHttpLocation(httpURL, nil, opts)

case "alicloud":
httpURL := "http://100.100.100.200/latest/meta-data/" + u.Path
return c.readHttpLocation(httpURL, nil, opts)
default:
return nil, fmt.Errorf("unknown metadata type: %q in %q", u.Host, location)
}
Expand Down

0 comments on commit 006d27e

Please sign in to comment.