From 9a2a91ebcd44bc6d70381421b0c93a1a9347305a Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Mon, 15 Oct 2018 11:21:40 -0700 Subject: [PATCH] pkg/types/installconfig: Add an (*InstallConfig).Tags() helper AWS resources created by the cluster (e.g. some elastic load-balancers) are currently missing the tectonicClusterID tag [1], which makes cleanup difficult. This helper makes it easy for those external tools to set the appropriate tags without needing local logic to generate them. [1]: https://github.com/openshift/installer/issues/458#issuecomment-429876113 --- pkg/types/installconfig.go | 15 +++++++++++++++ pkg/types/installconfig_test.go | 27 +++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 pkg/types/installconfig_test.go diff --git a/pkg/types/installconfig.go b/pkg/types/installconfig.go index 7daa719ea64..5dccafb2b16 100644 --- a/pkg/types/installconfig.go +++ b/pkg/types/installconfig.go @@ -48,6 +48,21 @@ func (c *InstallConfig) MasterCount() int { return 1 } +// Tags returns tags which should be added to resources created for +// the cluster. This includes both installer- and user-specified tags. +func (c *InstallConfig) Tags() (tags map[string]string) { + tags = make(map[string]string) + tags["tectonicClusterID"] = c.ClusterID + + if c.Platform.AWS != nil { + for key, value := range c.Platform.AWS.UserTags { + tags[key] = value + } + } + + return tags +} + // Admin is the configuration for the admin user. type Admin struct { // Email is the email address of the admin user. diff --git a/pkg/types/installconfig_test.go b/pkg/types/installconfig_test.go new file mode 100644 index 00000000000..40e13096fa0 --- /dev/null +++ b/pkg/types/installconfig_test.go @@ -0,0 +1,27 @@ +package types + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestTags(t *testing.T) { + config := &InstallConfig{ + ClusterID: "123", + Platform: Platform{ + AWS: &AWSPlatform{ + UserTags: map[string]string{ + "abc": "def", + }, + }, + }, + } + + expected := map[string]string{ + "abc": "def", + "tectonicClusterID": "123", + } + + assert.Equal(t, expected, config.Tags()) +}