mirror of https://github.com/k3s-io/k3s
Merge pull request #10717 from justinsb/aws_instance_not_found
AWS: Return InstanceNotFound from ExternalID when not foundpull/6/head
commit
9b9fd43973
|
@ -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)
|
// 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) {
|
func (aws *AWSCloud) ExternalID(name string) (string, error) {
|
||||||
// We must verify that the instance still exists
|
// We must verify that the instance still exists
|
||||||
instance, err := aws.getInstanceByNodeName(name)
|
instance, err := aws.findInstanceByNodeName(name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
@ -2253,7 +2253,8 @@ func (a *AWSCloud) getInstancesByNodeNames(nodeNames []string) ([]*ec2.Instance,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns the instance with the specified node name
|
// 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{
|
filters := []*ec2.Filter{
|
||||||
newEc2Filter("private-dns-name", nodeName),
|
newEc2Filter("private-dns-name", nodeName),
|
||||||
}
|
}
|
||||||
|
@ -2267,7 +2268,7 @@ func (a *AWSCloud) getInstanceByNodeName(nodeName string) (*ec2.Instance, error)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if len(instances) == 0 {
|
if len(instances) == 0 {
|
||||||
return nil, fmt.Errorf("no instances found for name: %s", nodeName)
|
return nil, nil
|
||||||
}
|
}
|
||||||
if len(instances) > 1 {
|
if len(instances) > 1 {
|
||||||
return nil, fmt.Errorf("multiple instances found for name: %s", nodeName)
|
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
|
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
|
// Add additional filters, to match on our tags
|
||||||
// This lets us run multiple k8s clusters in a single EC2 AZ
|
// This lets us run multiple k8s clusters in a single EC2 AZ
|
||||||
func (s *AWSCloud) addFilters(filters []*ec2.Filter) []*ec2.Filter {
|
func (s *AWSCloud) addFilters(filters []*ec2.Filter) []*ec2.Filter {
|
||||||
|
|
|
@ -408,6 +408,7 @@ func (nc *NodeController) monitorNodeStatus() error {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if _, err := instances.ExternalID(node.Name); err != nil && err == cloudprovider.InstanceNotFound {
|
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 {
|
if err := nc.kubeClient.Nodes().Delete(node.Name); err != nil {
|
||||||
glog.Errorf("Unable to delete node %s: %v", node.Name, err)
|
glog.Errorf("Unable to delete node %s: %v", node.Name, err)
|
||||||
continue
|
continue
|
||||||
|
|
Loading…
Reference in New Issue