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

Controller for all namespaces can't get object from indexer using provided OperatorResourceLister #640

Open
tired-old-man opened this issue Sep 18, 2023 · 0 comments
Labels
type: bug Something isn't working

Comments

@tired-old-man
Copy link

Expected Behavior

When developing Controller it should be able to resolve (reconcile) objects from all namespaces.

Actual Behaviour

The Controller implementation is not able to fetch object using provided OperatorResourceLister.

The following exception is thrown:

19:39:49.742 [all-namespaces-pod-operator-controller-1] INFO  o.f.b.AllNamespacesReconciler - Reconciler for request: Request{name='local-path-provisioner-957fdf8bc-2dxj2', namespace='kube-system'}
19:39:49.743 [all-namespaces-pod-operator-controller-2] ERROR c.c.n.o.p.o.AllNamespacesReconciler - Reconciler failed
java.lang.NullPointerException: Cannot invoke "io.kubernetes.client.informer.SharedIndexInformer.getIndexer()" because "sharedIndexInformer" is null
        at io.micronaut.kubernetes.client.operator.OperatorResourceLister.get(OperatorResourceLister.java:66)
        at org.foo.bar.AllNamespacesReconciler.reconcile(AllNamespacesReconciler.java:33)
        at io.micronaut.kubernetes.client.operator.controller.DefaultControllerBuilder.lambda$build$1(DefaultControllerBuilder.java:108)
        at io.kubernetes.client.extended.controller.DefaultController.worker(DefaultController.java:207)
        at io.kubernetes.client.extended.controller.DefaultController.lambda$run$1(DefaultController.java:154)
        at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:577)
        at java.base/java.util.concurrent.FutureTask.runAndReset(FutureTask.java:358)
        at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:305)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642)
        at java.base/java.lang.Thread.run(Thread.java:1623)

The problem lies in implementation of get method in OperatorResourceLister class.
It will try to fetch or compute shared index informer. But informer is registered for all namespaces ("").
The request if for a particular object in a namespace. Which will result in non existing shared index informer, hence the NullPointerException.

Steps To Reproduce

Simple operator to listen for pods in all namespaces.

@Operator(
        name = "all-namespaces-pod-operator",
        informer = @Informer(apiType = V1Pod.class, apiListType = V1PodList.class, namespace = Informer.ALL_NAMESPACES))
public class AllNamespacesReconciler implements ResourceReconciler<V1Pod> {

    private static final Logger log = LoggerFactory.getLogger(AllNamespacesReconciler.class);

    @Override
    public @NonNull Result reconcile(@NonNull Request request, @NonNull OperatorResourceLister<V1Pod> lister) {
        try {
            log.info("Reconciler for request: " + request);
            var pod = lister.get(request);

            log.info("Pod\n" + pod);
            return new Result(false, null);
        } catch (Exception e) {
            log.error("Reconciler failed", e);
            return new Result(true, Duration.ofSeconds(5));
        }
    }
}

Environment Information

OS: Windows 11 / WSL 2 (Ubuntu)

$ java -version
openjdk version "17.0.8.1" 2023-08-24
OpenJDK Runtime Environment Temurin-17.0.8.1+1 (build 17.0.8.1+1)
OpenJDK 64-Bit Server VM Temurin-17.0.8.1+1 (build 17.0.8.1+1, mixed mode, sharing)

mvn --version
Apache Maven 3.9.4 (dfbb324ad4a7c8fb0bf182e6d91b0ae20e3d2dd9)
Maven home: /home/user/.sdkman/candidates/maven/current
Java version: 17.0.8.1, vendor: Eclipse Adoptium, runtime: /home/user/.sdkman/candidates/java/17.0.8.1-tem
Default locale: en, platform encoding: UTF-8
OS name: "linux", version: "5.15.90.1-microsoft-standard-wsl2", arch: "amd64", family: "unix"

mn --version
Micronaut Version: 4.1.1

Example Application

No response

Version

4.1.1

@tired-old-man tired-old-man changed the title Controller for all namespaces can't fetch resource from indexer Controller for all namespaces can't get object from indexer using provided OperatorResourceLister Sep 18, 2023
@alvarosanchez alvarosanchez added the type: bug Something isn't working label Sep 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants