From 8d387a68aa0fb4c1c42d016fc7f6f54cbb7654a8 Mon Sep 17 00:00:00 2001 From: Dan Winship Date: Tue, 23 Jan 2024 08:25:52 -0500 Subject: [PATCH] Drop validation.IsValidSocketAddr It's not used anywhere, and if someone was going to validate an IP:port somewhere, they should think about exactly what they want rather than just using this function. (E.g., validation should be slightly different for an IP:port to bind to vs an IP:port to connect to.) Kubernetes-commit: 8fc691be940e73dac324e92c3207ed03df74b1ca --- pkg/util/validation/validation.go | 17 ---------------- pkg/util/validation/validation_test.go | 28 -------------------------- 2 files changed, 45 deletions(-) diff --git a/pkg/util/validation/validation.go b/pkg/util/validation/validation.go index 0b8a6cb35..6f8a2e26b 100644 --- a/pkg/util/validation/validation.go +++ b/pkg/util/validation/validation.go @@ -19,9 +19,7 @@ package validation import ( "fmt" "math" - "net" "regexp" - "strconv" "strings" "k8s.io/apimachinery/pkg/util/validation/field" @@ -493,18 +491,3 @@ func hasChDirPrefix(value string) []string { } return errs } - -// IsValidSocketAddr checks that string represents a valid socket address -// as defined in RFC 789. (e.g 0.0.0.0:10254 or [::]:10254)) -func IsValidSocketAddr(value string) []string { - var errs []string - ip, port, err := net.SplitHostPort(value) - if err != nil { - errs = append(errs, "must be a valid socket address format, (e.g. 0.0.0.0:10254 or [::]:10254)") - return errs - } - portInt, _ := strconv.Atoi(port) - errs = append(errs, IsValidPortNum(portInt)...) - errs = append(errs, IsValidIP(ip)...) - return errs -} diff --git a/pkg/util/validation/validation_test.go b/pkg/util/validation/validation_test.go index 499b13c73..c439e0398 100644 --- a/pkg/util/validation/validation_test.go +++ b/pkg/util/validation/validation_test.go @@ -710,31 +710,3 @@ func TestIsDomainPrefixedPath(t *testing.T) { } } } - -func TestIsValidSocketAddr(t *testing.T) { - goodValues := []string{ - "0.0.0.0:10254", - "127.0.0.1:8888", - "[2001:db8:1f70::999:de8:7648:6e8]:10254", - "[::]:10254", - } - for _, val := range goodValues { - if errs := IsValidSocketAddr(val); len(errs) != 0 { - t.Errorf("expected no errors for %q: %v", val, errs) - } - } - - badValues := []string{ - "0.0.0.0.0:2020", - "0.0.0.0", - "6.6.6.6:909090", - "2001:db8:1f70::999:de8:7648:6e8:87567:102545", - "", - "*", - } - for _, val := range badValues { - if errs := IsValidSocketAddr(val); len(errs) == 0 { - t.Errorf("expected errors for %q", val) - } - } -}