From adde7f548f8caedc989f34a867fa479acf8bfeb1 Mon Sep 17 00:00:00 2001 From: David Pratt Date: Thu, 21 Jan 2016 12:42:55 -0600 Subject: [PATCH 1/2] Fix AWS kubelet registration. This commit allows the AWS cloud provider plugin to work on EC2 instances that do not have a public IP. The EC2 metadata service returns a 404 for the 'public-ipv4' endpoint for private instances, and the plugin was bubbling this up as a fatal error. --- pkg/cloudprovider/providers/aws/aws.go | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/pkg/cloudprovider/providers/aws/aws.go b/pkg/cloudprovider/providers/aws/aws.go index 7365a9ae8ff..b876cfe421d 100644 --- a/pkg/cloudprovider/providers/aws/aws.go +++ b/pkg/cloudprovider/providers/aws/aws.go @@ -650,19 +650,23 @@ func (aws *AWSCloud) NodeAddresses(name string) ([]api.NodeAddress, error) { return nil, err } if self.nodeName == name || len(name) == 0 { + addresses := []api.NodeAddress{} + internalIP, err := aws.metadata.GetMetadata("local-ipv4") if err != nil { return nil, err } + addresses = append(addresses, api.NodeAddress{Type: api.NodeInternalIP, Address: internalIP}) + addresses = append(addresses, api.NodeAddress{Type: api.NodeLegacyHostIP, Address: internalIP}) + externalIP, err := aws.metadata.GetMetadata("public-ipv4") if err != nil { - return nil, err + //Perhaps only log this as a warning the first time this method is called? + } else { + addresses = append(addresses, api.NodeAddress{Type: api.NodeExternalIP, Address: externalIP}) } - return []api.NodeAddress{ - {Type: api.NodeInternalIP, Address: internalIP}, - {Type: api.NodeLegacyHostIP, Address: internalIP}, - {Type: api.NodeExternalIP, Address: externalIP}, - }, nil + + return addresses, nil } instance, err := aws.getInstanceByNodeName(name) if err != nil { From 57782459e68916691ac93fa8e434706de0af8e46 Mon Sep 17 00:00:00 2001 From: David Pratt Date: Tue, 9 Feb 2016 12:06:02 -0600 Subject: [PATCH 2/2] Log missing public IP from AWS metadata. --- pkg/cloudprovider/providers/aws/aws.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pkg/cloudprovider/providers/aws/aws.go b/pkg/cloudprovider/providers/aws/aws.go index b876cfe421d..628aa62fd09 100644 --- a/pkg/cloudprovider/providers/aws/aws.go +++ b/pkg/cloudprovider/providers/aws/aws.go @@ -657,11 +657,14 @@ func (aws *AWSCloud) NodeAddresses(name string) ([]api.NodeAddress, error) { return nil, err } addresses = append(addresses, api.NodeAddress{Type: api.NodeInternalIP, Address: internalIP}) + // Legacy compatibility: the private ip was the legacy host ip addresses = append(addresses, api.NodeAddress{Type: api.NodeLegacyHostIP, Address: internalIP}) externalIP, err := aws.metadata.GetMetadata("public-ipv4") if err != nil { - //Perhaps only log this as a warning the first time this method is called? + //TODO: It would be nice to be able to determine the reason for the failure, + // but the AWS client masks all failures with the same error description. + glog.V(2).Info("Could not determine public IP from AWS metadata.") } else { addresses = append(addresses, api.NodeAddress{Type: api.NodeExternalIP, Address: externalIP}) }