Post cluster objects' events to the current namespace, not to "default"
@@ -33,7 +33,12 @@ async def post_event(*, obj=None, ref=None, type, reason, message=''):
ref = hierarchies.build_object_reference(obj)
now = datetime.datetime.utcnow()
- namespace = ref.get('namespace') or 'default'
+
+ # See #164. For cluster-scoped objects, use the current namespace from the current context.
+ # It could be "default", but in some systems, we are limited to one specific namespace only.
+ namespace = ref.get('namespace') or auth.get_pykube_cfg().namespace
+ if not ref.get('namespace'):
+ ref = dict(ref, namespace=namespace)
# Prevent a common case of event posting errors but shortening the message.
if len(message) > MAX_MESSAGE_LENGTH:
