Skip to content

Commit

Permalink
chore: warning message should also be carried with APIStatusError
Browse files Browse the repository at this point in the history
Signed-off-by: STRRL <im@strrl.dev>
  • Loading branch information
STRRL committed Apr 17, 2023
1 parent 0d248e2 commit b2a9552
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pkg/webhook/admission/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func (h *validatingHandler) Handle(ctx context.Context, req Request) Response {
if err != nil {
var apiStatus apierrors.APIStatus
if errors.As(err, &apiStatus) {
return validationResponseFromStatus(false, apiStatus.Status())
return validationResponseFromStatus(false, apiStatus.Status()).WithWarnings(warnings...)
}
return Denied(err.Error()).WithWarnings(warnings...)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/webhook/admission/validator_custom.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func (h *validatorForType) Handle(ctx context.Context, req Request) Response {
if err != nil {
var apiStatus apierrors.APIStatus
if errors.As(err, &apiStatus) {
return validationResponseFromStatus(false, apiStatus.Status())
return validationResponseFromStatus(false, apiStatus.Status()).WithWarnings(warnings...)
}
return Denied(err.Error()).WithWarnings(warnings...)
}
Expand Down
9 changes: 6 additions & 3 deletions pkg/webhook/admission/validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,8 @@ var _ = Describe("validatingHandler", func() {
Expect(response.Allowed).Should(BeFalse())
Expect(response.Result.Code).Should(Equal(expectedError.Status().Code))
Expect(*response.Result).Should(Equal(expectedError.Status()))
Expect(response.AdmissionResponse.Warnings).Should(BeEmpty())
Expect(response.AdmissionResponse.Warnings).Should(ContainElements(warningMessage))
Expect(response.AdmissionResponse.Warnings).Should(ContainElements(anotherWarningMessage))

})

Expand All @@ -206,7 +207,8 @@ var _ = Describe("validatingHandler", func() {
Expect(response.Allowed).Should(BeFalse())
Expect(response.Result.Code).Should(Equal(expectedError.Status().Code))
Expect(*response.Result).Should(Equal(expectedError.Status()))
Expect(response.AdmissionResponse.Warnings).Should(BeEmpty())
Expect(response.AdmissionResponse.Warnings).Should(ContainElements(warningMessage))
Expect(response.AdmissionResponse.Warnings).Should(ContainElements(anotherWarningMessage))

})

Expand All @@ -225,7 +227,8 @@ var _ = Describe("validatingHandler", func() {
Expect(response.Allowed).Should(BeFalse())
Expect(response.Result.Code).Should(Equal(expectedError.Status().Code))
Expect(*response.Result).Should(Equal(expectedError.Status()))
Expect(response.AdmissionResponse.Warnings).Should(BeEmpty())
Expect(response.AdmissionResponse.Warnings).Should(ContainElements(warningMessage))
Expect(response.AdmissionResponse.Warnings).Should(ContainElements(anotherWarningMessage))

})

Expand Down

0 comments on commit b2a9552

Please sign in to comment.