From 54203aaa9e08bb058957c46bfee1e4191bc40644 Mon Sep 17 00:00:00 2001 From: Maxim Ivanov Date: Mon, 1 May 2017 16:29:35 +0100 Subject: [PATCH 1/2] fix AWS tagging to add missing tags only It seems that intention of original code was to build map of missing tags and call AWS API to add just them, but due to typo full set of tags was always (re)added --- pkg/cloudprovider/providers/aws/tags.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/pkg/cloudprovider/providers/aws/tags.go b/pkg/cloudprovider/providers/aws/tags.go index 33c2719e993..7b309c89efc 100644 --- a/pkg/cloudprovider/providers/aws/tags.go +++ b/pkg/cloudprovider/providers/aws/tags.go @@ -174,7 +174,7 @@ func (c *awsTagging) readRepairClusterTags(client EC2, resourceID string, lifecy } } - if err := c.createTags(client, resourceID, lifecycle, additionalTags); err != nil { + if err := c.createTags(client, resourceID, lifecycle, addTags); err != nil { return fmt.Errorf("error adding missing tags to resource %q: %v", resourceID, err) } @@ -184,9 +184,7 @@ func (c *awsTagging) readRepairClusterTags(client EC2, resourceID string, lifecy // createTags calls EC2 CreateTags, but adds retry-on-failure logic // We retry mainly because if we create an object, we cannot tag it until it is "fully created" (eventual consistency) // The error code varies though (depending on what we are tagging), so we simply retry on all errors -func (t *awsTagging) createTags(client EC2, resourceID string, lifecycle ResourceLifecycle, additionalTags map[string]string) error { - tags := t.buildTags(lifecycle, additionalTags) - +func (t *awsTagging) createTags(client EC2, resourceID string, lifecycle ResourceLifecycle, tags map[string]string) error { if tags == nil || len(tags) == 0 { return nil } From 9ef85a7e6d68cf25560c1d394b3af3390f687590 Mon Sep 17 00:00:00 2001 From: Maxim Ivanov Date: Tue, 2 May 2017 06:32:52 +0100 Subject: [PATCH 2/2] Restore buildTags in createTags --- pkg/cloudprovider/providers/aws/tags.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pkg/cloudprovider/providers/aws/tags.go b/pkg/cloudprovider/providers/aws/tags.go index 7b309c89efc..ef89d17266b 100644 --- a/pkg/cloudprovider/providers/aws/tags.go +++ b/pkg/cloudprovider/providers/aws/tags.go @@ -174,6 +174,10 @@ func (c *awsTagging) readRepairClusterTags(client EC2, resourceID string, lifecy } } + if len(addTags) == 0 { + return nil + } + if err := c.createTags(client, resourceID, lifecycle, addTags); err != nil { return fmt.Errorf("error adding missing tags to resource %q: %v", resourceID, err) } @@ -184,7 +188,9 @@ func (c *awsTagging) readRepairClusterTags(client EC2, resourceID string, lifecy // createTags calls EC2 CreateTags, but adds retry-on-failure logic // We retry mainly because if we create an object, we cannot tag it until it is "fully created" (eventual consistency) // The error code varies though (depending on what we are tagging), so we simply retry on all errors -func (t *awsTagging) createTags(client EC2, resourceID string, lifecycle ResourceLifecycle, tags map[string]string) error { +func (t *awsTagging) createTags(client EC2, resourceID string, lifecycle ResourceLifecycle, additionalTags map[string]string) error { + tags := t.buildTags(lifecycle, additionalTags) + if tags == nil || len(tags) == 0 { return nil }