-
Notifications
You must be signed in to change notification settings - Fork 87
Add a warning if patch doesn't succeed #339
Conversation
🤖 zincr found 1 problem , 0 warnings
Details on how to resolve are provided below ApprovalsAll proposed changes must be reviewed by project maintainers before they can be merged Not enough people have approved this pull request - please ensure that 1 additional user, who have not contributed to this pull request approve the changes.
|
🤖 zincr found 0 problems , 0 warnings
|
This pull request introduces 2 alerts when merging 3b75a8b into df4e51b - view on LGTM.com new alerts:
|
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 see the pain point and the purpose of this change. Indeed, it was highly unpleasant to notice that K8s API silently drops the data, thus breaking Kopf's functionality without raising any errors.
But I tend to consider this as a K8s's or K8s API's issue.
I'm not sure that we want to implement the K8s server-side logic on the client side (in the framework). It can change over time, and keeping it in sync will require effort. It works as it works. Or it fails.
The original problem is now solved with #331 — the state is persisted in annotations since kopf>=0.27rc1
. So, the pain should be less painful (despite it remains for e.g. function results).
It is also unreliable to assume that body+patch == patched_body
. Some fields can be changed on the server side after we have got our body, before the patch was applied — e.g. by other operators/controllers/k8s itself. Then, the patched_body will be different from body+patch, and it would be totally okay.
What we can do here, is to return the patch's response from the client function, and validate the body-vs-patch match on the top-level (in kopf.reactor.processing.apply_reaction_outcomes()
) to see the the returned body matches all the fields in the patch (without merging the patch into the body).
There was also an intention to extend the patch object to support regular JSON patches, as K8s and K8s clients prefer it for some reason. Not a priority though. But this change would make it even more difficult to maintain on the client side.
Thx for all the comments and suggestions. Had to add quite a bit of code. I think quality is OK and changes are safe. Missing is integration tests with the Kubernetes API responses, and especially integration tests with the |
06cbb9b
to
7377e0c
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.
Conceptually and architecturally, it looks good now. I will dive deep into the detailed code review (especially, tests) a little bit later, if you don't mind.
Implemented in nolar/kopf#527, available since |
What do these changes do?
The situation
merge-patch+json
patchmerge-patch+json
patch but responds200 OK
leads to bugs and confusion, when testing operators.
With this change, kopf will check, if the
merge-patch+json
patch was merged and be verbose, if the patch was not exactly successful.Description
Before: When a patch wasn't merged, then kopf didn't report anything.
After: When a patch wasn't merged, then kopf will report if ran in
--verbose
mode.This will help users to debug their operators. Especially, when they use OpenAPI schemas in their CRDs.
Not sure if the check is in the right place and the logger is setup appropriately.
No risky changes.
Issues/PRs
If a patch is not merged, then it is usually because of a schema mismatch of the CRD. For this reason it was discussed to move the internal kopf
status
to the annotations. #308 #321Type of changes
Checklist
CONTRIBUTORS.txt