mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-28 05:57:25 +00:00
Merge pull request #4883 from smarterclayton/fix_tcpsocket_validation
TCPSocket could not be used as it was not checked in validation
This commit is contained in:
commit
c7cbc5c991
@ -469,6 +469,14 @@ func validateTCPSocketAction(tcp *api.TCPSocketAction) errs.ValidationErrorList
|
|||||||
return allErrors
|
return allErrors
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func validateTCPSocketAction(tcp *api.TCPSocketAction) errs.ValidationErrorList {
|
||||||
|
allErrors := errs.ValidationErrorList{}
|
||||||
|
if len(tcp.Port.StrVal) == 0 && tcp.Port.IntVal == 0 {
|
||||||
|
allErrors = append(allErrors, errs.NewFieldRequired("port", tcp.Port))
|
||||||
|
}
|
||||||
|
return allErrors
|
||||||
|
}
|
||||||
|
|
||||||
func validateHandler(handler *api.Handler) errs.ValidationErrorList {
|
func validateHandler(handler *api.Handler) errs.ValidationErrorList {
|
||||||
numHandlers := 0
|
numHandlers := 0
|
||||||
allErrors := errs.ValidationErrorList{}
|
allErrors := errs.ValidationErrorList{}
|
||||||
|
@ -496,6 +496,32 @@ func TestValidateContainers(t *testing.T) {
|
|||||||
ImagePullPolicy: "IfNotPresent",
|
ImagePullPolicy: "IfNotPresent",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
"invalid lifecycle, no tcp socket port.": {
|
||||||
|
{
|
||||||
|
Name: "life-123",
|
||||||
|
Image: "image",
|
||||||
|
Lifecycle: &api.Lifecycle{
|
||||||
|
PreStop: &api.Handler{
|
||||||
|
TCPSocket: &api.TCPSocketAction{},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
ImagePullPolicy: "IfNotPresent",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"invalid lifecycle, zero tcp socket port.": {
|
||||||
|
{
|
||||||
|
Name: "life-123",
|
||||||
|
Image: "image",
|
||||||
|
Lifecycle: &api.Lifecycle{
|
||||||
|
PreStop: &api.Handler{
|
||||||
|
TCPSocket: &api.TCPSocketAction{
|
||||||
|
Port: util.IntOrString{IntVal: 0},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
ImagePullPolicy: "IfNotPresent",
|
||||||
|
},
|
||||||
|
},
|
||||||
"invalid lifecycle, no action.": {
|
"invalid lifecycle, no action.": {
|
||||||
{
|
{
|
||||||
Name: "life-123",
|
Name: "life-123",
|
||||||
@ -506,6 +532,28 @@ func TestValidateContainers(t *testing.T) {
|
|||||||
ImagePullPolicy: "IfNotPresent",
|
ImagePullPolicy: "IfNotPresent",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
"invalid liveness probe, no tcp socket port.": {
|
||||||
|
{
|
||||||
|
Name: "life-123",
|
||||||
|
Image: "image",
|
||||||
|
LivenessProbe: &api.Probe{
|
||||||
|
Handler: api.Handler{
|
||||||
|
TCPSocket: &api.TCPSocketAction{},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
ImagePullPolicy: "IfNotPresent",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"invalid liveness probe, no action.": {
|
||||||
|
{
|
||||||
|
Name: "life-123",
|
||||||
|
Image: "image",
|
||||||
|
LivenessProbe: &api.Probe{
|
||||||
|
Handler: api.Handler{},
|
||||||
|
},
|
||||||
|
ImagePullPolicy: "IfNotPresent",
|
||||||
|
},
|
||||||
|
},
|
||||||
"privilege disabled": {
|
"privilege disabled": {
|
||||||
{Name: "abc", Image: "image", Privileged: true},
|
{Name: "abc", Image: "image", Privileged: true},
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user