From 40430e13a601a3c262df24f897a825a8ba35fbd9 Mon Sep 17 00:00:00 2001 From: Dee Kryvenko <109895+dee-kryvenko@users.noreply.github.com> Date: Mon, 4 Jan 2021 14:10:03 -0800 Subject: [PATCH 1/2] validateTypeStringNullableIntOrPercent should tolerate `100%` value --- kubernetes/validators.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kubernetes/validators.go b/kubernetes/validators.go index f89463949a..026056c183 100644 --- a/kubernetes/validators.go +++ b/kubernetes/validators.go @@ -281,7 +281,7 @@ func validateTypeStringNullableIntOrPercent(v interface{}, key string) (ws []str if err != nil { es = append(es, fmt.Errorf("%s: cannot parse '%s' as percent: %s", key, value, err)) } - if percent < 0 || percent >= 100 { + if percent < 0 || percent > 100 { es = append(es, fmt.Errorf("%s: '%s' is not between 0%% and 100%%", key, value)) } } else if _, err := strconv.ParseInt(value, 10, 32); err != nil { From e58ea932b138c60a6685bc66c90d3c8eab116226 Mon Sep 17 00:00:00 2001 From: John Houston Date: Wed, 31 Mar 2021 16:30:20 -0400 Subject: [PATCH 2/2] Add unit test for validateTypeStringNullableIntOrPercent --- kubernetes/validators_test.go | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/kubernetes/validators_test.go b/kubernetes/validators_test.go index a35aff4633..d4ab9e7717 100644 --- a/kubernetes/validators_test.go +++ b/kubernetes/validators_test.go @@ -131,3 +131,33 @@ func TestValidateNonNegativeInteger(t *testing.T) { } } } + +func TestValidateTypeStringNullableIntOrPercent(t *testing.T) { + validCases := []string{ + "", + "1", + "100", + "1%", + "100%", + } + for _, data := range validCases { + _, es := validateTypeStringNullableIntOrPercent(data, "replicas") + if len(es) > 0 { + t.Fatalf("Expected %q to be valid: %#v", data, es) + } + } + invalidCases := []string{ + " ", + "0.1", + "test", + "!@@#$", + "💣", + "%", + } + for _, data := range invalidCases { + _, es := validateTypeStringNullableIntOrPercent(data, "replicas") + if len(es) == 0 { + t.Fatalf("Expected %q to be invalid", data) + } + } +}