Skip to content

context.getSecondaryResource not containing some generated resources #2310

@fhalde

Description

@fhalde

Bug Report

What did you do?

I have a simple Managed dependent reconciler with the following configuration

@ControllerConfiguration(
        name = "workload-reconciler",
        dependents = {
                @Dependent(name = "namespace", type = NamespaceDependentResource.class),
                @Dependent(name = "role", type = RoleDependentResource.class, dependsOn = {"namespace"}),
                @Dependent(name = "role-binding", type = RoleBindingDependentResource.class, dependsOn = {"namespace", "role"})
        })

i.e. the dependency chain is – role depends on namespace & role-binding depends on role & namespace. All dependends extend the CRUDKubernetesDependentResource

What did you expect to see?

Inside the RoleBindingDependentResource, I have implemented the desired method that calls context.getSecondaryResource to get the role & namespace.

What did you see instead? Under which circumstances?

Weirdly, context.getSecondaryResource is only able to return the Namespace but not the role

System.out.println(context.getSecondaryResource(Namespace.class).orElse(null)); // Namespace object
System.out.println(context.getSecondaryResource(Role.class).orElse(null)); // prints null

Environment

Kubernetes cluster type:

kind ( local )

$ Mention java-operator-sdk version from pom.xml file

4.8.1

$ java -version

openjdk version "21.0.2" 2024-01-16 LTS
OpenJDK Runtime Environment Corretto-21.0.2.13.1 (build 21.0.2+13-LTS)
OpenJDK 64-Bit Server VM Corretto-21.0.2.13.1 (build 21.0.2+13-LTS, mixed mode, sharing)

$ kubectl version

Client Version: v1.29.0
Kustomize Version: v5.0.4-0.20230601165947-6ce0bf390ce3
Server Version: v1.29.2

Possible Solution

Additional context

I probably don't consider this as a bug and could be a genuine misunderstanding of the dependsOn and context.getSecondaryResource

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions