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

Question: Loading CRD resources as part of list #2500

Closed
nbn opened this issue Sep 18, 2020 · 1 comment
Closed

Question: Loading CRD resources as part of list #2500

nbn opened this issue Sep 18, 2020 · 1 comment

Comments

@nbn
Copy link

nbn commented Sep 18, 2020

Hi,
Have used the API for a while to read and process resources prior to deployment
I have a use case where I read a yaml list from an inputstream into a list, manipulate each element and update them on the server.

The code looks roughly like this

        List<HasMetadata> metadataList = client.load(resourceAsStream).get();
        for (HasMetadata metadata : metadataList) {
            System.out.println("Found metadata" + metadata.getMetadata().getName());
            processFromMetadata(metadata);
        }

The client is an adapted OpenshiftClient, and have worked flawlessly up until now, where we include CRD objects for a prometheus operator (using monitoring.coreos.com/v1).

I have tried creating a typed DSL and register it with the json deserializer

KubernetesDeserializer.registerCustomKind("monitoring.coreos.com/v1", "ServiceMonitor", ServiceMonitor.class);

And if I extract a MixedOperation wrapper client, I can read a service monitor resource from a single file and apply it in the target cluster.

        MixedOperation<...> smclient = client.customResources(crdContext,...);
        ServiceMonitor serviceMonitor = smclient.load(resourceAsStream).get();
        System.out.println("Found " +serviceMonitor.getMetadata().getName());
        processServiceMonitor(serviceMonitor);

So I can work with CRDs as an entity, but I cannot load it as part of a YAML list.

Whenever I try the original generic HasMetadata approach the NamespaceVisitFromServerGetWatchDeleteRecreateWaitApplicatbleListImpl class tries to locate a Handler to the deserialized ServiceMonitor Kind, but fails to find one (return null and then throws a NullPointerException, which is probably a flaw in itself).
And this is even though I have registered the customResource..

        client.customResource(crdContext);
        List<HasMetadata> metadataList = client.load(resourceAsStream).get();
        for (HasMetadata metadata : metadataList) {
            System.out.println("Found metadata" + metadata.getMetadata().getName());
            processFromMetadata(metadata);
        }

Looking into the current extensions (openshift, knative, service-catalog, etc) I can see there is (velocity) code to produce objects to back up the resource handling.

How Can I Do Something Similar with CRDs?

@nbn
Copy link
Author

nbn commented Sep 29, 2020

Thanks to @rohanKanojia the monitoring objects were included as inherent objects, fixing #2321. This means that from 4.11.1 this is native.

@nbn nbn closed this as completed Sep 29, 2020
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

No branches or pull requests

1 participant