Search in sources :

Example 41 with Template

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

the class KubernetesFactoryWithPodTemplateTestBase method testEnvFromPodTemplate.

@Test
public void testEnvFromPodTemplate() {
    final Container mainContainer = KubernetesPodTemplateTestUtils.getContainerWithName(resultPod.getSpec(), Constants.MAIN_CONTAINER_NAME);
    assertThat(mainContainer.getEnv(), // The expected env is defined in the test/resources/testing-pod-template.yaml.
    hasItems(new EnvVarBuilder().withName("ENV_OF_POD_TEMPLATE").withValue("env-value-of-pod-template").build()));
}
Also used : Container(io.fabric8.kubernetes.api.model.Container) EnvVarBuilder(io.fabric8.kubernetes.api.model.EnvVarBuilder) Test(org.junit.Test)

Example 42 with Template

use of io.fabric8.openshift.api.model.Template in project syndesis-qe by syndesisio.

the class Syndesis method enableTestSupport.

private boolean enableTestSupport() {
    TestUtils.waitFor(() -> "AtLatestKnown".equalsIgnoreCase(getSubscription().getJSONObject("status").getString("state")), 2, 60 * 3, "CSV didn't get installed in time");
    JSONObject json = new JSONObject(OpenShiftUtils.getInstance().customResource(getCSVContext()).get(TestConfiguration.openShiftNamespace(), "fuse-online-operator.v7.9.0"));
    JSONObject operatorDeployment = json.getJSONObject("spec").getJSONObject("install").getJSONObject("spec").getJSONArray("deployments").getJSONObject(0);
    JSONArray envVars = operatorDeployment.getJSONObject("spec").getJSONObject("template").getJSONObject("spec").getJSONArray("containers").getJSONObject(0).getJSONArray("env");
    envVars.put(TestUtils.map("name", "TEST_SUPPORT", "value", "true"));
    try {
        OpenShiftUtils.getInstance().customResource(getCSVContext()).edit(TestConfiguration.openShiftNamespace(), "fuse-online-operator.v7.9.0", json.toMap());
        return true;
    } catch (Exception e) {
        log.error("Couldn't edit Syndesis CSV", e);
        return false;
    }
}
Also used : JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) TimeoutException(java.util.concurrent.TimeoutException) JSONException(org.json.JSONException) WaiterException(cz.xtf.core.waiting.WaiterException) KubernetesClientException(io.fabric8.kubernetes.client.KubernetesClientException) IOException(java.io.IOException)

Example 43 with Template

use of io.fabric8.openshift.api.model.Template in project syndesis-qe by syndesisio.

the class AMQ method deploy.

@Override
public void deploy() {
    if (!isDeployed()) {
        Template template;
        try (InputStream is = ClassLoader.getSystemResourceAsStream("templates/syndesis-amq.yml")) {
            template = OpenShiftUtils.getInstance().templates().load(is).get();
        } catch (IOException ex) {
            throw new IllegalArgumentException("Unable to read template ", ex);
        }
        Map<String, String> templateParams = new HashMap<>();
        templateParams.put("MQ_USERNAME", "amq");
        templateParams.put("MQ_PASSWORD", "topSecret");
        OpenShiftUtils.getInstance().templates().withName("syndesis-amq").delete();
        TestUtils.waitFor(() -> OpenShiftUtils.getInstance().templates().withName("syndesis-amq").get() == null, 3, 30, "syndesis-amq template still exist after delete");
        KubernetesList processedTemplate = OpenShiftUtils.getInstance().recreateAndProcessTemplate(template, templateParams);
        OpenShiftUtils.getInstance().createResources(processedTemplate);
        if (OpenShiftUtils.getInstance().getServices().stream().noneMatch(service -> "broker-amq-tcp".equals(service.getMetadata().getName()))) {
            OpenShiftUtils.getInstance().createService(OpenShiftUtils.getInstance().services().load(Paths.get("../utilities/src/main/resources/templates/syndesis-default-amq-service.yml").toFile()).get());
        }
    }
    addAccounts();
}
Also used : HashMap(java.util.HashMap) InputStream(java.io.InputStream) IOException(java.io.IOException) KubernetesList(io.fabric8.kubernetes.api.model.KubernetesList) Template(io.fabric8.openshift.api.model.Template)

