From fae2ce9bbf7c94b8f06fc777d16f4a7b73519ba3 Mon Sep 17 00:00:00 2001 From: vishal Date: Fri, 2 Jul 2021 16:17:57 -0400 Subject: [PATCH 1/2] Cluster up nits --- pkg/lib/configreader/errors.go | 8 ++++++++ pkg/lib/configreader/string.go | 7 +++++++ pkg/lib/regex/regex.go | 6 ++++++ pkg/types/clusterconfig/cluster_config.go | 6 +++--- pkg/types/clusterstate/clusterstate.go | 1 + 5 files changed, 25 insertions(+), 3 deletions(-) diff --git a/pkg/lib/configreader/errors.go b/pkg/lib/configreader/errors.go index c6509d09be..3c3a4aacdc 100644 --- a/pkg/lib/configreader/errors.go +++ b/pkg/lib/configreader/errors.go @@ -35,6 +35,7 @@ const ( ErrLeadingWhitespace = "configreader.leading_whitespace" ErrTrailingWhitespace = "configreader.trailing_whitespace" ErrAlphaNumericDashUnderscore = "configreader.alpha_numeric_dash_underscore" + ErrAlphaNumericDash = "configreader.alpha_numeric_dash" ErrAlphaNumericDotUnderscore = "configreader.alpha_numeric_dot_underscore" ErrAlphaNumericDashDotUnderscore = "configreader.alpha_numeric_dash_dot_underscore" ErrInvalidAWSTag = "configreader.invalid_aws_tag" @@ -140,6 +141,13 @@ func ErrorAlphaNumericDashUnderscore(provided string) error { }) } +func ErrorAlphaNumericDash(provided string) error { + return errors.WithStack(&errors.Error{ + Kind: ErrAlphaNumericDash, + Message: fmt.Sprintf("%s must contain only letters, numbers, and dashes", s.UserStr(provided)), + }) +} + func ErrorAlphaNumericDotUnderscore(provided string) error { return errors.WithStack(&errors.Error{ Kind: ErrAlphaNumericDotUnderscore, diff --git a/pkg/lib/configreader/string.go b/pkg/lib/configreader/string.go index 63ab85a5dc..07931acc9e 100644 --- a/pkg/lib/configreader/string.go +++ b/pkg/lib/configreader/string.go @@ -54,6 +54,7 @@ type StringValidation struct { AlphaNumericDashUnderscoreOrEmpty bool AlphaNumericDashUnderscore bool AlphaNumericDotUnderscore bool + AlphaNumericDash bool AWSTag bool DNS1035 bool DNS1123 bool @@ -334,6 +335,12 @@ func ValidateStringVal(val string, v *StringValidation) error { } } + if v.AlphaNumericDash { + if !regex.IsAlphaNumericDash(val) { + return ErrorAlphaNumericDash(val) + } + } + if v.AlphaNumericDashUnderscoreOrEmpty { if !regex.IsAlphaNumericDashUnderscore(val) && val != "" { return ErrorAlphaNumericDashUnderscore(val) diff --git a/pkg/lib/regex/regex.go b/pkg/lib/regex/regex.go index 7ee75f8677..3a702fa0c8 100644 --- a/pkg/lib/regex/regex.go +++ b/pkg/lib/regex/regex.go @@ -67,6 +67,12 @@ func IsAlphaNumericDotUnderscore(s string) bool { return _alphaNumericDotUnderscoreRegex.MatchString(s) } +var _alphaNumericDashRegex = regexp.MustCompile(`^[a-zA-Z0-9\-]+$`) + +func IsAlphaNumericDash(s string) bool { + return _alphaNumericDashRegex.MatchString(s) +} + // used the evaluated form of // https://github.com/docker/distribution/blob/3150937b9f2b1b5b096b2634d0e7c44d4a0f89fb/reference/regexp.go#L68-L70 var _dockerValidImage = regexp.MustCompile( diff --git a/pkg/types/clusterconfig/cluster_config.go b/pkg/types/clusterconfig/cluster_config.go index b48f9e403a..536516bc85 100644 --- a/pkg/types/clusterconfig/cluster_config.go +++ b/pkg/types/clusterconfig/cluster_config.go @@ -705,9 +705,9 @@ var nodeGroupsFieldValidation *cr.StructValidation = &cr.StructValidation{ { StructField: "Name", StringValidation: &cr.StringValidation{ - Required: true, - AlphaNumericDashUnderscore: true, - MaxLength: _maxNodeGroupLength, + Required: true, + AlphaNumericDash: true, + MaxLength: _maxNodeGroupLength, }, }, { diff --git a/pkg/types/clusterstate/clusterstate.go b/pkg/types/clusterstate/clusterstate.go index 60e859d52c..73747c0f30 100644 --- a/pkg/types/clusterstate/clusterstate.go +++ b/pkg/types/clusterstate/clusterstate.go @@ -142,6 +142,7 @@ func GetClusterState(stacks ClusterStacks) State { } if slices.HasString([]string{ + cloudformation.StackStatusCreateInProgress, cloudformation.StackStatusCreateComplete, cloudformation.StackStatusUpdateComplete, cloudformation.StackStatusRollbackComplete, From 9d5d46960116c91109a577d86bac500c10692c49 Mon Sep 17 00:00:00 2001 From: vishal Date: Fri, 2 Jul 2021 17:29:09 -0400 Subject: [PATCH 2/2] Add other relevant in progress states --- pkg/types/clusterstate/clusterstate.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pkg/types/clusterstate/clusterstate.go b/pkg/types/clusterstate/clusterstate.go index 73747c0f30..5a3f8c688b 100644 --- a/pkg/types/clusterstate/clusterstate.go +++ b/pkg/types/clusterstate/clusterstate.go @@ -144,8 +144,11 @@ func GetClusterState(stacks ClusterStacks) State { if slices.HasString([]string{ cloudformation.StackStatusCreateInProgress, cloudformation.StackStatusCreateComplete, + cloudformation.StackStatusUpdateInProgress, cloudformation.StackStatusUpdateComplete, + cloudformation.StackStatusRollbackInProgress, cloudformation.StackStatusRollbackComplete, + cloudformation.StackStatusUpdateRollbackInProgress, cloudformation.StackStatusUpdateRollbackComplete, }, controlPlaneStatus) { return StateClusterExists