Merge pull request #10717 from justinsb/aws_instance_not_found

AWS: Return InstanceNotFound from ExternalID when not found
pull/6/head
Yu-Ju Hong 2015-07-06 09:59:38 -07:00
commit 9b9fd43973
2 changed files with 15 additions and 3 deletions

View File

@ -660,7 +660,7 @@ func (aws *AWSCloud) NodeAddresses(name string) ([]api.NodeAddress, error) {
// Note that if the instance does not exist or is no longer running, we must return ("", cloudprovider.InstanceNotFound)
func (aws *AWSCloud) ExternalID(name string) (string, error) {
// We must verify that the instance still exists
instance, err := aws.getInstanceByNodeName(name)
instance, err := aws.findInstanceByNodeName(name)
if err != nil {
return "", err
}
@ -2253,7 +2253,8 @@ func (a *AWSCloud) getInstancesByNodeNames(nodeNames []string) ([]*ec2.Instance,
}
// Returns the instance with the specified node name
func (a *AWSCloud) getInstanceByNodeName(nodeName string) (*ec2.Instance, error) {
// Returns nil if it does not exist
func (a *AWSCloud) findInstanceByNodeName(nodeName string) (*ec2.Instance, error) {
filters := []*ec2.Filter{
newEc2Filter("private-dns-name", nodeName),
}
@ -2267,7 +2268,7 @@ func (a *AWSCloud) getInstanceByNodeName(nodeName string) (*ec2.Instance, error)
return nil, err
}
if len(instances) == 0 {
return nil, fmt.Errorf("no instances found for name: %s", nodeName)
return nil, nil
}
if len(instances) > 1 {
return nil, fmt.Errorf("multiple instances found for name: %s", nodeName)
@ -2275,6 +2276,16 @@ func (a *AWSCloud) getInstanceByNodeName(nodeName string) (*ec2.Instance, error)
return instances[0], nil
}
// Returns the instance with the specified node name
// Like findInstanceByNodeName, but returns error if node not found
func (a *AWSCloud) getInstanceByNodeName(nodeName string) (*ec2.Instance, error) {
instance, err := a.findInstanceByNodeName(nodeName)
if err == nil && instance == nil {
return nil, fmt.Errorf("no instances found for name: %s", nodeName)
}
return instance, err
}
// Add additional filters, to match on our tags
// This lets us run multiple k8s clusters in a single EC2 AZ
func (s *AWSCloud) addFilters(filters []*ec2.Filter) []*ec2.Filter {

View File

@ -408,6 +408,7 @@ func (nc *NodeController) monitorNodeStatus() error {
continue
}
if _, err := instances.ExternalID(node.Name); err != nil && err == cloudprovider.InstanceNotFound {
glog.Infof("Deleting node (no longer present in cloud provider): %s", node.Name)
if err := nc.kubeClient.Nodes().Delete(node.Name); err != nil {
glog.Errorf("Unable to delete node %s: %v", node.Name, err)
continue