Fixing EndpointSlice port validation

This updates EndpointSlice port validation to mirror the validation
already in use for Service and Endpoint ports. This is required to
ensure all valid Service ports can be mapped directly to EndpointSlice
ports.
This commit is contained in:
Rob Scott
2019-10-28 15:22:01 -07:00
parent 9731b51d23
commit fe54e1f386
7 changed files with 43 additions and 23 deletions

View File

@@ -18,6 +18,7 @@ package validation
import (
"fmt"
"strings"
"testing"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -104,6 +105,20 @@ func TestValidateEndpointSlice(t *testing.T) {
}},
},
},
"long-port-name": {
expectedErrors: 0,
endpointSlice: &discovery.EndpointSlice{
ObjectMeta: standardMeta,
AddressType: addressTypePtr(discovery.AddressTypeIP),
Ports: []discovery.EndpointPort{{
Name: utilpointer.StringPtr(strings.Repeat("a", 63)),
Protocol: protocolPtr(api.ProtocolTCP),
}},
Endpoints: []discovery.Endpoint{{
Addresses: generateIPAddresses(1),
}},
},
},
"empty-ports-and-endpoints": {
expectedErrors: 0,
endpointSlice: &discovery.EndpointSlice{
@@ -200,6 +215,18 @@ func TestValidateEndpointSlice(t *testing.T) {
Endpoints: []discovery.Endpoint{},
},
},
"bad-port-name-length": {
expectedErrors: 1,
endpointSlice: &discovery.EndpointSlice{
ObjectMeta: standardMeta,
AddressType: addressTypePtr(discovery.AddressTypeIP),
Ports: []discovery.EndpointPort{{
Name: utilpointer.StringPtr(strings.Repeat("a", 64)),
Protocol: protocolPtr(api.ProtocolTCP),
}},
Endpoints: []discovery.Endpoint{},
},
},
"invalid-port-protocol": {
expectedErrors: 1,
endpointSlice: &discovery.EndpointSlice{