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

OpenShift - NPE when loading resources from InputStream #2066

Closed
pk044 opened this issue Mar 16, 2020 · 5 comments · Fixed by #2211
Closed

OpenShift - NPE when loading resources from InputStream #2066

pk044 opened this issue Mar 16, 2020 · 5 comments · Fixed by #2211
Assignees
Labels

Comments

@pk044
Copy link

pk044 commented Mar 16, 2020

Judging from a quick debug session, it seems like the client can't find an appropriate handler for loading this sample yml file.
image

here's a project that will let you reproduce the issue:
https://github.com/pk044/fabric8-k8s-openshift-bug

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
nginx-deployment5
nginx-deployment5-142
nginx-deployment5-157
nginx-deployment5-50
Exception in thread "main" java.lang.NullPointerException
	at io.fabric8.kubernetes.client.dsl.internal.NamespaceVisitFromServerGetWatchDeleteRecreateWaitApplicableListImpl.acceptVisitors(NamespaceVisitFromServerGetWatchDeleteRecreateWaitApplicableListImpl.java:331)
	at io.fabric8.kubernetes.client.dsl.internal.NamespaceVisitFromServerGetWatchDeleteRecreateWaitApplicableListImpl.get(NamespaceVisitFromServerGetWatchDeleteRecreateWaitApplicableListImpl.java:323)
	at io.fabric8.kubernetes.client.dsl.internal.NamespaceVisitFromServerGetWatchDeleteRecreateWaitApplicableListImpl.get(NamespaceVisitFromServerGetWatchDeleteRecreateWaitApplicableListImpl.java:64)
	at Sample.main(Sample.java:12)

Process finished with exit code 1

I used CRC to test this - but the problem occurs in the previous versions.

@rohanKanojia rohanKanojia self-assigned this Apr 3, 2020
@rohanKanojia
Copy link
Member

@pk044 : Hi, Could you please share NPE stacktrace? I tried but could not reproduce your error. This is the code I used:

        try (DefaultOpenShiftClient client = new DefaultOpenShiftClient()) {
            client.deploymentConfigs().inNamespace("rokumar").list().getItems().forEach(
                    workload -> System.out.println(workload.getMetadata().getName()));
            client.load(OpenshiftNPEBug.class.getResourceAsStream("/example.yml")).get();
        }

The only difference between yours and my reproducer is /example.yml

@pk044
Copy link
Author

pk044 commented Apr 7, 2020

@rohanKanojia i currently don't have the access to any openshift cluster, you can clone the project and check out the stacktrace if you want.

i don't think that the path passed to getResourceAsStream is bugged - i can read the file with java stdlib just fine

@rohanKanojia
Copy link
Member

@pk044 : ah, looks like I misunderstood the issue. I can reproduce it now

@rohanKanojia
Copy link
Member

I think I found the issue, looks like openshift handler file is not present in kubernetes-openshift-uberjar which you are using in your project:

~/Downloads : $ cd kubernetes-openshift-uberjar-4.9.0/
~/Downloads/kubernetes-openshift-uberjar-4.9.0 : $ cd META-INF/
maven/    services/ 
~/Downloads/kubernetes-openshift-uberjar-4.9.0 : $ cd META-INF/services/
~/Downloads/kubernetes-openshift-uberjar-4.9.0/META-INF/services : $ ls
io.fabric8.kubernetes.api.KubernetesResourceMappingProvider  io.fabric8.kubernetes.client.ExtensionAdapter  io.fabric8.kubernetes.client.ResourceHandler  io.fabric8.kubernetes.client.ServiceToURLProvider
~/Downloads/kubernetes-openshift-uberjar-4.9.0/META-INF/services : $ cat io.fabric8.kubernetes.client.ResourceHandler

io.fabric8.kubernetes.client.handlers.ClusterRoleBindingHandler
io.fabric8.kubernetes.client.handlers.LimitRangeHandler
io.fabric8.kubernetes.client.handlers.ReplicaSetHandler
io.fabric8.kubernetes.client.handlers.CSIDriverHandler
io.fabric8.kubernetes.client.handlers.EndpointSliceHandler
io.fabric8.kubernetes.client.handlers.RoleHandler
io.fabric8.kubernetes.client.handlers.CronJobHandler
io.fabric8.kubernetes.client.handlers.PodMetricsHandler
io.fabric8.kubernetes.client.handlers.VolumeAttachmentHandler
io.fabric8.kubernetes.client.handlers.RoleBindingHandler
io.fabric8.kubernetes.client.handlers.PodPresetHandler
io.fabric8.kubernetes.client.handlers.HorizontalPodAutoscalerHandler
io.fabric8.kubernetes.client.handlers.ComponentStatusHandler
io.fabric8.kubernetes.client.handlers.CSINodeHandler
io.fabric8.kubernetes.client.handlers.DaemonSetHandler
io.fabric8.kubernetes.client.handlers.PodTemplateHandler
io.fabric8.kubernetes.client.handlers.LeaseHandler
io.fabric8.kubernetes.client.handlers.ServiceHandler
io.fabric8.kubernetes.client.handlers.ControllerRevisionHandler
io.fabric8.kubernetes.client.handlers.NodeHandler
io.fabric8.kubernetes.client.handlers.JobHandler
io.fabric8.kubernetes.client.handlers.EndpointsHandler
io.fabric8.kubernetes.client.handlers.NodeMetricsHandler
io.fabric8.kubernetes.client.handlers.EventHandler
io.fabric8.kubernetes.client.handlers.ValidatingWebhookConfigurationHandler
io.fabric8.kubernetes.client.handlers.IngressHandler
io.fabric8.kubernetes.client.handlers.ReplicationControllerHandler
io.fabric8.kubernetes.client.handlers.PodDisruptionBudgetHandler
io.fabric8.kubernetes.client.handlers.PodHandler
io.fabric8.kubernetes.client.handlers.PersistentVolumeHandler
io.fabric8.kubernetes.client.handlers.StatefulSetHandler
io.fabric8.kubernetes.client.handlers.ConfigMapHandler
io.fabric8.kubernetes.client.handlers.CertificateSigningRequestHandler
io.fabric8.kubernetes.client.handlers.PriorityClassHandler
io.fabric8.kubernetes.client.handlers.CustomResourceDefinitionHandler
io.fabric8.kubernetes.client.handlers.StorageClassHandler
io.fabric8.kubernetes.client.handlers.NamespaceHandler
io.fabric8.kubernetes.client.handlers.ResourceQuotaHandler
io.fabric8.kubernetes.client.handlers.ClusterRoleHandler
io.fabric8.kubernetes.client.handlers.SecretHandler
io.fabric8.kubernetes.client.handlers.NetworkPolicyHandler
io.fabric8.kubernetes.client.handlers.PersistentVolumeClaimHandler
io.fabric8.kubernetes.client.handlers.PodSecurityPolicyHandler
io.fabric8.kubernetes.client.handlers.ServiceAccountHandler
io.fabric8.kubernetes.client.handlers.DeploymentHandler
io.fabric8.kubernetes.client.handlers.MutatingWebhookConfigurationHandler

