use of io.fabric8.openshift.api.model.Template in project fabric8-maven-plugin by fabric8io.
the class ReplicSetOpenShiftConverter method convert.
@Override
public HasMetadata convert(HasMetadata item, boolean trimImageInContainerSpec, boolean enableAutomaticTrigger) {
ReplicaSet resource = (ReplicaSet) item;
ReplicationControllerBuilder builder = new ReplicationControllerBuilder();
builder.withMetadata(resource.getMetadata());
ReplicaSetSpec spec = resource.getSpec();
if (spec != null) {
ReplicationControllerFluent.SpecNested<ReplicationControllerBuilder> specBuilder = builder.withNewSpec();
Integer replicas = spec.getReplicas();
if (replicas != null) {
specBuilder.withReplicas(replicas);
}
LabelSelector selector = spec.getSelector();
if (selector != null) {
Map<String, String> matchLabels = selector.getMatchLabels();
if (matchLabels != null && !matchLabels.isEmpty()) {
specBuilder.withSelector(matchLabels);
}
}
PodTemplateSpec template = spec.getTemplate();
if (template != null) {
specBuilder.withTemplate(template);
}
specBuilder.endSpec();
}
return builder.build();
}
use of io.fabric8.openshift.api.model.Template in project fabric8-maven-plugin by fabric8io.
the class AbstractResourceMojo method writeResourcesIndividualAndComposite.
public static File writeResourcesIndividualAndComposite(KubernetesList resources, File resourceFileBase, ResourceFileType resourceFileType, Logger log, Boolean generateRoute) throws MojoExecutionException {
// Creating a new items list. This will be used to generate openshift.yml
List<HasMetadata> newItemList = new ArrayList<>();
if (!generateRoute) {
// if flag is set false, this will remove the Route resource from resources list
for (HasMetadata item : resources.getItems()) {
if (item.getKind().equalsIgnoreCase("Route")) {
continue;
}
newItemList.add(item);
}
// update the resource with new list
resources.setItems(newItemList);
}
// entity is object which will be sent to writeResource for openshift.yml
// if generateRoute is false, this will be set to resources with new list
// otherwise it will be set to resources with old list.
Object entity = resources;
// if the list contains a single Template lets unwrap it
// in resources already new or old as per condition is set.
// no need to worry about this for dropping Route.
Template template = getSingletonTemplate(resources);
if (template != null) {
entity = template;
}
File file = writeResource(resourceFileBase, entity, resourceFileType);
// write separate files, one for each resource item
// resources passed to writeIndividualResources is also new one.
writeIndividualResources(resources, resourceFileBase, resourceFileType, log, generateRoute);
return file;
}
use of io.fabric8.openshift.api.model.Template in project fabric8-maven-plugin by fabric8io.
the class ApplyMojo method overrideTemplateParameters.
/**
* Before applying the given template lets allow template parameters to be overridden via the maven
* properties - or optionally - via the command line if in interactive mode.
*/
protected static void overrideTemplateParameters(Template template, MavenProject project, Logger log) {
List<io.fabric8.openshift.api.model.Parameter> parameters = template.getParameters();
if (parameters != null && project != null) {
Properties properties = getProjectAndFabric8Properties(project);
boolean missingProperty = false;
for (io.fabric8.openshift.api.model.Parameter parameter : parameters) {
String parameterName = parameter.getName();
String name = "fabric8.apply." + parameterName;
String propertyValue = properties.getProperty(name);
if (propertyValue != null) {
log.info("Overriding template parameter " + name + " with value: " + propertyValue);
parameter.setValue(propertyValue);
} else {
missingProperty = true;
log.info("No property defined for template parameter: " + name);
}
}
if (missingProperty) {
log.debug("Current properties " + new TreeSet<>(properties.keySet()));
}
}
}
use of io.fabric8.openshift.api.model.Template in project fabric8-maven-plugin by fabric8io.
the class ResourceMojo method extractAndRemoveTemplates.
private Template extractAndRemoveTemplates(List<HasMetadata> items) {
Template extractedTemplate = null;
for (HasMetadata item : new ArrayList<>(items)) {
if (item instanceof Template && !KubernetesResourceUtil.isAppCatalogResource(item)) {
Template template = (Template) item;
if (extractedTemplate == null) {
extractedTemplate = template;
} else {
extractedTemplate = Templates.combineTemplates(extractedTemplate, template);
}
items.remove(item);
}
}
if (extractedTemplate != null) {
extractedTemplate.setObjects(items);
}
return extractedTemplate;
}
use of io.fabric8.openshift.api.model.Template in project fabric8-maven-plugin by fabric8io.
the class ResourceMojo method createTemplateWithObjects.
private static Template createTemplateWithObjects(KubernetesList kubernetesResources, Template template) {
List<io.fabric8.openshift.api.model.Parameter> parameters = template.getParameters();
List<HasMetadata> items = kubernetesResources.getItems();
Template tempTemplate = null;
if (parameters != null && parameters.size() > 0 && items != null && items.size() > 0) {
tempTemplate = new Template();
tempTemplate.setMetadata(template.getMetadata());
tempTemplate.setParameters(parameters);
tempTemplate.setObjects(items);
}
return tempTemplate;
}
Aggregations