mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-15 14:14:39 +00:00
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:
@@ -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
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user