Search in sources :

Example 16 with Template

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();
}
Also used : ReplicaSetSpec(io.fabric8.kubernetes.api.model.extensions.ReplicaSetSpec) LabelSelector(io.fabric8.kubernetes.api.model.LabelSelector) ReplicaSet(io.fabric8.kubernetes.api.model.extensions.ReplicaSet)

Example 17 with Template

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;
}
Also used : HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) ArrayList(java.util.ArrayList) File(java.io.File) Template(io.fabric8.openshift.api.model.Template)

Example 18 with Template

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()));
        }
    }
}
Also used : TreeSet(java.util.TreeSet) Parameter(org.apache.maven.plugins.annotations.Parameter) KubernetesHelper.createIntOrString(io.fabric8.kubernetes.api.KubernetesHelper.createIntOrString) Properties(java.util.Properties)

Example 19 with Template

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;
}
Also used : ArrayList(java.util.ArrayList) Template(io.fabric8.openshift.api.model.Template)

Example 20 with Template

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;
}
Also used : Parameter(org.apache.maven.plugins.annotations.Parameter) 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