Search in sources :

Example 81 with Template

use of io.fabric8.openshift.api.model.Template in project flink by apache.

the class DecoratorWithPodTemplateTestBase method testPodTolerationsMerging.

@Test
public void testPodTolerationsMerging() {
    final List<Toleration> expectedTolerations = Arrays.asList(new Toleration("NoSchedule", "key1", "Equal", null, "value1"), // The toleration from pod template
    new Toleration("NoExecute", "key2-of-pod-template", "Exists", 6000L, null));
    assertThat(this.resultPod.getPodWithoutMainContainer().getSpec().getTolerations(), Matchers.containsInAnyOrder(expectedTolerations.toArray()));
}
Also used : Toleration(io.fabric8.kubernetes.api.model.Toleration) Test(org.junit.Test)

Example 82 with Template

use of io.fabric8.openshift.api.model.Template in project zeppelin by apache.

the class K8sRemoteInterpreterProcess method apply.

/**
 * Apply spec file(s) in the path.
 * @param path Path to the K8s resources
 * @param delete set to true, the K8s resources are deleted
 * @param templateProperties properties to enrich the template
 */
void apply(File path, boolean delete, Properties templateProperties) throws IOException {
    if (path.getName().startsWith(".") || path.isHidden() || path.getName().endsWith("~")) {
        LOGGER.info("Skip {}", path.getAbsolutePath());
        return;
    }
    if (path.isDirectory()) {
        File[] files = path.listFiles();
        Arrays.sort(files);
        if (delete) {
            ArrayUtils.reverse(files);
        }
        for (File f : files) {
            apply(f, delete, templateProperties);
        }
    } else if (path.isFile()) {
        K8sSpecTemplate specTemplate = new K8sSpecTemplate();
        specTemplate.loadProperties(templateProperties);
        String template = specTemplate.render(path);
        ParameterNamespaceListVisitFromServerGetDeleteRecreateWaitApplicable<HasMetadata> k8sObjects = client.load(IOUtils.toInputStream(template, StandardCharsets.UTF_8));
        LOGGER.info("Apply {} with {} K8s Objects", path.getAbsolutePath(), k8sObjects.get().size());
        LOGGER.debug(template);
        if (delete) {
            k8sObjects.inNamespace(interpreterNamespace).delete();
        } else {
            k8sObjects.inNamespace(interpreterNamespace).createOrReplace();
        }
    } else {
        LOGGER.error("Can't apply {}", path.getAbsolutePath());
    }
}
Also used : ParameterNamespaceListVisitFromServerGetDeleteRecreateWaitApplicable(io.fabric8.kubernetes.client.dsl.ParameterNamespaceListVisitFromServerGetDeleteRecreateWaitApplicable) File(java.io.File)

Example 83 with Template

use of io.fabric8.openshift.api.model.Template in project fabric8 by fabric8io.

the class SessionListener method expandTemplate.

protected Object expandTemplate(Controller controller, Configuration configuration, Logger log, String namespace, String sourceName, Object dto) {
    if (dto instanceof Template) {
        Template template = (Template) dto;
        KubernetesHelper.setNamespace(template, namespace);
        String parameterNamePrefix = "";
        overrideTemplateParameters(template, configuration.getProperties(), parameterNamePrefix);
        log.status("Applying template in namespace " + namespace);
        controller.installTemplate(template, sourceName);
        dto = controller.processTemplate(template, sourceName);
        if (dto == null) {
            throw new IllegalArgumentException("Failed to process Template!");
        }
    }
    return dto;
}
Also used : Util.readAsString(io.fabric8.arquillian.utils.Util.readAsString) Template(io.fabric8.openshift.api.model.Template)

Example 84 with Template

use of io.fabric8.openshift.api.model.Template in project fabric8 by fabric8io.

the class ParseTest method testParseTemplate.

@Test
public void testParseTemplate() throws Exception {
    Template template = assertParseExampleFile("template.json", Template.class);
    List<HasMetadata> objects = template.getObjects();
    assertNotEmpty("objects", objects);
    assertTrue("size is " + objects.size(), objects.size() == 2);
    Object service = objects.get(0);
    assertThat(service).isInstanceOf(Service.class);
    Object rc = objects.get(1);
    assertThat(rc).isInstanceOf(ReplicationController.class);
    System.out.println("Generated JSON: " + toJson(template));
}
Also used : Template(io.fabric8.openshift.api.model.Template) Test(org.junit.Test)

Example 85 with Template

use of io.fabric8.openshift.api.model.Template in project keycloak by keycloak.

the class KeycloakDeployment method getReconciledResource.

@Override
public Optional<HasMetadata> getReconciledResource() {
    // clone not to change the base template
    Deployment baseDeployment = new DeploymentBuilder(this.baseDeployment).build();
    Deployment reconciledDeployment;
    if (existingDeployment == null) {
        Log.info("No existing Deployment found, using the default");
        reconciledDeployment = baseDeployment;
    } else {
        Log.info("Existing Deployment found, updating specs");
        reconciledDeployment = existingDeployment;
        // don't override metadata, just specs
        reconciledDeployment.setSpec(baseDeployment.getSpec());
    }
    return Optional.of(reconciledDeployment);
}
Also used : Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) DeploymentBuilder(io.fabric8.kubernetes.api.model.apps.DeploymentBuilder)

Aggregations

Template (io.fabric8.openshift.api.model.Template)32 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)24 IOException (java.io.IOException)20 KubernetesList (io.fabric8.kubernetes.api.model.KubernetesList)16 HashMap (java.util.HashMap)15 Test (org.junit.Test)15 File (java.io.File)14 KubernetesClientException (io.fabric8.kubernetes.client.KubernetesClientException)12 Service (io.fabric8.kubernetes.api.model.Service)11 Parameter (io.fabric8.openshift.api.model.Parameter)9 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)8 Container (io.fabric8.kubernetes.api.model.Container)8 PodTemplateSpec (io.fabric8.kubernetes.api.model.PodTemplateSpec)8 ReplicationController (io.fabric8.kubernetes.api.model.ReplicationController)8 OpenShiftNotAvailableException (io.fabric8.openshift.client.OpenShiftNotAvailableException)8 FileNotFoundException (java.io.FileNotFoundException)8 ArrayList (java.util.ArrayList)8 Map (java.util.Map)8 PodSpec (io.fabric8.kubernetes.api.model.PodSpec)7 OpenShiftHelper (io.vertx.it.openshift.utils.OpenShiftHelper)7