| @@ -30,6 +30,7 @@ import ( | |||||||
| 	"code.google.com/p/goauth2/compute/serviceaccount" | 	"code.google.com/p/goauth2/compute/serviceaccount" | ||||||
| 	compute "code.google.com/p/google-api-go-client/compute/v1" | 	compute "code.google.com/p/google-api-go-client/compute/v1" | ||||||
| 	"github.com/GoogleCloudPlatform/kubernetes/pkg/cloudprovider" | 	"github.com/GoogleCloudPlatform/kubernetes/pkg/cloudprovider" | ||||||
|  | 	"github.com/golang/glog" | ||||||
| ) | ) | ||||||
|  |  | ||||||
| // GCECloud is an implementation of Interface, TCPLoadBalancer and Instances for Google Compute Engine. | // GCECloud is an implementation of Interface, TCPLoadBalancer and Instances for Google Compute Engine. | ||||||
| @@ -105,10 +106,7 @@ func (gce *GCECloud) Zones() (cloudprovider.Zones, bool) { | |||||||
| } | } | ||||||
|  |  | ||||||
| func makeHostLink(projectID, zone, host string) string { | func makeHostLink(projectID, zone, host string) string { | ||||||
| 	ix := strings.Index(host, ".") | 	host = canonicalizeInstanceName(host) | ||||||
| 	if ix != -1 { |  | ||||||
| 		host = host[:ix] |  | ||||||
| 	} |  | ||||||
| 	return fmt.Sprintf("https://www.googleapis.com/compute/v1/projects/%s/zones/%s/instances/%s", | 	return fmt.Sprintf("https://www.googleapis.com/compute/v1/projects/%s/zones/%s/instances/%s", | ||||||
| 		projectID, zone, host) | 		projectID, zone, host) | ||||||
| } | } | ||||||
| @@ -189,10 +187,23 @@ func (gce *GCECloud) DeleteTCPLoadBalancer(name, region string) error { | |||||||
| 	return err | 	return err | ||||||
| } | } | ||||||
|  |  | ||||||
|  | // Take a GCE instance 'hostname' and break it down to something that can be fed | ||||||
|  | // to the GCE API client library.  Basically this means reducing 'kubernetes- | ||||||
|  | // minion-2.c.my-proj.internal' to 'kubernetes-minion-2' if necessary. | ||||||
|  | func canonicalizeInstanceName(name string) string { | ||||||
|  | 	ix := strings.Index(name, ".") | ||||||
|  | 	if ix != -1 { | ||||||
|  | 		name = name[:ix] | ||||||
|  | 	} | ||||||
|  | 	return name | ||||||
|  | } | ||||||
|  |  | ||||||
| // IPAddress is an implementation of Instances.IPAddress. | // IPAddress is an implementation of Instances.IPAddress. | ||||||
| func (gce *GCECloud) IPAddress(instance string) (net.IP, error) { | func (gce *GCECloud) IPAddress(instance string) (net.IP, error) { | ||||||
|  | 	instance = canonicalizeInstanceName(instance) | ||||||
| 	res, err := gce.service.Instances.Get(gce.projectID, gce.zone, instance).Do() | 	res, err := gce.service.Instances.Get(gce.projectID, gce.zone, instance).Do() | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
|  | 		glog.Errorf("Failed to retrieve TargetInstance resource for instance:%s", instance) | ||||||
| 		return nil, err | 		return nil, err | ||||||
| 	} | 	} | ||||||
| 	ip := net.ParseIP(res.NetworkInterfaces[0].AccessConfigs[0].NatIP) | 	ip := net.ParseIP(res.NetworkInterfaces[0].AccessConfigs[0].NatIP) | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Joe Beda
					Joe Beda