use of io.fabric8.openshift.api.model.Template in project fabric8 by jboss-fuse.
the class Controller method printSummary.
protected void printSummary(Object kubeResource) throws IOException {
if (kubeResource != null) {
LOG.debug(" " + kubeResource.getClass().getSimpleName() + " " + kubeResource);
}
if (kubeResource instanceof Template) {
Template template = (Template) kubeResource;
String id = getName(template);
LOG.info(" Template " + id + " " + summaryText(template));
printSummary(template.getObjects());
return;
}
List<HasMetadata> list = toItemList(kubeResource);
for (HasMetadata object : list) {
if (object != null) {
if (object == list) {
LOG.debug("Ignoring recursive list " + list);
continue;
} else if (object instanceof List) {
printSummary(object);
} else {
String kind = object.getClass().getSimpleName();
String id = getObjectId(object);
LOG.info(" " + kind + " " + id + " " + summaryText(object));
}
}
}
}
use of io.fabric8.openshift.api.model.Template in project fabric8 by jboss-fuse.
the class Controller method doCreateReplicationController.
protected void doCreateReplicationController(ReplicationController replicationController, String namespace, String sourceName) {
LOG.info("Creating a ReplicationController from " + sourceName + " namespace " + namespace + " name " + getName(replicationController));
try {
// lets check that if secrets are required they exist
ReplicationControllerSpec spec = replicationController.getSpec();
if (spec != null) {
PodTemplateSpec template = spec.getTemplate();
if (template != null) {
PodSpec podSpec = template.getSpec();
validatePodSpec(podSpec, namespace);
}
}
Object answer;
if (Strings.isNotBlank(namespace)) {
answer = kubernetesClient.replicationControllers().inNamespace(namespace).create(replicationController);
} else {
answer = kubernetesClient.replicationControllers().inNamespace(getNamespace()).create(replicationController);
}
logGeneratedEntity("Created ReplicationController: ", namespace, replicationController, answer);
} catch (Exception e) {
onApplyError("Failed to create ReplicationController from " + sourceName + ". " + e + ". " + replicationController, e);
}
}
use of io.fabric8.openshift.api.model.Template in project fabric8 by jboss-fuse.
the class Templates method combineTemplates.
public static Template combineTemplates(Template firstTemplate, Template template) {
List<HasMetadata> objects = template.getObjects();
if (objects != null) {
for (HasMetadata object : objects) {
addTemplateObject(firstTemplate, object);
}
}
List<Parameter> parameters = firstTemplate.getParameters();
if (parameters == null) {
parameters = new ArrayList<>();
firstTemplate.setParameters(parameters);
}
combineParameters(parameters, template.getParameters());
String name = KubernetesHelper.getName(template);
if (Strings.isNotBlank(name)) {
// lets merge all the fabric8 annotations using the template id qualifier as a postfix
Map<String, String> annotations = KubernetesHelper.getOrCreateAnnotations(firstTemplate);
Map<String, String> otherAnnotations = KubernetesHelper.getOrCreateAnnotations(template);
Set<Map.Entry<String, String>> entries = otherAnnotations.entrySet();
for (Map.Entry<String, String> entry : entries) {
String key = entry.getKey();
String value = entry.getValue();
if (!annotations.containsKey(key)) {
annotations.put(key, value);
}
}
}
return firstTemplate;
}
use of io.fabric8.openshift.api.model.Template in project fabric8 by jboss-fuse.
the class Templates method processTemplatesLocally.
/**
* Lets locally process the templates so that we can process templates on any kubernetes environment
*/
public static KubernetesList processTemplatesLocally(Template entity, boolean failOnMissingParameterValue) throws IOException {
List<HasMetadata> objects = null;
if (entity != null) {
objects = entity.getObjects();
if (objects == null || objects.isEmpty()) {
return null;
}
}
List<Parameter> parameters = entity != null ? entity.getParameters() : null;
if (parameters != null && !parameters.isEmpty()) {
String json = "{\"kind\": \"List\", \"apiVersion\": \"" + KubernetesHelper.defaultApiVersion + "\",\n" + " \"items\": " + KubernetesHelper.toJson(objects) + " }";
// lets make a few passes in case there's expressions in values
for (int i = 0; i < 5; i++) {
for (Parameter parameter : parameters) {
String name = parameter.getName();
String regex = "${" + name + "}";
String value = parameter.getValue();
// TODO generate random strings for passwords etc!
if (Strings.isNullOrBlank(value)) {
if (failOnMissingParameterValue) {
throw new IllegalArgumentException("No value available for parameter name: " + name);
} else {
value = "";
}
}
json = Strings.replaceAllWithoutRegex(json, regex, value);
}
}
return OBJECT_MAPPER.readerFor(KubernetesList.class).readValue(json);
} else {
KubernetesList answer = new KubernetesList();
answer.setItems(objects);
return answer;
}
}
Aggregations