tempalte-1.4.0

KOSI Plugin template Version 1.4.0

Summary

By giving a template name and a saveTo-fileName we can read the corresponding template and save the generated file from the template engine to the process folder with the value of target.

Keys

target

The target file, where the the results of the templating will be written into.

Example template for using KOSI globals:

api: {{package.apiversion}}
package:
  name: {{package.name}}
  package: {{package.version}}
  file: {{package.includes.files.input}}
  container-registry: {{package.includes.containers.registry.image}}
values:
  values-ip0: {{values.ipNormal}}
  values-ip1: {{values.IPList[0]}}

tmpl

The tmpl key refers to the template .yaml file, which requests values from other files uses the templating.

Example

install
{
    template(tmpl='"template.yaml"'; target='"result.yaml"');
}

How to use the template engine

This template is based on scriban. (Click here for a Demo)

When you use kosi install -f…

kosi install -f uservalues.yaml

…the content of the stated yaml files will be written into the mergeduservalues.yaml. For the mergeduervalues.yaml the keyword is values, which references the content of the mergeduservalues.yaml.

Example for mergeduservalues.yaml:

IPList:
  - ip1: 127.0.0.1
  - ip2: 192.128.16.1
  - ip3: 192.128.18.14
ipNormal: 12.10.45.23

The template plugin can be used to read the content from the package.yaml and the mergeduservalues.yaml and write the requested values from the template.yaml into the file which is stated in the target parameter.

You can use a point structure to use values of keys in the yaml files.
The keyword for the package.yaml is package.

Example of a package.kosi:

languageversion = "0.1.0";
apiversion = "kubernative/kubeops/kosi/user/v3";
name = "kosi-example-packagev3";
description = "kosi-example-package";
version = "0.1.0";
docs = "docs.tgz";
logo = "logo.png";

files =
{
  input="template.yaml";
}

containers =
{
    example=["docker.io", "nginx", "latest"];
}

install
{
    template(tmpl='"template.yaml"'; target='"result.yaml"');
}

The target path can also be an absolute path, for example /user/target.yaml.

So for example when you want the value of the name element in the package.yaml, you have to use package.name in the template.yaml.

name: {{package.name}}

The key can have any name.

It is important to know that you have to use the root element for navigating through the elements of a .yaml file. So for example the input-element in the package.yaml is accessible with package.includes.files.input, because the input-element is a subelement of the files-Tree in the includes-tree. Because the template.yaml is a yaml file, you have to use a key value structure, without the key-value structure the template engine cannot read the template.yaml.

Example for reading the value of input:

input_file: {{package.includes.files.input}}