Skip to content

Access secondary resources by ResourceID #1410

Closed
@grawinkel

Description

@grawinkel

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);
    }

Activity

csviri

csviri commented on Aug 22, 2022

@csviri
Collaborator

(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.

self-assigned this
on Sep 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

    Development

    Participants

    @grawinkel@csviri

    Issue actions

      Access secondary resources by ResourceID · Issue #1410 · operator-framework/java-operator-sdk