Lack of supporting multiple operations for one admission webhook endpoint
mehrdad-khojastefar opened this issue · comments
Long story short
As we can see in the official k8s docs we can have multiple operations for one webhook.
But in the kopf I realized we can not!
This is my workaround now and basically i am having 2 endpoints which is not necessary at all. I should have been able to wrap these two function in just one endpoint because as you can see the logic is the same.
@kopf.on.validate("kopfexample", operation="CREATE")
def create(spec, **_):
try:
create_or_update(spec)
except kopf.AdmissionError as error:
raise error
@kopf.on.validate("tempaccess", operation="UPDATE")
def update(spec, **_):
try:
create_or_update(spec)
except kopf.AdmissionError as error:
raise error
def create_or_update(spec):
""" My core logic """
I've investigated more and found this line in the kopf.on.validate
's code.
operation: Optional[reviews.Operation] = None, # -> .webhooks.*.rules.*.operations[0]
and this line on admission.build_webhook
function
'operations': ['*'] if handler.operation is None else [handler.operation],
So is there a reason to do it like this?
Kopf version
1.36.2
Kubernetes version
No response
Python version
3.11
Code
No response
Logs
No response
Additional information
No response