Skip to content

Commit

Permalink
Merge pull request #697 from ndbaker1/automated-cherry-pick-of-#674-u…
Browse files Browse the repository at this point in the history
…pstream-release-1.25

[release-1.25] Automated cherry pick of #674: do not allow ec2 instance ID not found in tagging path
  • Loading branch information
k8s-ci-robot authored Oct 25, 2023
2 parents 569c6cd + 12346db commit 663dd65
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
6 changes: 2 additions & 4 deletions pkg/providers/v1/tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
Expand Down
5 changes: 3 additions & 2 deletions pkg/providers/v1/tags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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",
},
}

Expand Down

0 comments on commit 663dd65

Please sign in to comment.