nolar / kopf

A Python framework to write Kubernetes operators in just a few lines of code
https://kopf.readthedocs.io/
MIT License
2.07k stars 158 forks source link

any way to to retrigger the failed on.create / on.update / on.delete event #703

Open sajuptpm opened 3 years ago

sajuptpm commented 3 years ago

Context:

Does kopf.daemon handler help ? for example, retry infinitely ? :) We can use daemon handler as a Control Loop ?

nolar commented 3 years ago

If kubectl does not change the resource, Kopf will never know that anything was attempted at all.

One hack to think about is to ensure the changes on every kubectl apply. For this, put a label/annotation/field X with a value of 1 in yaml. In the operator, always overwrite it to 2. Every time kubectl apply is called, it will modify it back to 1 and trigger the processing cycle.

This hack does not work if you cannot make a convention to have that X in yamls.

If you would wait indefinitely long (I’d say, several weeks to a couple of months — depends on my free time), there would be mutating admission handlers (google: dynamic admission control). They would be able to inject random values to X themselves. But only if kubectl initiates talking to the K8s API at all (I’m not sure about this).

sajuptpm commented 3 years ago

mutating admission webhook is a good option for this use case, thanks for the suggestion. right now i am using validating admission webhook for validate the CR spec before applying it to etcd.