From 7a5166b9ffad5183004f515a84ebaa7430b33536 Mon Sep 17 00:00:00 2001 From: vadasambar Date: Thu, 23 Mar 2023 18:25:09 +0530 Subject: [PATCH] fix: implement function to identify if node is present in aws - this is a follow-up to https://github.com/kubernetes/autoscaler/pull/5054 - this might fix https://github.com/kubernetes/autoscaler/issues/4456 Signed-off-by: vadasambar fix: make `HasInstance` in aws provider thread-safe Signed-off-by: vadasambar (cherry picked from commit 1cb55fe546ed0e5c12b8c709d90db09970ae4107) --- .../cloudprovider/aws/aws_cloud_provider.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/cluster-autoscaler/cloudprovider/aws/aws_cloud_provider.go b/cluster-autoscaler/cloudprovider/aws/aws_cloud_provider.go index 23b00fb4668..3ad19cf835c 100644 --- a/cluster-autoscaler/cloudprovider/aws/aws_cloud_provider.go +++ b/cluster-autoscaler/cloudprovider/aws/aws_cloud_provider.go @@ -121,8 +121,19 @@ func (aws *awsCloudProvider) NodeGroupForNode(node *apiv1.Node) (cloudprovider.N } // HasInstance returns whether a given node has a corresponding instance in this cloud provider -func (aws *awsCloudProvider) HasInstance(*apiv1.Node) (bool, error) { - return true, cloudprovider.ErrNotImplemented +func (aws *awsCloudProvider) HasInstance(node *apiv1.Node) (bool, error) { + awsRef, err := AwsRefFromProviderId(node.Spec.ProviderID) + if err != nil { + return false, err + } + + // we don't care about the status + status, err := aws.awsManager.asgCache.InstanceStatus(*awsRef) + if status != nil { + return true, nil + } + + return false, fmt.Errorf("node is not present in aws: %v", err) } // Pricing returns pricing model for this cloud provider or error if not available.