Merge pull request #23317 from aanm/removing-ipv4-enforcement

Automatic merge from submit-queue

Remove requirement that Endpoints IPs be IPv4

Signed-off-by: André Martins <aanm90@gmail.com>

Release Note: The `Endpoints` API object now allows IPv6 addresses to be stored.  Other components of the system are not ready for IPv6 yet, and many cloud providers are not IPv6 compatible, but installations that use their own controller logic can now store v6 endpoints.
This commit is contained in:
k8s-merge-robot
2016-04-21 03:34:50 -07:00
9 changed files with 25 additions and 18 deletions

View File

@@ -155,9 +155,9 @@ func IsValidPortName(port string) bool {
return false
}
// IsValidIPv4 tests that the argument is a valid IPv4 address.
func IsValidIPv4(value string) bool {
return net.ParseIP(value) != nil && net.ParseIP(value).To4() != nil
// IsValidIP tests that the argument is a valid IP address.
func IsValidIP(value string) bool {
return net.ParseIP(value) != nil
}
const percentFmt string = "[0-9]+%"

View File

@@ -281,6 +281,11 @@ func TestIsValidLabelValue(t *testing.T) {
func TestIsValidIP(t *testing.T) {
goodValues := []string{
"::1",
"2a00:79e0:2:0:f1c3:e797:93c1:df80",
"::",
"2001:4860:4860::8888",
"::fff:1.1.1.1",
"1.1.1.1",
"1.1.1.01",
"255.0.0.1",
@@ -288,22 +293,20 @@ func TestIsValidIP(t *testing.T) {
"0.0.0.0",
}
for _, val := range goodValues {
if !IsValidIPv4(val) {
if !IsValidIP(val) {
t.Errorf("expected true for %q", val)
}
}
badValues := []string{
"2a00:79e0:2:0:f1c3:e797:93c1:df80", // This is valid IPv6
"a",
"[2001:db8:0:1]:80",
"myhost.mydomain",
"-1.0.0.0",
"1.0.0.256",
"1.0.0.1.1",
"1.0.0.1.",
"[2001:db8:0:1]",
"a",
}
for _, val := range badValues {
if IsValidIPv4(val) {
if IsValidIP(val) {
t.Errorf("expected false for %q", val)
}
}