Skip to content

Commit 81fea36

Browse files
committed
merged upstream
1 parent 925e1c3 commit 81fea36

File tree

4 files changed

+50
-9
lines changed

4 files changed

+50
-9
lines changed

go.mod

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ require (
5151
github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161 // indirect
5252
github.com/NYTimes/gziphandler v1.1.1 // indirect
5353
github.com/antlr4-go/antlr/v4 v4.13.0 // indirect
54-
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 // indirect
5554
github.com/aws/aws-sdk-go-v2/credentials v1.17.67
5655
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.30 // indirect
5756
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.34 // indirect

pkg/controllers/tagging/tagging_controller.go

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -322,9 +322,9 @@ func (tc *Controller) tagEc2Instance(ctx context.Context, node *v1.Node) error {
322322
var err error
323323
instanceID, _ := awsv1.KubernetesInstanceID(node.Spec.ProviderID).MapToAWSInstanceID()
324324
if tc.batchingEnabled {
325-
err = tc.cloud.TagResourceBatch(context.TODO(), string(instanceID), tc.tags)
325+
err = tc.cloud.TagResourceBatch(ctx, string(instanceID), tc.tags)
326326
} else {
327-
err = tc.cloud.TagResource(string(instanceID), tc.tags)
327+
err = tc.cloud.TagResource(ctx, string(instanceID), tc.tags)
328328
}
329329

330330
if err != nil {
@@ -381,16 +381,12 @@ func (tc *Controller) untagNodeResources(ctx context.Context, node *taggingContr
381381
func (tc *Controller) untagEc2Instance(ctx context.Context, node *taggingControllerNode) error {
382382
instanceID, _ := awsv1.KubernetesInstanceID(node.providerID).MapToAWSInstanceID()
383383

384-
<<<<<<< HEAD
385-
err := tc.cloud.UntagResource(ctx, string(instanceID), tc.tags)
386-
=======
387384
var err error
388385
if tc.batchingEnabled {
389386
err = tc.cloud.UntagResourceBatch(context.TODO(), string(instanceID), tc.tags)
390387
} else {
391-
err = tc.cloud.UntagResource(string(instanceID), tc.tags)
388+
err = tc.cloud.UntagResource(ctx, string(instanceID), tc.tags)
392389
}
393-
>>>>>>> upstream/master
394390

395391
if err != nil {
396392
klog.Errorf("Error in untagging EC2 instance %s for node %s, error: %v", instanceID, node.name, err)

pkg/controllers/tagging/tagging_controller_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ func Test_NodesJoiningAndLeaving(t *testing.T) {
245245

246246
cnt := 0
247247
for tc.workqueue.Len() > 0 {
248-
tc.process()
248+
tc.process(context.TODO())
249249
cnt++
250250
// sleep briefly because of exponential backoff when requeueing failed workitem
251251
// resulting in workqueue to be empty if checked immediately

pkg/providers/v1/tags.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,26 @@ func (c *Cloud) TagResource(ctx context.Context, resourceID string, tags map[str
336336
return nil
337337
}
338338

339+
// TagResourceBatch calls EC2 and tag the resource associated to resourceID with the supplied tags
340+
// calls are batched based on batcher configuration.
341+
func (c *Cloud) TagResourceBatch(ctx context.Context, resourceID string, tags map[string]string) error {
342+
request := &ec2.CreateTagsInput{
343+
Resources: []string{resourceID},
344+
Tags: buildAwsTags(tags),
345+
}
346+
347+
output, err := c.createTagsBatcher.createTags(ctx, request)
348+
349+
if err != nil {
350+
klog.Errorf("Error occurred trying to tag resources, %v", err)
351+
return err
352+
}
353+
354+
klog.Infof("Done calling create-tags to EC2: %v", output)
355+
356+
return nil
357+
}
358+
339359
// UntagResource calls EC2 and tag the resource associated to resourceID
340360
// with the supplied tags
341361
func (c *Cloud) UntagResource(ctx context.Context, resourceID string, tags map[string]string) error {
@@ -362,6 +382,32 @@ func (c *Cloud) UntagResource(ctx context.Context, resourceID string, tags map[s
362382
return nil
363383
}
364384

385+
// UntagResourceBatch calls EC2 and tag the resource associated to resourceID with the supplied tags
386+
// calls are batched based on batcher configuration.
387+
func (c *Cloud) UntagResourceBatch(ctx context.Context, resourceID string, tags map[string]string) error {
388+
request := &ec2.DeleteTagsInput{
389+
Resources: []string{resourceID},
390+
Tags: buildAwsTags(tags),
391+
}
392+
393+
output, err := c.deleteTagsBatcher.deleteTags(ctx, request)
394+
395+
if err != nil {
396+
// An instance not found should not fail the untagging workflow as it
397+
// would for tagging, since the target state is already reached.
398+
if IsAWSErrorInstanceNotFound(err) {
399+
klog.Infof("Couldn't find resource when trying to untag it hence skipping it, %v", err)
400+
return nil
401+
}
402+
klog.Errorf("Error occurred trying to untag resources, %v", err)
403+
return err
404+
}
405+
406+
klog.Infof("Done calling delete-tags to EC2: %v", output)
407+
408+
return nil
409+
}
410+
365411
func buildAwsTags(tags map[string]string) []ec2types.Tag {
366412
var awsTags []ec2types.Tag
367413
for k, v := range tags {

0 commit comments

Comments
 (0)