-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
⚠ pkg/webhook/admission: use Result.Message instead of Result.Reason #1539
⚠ pkg/webhook/admission: use Result.Message instead of Result.Reason #1539
Conversation
Hi @bhcleek. Thanks for your PR. I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
Trying to think of ways this compat break could bite someone. We should be very certain we can't think of any. |
I was torn on whether to mark this with I don't think this will break any controller-runtime clients, but it will cause |
Is there anything we can do to move this forward? |
/ok-to-test |
/retest |
Use Result.Message instead of Result.Reason for the user supplied portion. Reason is intended to be machine readable while Message is intended to be human readable. While each is documented as being informational only, the Is* family of functions in k8s.io/apimachinery/pkg/api/errors rely on the StatusReason. This change allows controllers to rely on "k8s.io/apimachinery/pkg/api/errors".IsForbidden to deal with errors consistently regardless of whether the operation failed due to an admission webhook implemented with controller-runtime, a standard kubernetes failure (e.g related to RBAC), or another controller not implemented with controller-runtime. See kubernetes/kubernetes#101926 for more information
3ff152d
to
2c95a03
Compare
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 think the piece of this that gives me some pause is that this change is API compatible, but it breaks semantics. So calling code will compile and run just fine, but what's happening may not be what a caller expects (e.g. perhaps a caller really does want to set a custom reason)
I do agree that it makes more sense to expose the message and auto-populate the reason.
I would almost prefer that we find a way to break the Go API so that users are confronted with this breakage.
}, | ||
}, | ||
} | ||
if len(reason) > 0 { | ||
resp.Result.Reason = metav1.StatusReason(reason) | ||
if len(message) > 0 { |
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.
Nit: Do we need to check the length of message or can we just always set resp.Result.Message
? metav1.Status.Message
is a string type, so leaving it "unset" is the same as setting it to an empty string.
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.
You're right, we no longer need to check the length here. Is it worth changing or should we keep it as-is if there aren't other changes to be made?
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 think the piece of this that gives me some pause is that this change is API compatible, but it breaks semantics. So calling code will compile and run just fine, but what's happening may not be what a caller expects (e.g. perhaps a caller really does want to set a custom reason)
I do agree that it makes more sense to expose the message and auto-populate the reason.
I would almost prefer that we find a way to break the Go API so that users are confronted with this breakage.
Given that controller-runtime is still pre-1.0, this kind of breaking change in semantics seems appropriate to me, but I'll happily defer to you if you feel strongly. I see a couple of possibilities for addressing your concerns about the changing semantics:
- break the API by removing the second parameter of
ValidationResponse
entirely so that existing code will fail on compile and introduce a newValidationResponseWithReasonAndMessage
to allow both the reason and message to be provided. - Keep API compatibility, but introduce
func ValidationResponseWithReason(allowed bool, reason, message string) Response
to allow users to migrate if they really do want to provide a custom reason.
What do you think?
}, | ||
}, | ||
} | ||
if len(reason) > 0 { | ||
resp.Result.Reason = metav1.StatusReason(reason) | ||
if len(message) > 0 { |
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.
You're right, we no longer need to check the length here. Is it worth changing or should we keep it as-is if there aren't other changes to be made?
@bhcleek is this still needed now that kubernetes/kubernetes#101926 merged? Like Joe I'd prefer not to introduce breaking changes the compiler can't point out. |
While this isn't strictly needed with the next version of Kubernetes or later, it's still useful for people on the current version of Kubernetes or earlier. I'd also add, that IMHO this is closer to the expectations that people may have given how this message can be surfaced to users. |
The Kubernetes project currently lacks enough contributors to adequately respond to all issues and PRs. This bot triages issues and PRs according to the following rules:
You can:
Please send feedback to sig-contributor-experience at kubernetes/community. /lifecycle stale |
/remove-lifecycle stale |
Where do we stand with this? Should we close it or is there something we can do to push forward on the alignment with kubernetes error expectations? |
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.
/hold
@joelanford are you good with this?
The Kubernetes project currently lacks enough contributors to adequately respond to all issues and PRs. This bot triages issues and PRs according to the following rules:
You can:
Please send feedback to sig-contributor-experience at kubernetes/community. /lifecycle stale |
/remove-lifecycle stale |
The Kubernetes project currently lacks enough contributors to adequately respond to all issues and PRs. This bot triages issues and PRs according to the following rules:
You can:
Please send feedback to sig-contributor-experience at kubernetes/community. /lifecycle stale |
/remove-lifecycle stale |
I think it would be good if this change is surfaced via compile errors to consumers. I would suggest:
I think this would signal clearly to consumers that the API changed and the new set of funcs should cover relevant use cases. |
I can make that change. The edit: formatting |
Sounds good. I don't think we have to set the reason when allowed is true. reason is part of (btw just my opinion, would be probably good to get consensus before investing the effort to change the implementation) |
Yeah, the few places I need it, |
Why is a reason needed for Allowed? |
If |
After making the changes locally that you suggested, @sbueringer, I'm less convinced that's the direction this should go. Being able to provide the human readable message to I know you're trying to avoid unexpected breakages, but given that controller-runtime regularly breaks across releases and effectively abuses semantic versioning anyway in order to be able to break backward compatibility without violating semantic versioning coupled with the greater burden that those suggestions would put on users, I'm not sure we should make those changes. 🤔 Having expressed my skepticism, I want to be clear that I will submit the changes if there's consensus. |
Okay no worries :). Just my opinion, I'm fine either way. |
The Kubernetes project currently lacks enough contributors to adequately respond to all issues and PRs. This bot triages issues and PRs according to the following rules:
You can:
Please send feedback to sig-contributor-experience at kubernetes/community. /lifecycle stale |
The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs. This bot triages issues and PRs according to the following rules:
You can:
Please send feedback to sig-contributor-experience at kubernetes/community. /lifecycle rotten |
/remove-lifecycle rotten @alvaroaleman with only 21 open PRs, I'm wondering if there's anything we can do to move this forward. |
/hold cancel |
Use Result.Message instead of Result.Reason for the user supplied
portion. Reason is intended to be machine readable while Message is
intended to be human readable. While each is documented as being
informational only, the Is* family of functions in
k8s.io/apimachinery/pkg/api/errors rely on the StatusReason.
This change allows controllers to rely on
"k8s.io/apimachinery/pkg/api/errors".IsForbidden to deal with errors
consistently regardless of whether the operation failed due to an
admission webhook implemented with controller-runtime, a standard
kubernetes failure (e.g related to RBAC), or another controller not
implemented with controller-runtime.
See kubernetes/kubernetes#101926 for more information