mirror of https://github.com/kubernetes/kops.git
Merge pull request #9135 from justinsb/gce_no_hostname_no_worries
GCE: don't rely on hostname being correct
This commit is contained in:
commit
e6d73b5ba0
2
Makefile
2
Makefile
|
|
@ -357,7 +357,7 @@ push: crossbuild-nodeup
|
||||||
|
|
||||||
.PHONY: push-gce-dry
|
.PHONY: push-gce-dry
|
||||||
push-gce-dry: push
|
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
|
.PHONY: push-gce-dry
|
||||||
push-aws-dry: push
|
push-aws-dry: push
|
||||||
|
|
|
||||||
|
|
@ -153,6 +153,12 @@ func (b *KubeletOptionsBuilder) BuildOptions(o interface{}) error {
|
||||||
}
|
}
|
||||||
clusterSpec.CloudConfig.Multizone = fi.Bool(true)
|
clusterSpec.CloudConfig.Multizone = fi.Bool(true)
|
||||||
clusterSpec.CloudConfig.NodeTags = fi.String(GCETagForRole(b.Context.ClusterName, kops.InstanceGroupRoleNode))
|
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 {
|
if cloudProvider == kops.CloudProviderVSphere {
|
||||||
|
|
|
||||||
|
|
@ -226,6 +226,7 @@ kubelet:
|
||||||
featureGates:
|
featureGates:
|
||||||
ExperimentalCriticalPodAnnotation: "true"
|
ExperimentalCriticalPodAnnotation: "true"
|
||||||
hairpinMode: promiscuous-bridge
|
hairpinMode: promiscuous-bridge
|
||||||
|
hostnameOverride: '@gce'
|
||||||
kubeconfigPath: /var/lib/kubelet/kubeconfig
|
kubeconfigPath: /var/lib/kubelet/kubeconfig
|
||||||
logLevel: 2
|
logLevel: 2
|
||||||
networkPluginMTU: 9001
|
networkPluginMTU: 9001
|
||||||
|
|
@ -244,6 +245,7 @@ masterKubelet:
|
||||||
featureGates:
|
featureGates:
|
||||||
ExperimentalCriticalPodAnnotation: "true"
|
ExperimentalCriticalPodAnnotation: "true"
|
||||||
hairpinMode: promiscuous-bridge
|
hairpinMode: promiscuous-bridge
|
||||||
|
hostnameOverride: '@gce'
|
||||||
kubeconfigPath: /var/lib/kubelet/kubeconfig
|
kubeconfigPath: /var/lib/kubelet/kubeconfig
|
||||||
logLevel: 2
|
logLevel: 2
|
||||||
networkPluginMTU: 9001
|
networkPluginMTU: 9001
|
||||||
|
|
|
||||||
|
|
@ -226,6 +226,7 @@ kubelet:
|
||||||
featureGates:
|
featureGates:
|
||||||
ExperimentalCriticalPodAnnotation: "true"
|
ExperimentalCriticalPodAnnotation: "true"
|
||||||
hairpinMode: promiscuous-bridge
|
hairpinMode: promiscuous-bridge
|
||||||
|
hostnameOverride: '@gce'
|
||||||
kubeconfigPath: /var/lib/kubelet/kubeconfig
|
kubeconfigPath: /var/lib/kubelet/kubeconfig
|
||||||
logLevel: 2
|
logLevel: 2
|
||||||
networkPluginMTU: 9001
|
networkPluginMTU: 9001
|
||||||
|
|
@ -244,6 +245,7 @@ masterKubelet:
|
||||||
featureGates:
|
featureGates:
|
||||||
ExperimentalCriticalPodAnnotation: "true"
|
ExperimentalCriticalPodAnnotation: "true"
|
||||||
hairpinMode: promiscuous-bridge
|
hairpinMode: promiscuous-bridge
|
||||||
|
hostnameOverride: '@gce'
|
||||||
kubeconfigPath: /var/lib/kubelet/kubeconfig
|
kubeconfigPath: /var/lib/kubelet/kubeconfig
|
||||||
logLevel: 2
|
logLevel: 2
|
||||||
networkPluginMTU: 9001
|
networkPluginMTU: 9001
|
||||||
|
|
|
||||||
|
|
@ -226,6 +226,7 @@ kubelet:
|
||||||
featureGates:
|
featureGates:
|
||||||
ExperimentalCriticalPodAnnotation: "true"
|
ExperimentalCriticalPodAnnotation: "true"
|
||||||
hairpinMode: promiscuous-bridge
|
hairpinMode: promiscuous-bridge
|
||||||
|
hostnameOverride: '@gce'
|
||||||
kubeconfigPath: /var/lib/kubelet/kubeconfig
|
kubeconfigPath: /var/lib/kubelet/kubeconfig
|
||||||
logLevel: 2
|
logLevel: 2
|
||||||
networkPluginMTU: 9001
|
networkPluginMTU: 9001
|
||||||
|
|
@ -244,6 +245,7 @@ masterKubelet:
|
||||||
featureGates:
|
featureGates:
|
||||||
ExperimentalCriticalPodAnnotation: "true"
|
ExperimentalCriticalPodAnnotation: "true"
|
||||||
hairpinMode: promiscuous-bridge
|
hairpinMode: promiscuous-bridge
|
||||||
|
hostnameOverride: '@gce'
|
||||||
kubeconfigPath: /var/lib/kubelet/kubeconfig
|
kubeconfigPath: /var/lib/kubelet/kubeconfig
|
||||||
logLevel: 2
|
logLevel: 2
|
||||||
networkPluginMTU: 9001
|
networkPluginMTU: 9001
|
||||||
|
|
|
||||||
|
|
@ -162,6 +162,7 @@ kubelet:
|
||||||
featureGates:
|
featureGates:
|
||||||
ExperimentalCriticalPodAnnotation: "true"
|
ExperimentalCriticalPodAnnotation: "true"
|
||||||
hairpinMode: promiscuous-bridge
|
hairpinMode: promiscuous-bridge
|
||||||
|
hostnameOverride: '@gce'
|
||||||
kubeconfigPath: /var/lib/kubelet/kubeconfig
|
kubeconfigPath: /var/lib/kubelet/kubeconfig
|
||||||
logLevel: 2
|
logLevel: 2
|
||||||
networkPluginMTU: 9001
|
networkPluginMTU: 9001
|
||||||
|
|
|
||||||
|
|
@ -226,6 +226,7 @@ kubelet:
|
||||||
featureGates:
|
featureGates:
|
||||||
ExperimentalCriticalPodAnnotation: "true"
|
ExperimentalCriticalPodAnnotation: "true"
|
||||||
hairpinMode: promiscuous-bridge
|
hairpinMode: promiscuous-bridge
|
||||||
|
hostnameOverride: '@gce'
|
||||||
kubeconfigPath: /var/lib/kubelet/kubeconfig
|
kubeconfigPath: /var/lib/kubelet/kubeconfig
|
||||||
logLevel: 2
|
logLevel: 2
|
||||||
networkPluginMTU: 9001
|
networkPluginMTU: 9001
|
||||||
|
|
@ -244,6 +245,7 @@ masterKubelet:
|
||||||
featureGates:
|
featureGates:
|
||||||
ExperimentalCriticalPodAnnotation: "true"
|
ExperimentalCriticalPodAnnotation: "true"
|
||||||
hairpinMode: promiscuous-bridge
|
hairpinMode: promiscuous-bridge
|
||||||
|
hostnameOverride: '@gce'
|
||||||
kubeconfigPath: /var/lib/kubelet/kubeconfig
|
kubeconfigPath: /var/lib/kubelet/kubeconfig
|
||||||
logLevel: 2
|
logLevel: 2
|
||||||
networkPluginMTU: 9001
|
networkPluginMTU: 9001
|
||||||
|
|
|
||||||
|
|
@ -162,6 +162,7 @@ kubelet:
|
||||||
featureGates:
|
featureGates:
|
||||||
ExperimentalCriticalPodAnnotation: "true"
|
ExperimentalCriticalPodAnnotation: "true"
|
||||||
hairpinMode: promiscuous-bridge
|
hairpinMode: promiscuous-bridge
|
||||||
|
hostnameOverride: '@gce'
|
||||||
kubeconfigPath: /var/lib/kubelet/kubeconfig
|
kubeconfigPath: /var/lib/kubelet/kubeconfig
|
||||||
logLevel: 2
|
logLevel: 2
|
||||||
networkPluginMTU: 9001
|
networkPluginMTU: 9001
|
||||||
|
|
|
||||||
|
|
@ -491,6 +491,21 @@ func evaluateHostnameOverride(hostnameOverride string) (string, error) {
|
||||||
return *(result.Reservations[0].Instances[0].PrivateDnsName), nil
|
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" {
|
if k == "@digitalocean" {
|
||||||
// @digitalocean means to use the private ipv4 address of a droplet as the hostname override
|
// @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")
|
vBytes, err := vfs.Context.ReadFile("metadata://digitalocean/interfaces/private/0/ipv4/address")
|
||||||
|
|
|
||||||
|
|
@ -97,7 +97,7 @@ func (c *VFSContext) ReadFile(location string, options ...VFSOption) ([]byte, er
|
||||||
case "metadata":
|
case "metadata":
|
||||||
switch u.Host {
|
switch u.Host {
|
||||||
case "gce":
|
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 := make(map[string]string)
|
||||||
httpHeaders["Metadata-Flavor"] = "Google"
|
httpHeaders["Metadata-Flavor"] = "Google"
|
||||||
return c.readHTTPLocation(httpURL, httpHeaders, opts)
|
return c.readHTTPLocation(httpURL, httpHeaders, opts)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue