Skip to content

Fix default cluster tag validation #1380

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions pkg/types/clusterconfig/clusterconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -626,9 +626,14 @@ func (cc *Config) Validate(awsClient *aws.Client) error {
}
}

for tagName := range cc.Tags {
for tagName, tagValue := range cc.Tags {
if strings.HasPrefix(tagName, "cortex.dev/") {
return errors.Wrap(cr.ErrorCantHavePrefix(tagName, "cortex.dev/"), TagsKey)
if tagName != ClusterNameTag {
return errors.Wrap(cr.ErrorCantHavePrefix(tagName, "cortex.dev/"), TagsKey)
}
if tagValue != cc.ClusterName {
return errors.Wrap(ErrorCantOverrideDefaultTag(), TagsKey)
}
}
}
cc.Tags[ClusterNameTag] = cc.ClusterName
Expand Down
8 changes: 8 additions & 0 deletions pkg/types/clusterconfig/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ const (
ErrInvalidInstanceType = "clusterconfig.invalid_instance_type"
ErrIOPSNotSupported = "clusterconfig.iops_not_supported"
ErrIOPSTooLarge = "clusterconfig.iops_too_large"
ErrCantOverrideDefaultTag = "clusterconfig.cant_override_default_tag"
ErrSSLCertificateARNNotFound = "clusterconfig.ssl_certificate_arn_not_found"
)

Expand Down Expand Up @@ -235,6 +236,13 @@ func ErrorIOPSTooLarge(iops int64, volumeSize int64) error {
})
}

func ErrorCantOverrideDefaultTag() error {
return errors.WithStack(&errors.Error{
Kind: ErrCantOverrideDefaultTag,
Message: fmt.Sprintf("the \"%s\" tag cannot be overridden (it is set by default, and will always be equal to your cluster name)", ClusterNameTag),
})
}

func ErrorSSLCertificateARNNotFound(sslCertificateARN string, region string) error {
return errors.WithStack(&errors.Error{
Kind: ErrSSLCertificateARNNotFound,
Expand Down