Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
ee4cd972
Commit
ee4cd972
authored
Jun 16, 2015
by
Jordan Liggitt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Validate port protocol case strictly
parent
9f60f3ce
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
9 additions
and
8 deletions
+9
-8
validation.go
pkg/api/validation/validation.go
+3
-3
validation_test.go
pkg/api/validation/validation_test.go
+1
-1
dns.go
test/e2e/dns.go
+5
-4
No files found.
pkg/api/validation/validation.go
View file @
ee4cd972
...
@@ -610,7 +610,7 @@ func validatePorts(ports []api.ContainerPort) errs.ValidationErrorList {
...
@@ -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
(
string
s
.
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
)
...
)
...
@@ -1139,7 +1139,7 @@ func validateServicePort(sp *api.ServicePort, requireName bool, allNames *util.S
...
@@ -1139,7 +1139,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
(
string
s
.
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
))
}
}
...
@@ -1627,7 +1627,7 @@ func validateEndpointPort(port *api.EndpointPort, requireName bool) errs.Validat
...
@@ -1627,7 +1627,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
(
string
s
.
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
...
...
pkg/api/validation/validation_test.go
View file @
ee4cd972
...
@@ -493,7 +493,6 @@ func TestValidatePorts(t *testing.T) {
...
@@ -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) {
...
@@ -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"
,
""
},
}
}
...
...
test/e2e/dns.go
View file @
ee4cd972
...
@@ -18,6 +18,9 @@ package e2e
...
@@ -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 (
...
@@ -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() {
...
@@ -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() {
...
@@ -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
,
},
},
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment