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

NullPointerException for CustomResource - (missing default handler for GenericKubernetesResource) #3392

Closed
arturk9 opened this issue Aug 9, 2021 · 3 comments · Fixed by #3525

Comments

@arturk9
Copy link

arturk9 commented Aug 9, 2021

Hello!

I would like to ask you if it would be possible to implement default handler for GenericKubernetesResource?

For example, resource

apiVersion: consul.hashicorp.com/v1alpha1
kind: ServiceDefaults
metadata:
  name: web
spec:
  protocol: http

when loaded by:

var contentsInputStream = MethodHandles.lookup().lookupClass().getResourceAsStream(customResourceYamlPath)
kubernetesClient.load(contentsInputStream).get()

Returns:

Exception in thread "main" java.lang.NullPointerException
	at io.fabric8.kubernetes.client.dsl.internal.NamespaceVisitFromServerGetWatchDeleteRecreateWaitApplicableListImpl.acceptVisitors(NamespaceVisitFromServerGetWatchDeleteRecreateWaitApplicableListImpl.java:291)
	at io.fabric8.kubernetes.client.dsl.internal.NamespaceVisitFromServerGetWatchDeleteRecreateWaitApplicableListImpl.get(NamespaceVisitFromServerGetWatchDeleteRecreateWaitApplicableListImpl.java:283)
	at io.fabric8.kubernetes.client.dsl.internal.NamespaceVisitFromServerGetWatchDeleteRecreateWaitApplicableListImpl.get(NamespaceVisitFromServerGetWatchDeleteRecreateWaitApplicableListImpl.java:63)
@shawkins
Copy link
Contributor

shawkins commented Aug 9, 2021

The NPE has been replaced with a KubernetesClientException. I don't think you can do this generically as the item does not provide if it's namespaced nor what the plural is.

Try instead:
kubernetesClient.genericKubernetesResource(context).load(stream)

@manusa
Copy link
Member

manusa commented Aug 10, 2021

kubernetesClient.load(contentsInputStream).get()

Being able to do this is part of the Generic Resource next steps and should be possible after implementing:

So for those (valid) resources for which we don't have enough information to interact with the API server, we could perform (and cache) a request to the ApiGroupList and ApiResourceList endpoints to fetch the required parameters (scope, plural, etc.). With this information, then we can interact with the API server for any valid (and known) resource.

@shawkins
Copy link
Contributor

With this information, then we can interact with the API server for any valid (and known) resource.

There is a placeholder method for that in Handlers

public static <T extends HasMetadata, V extends VisitableBuilder<T, V>> ResourceHandler<T, V> get(T meta) {
which can eventually be expanded to support this. For now passing in the context is the only option.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants