Merge pull request #59431 from agau4779/instance-comparable-host-path

Automatic merge from submit-queue. If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

[GCE] Instance comparable host path

**What this PR does / why we need it**:
When creating a new TargetPool, insert new instances with the comparable host path instead of the full path, e.g. /zone/%s/instances/%s instead of the full https://www.googleapis.com/compute/v1/projects/... url. 

With this change, `createTargetPoolAndHealthCheck` and `updateTargetPool` insert gceInstance paths in a consistent manner. 


**Which issue(s) this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close the issue(s) when PR gets merged)*:
Fixes #

**Release note**:
```release-note
NONE
```
pull/6/head
Kubernetes Submit Queue 2018-02-06 15:11:18 -08:00 committed by GitHub
commit bf73cdf4e7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 6 deletions

View File

@ -67,6 +67,11 @@ func getZone(n *v1.Node) string {
return zone
}
func makeHostURL(projectsApiEndpoint, projectID, zone, host string) string {
host = canonicalizeInstanceName(host)
return projectsApiEndpoint + strings.Join([]string{projectID, "zones", zone, "instances", host}, "/")
}
// ToInstanceReferences returns instance references by links
func (gce *GCECloud) ToInstanceReferences(zone string, instanceNames []string) (refs []*compute.InstanceReference) {
for _, ins := range instanceNames {

View File

@ -535,7 +535,7 @@ func (gce *GCECloud) createTargetPoolAndHealthCheck(svc *v1.Service, name, servi
var instances []string
for _, host := range hosts {
instances = append(instances, makeHostURL(gce.service.BasePath, gce.projectID, host.Zone, host.Name))
instances = append(instances, host.makeComparableHostPath())
}
glog.Infof("Creating targetpool %v with %d healthchecks", name, len(hcLinks))
pool := &compute.TargetPool{
@ -732,11 +732,6 @@ func nodeNames(nodes []*v1.Node) []string {
return ret
}
func makeHostURL(projectsApiEndpoint, projectID, zone, host string) string {
host = canonicalizeInstanceName(host)
return projectsApiEndpoint + strings.Join([]string{projectID, "zones", zone, "instances", host}, "/")
}
func hostURLToComparablePath(hostURL string) string {
idx := strings.Index(hostURL, "/zones/")
if idx < 0 {