Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[release-1.25] Automated cherry pick of #674: do not allow ec2 instance ID not found in tagging path #697

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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