mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-31 15:25:57 +00:00
AWS: Return InstanceNotFound from ExternalID when not found
Despite finding and documenting the importance of this, I was still doing it wrong!
This commit is contained in:
parent
8884e116e5
commit
591a113406
@ -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 {
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user