kopf cr status update
Keywords
status update
Problem
Does the framework provide a way for CR status update?
My operator creates a pod and the custom resource needs to keep track/be in sync with the pod status.
Thanks.
Hi @odra ,
If I read your question right, you can just return a dict on your handlers and it will be set on your CRD's status field.
Alternatively, you can use the patch variable.
Cheers !
>>> If I read your question right, you can just return a dict on your handlers and it will be set on your CRD's status field.
I have a handler that us watching for batchv1.jobs resources and it needs to update the CR from that event handler.
I don't think returning a dict from that function will update the CR status, correct?
>>> Alternatively, you can use the patch variable.
Does that mean I need to invoke a kubernetes client method to patch my CR status?
I think it might be easier with this sample python code:
@kopf.on.event('batchv1.jobs')
def handler_job(event, status, **kwargs):
conditions = status.get('conditions', [])
if len(conditions) == 0:
# TODO: update custom resource status that job is still running
return
condition = conditions[0]
condition_type = condition.get('type')
condition_status = condition.get('status')
if condition_type != 'Complete' and condition_status != 'True':
# TODO: update custom resource status that job is still running
return
# TODO: update custom resource status that job is done
I need to update a CR status from the above function.
I have a handler that us watching for
batchv1.jobsresources and it needs to update the CR from that event handler. I don't think returning a dict from that function will update the CR status, correct?
Correct, it will not. If you need to watch a resource kind A and modify a resource of kind B, then you do it by patching it with any client library you like, explicitly. Kopf does not provide such functionality. A few names to start with: kubernetes (the "official client library"), pykube-ng (just nice and easy to use).
Pykorm is a good lib too :P
Thanks, that makes sense, but let me raise another question: why isn't a client available from the framework, such as kopf.client? Is it just to provide some level of flexibility to users so they choose whatever they want to use?
First, making own client requires effort and time investment, which I cannot afford. Especially for later maintenance.
Second, making own client implies that it is different or better than the existing ones. I see nothing innovative which can be added to this topic, except maybe for Pydantic-based approach a la FastAPI and alike — but see point 1.
Flexibility for users is also on the list, but not as the primary goal or reason.
I totally agree with you point about not creating a new client but my question was more oriented to choosing an existing one and wrapping it up in the framework itself.