Create a template in openshift cluster using fabric8io

258 Views Asked by At

I'm trying to use fabric8 java libraries to interact with my local minishift cluster (openshift). Basically my java application has to create a new project and create a template. This is due to the fact that in openshift a custom template has to be created for each new project. With "create a template" I mean I need my custom template to be seen in the catalog panel of my openshift web console (or with [$ oc get templates] using a terminal). I need to do the equivalent of "oc apply -f my-template-file.yaml", but with fabric8 libraries in java. Here is a link to an example of usage https://github.com/fabric8io/kubernetes-client/blob/master/kubernetes-examples/src/main/java/io/fabric8/openshift/examples/TemplateExample.java

I've tried to do

        final Template loadedTemplate = client.templates()
          .load(TemplateExample.class.getResourceAsStream("/my-template-file.yaml")).get();
        for (Parameter p : loadedTemplate.getParameters()) {
          final String required = Boolean.TRUE.equals(p.getRequired()) ? "*" : "";
          logger.info("Loaded parameter from template: {}{} - '{}' ({})",
            p.getName(), required, p.getValue(), p.getGenerate());

But what I'm getting is a null pointer exception in method load() (line 2) I thought it was becouse the path to the file is wrong, but the same error shows up even if i use

Paths.get("/my-template-file.yaml").toAbsolutePath().normalize().toString();

instead of "/my-template-file.yaml"

0

There are 0 best solutions below