From 12346db6dc0a69189054ed092869cdacea18db45 Mon Sep 17 00:00:00 2001 From: Nicholas Baker Date: Fri, 13 Oct 2023 15:13:20 -0700 Subject: [PATCH] do not allow ec2 instance ID not found in tagging path --- pkg/providers/v1/tags.go | 6 ++---- pkg/providers/v1/tags_test.go | 5 +++-- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/pkg/providers/v1/tags.go b/pkg/providers/v1/tags.go index daef72e639..beaaf0ca7d 100644 --- a/pkg/providers/v1/tags.go +++ b/pkg/providers/v1/tags.go @@ -322,10 +322,6 @@ func (c *Cloud) TagResource(resourceID string, tags map[string]string) error { output, err := c.ec2.CreateTags(request) if err != nil { - if isAWSErrorInstanceNotFound(err) { - klog.Infof("Couldn't find resource when trying to tag it hence skipping it, %v", err) - return nil - } klog.Errorf("Error occurred trying to tag resources, %v", err) return err } @@ -346,6 +342,8 @@ func (c *Cloud) UntagResource(resourceID string, tags map[string]string) error { output, err := c.ec2.DeleteTags(request) if err != nil { + // An instance not found should not fail the untagging workflow as it + // would for tagging, since the target state is already reached. if isAWSErrorInstanceNotFound(err) { klog.Infof("Couldn't find resource when trying to untag it hence skipping it, %v", err) return nil diff --git a/pkg/providers/v1/tags_test.go b/pkg/providers/v1/tags_test.go index 17e1958ba9..af2e70927e 100644 --- a/pkg/providers/v1/tags_test.go +++ b/pkg/providers/v1/tags_test.go @@ -24,6 +24,7 @@ import ( "testing" "github.com/aws/aws-sdk-go/aws" + "github.com/aws/aws-sdk-go/aws/awserr" "github.com/aws/aws-sdk-go/service/ec2" "github.com/stretchr/testify/assert" "k8s.io/klog/v2" @@ -268,8 +269,8 @@ func TestTagResource(t *testing.T) { { name: "tagging failed due to resource not found error", instanceID: "i-not-found", - err: nil, - expectedMessage: "Couldn't find resource when trying to tag it hence skipping it", + err: awserr.New("InvalidInstanceID.NotFound", "Instance not found", nil), + expectedMessage: "Error occurred trying to tag resources", }, }