Search in sources :

Example 1 with Parameter

use of org.apache.maven.plugins.annotations.Parameter 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 2 with Parameter

use of org.apache.maven.plugins.annotations.Parameter in project fabric8-maven-plugin by fabric8io.

the class HelmMojo method createTemplateParameters.

private void createTemplateParameters(File outputDir, Template template, File templatesDir) throws MojoExecutionException {
    JsonNodeFactory nodeFactory = JsonNodeFactory.instance;
    ObjectNode values = nodeFactory.objectNode();
    List<io.fabric8.openshift.api.model.Parameter> parameters = template.getParameters();
    if (parameters == null || parameters.isEmpty()) {
        return;
    }
    List<HelmParameter> helmParameters = new ArrayList<>();
    for (io.fabric8.openshift.api.model.Parameter parameter : parameters) {
        HelmParameter helmParameter = new HelmParameter(parameter);
        helmParameter.addToValue(values);
        helmParameters.add(helmParameter);
    }
    File outputChartFile = new File(outputDir, "values.yaml");
    try {
        saveYaml(values, outputChartFile);
    } catch (IOException e) {
        throw new MojoExecutionException("Failed to save chart values " + outputChartFile + ": " + e, e);
    }
    // now lets replace all the parameter expressions in each template
    File[] files = templatesDir.listFiles();
    if (files != null) {
        for (File file : files) {
            if (file.isFile()) {
                String extension = Files.getExtension(file.getName()).toLowerCase();
                if (extension.equals("yaml") || extension.equals("yml")) {
                    convertTemplateParameterExpressionsWithHelmExpressions(file, helmParameters);
                }
            }
        }
    }
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ArrayList(java.util.ArrayList) IOException(java.io.IOException) JsonNodeFactory(com.fasterxml.jackson.databind.node.JsonNodeFactory) Parameter(org.apache.maven.plugins.annotations.Parameter) File(java.io.File)

Aggregations

Parameter (org.apache.maven.plugins.annotations.Parameter)2 JsonNodeFactory (com.fasterxml.jackson.databind.node.JsonNodeFactory)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 KubernetesHelper.createIntOrString (io.fabric8.kubernetes.api.KubernetesHelper.createIntOrString)1 File (java.io.File)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Properties (java.util.Properties)1 TreeSet (java.util.TreeSet)1 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)1