nolar / kopf

A Python framework to write Kubernetes operators in just a few lines of code

Home Page:https://kopf.readthedocs.io/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

kopf does not tolerate annotations while patching finalizer

lkoniecz opened this issue · comments

Long story short

I tried to distinquish an operator that works in my cluster with those than my team and I run locally.
Used https://kopf.readthedocs.io/en/stable/filters/#metadata-filters for resource filtering.

It works and the handlers are being invoked correctly, but working operators go into a patching war, one putting a finalizer while other constantly removing it.

Yes, I know peering - but from what I read the highest prio wins. I need more than one working simultanously.

Kopf version

1.36.2

Kubernetes version

1.24

Python version

3.9

Code

import kopf

def metadata_filter() -> dict:
    return {
        'dev.operator.env.name': os.getenv('ENV_NAME', default='some-env')
    }

@kopf.on.create('awsrequests', annotations=metadata_filter())
def handler(patch, **kwargs):
    # do some stuff
    pass

Logs

{"message": "Patching with: {'metadata': {'finalizers': []}}", "timestamp": "2023-09-20T10:46:39.601150+00:00", "object": {"apiVersion": "redacted/v1", "kind": "HTTPRequest", "name": "generate-token", "uid": "bb884f9b-dfa0-4144-a706-a455ad13f08d", "namespace": "operators"}, "severity": "debug"}
{"message": "Removing the finalizer, as there are no handlers requiring it.", "timestamp": "2023-09-20T10:46:39.969490+00:00", "object": {"apiVersion": "redacted/v1", "kind": "HTTPRequest", "name": "generate-token", "uid": "bb884f9b-dfa0-4144-a706-a455ad13f08d", "namespace": "operators"}, "severity": "debug"}
{"message": "Patching with: {'metadata': {'finalizers': []}}", "timestamp": "2023-09-20T10:46:41.108854+00:00", "object": {"apiVersion": "redacted/v1", "kind": "HTTPRequest", "name": "generate-token", "uid": "bb884f9b-dfa0-4144-a706-a455ad13f08d", "namespace": "operators"}, "severity": "debug"}
{"message": "Removing the finalizer, as there are no handlers requiring it.", "timestamp": "2023-09-20T10:46:41.473737+00:00", "object": {"apiVersion": "redacted/v1", "kind": "HTTPRequest", "name": "generate-token", "uid": "bb884f9b-dfa0-4144-a706-a455ad13f08d", "namespace": "operators"}, "severity": "debug"}
{"message": "Patching with: {'metadata': {'finalizers': []}}", "timestamp": "2023-09-20T10:46:41.474058+00:00", "object": {"apiVersion": "redacted/v1", "kind": "HTTPRequest", "name": "generate-token", "uid": "bb884f9b-dfa0-4144-a706-a455ad13f08d", "namespace": "operators"}, "severity": "debug"}

Additional information

No response

settings.persistence.finalizer settings does seem to solve the problem