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.
This commit is contained in:
CJ Cullen
2015-05-26 16:13:00 -07:00
parent b2449746b4
commit 2d85e4a094
5 changed files with 47 additions and 25 deletions

View File

@@ -43,9 +43,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 {
@@ -524,15 +526,17 @@ func addKey(metadataBefore, keyString string) string {
// 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
}