From e952c12dfe12e0c8776e7a989ab93dfac417d615 Mon Sep 17 00:00:00 2001 From: Arto Jantunen Date: Tue, 25 Sep 2018 10:45:41 +0300 Subject: [PATCH 1/2] AWS: Add a simple test for "shared" tag For some reason this wasn't done in 0b5ae5391ef9. --- pkg/cloudprovider/providers/aws/tags_test.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pkg/cloudprovider/providers/aws/tags_test.go b/pkg/cloudprovider/providers/aws/tags_test.go index c745451431b..2f1f3a44c74 100644 --- a/pkg/cloudprovider/providers/aws/tags_test.go +++ b/pkg/cloudprovider/providers/aws/tags_test.go @@ -57,6 +57,12 @@ func TestFindClusterID(t *testing.T) { }, ExpectedNew: "a", }, + { + Tags: map[string]string{ + TagNameKubernetesClusterPrefix + "a": "shared", + }, + ExpectedNew: "a", + }, { Tags: map[string]string{ TagNameKubernetesClusterPrefix + "a": "", From 986faed326089b6b92f582648dcd84b6a02a8cec Mon Sep 17 00:00:00 2001 From: Arto Jantunen Date: Tue, 25 Sep 2018 11:11:23 +0300 Subject: [PATCH 2/2] AWS: Add tests for awsTagging.hasClusterTag Among other things these tests verify the fix for issue #64230. --- pkg/cloudprovider/providers/aws/tags_test.go | 65 ++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/pkg/cloudprovider/providers/aws/tags_test.go b/pkg/cloudprovider/providers/aws/tags_test.go index 2f1f3a44c74..a8b55b80293 100644 --- a/pkg/cloudprovider/providers/aws/tags_test.go +++ b/pkg/cloudprovider/providers/aws/tags_test.go @@ -114,3 +114,68 @@ func TestFindClusterID(t *testing.T) { } } } + +func TestHasClusterTag(t *testing.T) { + awsServices := NewFakeAWSServices(TestClusterId) + c, err := newAWSCloud(CloudConfig{}, awsServices) + if err != nil { + t.Errorf("Error building aws cloud: %v", err) + return + } + grid := []struct { + Tags map[string]string + Expected bool + }{ + { + Tags: map[string]string{}, + }, + { + Tags: map[string]string{ + TagNameKubernetesClusterLegacy: TestClusterId, + }, + Expected: true, + }, + { + Tags: map[string]string{ + TagNameKubernetesClusterLegacy: "a", + }, + Expected: false, + }, + { + Tags: map[string]string{ + TagNameKubernetesClusterPrefix + TestClusterId: "owned", + }, + Expected: true, + }, + { + Tags: map[string]string{ + TagNameKubernetesClusterPrefix + TestClusterId: "", + }, + Expected: true, + }, + { + Tags: map[string]string{ + TagNameKubernetesClusterLegacy: "a", + TagNameKubernetesClusterPrefix + TestClusterId: "shared", + }, + Expected: true, + }, + { + Tags: map[string]string{ + TagNameKubernetesClusterPrefix + TestClusterId: "shared", + TagNameKubernetesClusterPrefix + "b": "shared", + }, + Expected: true, + }, + } + for _, g := range grid { + var ec2Tags []*ec2.Tag + for k, v := range g.Tags { + ec2Tags = append(ec2Tags, &ec2.Tag{Key: aws.String(k), Value: aws.String(v)}) + } + result := c.tagging.hasClusterTag(ec2Tags) + if result != g.Expected { + t.Errorf("Unexpected result for tags %v: %t", g.Tags, result) + } + } +}