From 40d34d214fddf7fc269d3087adbef22a8ad2c94d 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 fix: make `HasInstance` in aws provider thread-safe Signed-off-by: vadasambar (cherry picked from commit 1cb55fe546ed0e5c12b8c709d90db09970ae4107) --- .../cloudprovider/aws/aws_cloud_provider.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/cluster-autoscaler/cloudprovider/aws/aws_cloud_provider.go b/cluster-autoscaler/cloudprovider/aws/aws_cloud_provider.go index 4bf11960209d..4790f727f46a 100644 --- a/cluster-autoscaler/cloudprovider/aws/aws_cloud_provider.go +++ b/cluster-autoscaler/cloudprovider/aws/aws_cloud_provider.go @@ -119,6 +119,22 @@ func (aws *awsCloudProvider) NodeGroupForNode(node *apiv1.Node) (cloudprovider.N }, nil } +// HasInstance returns whether a given node has a corresponding instance in this cloud provider +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. func (aws *awsCloudProvider) Pricing() (cloudprovider.PricingModel, errors.AutoscalerError) { return nil, cloudprovider.ErrNotImplemented