use of io.fabric8.openshift.api.model.Template in project wildfly-camel by wildfly-extras.
the class KubernetesIntegrationTest method testKubernetesProducer.
@Test
public void testKubernetesProducer() throws Exception {
String kubernetesProducerURI = String.format("kubernetes:%s?category=pods&operation=createPod", getKubernetesMaster());
CamelContext camelctx = new DefaultCamelContext();
camelctx.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from("direct:start").to(kubernetesProducerURI);
}
});
ProducerTemplate template = camelctx.createProducerTemplate();
String podName = POD_NAME + "-producer";
camelctx.start();
KubernetesEndpoint kubernetesEndpoint = camelctx.getEndpoint(kubernetesProducerURI, KubernetesEndpoint.class);
String kubernetesNamespace = getNamespace(kubernetesEndpoint.getKubernetesClient());
try {
Map<String, Object> headers = new HashMap<>();
headers.put(KubernetesConstants.KUBERNETES_NAMESPACE_NAME, kubernetesNamespace);
headers.put(KubernetesConstants.KUBERNETES_POD_NAME, podName);
headers.put(KubernetesConstants.KUBERNETES_POD_SPEC, createPodSpec());
Pod pod = template.requestBodyAndHeaders("direct:start", null, headers, Pod.class);
Assert.assertNotNull("Expected pod to be not null", pod);
Assert.assertEquals("Pending", pod.getStatus().getPhase());
} finally {
// Clean up
Map<String, Object> headers = new HashMap<>();
headers.put(KubernetesConstants.KUBERNETES_NAMESPACE_NAME, kubernetesNamespace);
headers.put(KubernetesConstants.KUBERNETES_POD_NAME, podName);
template.requestBodyAndHeaders("kubernetes:" + getKubernetesMaster() + "?category=pods&operation=deletePod", null, headers);
camelctx.stop();
}
}
use of io.fabric8.openshift.api.model.Template in project fabric8-maven-plugin by fabric8io.
the class DebugEnricher method enableDebugging.
private boolean enableDebugging(HasMetadata entity, PodTemplateSpec template) {
if (template != null) {
PodSpec podSpec = template.getSpec();
if (podSpec != null) {
List<Container> containers = podSpec.getContainers();
if (containers.size() > 0) {
Container container = containers.get(0);
List<EnvVar> env = container.getEnv();
if (env == null) {
env = new ArrayList<>();
}
String remoteDebugPort = KubernetesResourceUtil.getEnvVar(env, ENV_VAR_JAVA_DEBUG_PORT, ENV_VAR_JAVA_DEBUG_PORT_DEFAULT);
boolean enabled = false;
if (KubernetesResourceUtil.setEnvVar(env, ENV_VAR_JAVA_DEBUG, "true")) {
container.setEnv(env);
enabled = true;
}
List<ContainerPort> ports = container.getPorts();
if (ports == null) {
ports = new ArrayList<>();
}
if (KubernetesResourceUtil.addPort(ports, remoteDebugPort, "debug", log)) {
container.setPorts(ports);
enabled = true;
}
if (enabled) {
log.info("Enabling debug on " + getKind(entity) + " " + KubernetesHelper.getName(entity) + " due to the property: " + ENABLE_DEBUG_MAVEN_PROPERTY);
return true;
}
}
}
}
return false;
}
use of io.fabric8.openshift.api.model.Template in project fabric8-maven-plugin by fabric8io.
the class KubernetesResourceUtil method loadResources.
public static Set<HasMetadata> loadResources(File manifest) throws IOException {
Object dto = KubernetesHelper.loadYaml(manifest, KubernetesResource.class);
if (dto == null) {
throw new IllegalStateException("Cannot load kubernetes YAML: " + manifest);
}
if (dto instanceof Template) {
Template template = (Template) dto;
boolean failOnMissingParameterValue = false;
dto = Templates.processTemplatesLocally(template, failOnMissingParameterValue);
}
Set<KubernetesResource<?>> resources = new LinkedHashSet<>();
Set<HasMetadata> entities = new TreeSet<>(new HasMetadataComparator());
for (KubernetesResource<?> resource : resources) {
entities.addAll(KubernetesHelper.toItemList(resource));
}
entities.addAll(KubernetesHelper.toItemList(dto));
return entities;
}
use of io.fabric8.openshift.api.model.Template in project fabric8-maven-plugin by fabric8io.
the class OpenShiftDependencyResources method addMissingParameters.
public void addMissingParameters(Template template) {
List<Parameter> parameters = template.getParameters();
if (parameters == null) {
parameters = new ArrayList<>();
}
Map<String, Parameter> map = new HashMap<>();
for (Parameter parameter : parameters) {
map.put(parameter.getName(), parameter);
}
mergeParametersIntoMap(map, parameters);
for (Parameter parameter : map.values()) {
if (!parameters.contains(parameter)) {
parameters.add(parameter);
}
}
template.setParameters(parameters);
}
use of io.fabric8.openshift.api.model.Template in project fabric8-maven-plugin by fabric8io.
the class OpenShiftDependencyResources method addOpenShiftResources.
public void addOpenShiftResources(List<HasMetadata> items, boolean isAppCatalog) {
for (HasMetadata item : items) {
if (item instanceof Template) {
Template template = (Template) item;
if (!KubernetesResourceUtil.isAppCatalogResource(template) && !isAppCatalog) {
List<HasMetadata> objects = notNullList(template.getObjects());
String sourceUrl = getSourceUrlAnnotation(template);
if (Strings.isNotBlank(sourceUrl)) {
for (HasMetadata object : objects) {
setSourceUrlAnnotationIfNotSet(object, sourceUrl);
}
}
addOpenShiftResources(objects, isAppCatalog);
mergeParametersIntoMap(templateParameters, notNullList(template.getParameters()));
continue;
}
}
KindAndName key = new KindAndName(item);
HasMetadata old = openshiftDependencyResources.get(key);
if (old != null && !isAppCatalog) {
log.warn("Duplicate OpenShift resources for %s at %s and %s", key, getSourceUrlAnnotation(old), getSourceUrlAnnotation(item));
}
openshiftDependencyResources.put(key, item);
}
}
Aggregations