Skip to content

Access secondary resources by ResourceID #1410

New issue

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

By clicking “No 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? No Sign in to your account

Closed
grawinkel opened this issue Aug 22, 2022 · 1 comment · Fixed by #1378
Closed

Access secondary resources by ResourceID #1410

grawinkel opened this issue Aug 22, 2022 · 1 comment · Fixed by #1378
Assignees

Comments

@grawinkel
Copy link

Feature Idea

During a reconcile, I try to access a specific secondary resource. For example, I manage multiple config maps that are all owned by the same primary resource. In the reconcile I would like to access a specific resource that I can name by "namespace" + "name". In v2, there was a ResourceID, which was useable to access the event source cache.
The current possible solution would be:

<Optional>ConfigMap getConfigMap(Context<X> context, String name, String namespace) {
        return context.getSecondaryResources(ConfigMap.class).stream().filter(
        c -> namespace.equals(c.getMetadata().getNamespace()) &&
            namespace.equals(c.getMetadata().getName())).findFirst();
    }

But I'd rather have a more specific access method

<Optional>ConfigMap getConfigMap(Context<X> context, String name, String namespace) {
        return context.getSecondaryResource(ConfigMap.class).get(new ResourceID(namespace, name);
    }
@csviri
Copy link
Collaborator

csviri commented Aug 22, 2022

(we already touched the topic on discord will add here a summary).

It the reconciler has a reference for the InformerEventSource this is already possible just by calling this method:
https://github.com/java-operator-sdk/java-operator-sdk/blob/1961be8427682f6dbd9383c7399d41a90eef3439/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/event/source/informer/ManagedInformerEventSource.java#L93

In case of dependent resource it might still be needed for example to calculate the status. But in case of managed dependent resources the event sources are not accessible. We might want to give access to them through the Context. cc @metacosm

This PR expands on this idea and make it possible event to access additional indexes on event sources:
#1378

It might be an option to have a predefined generic Discriminator that just calls the get method with the resource id. Will take a look how it might look like.

@csviri csviri linked a pull request Aug 22, 2022 that will close this issue
@csviri csviri self-assigned this Sep 2, 2022
@csviri csviri closed this as completed Sep 2, 2022
No Sign up for free to join this conversation on GitHub. Already have an account? No Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants