Skip to content

Commit

Permalink
Improve error from readiness probe validation (#5385)
Browse files Browse the repository at this point in the history
* Improve error from readiness probe validation

As described in #5382,
`failureThreshold` and `timeoutSeconds` in readinessprobe are
disapplowed only when `periodSeconds` is zero. This patch improves the
error.

- Error message after this patch:
```
error: services.serving.knative.dev "hello-example" could not be patched: Internal error occurred: admission webhook "webhook.serving.knative.dev" denied the request: mutation failed: timeoutSeconds is disallowed when periodSeconds is zero: spec.template.spec.containers[0].readinessProbe.failureThreshold, spec.template.spec.containers[0].readinessProbe.periodSeconds
```

* Remove periodSeconds from path in readiness validation error
  • Loading branch information
nak3 authored and knative-prow-robot committed Sep 4, 2019
1 parent 582ccb4 commit c1583f3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
10 changes: 8 additions & 2 deletions pkg/apis/serving/k8s_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -456,11 +456,17 @@ func validateReadinessProbe(p *corev1.Probe) *apis.FieldError {
// PeriodSeconds == 0 indicates Knative's special probe with aggressive retries
if p.PeriodSeconds == 0 {
if p.FailureThreshold != 0 {
errs = errs.Also(apis.ErrDisallowedFields("failureThreshold"))
errs = errs.Also(&apis.FieldError{
Message: "failureThreshold is disallowed when periodSeconds is zero",
Paths: []string{"failureThreshold"},
})
}

if p.TimeoutSeconds != 0 {
errs = errs.Also(apis.ErrDisallowedFields("timeoutSeconds"))
errs = errs.Also(&apis.FieldError{
Message: "timeoutSeconds is disallowed when periodSeconds is zero",
Paths: []string{"timeoutSeconds"},
})
}
} else {
if p.TimeoutSeconds < 1 {
Expand Down
10 changes: 8 additions & 2 deletions pkg/apis/serving/k8s_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,10 @@ func TestContainerValidation(t *testing.T) {
},
},
},
want: apis.ErrDisallowedFields("readinessProbe.failureThreshold"),
want: &apis.FieldError{
Message: "failureThreshold is disallowed when periodSeconds is zero",
Paths: []string{"readinessProbe.failureThreshold"},
},
}, {
name: "invalid readiness probe (has timeoutSeconds while using special probe)",
c: corev1.Container{
Expand All @@ -626,7 +629,10 @@ func TestContainerValidation(t *testing.T) {
},
},
},
want: apis.ErrDisallowedFields("readinessProbe.timeoutSeconds"),
want: &apis.FieldError{
Message: "timeoutSeconds is disallowed when periodSeconds is zero",
Paths: []string{"readinessProbe.timeoutSeconds"},
},
}, {
name: "out of bounds probe values",
c: corev1.Container{
Expand Down

0 comments on commit c1583f3

Please sign in to comment.