You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Custom event with kopf.info()
[2019-08-05 15:09:56,422] kopf.clients.events [WARNING ] Failed to post an event. Ignoring and continuing. Error: HTTPError('Event "kopf-event-tvlgd" is invalid: involvedObject.namespace: Invalid value: "": does not match event.namespace'). Event: type='Normal', reason='SA_DELETED', message='Managed service account got deleted'.
Default events:
[2019-08-05 15:12:47,217] kopf.clients.events [WARNING ] Failed to post an event. Ignoring and continuing. Error: HTTPError('Event "kopf-event-5zplb" is invalid: involvedObject.namespace: Invalid value: "": does not match event.namespace'). Event: type='Normal', reason='Logging', message="Handler 'create_ns' succeeded.".
Steps to Reproduce the Problem
No particular code is actually running
My controller is running with a cluster-admin role in it's own namespace.
import kopf@kopf.on.resume('', 'v1', 'namespaces')@kopf.on.create('', 'v1', 'namespaces')def create_fn(spec, **kwargs):
print(f"And here we are! Creating: {spec}")return {'message': 'hello world'} # will be the new status
Run with: kopf run --standalone ./example.py
...
[2019-08-05 15:19:54,389] kopf.clients.events [WARNING ] Failed to post an event. Ignoring and continuing. Error: HTTPError('Event "kopf-event-27kj9" is invalid: involvedObject.namespace: Invalid value: "": does not match event.namespace'). Event: type='Normal', reason='Logging', message='All handlers succeeded for resuming.'.
[2019-08-05 15:19:54,402] kopf.clients.events [WARNING ] Failed to post an event. Ignoring and continuing. Error: HTTPError('Event "kopf-event-vdnqq" is invalid: involvedObject.namespace: Invalid value: "": does not match event.namespace'). Event: type='Normal', reason='Logging', message="Handler 'create_fn' succeeded.".
[2019-08-05 15:19:54,416] kopf.clients.events [WARNING ] Failed to post an event. Ignoring and continuing. Error: HTTPError('Event "kopf-event-xf2ht" is invalid: involvedObject.namespace: Invalid value: "": does not match event.namespace'). Event: type='Normal', reason='Logging', message='All handlers succeeded for update.'.
...
Brief summary: K8s events are namespaced, there are no cluster-scoped events. Also, k8s events can refer to an object via spec.involvedObject of type ObjectReference. This structure contains namespace field, to refer to the involved object's namespace (also, name, uid, etc).
I could not find a way to post namespaced events for cluster-scoped resources. It always fails with namespace mismatch (regardless of which library is used).
For an isolated example, here is an attempt to do this for kind: Node. The same happens for any cluster-scoped involvedObject though.
If I assign a namespace to the involved object, in the assumption that the cluster-scoped object kind of "exists" in all namespaces at once, then the event is created. However, it is not shown on kubectl describe, as the attachment is wrong.
Surprisingly, in the same minikube deployment, I can see such events for kind: Node via:
So, conceptually it is possible for a namespaced event to refer to a non-namespaced object. But the API does not allow to do this, or I do it somehow wrong. The API documentation gives no clues on how to post such events.
Any help on how such events can or should be posted, is welcomed.
What I can do here, is to fix a little bit, to post the events to the current context's namespace (i.e. with the broken link, as explained above). At least, they will be visible there via kubectl get events. Though, it is unclear what is the use-case of the events except for kubectl describe. But the error messages in Kopf will be gone.
Commented by olivier-mauras at 2019-08-06 06:16:03+00:00
nolar Thanks for your extended reply.
Maybe I should describe my usecase to make things a bit more clear and maybe find an acceptable workaround. I actually don't mind at all the noise of the default events and had already ran kopf in quiet mode :)
Right now my controller is handling namespaces creations/update. For each namespace handled, the controller will create a set of predefined namespaced resources - service acounts, network policies.
I've seen your other comments about handling children deletions and indeed I thought it would be smart and as non convoluted as possible to have an on.delete handler for the children resources that would actually send a "delete" event to the namespace.
And so here's the problem with the event not working is that I can't "notify" the namespace of the modification.
What would be the best solution for this problem if we can't send event at this point?
Commented by olivier-mauras at 2019-08-06 07:07:50+00:00
Answering myself, something along the following that you posted in #153 would certainly work well
@kopf.on.event('', 'v1', 'services')defservice_event(meta, name, namespace, event, **_):
# filter out irrelevant servicesifnotmeta.get('labels', {}).get('my-app'):
return# Now, it is surely our service.# NB: the old service is already absent at this event, so there will be no HTTP 409 conflict.ifevent['type'] =='DELETED':
_recreate_service(name, namespace)
Just to clarify: Kopf is not a K8s client library, and is not going to be such. It only tries to be friendly to all existing K8s client libraries, leaving this choice to the developers.
The k8s-events support in Kopf is rudimentary: only to the extent needed for K8s<->Python integration of per-object logging (i.e. Python's logging system posting to /api/v1/.../events transparently). Plus some methods are publicly exposed also for the current object's logging.
This is the main purpose of Kopf: to marshal K8s activities/structures into Python primitives/functions/libraries, and back from Python to K8s.
Non-current object's logging is not intended as a feature (though, may work as a side effect, as in your example).
If you need to post some other sophisticated events for some other objects, you can use a client library API calls directly. In case of kubernetes client, it is CoreV1Api.create_namespaced_event. Some hints on the body's content can be taken from Kopf (kopf.clients.events).
Commented by olivier-mauras at 2019-08-06 08:53:42+00:00
nolar Thanks for your clarification, as you say what I thought as a feature is more a side effect :)
I just implemented the on.event() sample and it's works well enough in my use case
The changes are now in kopf==0.21. If the issue reappears, feel free to re-open.
Commented by cliffburdick at 2020-05-28 02:17:23+00:00
nolar for what it's worth, I'm seeing this in 0.27rc6. Periodically I see the following messages in the logs:
Failed to post an event. Ignoring and continuing. Status: 500. Message: Internal Server Error. Event: type='Normal', reason='Logging', message="Timer 'MonitorTriadSets' succeeded.".
Failed to post an event. Ignoring and continuing. Status: 500. Message: Internal Server Error. Event: type='Normal', reason='Logging', message="Timer 'MonitorTriadSets' succeeded.".
I have a timer called MonitorTriadSets that's set to interval=3, idle=3.
Commented by cliffburdick at 2020-08-01 04:17:01+00:00
nolar for what it's worth, I'm seeing this in 0.27rc6. Periodically I see the following messages in the logs:
Failed to post an event. Ignoring and continuing. Status: 500. Message: Internal Server Error. Event: type='Normal', reason='Logging', message="Timer 'MonitorTriadSets' succeeded.".
Failed to post an event. Ignoring and continuing. Status: 500. Message: Internal Server Error. Event: type='Normal', reason='Logging', message="Timer 'MonitorTriadSets' succeeded.".
I have a timer called MonitorTriadSets that's set to interval=3, idle=3.
nolar do you think this can be reopened since it appears to be occurring on timers? I'm not sure if there's a newer version maybe, but it seems the project hasn't been updated in many months.
The text was updated successfully, but these errors were encountered:
Hi @nolar it seems this is still happening with 0.28:
Failed to post an event. Ignoring and continuing. Status: 500. Message: The POST operation against Event could not be completed at this time, please try again.. Event: type='Normal', reason='Logging', message="Timer 'MonitorTriadSets' succeeded.".
Failed to post an event. Ignoring and continuing. Status: 500. Message: The POST operation against Event could not be completed at this time, please try again.. Event: type='Normal', reason='Logging', message="Timer 'MonitorTriadSets' succeeded.".
Looks like the error message, mentioned by @cliffburdick , was changed to something that explains the problem better, in K8s 1.23 in this PR kubernetes/kubernetes#104699
Expected Behavior
Be able to post events either custom of defaults.
Actual Behavior
Steps to Reproduce the Problem
No particular code is actually running
My controller is running with a cluster-admin role in it's own namespace.
A simple example like this gives the same result:
Run with:
kopf run --standalone ./example.py
Specifications
Python 3.7.4
olivier-mauras Thanks for reporting.
I fought with this issue few times, to no avail.
Brief summary: K8s events are namespaced, there are no cluster-scoped events. Also, k8s events can refer to an object via
spec.involvedObject
of typeObjectReference
. This structure containsnamespace
field, to refer to the involved object's namespace (also, name, uid, etc).I could not find a way to post namespaced events for cluster-scoped resources. It always fails with namespace mismatch (regardless of which library is used).
For an isolated example, here is an attempt to do this for
kind: Node
. The same happens for any cluster-scopedinvolvedObject
though.If I assign a namespace to the involved object, in the assumption that the cluster-scoped object kind of "exists" in all namespaces at once, then the event is created. However, it is not shown on
kubectl describe
, as the attachment is wrong.Surprisingly, in the same minikube deployment, I can see such events for
kind: Node
via:kubectl get events -o yaml | less
So, conceptually it is possible for a namespaced event to refer to a non-namespaced object. But the API does not allow to do this, or I do it somehow wrong. The API documentation gives no clues on how to post such events.
Any help on how such events can or should be posted, is welcomed.
What I can do here, is to fix a little bit, to post the events to the current context's namespace (i.e. with the broken link, as explained above). At least, they will be visible there via
kubectl get events
. Though, it is unclear what is the use-case of the events except forkubectl describe
. But the error messages in Kopf will be gone.nolar Thanks for your extended reply.
Maybe I should describe my usecase to make things a bit more clear and maybe find an acceptable workaround. I actually don't mind at all the noise of the default events and had already ran kopf in quiet mode :)
Right now my controller is handling namespaces creations/update. For each namespace handled, the controller will create a set of predefined namespaced resources - service acounts, network policies.
I've seen your other comments about handling children deletions and indeed I thought it would be smart and as non convoluted as possible to have an on.delete handler for the children resources that would actually send a "delete" event to the namespace.
So here's my code
And so here's the problem with the event not working is that I can't "notify" the namespace of the modification.
What would be the best solution for this problem if we can't send event at this point?
Answering myself, something along the following that you posted in #153 would certainly work well
olivier-mauras Ah, I see your point.
Just to clarify: Kopf is not a K8s client library, and is not going to be such. It only tries to be friendly to all existing K8s client libraries, leaving this choice to the developers.
The k8s-events support in Kopf is rudimentary: only to the extent needed for K8s<->Python integration of per-object logging (i.e. Python's
logging
system posting to/api/v1/.../events
transparently). Plus some methods are publicly exposed also for the current object's logging.This is the main purpose of Kopf: to marshal K8s activities/structures into Python primitives/functions/libraries, and back from Python to K8s.
Non-current object's logging is not intended as a feature (though, may work as a side effect, as in your example).
If you need to post some other sophisticated events for some other objects, you can use a client library API calls directly. In case of
kubernetes
client, it isCoreV1Api.create_namespaced_event
. Some hints on the body's content can be taken from Kopf (kopf.clients.events
).olivier-mauras Regarding the code example, please note, that label-filtering is now possible via the decorator kwargs, so that it will suppress excessive logging for not-matching objects: https://kopf.readthedocs.io/en/latest/handlers/#filtering
nolar Thanks for your clarification, as you say what I thought as a feature is more a side effect :)
I just implemented the on.event() sample and it's works well enough in my use case
The changes are now in
kopf==0.21
. If the issue reappears, feel free to re-open.nolar for what it's worth, I'm seeing this in 0.27rc6. Periodically I see the following messages in the logs:
I have a timer called MonitorTriadSets that's set to interval=3, idle=3.
nolar do you think this can be reopened since it appears to be occurring on timers? I'm not sure if there's a newer version maybe, but it seems the project hasn't been updated in many months.
The text was updated successfully, but these errors were encountered: