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

kubernetes client: set-up watchers using annotations #372

Open
snowdrop-bot opened this issue Jul 8, 2021 · 0 comments
Open

kubernetes client: set-up watchers using annotations #372

snowdrop-bot opened this issue Jul 8, 2021 · 0 comments

Comments

@snowdrop-bot
Copy link
Collaborator

Description

When using the Kubernetes client to watch resource related events, some boilerplate code is needed. Inspired by the reactive route support that exists for Vert.x, I think it would be very beneficial if watch events can be expressed using annotations.

Implementation ideas

As example, some annotations and classes can be introduced:

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.Method)
public @interface LabelSelector {
    String key()),
    String operation() default "In"),
    String[] values()
}

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.Method)
public @interface ResourceWatcher {
    /*
     * An optional namespace, if not set, watch all namespaces.
     * Can be defined using a placeholder
     */
    String namespace() default ALL_NAMESPACES,

    /*
     * An optional ID of an informer, if not defined, the watcher
     * is a plain watcher.
     * Can be defined using a placeholder
     */
    String informer() default NO_INCORMER, 

    /*
     * A list of selectors used to fine tune the resources that
     * should be watched
     */
    LabelSelector[] selectors() default {}

    /*
     * The acions for which this watcher should be notified. 
     * Default is all actions
     */
    Action[] actions() default { Action.ADDED, Action.MODIFIED, Action.DELETED, Action.ERROR }
}

interface WatchEvent<T> {
    T resource();
    Action action();
    Throwable error();
}

Those annotations can be then leveraged as:

class MyPodHandler {
    @ResourceWatcher(
        selectors = { 
            @LabelSelector(key = "application", values = "MyApp")
        },
        actions = { 
            Action.ADDED, 
            Action.MODIFIED, 
            Action.DELETED 
        }
    )
    void handlePodEvents(WatchEvent<Pod> event) {
    }
}

Behind the scenes, quarkus should:

  • set up watchers according to the annotations
  • define a proper life cycle hooks for the watcher so they get restarted in case of disconnection and closed when the quarkus application stops

quarkusio#18526


$upstream:18526$

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants