mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-09 12:07:47 +00:00
Merge pull request #9919 from liggitt/port_protocol_validation
Validate port protocol case strictly
This commit is contained in:
commit
3591a543d1
@ -610,7 +610,7 @@ func validatePorts(ports []api.ContainerPort) errs.ValidationErrorList {
|
|||||||
}
|
}
|
||||||
if len(port.Protocol) == 0 {
|
if len(port.Protocol) == 0 {
|
||||||
pErrs = append(pErrs, errs.NewFieldRequired("protocol"))
|
pErrs = append(pErrs, errs.NewFieldRequired("protocol"))
|
||||||
} else if !supportedPortProtocols.Has(strings.ToUpper(string(port.Protocol))) {
|
} else if !supportedPortProtocols.Has(string(port.Protocol)) {
|
||||||
pErrs = append(pErrs, errs.NewFieldNotSupported("protocol", port.Protocol))
|
pErrs = append(pErrs, errs.NewFieldNotSupported("protocol", port.Protocol))
|
||||||
}
|
}
|
||||||
allErrs = append(allErrs, pErrs.PrefixIndex(i)...)
|
allErrs = append(allErrs, pErrs.PrefixIndex(i)...)
|
||||||
@ -1144,7 +1144,7 @@ func validateServicePort(sp *api.ServicePort, requireName bool, allNames *util.S
|
|||||||
|
|
||||||
if len(sp.Protocol) == 0 {
|
if len(sp.Protocol) == 0 {
|
||||||
allErrs = append(allErrs, errs.NewFieldRequired("protocol"))
|
allErrs = append(allErrs, errs.NewFieldRequired("protocol"))
|
||||||
} else if !supportedPortProtocols.Has(strings.ToUpper(string(sp.Protocol))) {
|
} else if !supportedPortProtocols.Has(string(sp.Protocol)) {
|
||||||
allErrs = append(allErrs, errs.NewFieldNotSupported("protocol", sp.Protocol))
|
allErrs = append(allErrs, errs.NewFieldNotSupported("protocol", sp.Protocol))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1680,7 +1680,7 @@ func validateEndpointPort(port *api.EndpointPort, requireName bool) errs.Validat
|
|||||||
}
|
}
|
||||||
if len(port.Protocol) == 0 {
|
if len(port.Protocol) == 0 {
|
||||||
allErrs = append(allErrs, errs.NewFieldRequired("protocol"))
|
allErrs = append(allErrs, errs.NewFieldRequired("protocol"))
|
||||||
} else if !supportedPortProtocols.Has(strings.ToUpper(string(port.Protocol))) {
|
} else if !supportedPortProtocols.Has(string(port.Protocol)) {
|
||||||
allErrs = append(allErrs, errs.NewFieldNotSupported("protocol", port.Protocol))
|
allErrs = append(allErrs, errs.NewFieldNotSupported("protocol", port.Protocol))
|
||||||
}
|
}
|
||||||
return allErrs
|
return allErrs
|
||||||
|
@ -493,7 +493,6 @@ func TestValidatePorts(t *testing.T) {
|
|||||||
{Name: "easy", ContainerPort: 82, Protocol: "TCP"},
|
{Name: "easy", ContainerPort: 82, Protocol: "TCP"},
|
||||||
{Name: "as", ContainerPort: 83, Protocol: "UDP"},
|
{Name: "as", ContainerPort: 83, Protocol: "UDP"},
|
||||||
{Name: "do-re-me", ContainerPort: 84, Protocol: "UDP"},
|
{Name: "do-re-me", ContainerPort: 84, Protocol: "UDP"},
|
||||||
{Name: "baby-you-and-me", ContainerPort: 82, Protocol: "tcp"},
|
|
||||||
{ContainerPort: 85, Protocol: "TCP"},
|
{ContainerPort: 85, Protocol: "TCP"},
|
||||||
}
|
}
|
||||||
if errs := validatePorts(successCase); len(errs) != 0 {
|
if errs := validatePorts(successCase); len(errs) != 0 {
|
||||||
@ -522,6 +521,7 @@ func TestValidatePorts(t *testing.T) {
|
|||||||
"zero container port": {[]api.ContainerPort{{ContainerPort: 0, Protocol: "TCP"}}, errors.ValidationErrorTypeInvalid, "[0].containerPort", portRangeErrorMsg},
|
"zero container port": {[]api.ContainerPort{{ContainerPort: 0, Protocol: "TCP"}}, errors.ValidationErrorTypeInvalid, "[0].containerPort", portRangeErrorMsg},
|
||||||
"invalid container port": {[]api.ContainerPort{{ContainerPort: 65536, Protocol: "TCP"}}, errors.ValidationErrorTypeInvalid, "[0].containerPort", portRangeErrorMsg},
|
"invalid container port": {[]api.ContainerPort{{ContainerPort: 65536, Protocol: "TCP"}}, errors.ValidationErrorTypeInvalid, "[0].containerPort", portRangeErrorMsg},
|
||||||
"invalid host port": {[]api.ContainerPort{{ContainerPort: 80, HostPort: 65536, Protocol: "TCP"}}, errors.ValidationErrorTypeInvalid, "[0].hostPort", portRangeErrorMsg},
|
"invalid host port": {[]api.ContainerPort{{ContainerPort: 80, HostPort: 65536, Protocol: "TCP"}}, errors.ValidationErrorTypeInvalid, "[0].hostPort", portRangeErrorMsg},
|
||||||
|
"invalid protocol case": {[]api.ContainerPort{{ContainerPort: 80, Protocol: "tcp"}}, errors.ValidationErrorTypeNotSupported, "[0].protocol", ""},
|
||||||
"invalid protocol": {[]api.ContainerPort{{ContainerPort: 80, Protocol: "ICMP"}}, errors.ValidationErrorTypeNotSupported, "[0].protocol", ""},
|
"invalid protocol": {[]api.ContainerPort{{ContainerPort: 80, Protocol: "ICMP"}}, errors.ValidationErrorTypeNotSupported, "[0].protocol", ""},
|
||||||
"protocol required": {[]api.ContainerPort{{Name: "abc", ContainerPort: 80}}, errors.ValidationErrorTypeRequired, "[0].protocol", ""},
|
"protocol required": {[]api.ContainerPort{{Name: "abc", ContainerPort: 80}}, errors.ValidationErrorTypeRequired, "[0].protocol", ""},
|
||||||
}
|
}
|
||||||
|
@ -18,6 +18,9 @@ package e2e
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/latest"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/latest"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/client"
|
||||||
@ -25,8 +28,6 @@ import (
|
|||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
|
||||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/util/wait"
|
"github.com/GoogleCloudPlatform/kubernetes/pkg/util/wait"
|
||||||
"strings"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
. "github.com/onsi/ginkgo"
|
. "github.com/onsi/ginkgo"
|
||||||
. "github.com/onsi/gomega"
|
. "github.com/onsi/gomega"
|
||||||
@ -237,7 +238,7 @@ var _ = Describe("DNS", func() {
|
|||||||
Spec: api.ServiceSpec{
|
Spec: api.ServiceSpec{
|
||||||
ClusterIP: "None",
|
ClusterIP: "None",
|
||||||
Ports: []api.ServicePort{
|
Ports: []api.ServicePort{
|
||||||
{Port: 80, Name: "http", Protocol: "tcp"},
|
{Port: 80, Name: "http", Protocol: "TCP"},
|
||||||
},
|
},
|
||||||
Selector: testServiceSelector,
|
Selector: testServiceSelector,
|
||||||
},
|
},
|
||||||
@ -257,7 +258,7 @@ var _ = Describe("DNS", func() {
|
|||||||
},
|
},
|
||||||
Spec: api.ServiceSpec{
|
Spec: api.ServiceSpec{
|
||||||
Ports: []api.ServicePort{
|
Ports: []api.ServicePort{
|
||||||
{Port: 80, Name: "http", Protocol: "tcp"},
|
{Port: 80, Name: "http", Protocol: "TCP"},
|
||||||
},
|
},
|
||||||
Selector: testServiceSelector,
|
Selector: testServiceSelector,
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user