Commit 1c9ee749 authored by Ivan Shvedunov's avatar Ivan Shvedunov

Allow IP addresses to be used as node names

Fixes #32050
parent aee6d10b
...@@ -3435,9 +3435,11 @@ func validateEndpointAddress(address *api.EndpointAddress, fldPath *field.Path, ...@@ -3435,9 +3435,11 @@ func validateEndpointAddress(address *api.EndpointAddress, fldPath *field.Path,
if len(address.Hostname) > 0 { if len(address.Hostname) > 0 {
allErrs = append(allErrs, ValidateDNS1123Label(address.Hostname, fldPath.Child("hostname"))...) allErrs = append(allErrs, ValidateDNS1123Label(address.Hostname, fldPath.Child("hostname"))...)
} }
// During endpoint update, validate NodeName is DNS1123 compliant and transition rules allow the update // During endpoint update, verify that NodeName is a DNS subdomain and transition rules allow the update
if address.NodeName != nil { if address.NodeName != nil {
allErrs = append(allErrs, ValidateDNS1123Label(*address.NodeName, fldPath.Child("nodeName"))...) for _, msg := range ValidateNodeName(*address.NodeName, false) {
allErrs = append(allErrs, field.Invalid(fldPath.Child("nodeName"), *address.NodeName, msg))
}
} }
allErrs = append(allErrs, validateEpAddrNodeNameTransition(address, ipToNodeName, fldPath.Child("nodeName"))...) allErrs = append(allErrs, validateEpAddrNodeNameTransition(address, ipToNodeName, fldPath.Child("nodeName"))...)
if len(allErrs) > 0 { if len(allErrs) > 0 {
......
...@@ -8023,11 +8023,19 @@ func TestEndpointAddressNodeNameUpdateRestrictions(t *testing.T) { ...@@ -8023,11 +8023,19 @@ func TestEndpointAddressNodeNameUpdateRestrictions(t *testing.T) {
} }
} }
func TestEndpointAddressNodeNameInvalidDNS1123(t *testing.T) { func TestEndpointAddressNodeNameInvalidDNSSubdomain(t *testing.T) {
// Check NodeName DNS validation // Check NodeName DNS validation
endpoint := newNodeNameEndpoint("illegal.nodename") endpoint := newNodeNameEndpoint("illegal*.nodename")
errList := ValidateEndpoints(endpoint) errList := ValidateEndpoints(endpoint)
if len(errList) == 0 { if len(errList) == 0 {
t.Error("Endpoint should reject invalid NodeName") t.Error("Endpoint should reject invalid NodeName")
} }
} }
func TestEndpointAddressNodeNameCanBeAnIPAddress(t *testing.T) {
endpoint := newNodeNameEndpoint("10.10.1.1")
errList := ValidateEndpoints(endpoint)
if len(errList) != 0 {
t.Error("Endpoint should accept a NodeName that is an IP address")
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment