Unverified Commit bf73cdf4 authored by Kubernetes Submit Queue's avatar Kubernetes Submit Queue Committed by GitHub

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 ```
parents ebffd76a 41318d75
...@@ -67,6 +67,11 @@ func getZone(n *v1.Node) string { ...@@ -67,6 +67,11 @@ func getZone(n *v1.Node) string {
return zone 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 // ToInstanceReferences returns instance references by links
func (gce *GCECloud) ToInstanceReferences(zone string, instanceNames []string) (refs []*compute.InstanceReference) { func (gce *GCECloud) ToInstanceReferences(zone string, instanceNames []string) (refs []*compute.InstanceReference) {
for _, ins := range instanceNames { for _, ins := range instanceNames {
......
...@@ -535,7 +535,7 @@ func (gce *GCECloud) createTargetPoolAndHealthCheck(svc *v1.Service, name, servi ...@@ -535,7 +535,7 @@ func (gce *GCECloud) createTargetPoolAndHealthCheck(svc *v1.Service, name, servi
var instances []string var instances []string
for _, host := range hosts { 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)) glog.Infof("Creating targetpool %v with %d healthchecks", name, len(hcLinks))
pool := &compute.TargetPool{ pool := &compute.TargetPool{
...@@ -732,11 +732,6 @@ func nodeNames(nodes []*v1.Node) []string { ...@@ -732,11 +732,6 @@ func nodeNames(nodes []*v1.Node) []string {
return ret 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 { func hostURLToComparablePath(hostURL string) string {
idx := strings.Index(hostURL, "/zones/") idx := strings.Index(hostURL, "/zones/")
if idx < 0 { if idx < 0 {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment