Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update external service based on CRD and label selector #1041

Open
martinohansen opened this issue Jul 22, 2023 · 1 comment
Open

Update external service based on CRD and label selector #1041

martinohansen opened this issue Jul 22, 2023 · 1 comment
Labels
question Further information is requested

Comments

@martinohansen
Copy link

martinohansen commented Jul 22, 2023

Hi 👋

Thanks for this wonderful project. I hope I can find advice here on how to build this kind of operator:

I’m trying to manage an external resource (External) based on a custom resource definition (CRD). The CRD includes a label selector in its spec that targets one or more Kubernetes services (SVCs).

The operator needs to patch External when there are changes in either the CRD or any of the SVCs. This means the SVCs that the operator monitors can vary over time, both with and without changes to the CRD.

What is the suggested way of doing this?

Thanks in advance.

@martinohansen martinohansen added the question Further information is requested label Jul 22, 2023
@asteven
Copy link
Contributor

asteven commented Jul 23, 2023

I think you could dynamically register a handler, but not sure about un-registering.
https://kopf.readthedocs.io/en/stable/handlers/#registering

Maybe you could have a generic handler for services and adjust some global state which is then interpreted by a filter callback?
https://kopf.readthedocs.io/en/stable/filters/#callback-filters

e.g.

filter_spec = {}


@kopf.on.create('my-crd')
def my_crd_handler(spec, **_):
    filter_spec['something'] = spec.whatever


def filter_function(spec, **_):
    # inspect filter_spec and return True | False.
    pass
    

@kopf.on.update('', 'v1', 'service', when=filter_function)
def my_service_handler(spec, **_):
    # do your thing with service resource
    pass

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants