-
Notifications
You must be signed in to change notification settings - Fork 1.2k
⚠️ admission responses with raw Status #1129
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
Changes from 1 commit
1902414
2c49665
f61e953
1f5be8a
a76edb0
47eafd8
9f235ae
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -21,6 +21,8 @@ import ( | |||||||||||||||
| "net/http" | ||||||||||||||||
|
|
||||||||||||||||
| "k8s.io/api/admission/v1beta1" | ||||||||||||||||
| "k8s.io/apimachinery/pkg/api/errors" | ||||||||||||||||
| metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||||||||||||||||
| "k8s.io/apimachinery/pkg/runtime" | ||||||||||||||||
| ) | ||||||||||||||||
|
|
||||||||||||||||
|
|
@@ -67,7 +69,13 @@ func (h *validatingHandler) Handle(ctx context.Context, req Request) Response { | |||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| err = obj.ValidateCreate() | ||||||||||||||||
|
|
||||||||||||||||
| if err != nil { | ||||||||||||||||
|
|
||||||||||||||||
| isStatusError, status := isStatusError(&err) | ||||||||||||||||
| if isStatusError { | ||||||||||||||||
| return ValidationResponseFromStatus(false, status) | ||||||||||||||||
|
||||||||||||||||
| isStatusError, status := isStatusError(&err) | |
| if isStatusError { | |
| return ValidationResponseFromStatus(false, status) | |
| var statusError errors.StatusError | |
| if goerrors.As(&statusError) { | |
| return ... | |
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(the other nice thing about this is that if the status error is wrapped in such a way that it's intended to be unwrapped, we'll still pull the status)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is there any corresponding interface for status-returning errors in the k8s api errors package that we should be asserting on? (basically, is there a pattern for "my custom error returns status information)
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this method is a bit weirdly named -- I'd just expect it to return a bool.
The entire thing should be replacable with errors.As (see above)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know that this needs to be a public helper method at the moment, especially since it's basically just constructing an object from the listed fields.