Use Node IP Address instead of Node.Name in minion.ResourceLocation.

Refactor GetNodeHostIP into pkg/util/node (instead of pkg/util to break import cycle).

Include internalIP in gce NodeAddresses. Remove NodeLegacyHostIP
This commit is contained in:
CJ Cullen
2015-05-26 16:13:00 -07:00
parent ac82f50afb
commit 4e5d0da839
5 changed files with 47 additions and 30 deletions

View File

@@ -42,9 +42,11 @@ import (
"google.golang.org/cloud/compute/metadata"
)
const ProviderName = "gce"
const EXTERNAL_IP_METADATA_URL = "http://169.254.169.254/computeMetadata/v1/instance/network-interfaces/0/access-configs/0/external-ip"
const (
ProviderName = "gce"
EXTERNAL_IP_METADATA_URL = "http://169.254.169.254/computeMetadata/v1/instance/network-interfaces/0/access-configs/0/external-ip"
INTERNAL_IP_METADATA_URL = "http://169.254.169.254/computeMetadata/v1/instance/network-interfaces/0/ip"
)
// GCECloud is an implementation of Interface, TCPLoadBalancer and Instances for Google Compute Engine.
type GCECloud struct {
@@ -476,15 +478,17 @@ func (gce *GCECloud) getInstanceByName(name string) (*compute.Instance, error) {
// NodeAddresses is an implementation of Instances.NodeAddresses.
func (gce *GCECloud) NodeAddresses(_ string) ([]api.NodeAddress, error) {
internalIP, err := gce.metadataAccess(INTERNAL_IP_METADATA_URL)
if err != nil {
return nil, fmt.Errorf("couldn't get internal IP: %v", err)
}
externalIP, err := gce.metadataAccess(EXTERNAL_IP_METADATA_URL)
if err != nil {
return nil, fmt.Errorf("couldn't get external IP: %v", err)
}
return []api.NodeAddress{
{Type: api.NodeInternalIP, Address: internalIP},
{Type: api.NodeExternalIP, Address: externalIP},
// TODO(mbforbes): Remove NodeLegacyHostIP once v1beta1 is removed.
{Type: api.NodeLegacyHostIP, Address: externalIP},
}, nil
}