Skip to content

Commit

Permalink
pkg/types/installconfig: Add an (*InstallConfig).Tags() helper
Browse files Browse the repository at this point in the history
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]: #458 (comment)
  • Loading branch information
wking committed Oct 15, 2018
1 parent e2547ee commit 9a2a91e
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
15 changes: 15 additions & 0 deletions pkg/types/installconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
27 changes: 27 additions & 0 deletions pkg/types/installconfig_test.go
Original file line number Diff line number Diff line change
@@ -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())
}

0 comments on commit 9a2a91e

Please sign in to comment.