Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

⚠️ feat: new features about support warning with webhook #2014

Merged
merged 13 commits into from
Apr 19, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
chore: warning message should also be carried with APIStatusError
Signed-off-by: STRRL <[email protected]>
STRRL committed Apr 17, 2023

Unverified

This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
commit b2a955209912f188758a1ae2281f8cea691a6126
2 changes: 1 addition & 1 deletion pkg/webhook/admission/validator.go
Original file line number Diff line number Diff line change
@@ -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...)
}
2 changes: 1 addition & 1 deletion pkg/webhook/admission/validator_custom.go
Original file line number Diff line number Diff line change
@@ -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...)
}
9 changes: 6 additions & 3 deletions pkg/webhook/admission/validator_test.go
Original file line number Diff line number Diff line change
@@ -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))

})

@@ -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))

})

@@ -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))

})