Skip to content

Commit

Permalink
Merge pull request #9135 from justinsb/gce_no_hostname_no_worries
Browse files Browse the repository at this point in the history
GCE: don't rely on hostname being correct
  • Loading branch information
k8s-ci-robot authored May 23, 2020
2 parents 3ece306 + 7228223 commit e6d73b5
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 2 deletions.
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

0 comments on commit e6d73b5

Please sign in to comment.