Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GCE: don't rely on hostname being correct #9135

Merged
merged 2 commits into from
May 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ push: crossbuild-nodeup

.PHONY: push-gce-dry
push-gce-dry: push
ssh ${TARGET} sudo /tmp/nodeup --conf=metadata://gce/config --dryrun --v=8
ssh ${TARGET} sudo /tmp/nodeup --conf=metadata://gce/instance/attributes/config --dryrun --v=8

.PHONY: push-gce-dry
push-aws-dry: push
Expand Down
6 changes: 6 additions & 0 deletions pkg/model/components/kubelet.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,12 @@ func (b *KubeletOptionsBuilder) BuildOptions(o interface{}) error {
}
clusterSpec.CloudConfig.Multizone = fi.Bool(true)
clusterSpec.CloudConfig.NodeTags = fi.String(GCETagForRole(b.Context.ClusterName, kops.InstanceGroupRoleNode))

// Use the hostname from the GCE metadata service
// if hostnameOverride is not set.
if clusterSpec.Kubelet.HostnameOverride == "" {
clusterSpec.Kubelet.HostnameOverride = "@gce"
}
}

if cloudProvider == kops.CloudProviderVSphere {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ kubelet:
featureGates:
ExperimentalCriticalPodAnnotation: "true"
hairpinMode: promiscuous-bridge
hostnameOverride: '@gce'
kubeconfigPath: /var/lib/kubelet/kubeconfig
logLevel: 2
networkPluginMTU: 9001
Expand All @@ -244,6 +245,7 @@ masterKubelet:
featureGates:
ExperimentalCriticalPodAnnotation: "true"
hairpinMode: promiscuous-bridge
hostnameOverride: '@gce'
kubeconfigPath: /var/lib/kubelet/kubeconfig
logLevel: 2
networkPluginMTU: 9001
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ kubelet:
featureGates:
ExperimentalCriticalPodAnnotation: "true"
hairpinMode: promiscuous-bridge
hostnameOverride: '@gce'
kubeconfigPath: /var/lib/kubelet/kubeconfig
logLevel: 2
networkPluginMTU: 9001
Expand All @@ -244,6 +245,7 @@ masterKubelet:
featureGates:
ExperimentalCriticalPodAnnotation: "true"
hairpinMode: promiscuous-bridge
hostnameOverride: '@gce'
kubeconfigPath: /var/lib/kubelet/kubeconfig
logLevel: 2
networkPluginMTU: 9001
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ kubelet:
featureGates:
ExperimentalCriticalPodAnnotation: "true"
hairpinMode: promiscuous-bridge
hostnameOverride: '@gce'
kubeconfigPath: /var/lib/kubelet/kubeconfig
logLevel: 2
networkPluginMTU: 9001
Expand All @@ -244,6 +245,7 @@ masterKubelet:
featureGates:
ExperimentalCriticalPodAnnotation: "true"
hairpinMode: promiscuous-bridge
hostnameOverride: '@gce'
kubeconfigPath: /var/lib/kubelet/kubeconfig
logLevel: 2
networkPluginMTU: 9001
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ kubelet:
featureGates:
ExperimentalCriticalPodAnnotation: "true"
hairpinMode: promiscuous-bridge
hostnameOverride: '@gce'
kubeconfigPath: /var/lib/kubelet/kubeconfig
logLevel: 2
networkPluginMTU: 9001
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ kubelet:
featureGates:
ExperimentalCriticalPodAnnotation: "true"
hairpinMode: promiscuous-bridge
hostnameOverride: '@gce'
kubeconfigPath: /var/lib/kubelet/kubeconfig
logLevel: 2
networkPluginMTU: 9001
Expand All @@ -244,6 +245,7 @@ masterKubelet:
featureGates:
ExperimentalCriticalPodAnnotation: "true"
hairpinMode: promiscuous-bridge
hostnameOverride: '@gce'
kubeconfigPath: /var/lib/kubelet/kubeconfig
logLevel: 2
networkPluginMTU: 9001
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ kubelet:
featureGates:
ExperimentalCriticalPodAnnotation: "true"
hairpinMode: promiscuous-bridge
hostnameOverride: '@gce'
kubeconfigPath: /var/lib/kubelet/kubeconfig
logLevel: 2
networkPluginMTU: 9001
Expand Down
15 changes: 15 additions & 0 deletions upup/pkg/fi/nodeup/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,21 @@ func evaluateHostnameOverride(hostnameOverride string) (string, error) {
return *(result.Reservations[0].Instances[0].PrivateDnsName), nil
}

if k == "@gce" {
// We recognize @gce as meaning the hostname from the GCE metadata service
// This lets us tolerate broken hostnames (i.e. systemd)
b, err := vfs.Context.ReadFile("metadata://gce/instance/hostname")
if err != nil {
return "", fmt.Errorf("error reading hostname from GCE metadata: %v", err)
}

// We only want to use the first portion of the fully-qualified name
// e.g. foo.c.project.internal => foo
fullyQualified := string(b)
bareHostname := strings.Split(fullyQualified, ".")[0]
return bareHostname, nil
}

if k == "@digitalocean" {
// @digitalocean means to use the private ipv4 address of a droplet as the hostname override
vBytes, err := vfs.Context.ReadFile("metadata://digitalocean/interfaces/private/0/ipv4/address")
Expand Down
2 changes: 1 addition & 1 deletion util/pkg/vfs/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func (c *VFSContext) ReadFile(location string, options ...VFSOption) ([]byte, er
case "metadata":
switch u.Host {
case "gce":
httpURL := "http://169.254.169.254/computeMetadata/v1/instance/attributes/" + u.Path
httpURL := "http://169.254.169.254/computeMetadata/v1/" + u.Path
httpHeaders := make(map[string]string)
httpHeaders["Metadata-Flavor"] = "Google"
return c.readHTTPLocation(httpURL, httpHeaders, opts)
Expand Down