mirror of
				https://github.com/optim-enterprises-bv/kubernetes.git
				synced 2025-11-04 12:18:16 +00:00 
			
		
		
		
	Removing IPv4 enforcement on Endpoints
Signed-off-by: André Martins <aanm90@gmail.com>
This commit is contained in:
		@@ -15235,7 +15235,7 @@
 | 
				
			|||||||
    "properties": {
 | 
					    "properties": {
 | 
				
			||||||
     "ip": {
 | 
					     "ip": {
 | 
				
			||||||
      "type": "string",
 | 
					      "type": "string",
 | 
				
			||||||
      "description": "The IP of this endpoint. May not be loopback (127.0.0.0/8), link-local (169.254.0.0/16), or link-local multicast ((224.0.0.0/24)."
 | 
					      "description": "The IP of this endpoint. May not be loopback (127.0.0.0/8), link-local (169.254.0.0/16), or link-local multicast ((224.0.0.0/24). IPv6 is also accepted but not fully supported on all platforms. Also, certain kubernetes components, like kube-proxy, are not IPv6 ready."
 | 
				
			||||||
     },
 | 
					     },
 | 
				
			||||||
     "targetRef": {
 | 
					     "targetRef": {
 | 
				
			||||||
      "$ref": "v1.ObjectReference",
 | 
					      "$ref": "v1.ObjectReference",
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -7685,7 +7685,7 @@ The resulting set of endpoints can be viewed as:<br>
 | 
				
			|||||||
<tbody>
 | 
					<tbody>
 | 
				
			||||||
<tr>
 | 
					<tr>
 | 
				
			||||||
<td class="tableblock halign-left valign-top"><p class="tableblock">ip</p></td>
 | 
					<td class="tableblock halign-left valign-top"><p class="tableblock">ip</p></td>
 | 
				
			||||||
<td class="tableblock halign-left valign-top"><p class="tableblock">The IP of this endpoint. May not be loopback (127.0.0.0/8), link-local (169.254.0.0/16), or link-local multicast ((224.0.0.0/24).</p></td>
 | 
					<td class="tableblock halign-left valign-top"><p class="tableblock">The IP of this endpoint. May not be loopback (127.0.0.0/8), link-local (169.254.0.0/16), or link-local multicast ((224.0.0.0/24). IPv6 is also accepted but not fully supported on all platforms. Also, certain kubernetes components, like kube-proxy, are not IPv6 ready.</p></td>
 | 
				
			||||||
<td class="tableblock halign-left valign-top"><p class="tableblock">true</p></td>
 | 
					<td class="tableblock halign-left valign-top"><p class="tableblock">true</p></td>
 | 
				
			||||||
<td class="tableblock halign-left valign-top"><p class="tableblock">string</p></td>
 | 
					<td class="tableblock halign-left valign-top"><p class="tableblock">string</p></td>
 | 
				
			||||||
<td class="tableblock halign-left valign-top"></td>
 | 
					<td class="tableblock halign-left valign-top"></td>
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1624,6 +1624,8 @@ type EndpointSubset struct {
 | 
				
			|||||||
// EndpointAddress is a tuple that describes single IP address.
 | 
					// EndpointAddress is a tuple that describes single IP address.
 | 
				
			||||||
type EndpointAddress struct {
 | 
					type EndpointAddress struct {
 | 
				
			||||||
	// The IP of this endpoint.
 | 
						// The IP of this endpoint.
 | 
				
			||||||
 | 
						// IPv6 is also accepted but not fully supported on all platforms. Also, certain
 | 
				
			||||||
 | 
						// kubernetes components, like kube-proxy, are not IPv6 ready.
 | 
				
			||||||
	// TODO: This should allow hostname or IP, see #4447.
 | 
						// TODO: This should allow hostname or IP, see #4447.
 | 
				
			||||||
	IP string
 | 
						IP string
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1998,6 +1998,8 @@ type EndpointAddress struct {
 | 
				
			|||||||
	// The IP of this endpoint.
 | 
						// The IP of this endpoint.
 | 
				
			||||||
	// May not be loopback (127.0.0.0/8), link-local (169.254.0.0/16),
 | 
						// May not be loopback (127.0.0.0/8), link-local (169.254.0.0/16),
 | 
				
			||||||
	// or link-local multicast ((224.0.0.0/24).
 | 
						// or link-local multicast ((224.0.0.0/24).
 | 
				
			||||||
 | 
						// IPv6 is also accepted but not fully supported on all platforms. Also, certain
 | 
				
			||||||
 | 
						// kubernetes components, like kube-proxy, are not IPv6 ready.
 | 
				
			||||||
	// TODO: This should allow hostname or IP, See #4447.
 | 
						// TODO: This should allow hostname or IP, See #4447.
 | 
				
			||||||
	IP string `json:"ip"`
 | 
						IP string `json:"ip"`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -333,7 +333,7 @@ func (EmptyDirVolumeSource) SwaggerDoc() map[string]string {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
var map_EndpointAddress = map[string]string{
 | 
					var map_EndpointAddress = map[string]string{
 | 
				
			||||||
	"":          "EndpointAddress is a tuple that describes single IP address.",
 | 
						"":          "EndpointAddress is a tuple that describes single IP address.",
 | 
				
			||||||
	"ip":        "The IP of this endpoint. May not be loopback (127.0.0.0/8), link-local (169.254.0.0/16), or link-local multicast ((224.0.0.0/24).",
 | 
						"ip":        "The IP of this endpoint. May not be loopback (127.0.0.0/8), link-local (169.254.0.0/16), or link-local multicast ((224.0.0.0/24). IPv6 is also accepted but not fully supported on all platforms. Also, certain kubernetes components, like kube-proxy, are not IPv6 ready.",
 | 
				
			||||||
	"targetRef": "Reference to object providing the endpoint.",
 | 
						"targetRef": "Reference to object providing the endpoint.",
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -2599,8 +2599,8 @@ func validateEndpointSubsets(subsets []api.EndpointSubset, fldPath *field.Path)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
func validateEndpointAddress(address *api.EndpointAddress, fldPath *field.Path) field.ErrorList {
 | 
					func validateEndpointAddress(address *api.EndpointAddress, fldPath *field.Path) field.ErrorList {
 | 
				
			||||||
	allErrs := field.ErrorList{}
 | 
						allErrs := field.ErrorList{}
 | 
				
			||||||
	if !validation.IsValidIPv4(address.IP) {
 | 
						if !validation.IsValidIP(address.IP) {
 | 
				
			||||||
		allErrs = append(allErrs, field.Invalid(fldPath.Child("ip"), address.IP, "must be a valid IPv4 address"))
 | 
							allErrs = append(allErrs, field.Invalid(fldPath.Child("ip"), address.IP, "must be a valid IP address"))
 | 
				
			||||||
		return allErrs
 | 
							return allErrs
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return validateIpIsNotLinkLocalOrLoopback(address.IP, fldPath.Child("ip"))
 | 
						return validateIpIsNotLinkLocalOrLoopback(address.IP, fldPath.Child("ip"))
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -4909,13 +4909,13 @@ func TestValidateEndpoints(t *testing.T) {
 | 
				
			|||||||
				ObjectMeta: api.ObjectMeta{Name: "mysvc", Namespace: "namespace"},
 | 
									ObjectMeta: api.ObjectMeta{Name: "mysvc", Namespace: "namespace"},
 | 
				
			||||||
				Subsets: []api.EndpointSubset{
 | 
									Subsets: []api.EndpointSubset{
 | 
				
			||||||
					{
 | 
										{
 | 
				
			||||||
						Addresses: []api.EndpointAddress{{IP: "2001:0db8:85a3:0042:1000:8a2e:0370:7334"}},
 | 
											Addresses: []api.EndpointAddress{{IP: "[2001:0db8:85a3:0042:1000:8a2e:0370:7334]"}},
 | 
				
			||||||
						Ports:     []api.EndpointPort{{Name: "a", Port: 93, Protocol: "TCP"}},
 | 
											Ports:     []api.EndpointPort{{Name: "a", Port: 93, Protocol: "TCP"}},
 | 
				
			||||||
					},
 | 
										},
 | 
				
			||||||
				},
 | 
									},
 | 
				
			||||||
			},
 | 
								},
 | 
				
			||||||
			errorType:   "FieldValueInvalid",
 | 
								errorType:   "FieldValueInvalid",
 | 
				
			||||||
			errorDetail: "must be a valid IPv4 address",
 | 
								errorDetail: "must be a valid IP address",
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
		"Multiple ports, one without name": {
 | 
							"Multiple ports, one without name": {
 | 
				
			||||||
			endpoints: api.Endpoints{
 | 
								endpoints: api.Endpoints{
 | 
				
			||||||
@@ -4965,7 +4965,7 @@ func TestValidateEndpoints(t *testing.T) {
 | 
				
			|||||||
				},
 | 
									},
 | 
				
			||||||
			},
 | 
								},
 | 
				
			||||||
			errorType:   "FieldValueInvalid",
 | 
								errorType:   "FieldValueInvalid",
 | 
				
			||||||
			errorDetail: "must be a valid IPv4 address",
 | 
								errorDetail: "must be a valid IP address",
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
		"Port missing number": {
 | 
							"Port missing number": {
 | 
				
			||||||
			endpoints: api.Endpoints{
 | 
								endpoints: api.Endpoints{
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -155,9 +155,9 @@ func IsValidPortName(port string) bool {
 | 
				
			|||||||
	return false
 | 
						return false
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// IsValidIPv4 tests that the argument is a valid IPv4 address.
 | 
					// IsValidIP tests that the argument is a valid IP address.
 | 
				
			||||||
func IsValidIPv4(value string) bool {
 | 
					func IsValidIP(value string) bool {
 | 
				
			||||||
	return net.ParseIP(value) != nil && net.ParseIP(value).To4() != nil
 | 
						return net.ParseIP(value) != nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const percentFmt string = "[0-9]+%"
 | 
					const percentFmt string = "[0-9]+%"
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -281,6 +281,11 @@ func TestIsValidLabelValue(t *testing.T) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
func TestIsValidIP(t *testing.T) {
 | 
					func TestIsValidIP(t *testing.T) {
 | 
				
			||||||
	goodValues := []string{
 | 
						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.1",
 | 
				
			||||||
		"1.1.1.01",
 | 
							"1.1.1.01",
 | 
				
			||||||
		"255.0.0.1",
 | 
							"255.0.0.1",
 | 
				
			||||||
@@ -288,22 +293,20 @@ func TestIsValidIP(t *testing.T) {
 | 
				
			|||||||
		"0.0.0.0",
 | 
							"0.0.0.0",
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	for _, val := range goodValues {
 | 
						for _, val := range goodValues {
 | 
				
			||||||
		if !IsValidIPv4(val) {
 | 
							if !IsValidIP(val) {
 | 
				
			||||||
			t.Errorf("expected true for %q", val)
 | 
								t.Errorf("expected true for %q", val)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	badValues := []string{
 | 
						badValues := []string{
 | 
				
			||||||
		"2a00:79e0:2:0:f1c3:e797:93c1:df80", // This is valid IPv6
 | 
							"[2001:db8:0:1]:80",
 | 
				
			||||||
		"a",
 | 
					 | 
				
			||||||
		"myhost.mydomain",
 | 
							"myhost.mydomain",
 | 
				
			||||||
		"-1.0.0.0",
 | 
							"-1.0.0.0",
 | 
				
			||||||
		"1.0.0.256",
 | 
							"[2001:db8:0:1]",
 | 
				
			||||||
		"1.0.0.1.1",
 | 
							"a",
 | 
				
			||||||
		"1.0.0.1.",
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	for _, val := range badValues {
 | 
						for _, val := range badValues {
 | 
				
			||||||
		if IsValidIPv4(val) {
 | 
							if IsValidIP(val) {
 | 
				
			||||||
			t.Errorf("expected false for %q", val)
 | 
								t.Errorf("expected false for %q", val)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user