-
-
Notifications
You must be signed in to change notification settings - Fork 166
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
One handler function attached to 2 events causes 2 fields in status to be created instead of one? #571
Comments
Hello. The described behaviour seems to be as expected. The handlers write their functions' results into And it is impossible to assign explicit ids to both handlers via One reason why you were lucky in the past, most likely, is that on-field handlers were an equivalent of on-update limited to a field context for some time. Later (in 0.28), they were fixed to be triggered really in the context of any field change — including the field's creation (a change from Maybe duplicates #566; especially see the rationale in #566 (comment) Anyway, storing the function results into A better way here is to be explicit about your storage intentions: @kopf.on.create("foo.example.com", "v1", "bar")
@kopf.on.field("foo.example.com", "v1", "bar", field="spec.some_field")
def my_config_map(*, body, logger, patch, **kwargs):
# ^^^^^
patch.status['my-field'] = "some-resource-name-12345-abc123c"
#^^^^^^^^^^^^^^^^^^^^^^^ The In that case, the object will be patched twice — one time for each handler — but at least it will patch the same field. Alternatively, you can reconsider the usage of the on-field handler as suggested in the comment linked above, essentially with this trick: @kopf.on.field(...
when=lambda cause, **_: cause.reason != kopf.Reason.CREATE) |
Ah brilliant, i completely missed I think for my case it's actually appropriate to drop the .on.create, and not filter with .on.field. i.e.
If i have understood correctly, this handler will get called when the field first appears (likely when the resource is created) as well as when it changes. So having a seperate create handler is not required. To clarify one more thing, if i return None from my handler (or rather, i don't return anything), will it create a None in the status field? Or nothing? I.e. in the example above would i get:
or
|
Regarding Nones: No, A side-note: |
Regarding on-field handlers: Yes, exactly! Indeed, the only handler would be a better solution here, if the field is the only interest. Please still be aware that the differences between object creation and putting a field on the existing objects are almost invisible for the handler — in both cases, it is a change of the field from I am still not sure how to deal with the object deletion. Regardless of the implementation, but on a sematic level: Should it be a change of the field from a These on-field handlers add too much ambiguity on the sematic level — not for the first time. This is why I am so much in favour of usual on-create/update/delete/resume handlers with |
I have adopted your suggested approach and it works great. Thanks for your help once again! |
Long story short
If i decorate a function with 2 different
@kopf.on
handlers they seem to update different fields instatus
.This means I can't have a
kopf.on.create
andkopf.on.field
both updatestatus.some_field
, i'll actually end up with 2 fields instead.I`m pretty sure this didn't use to happen, but i don't know if i "got lucky" before...
Description
Recently upgraded an older kopf based operator. It had something like this:
It creates a resource (lets say a ConfigMap for the sake of argument).
Previously the status was set to:
(0.23ish)
But now im seeing something like
With 0.28.
I am not sure if this is a regression or i was just getting lucky before, so on the off chance its a regression I thought i should report it. If it's not a regression is there anyway to force them both to write to
my_config_map
? This PR looks like it would give me enough control to that, but otherwise i'm not sure how to proceed. zalando-incubator/kopf#320Environment
The text was updated successfully, but these errors were encountered: