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()));
}
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;
}
}
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();
}
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);
}
}
}
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;
}
Aggregations