Example 44 with Template

use of io.fabric8.openshift.api.model.Template in project kie-wb-common by kiegroup.

the class OpenShiftClient method createFromTemplate.

private void createFromTemplate(OpenShiftRuntimeConfig runtimeConfig) throws OpenShiftClientException {
    OpenShiftTemplate template = new OpenShiftTemplate(this, runtimeConfig);
    Map<String, String> parameters = new LinkedHashMap<String, String>();
    parameters.putAll(OpenShiftParameters.fromRuntimeConfig(runtimeConfig));
    String kieServerContainerDeployment = runtimeConfig.getKieServerContainerDeployment();
    if (kieServerContainerDeployment != null && !kieServerContainerDeployment.trim().isEmpty()) {
        parameters.put(OpenShiftProperty.KIE_SERVER_CONTAINER_DEPLOYMENT.envKey(), kieServerContainerDeployment);
    }
    KubernetesList kubeList = template.process(parameters);
    if (kubeList != null && kubeList.getItems().size() > 0) {
        try {
            DeploymentConfig dc = getDeploymentConfig(kubeList, runtimeConfig.getServiceName());
            if (dc != null) {
                dc.getSpec().setReplicas(0);
            }
            String prjName = runtimeConfig.getProjectName();
            delegate.lists().inNamespace(prjName).create(kubeList);
        } catch (Throwable t) {
            throw new OpenShiftClientException(t.getMessage(), t);
        }
    }
}
Also used : OpenShiftClientException(org.guvnor.ala.openshift.access.exceptions.OpenShiftClientException) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) KubernetesList(io.fabric8.kubernetes.api.model.KubernetesList) DoneableDeploymentConfig(io.fabric8.openshift.api.model.DoneableDeploymentConfig) DeploymentConfig(io.fabric8.openshift.api.model.DeploymentConfig) LinkedHashMap(java.util.LinkedHashMap)

Example 45 with Template

use of io.fabric8.openshift.api.model.Template in project kie-wb-common by kiegroup.

the class OpenShiftTemplate method load.

@SuppressWarnings({ "rawtypes", "unchecked" })
private Template load(InputStream templateStream) {
    String generatedName = Utils.randomString("template-", 10);
    Template temp = null;
    Object item = Serialization.unmarshal(templateStream);
    if (item instanceof Template) {
        temp = (Template) item;
    } else if (item instanceof HasMetadata) {
        HasMetadata h = (HasMetadata) item;
        temp = new TemplateBuilder().withNewMetadata().withName(generatedName).withNamespace(h != null && h.getMetadata() != null ? h.getMetadata().getNamespace() : null).endMetadata().withObjects(h).build();
    } else if (item instanceof KubernetesResourceList) {
        List<HasMetadata> list = ((KubernetesResourceList<HasMetadata>) item).getItems();
        temp = new TemplateBuilder().withNewMetadata().withName(generatedName).endMetadata().withObjects(list.toArray(new HasMetadata[list.size()])).build();
    } else if (item instanceof HasMetadata[]) {
        temp = new TemplateBuilder().withNewMetadata().withName(generatedName).endMetadata().withObjects((HasMetadata[]) item).build();
    } else if (item instanceof Collection) {
        List<HasMetadata> items = new ArrayList<>();
        for (Object o : (Collection) item) {
            if (o instanceof HasMetadata) {
                items.add((HasMetadata) o);
            }
        }
        temp = new TemplateBuilder().withNewMetadata().withName(generatedName).endMetadata().withObjects(items.toArray(new HasMetadata[items.size()])).build();
    }
    return temp;
}
Also used : HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) TemplateBuilder(io.fabric8.openshift.api.model.TemplateBuilder) KubernetesResourceList(io.fabric8.kubernetes.api.model.KubernetesResourceList) ArrayList(java.util.ArrayList) Collection(java.util.Collection) DoneableTemplate(io.fabric8.openshift.api.model.DoneableTemplate) Template(io.fabric8.openshift.api.model.Template)

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