From 36deb14f58f4acab9f5dca4d92e9e65aae3e4e77 Mon Sep 17 00:00:00 2001 From: Derek Parker Date: Sat, 8 Aug 2015 10:20:29 -0500 Subject: [PATCH 1/2] Handle full hostname when computing host tag on GCE The current code assumes the full domain name will not be included, which is not always the case. This patch adds support for computing the host tag from a fully qualified domain name. --- pkg/cloudprovider/gce/gce.go | 1 + pkg/cloudprovider/gce/gce_test.go | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/pkg/cloudprovider/gce/gce.go b/pkg/cloudprovider/gce/gce.go index b43dee2235f..4d3156d965f 100644 --- a/pkg/cloudprovider/gce/gce.go +++ b/pkg/cloudprovider/gce/gce.go @@ -445,6 +445,7 @@ func (gce *GCECloud) CreateTCPLoadBalancer(name, region string, externalIP net.I // This is kind of hacky, but the managed instance group adds 4 random chars and a hyphen // to the base name. func (gce *GCECloud) computeHostTag(host string) string { + host = strings.SplitN(host, ".", 2)[0] return host[:len(host)-5] } diff --git a/pkg/cloudprovider/gce/gce_test.go b/pkg/cloudprovider/gce/gce_test.go index bc2ae1a4a5c..3f916848135 100644 --- a/pkg/cloudprovider/gce/gce_test.go +++ b/pkg/cloudprovider/gce/gce_test.go @@ -50,6 +50,10 @@ func TestGetHostTag(t *testing.T) { host: "gke-test-ea6e8c80-node-8ytk", expected: "gke-test-ea6e8c80-node", }, + { + host: "kubernetes-minion-559o.c.PROJECT_NAME.internal", + expected: "kubernetes-minion", + }, } gce := &GCECloud{} From 473f8bea541aa3549b74033dcd5f91e1e4d3517f Mon Sep 17 00:00:00 2001 From: Alex Robinson Date: Mon, 24 Aug 2015 23:03:42 +0000 Subject: [PATCH 2/2] Be more lenient when deriving the node tag from a node name on GCE. --- pkg/cloudprovider/gce/gce.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/pkg/cloudprovider/gce/gce.go b/pkg/cloudprovider/gce/gce.go index 4d3156d965f..bfacb53fa14 100644 --- a/pkg/cloudprovider/gce/gce.go +++ b/pkg/cloudprovider/gce/gce.go @@ -443,10 +443,15 @@ func (gce *GCECloud) CreateTCPLoadBalancer(name, region string, externalIP net.I } // This is kind of hacky, but the managed instance group adds 4 random chars and a hyphen -// to the base name. +// to the base name. Older naming schemes put a hyphen and an incrementing index after +// the base name. Thus we pull off the characters after the final dash to support both. func (gce *GCECloud) computeHostTag(host string) string { host = strings.SplitN(host, ".", 2)[0] - return host[:len(host)-5] + lastHyphen := strings.LastIndex(host, "-") + if lastHyphen == -1 { + return host + } + return host[:lastHyphen] } // UpdateTCPLoadBalancer is an implementation of TCPLoadBalancer.UpdateTCPLoadBalancer.