However when I use openshift-client as a dependency:

        <dependency>
            <groupId>io.fabric8</groupId>
            <artifactId>openshift-client</artifactId>
            <version>${kubernetes-client.version}</version>
        </dependency>

I don't face this error anymore since openshift related handlers are present now:

~/Downloads : $ cd openshift-client-4.9.0/
~/Downloads/openshift-client-4.9.0 : $ cd META-INF/
~/Downloads/openshift-client-4.9.0/META-INF : $ ls
jandex.idx  MANIFEST.MF  maven  services
~/Downloads/openshift-client-4.9.0/META-INF : $ cd services/
~/Downloads/openshift-client-4.9.0/META-INF/services : $ ls
io.fabric8.kubernetes.client.ExtensionAdapter  io.fabric8.kubernetes.client.ResourceHandler  io.fabric8.kubernetes.client.ServiceToURLProvider
~/Downloads/openshift-client-4.9.0/META-INF/services : $ cat io.fabric8.kubernetes.client.ResourceHandler

io.fabric8.openshift.client.handlers.ImageStreamTagHandler
io.fabric8.openshift.client.handlers.SecurityContextConstraintsHandler
io.fabric8.openshift.client.handlers.GroupHandler
io.fabric8.openshift.client.handlers.OAuthAccessTokenHandler
io.fabric8.openshift.client.handlers.DeploymentConfigHandler
io.fabric8.openshift.client.handlers.ImageHandler
io.fabric8.openshift.client.handlers.UserHandler
io.fabric8.openshift.client.handlers.BuildConfigHandler
io.fabric8.openshift.client.handlers.TemplateHandler
io.fabric8.openshift.client.handlers.RouteHandler
io.fabric8.openshift.client.handlers.NetNamespaceHandler
io.fabric8.openshift.client.handlers.OpenshiftRoleHandler
io.fabric8.openshift.client.handlers.OAuthClientAuthorizationHandler
io.fabric8.openshift.client.handlers.OpenshiftClusterRoleBindingHandler
io.fabric8.openshift.client.handlers.BuildHandler
io.fabric8.openshift.client.handlers.OpenshiftRoleBindingHandler
io.fabric8.openshift.client.handlers.ProjectHandler
io.fabric8.openshift.client.handlers.OAuthClientHandler
io.fabric8.openshift.client.handlers.OAuthAuthorizeTokenHandler
io.fabric8.openshift.client.handlers.IdentityHandler
io.fabric8.openshift.client.handlers.ImageStreamHandler
~/Downloads/openshift-client-4.9.0/META-INF/services : $ 

Need to check whether it's possible to merge these both kubernetes-client and openshift-client handler files inside uberjar. But for now, I think you can use this as a workaround(in case you want handlers for both OpenShift and Kubernetes resources):

        <dependency>
            <groupId>io.fabric8</groupId>
            <artifactId>kubernetes-client</artifactId>
            <version>${kubernetes-client.version}</version>
        </dependency>
        <dependency>
            <groupId>io.fabric8</groupId>
            <artifactId>openshift-client</artifactId>
            <version>${kubernetes-client.version}</version>
        </dependency>

rohanKanojia added a commit to rohanKanojia/kubernetes-client that referenced this issue May 7, 2020
…ontains both Openshift and Kubernetes resources
rohanKanojia added a commit to rohanKanojia/kubernetes-client that referenced this issue May 7, 2020
rohanKanojia added a commit to rohanKanojia/kubernetes-client that referenced this issue May 7, 2020
rohanKanojia added a commit to rohanKanojia/kubernetes-client that referenced this issue May 8, 2020
rohanKanojia added a commit to rohanKanojia/kubernetes-client that referenced this issue May 8, 2020
@manusa
Copy link
Member

manusa commented May 8, 2020

For the record, most of the work necessary to discover and be able to provide #2211 that should fix this issue was performed by @rohanKanojia while working on his PR.

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