This is the multi-page printable view of this section. Click here to print.

Return to the regular view of this page.

targets

Required, defines targets for this kluctl project.

Specifies a list of targets for which commands can be invoked. A target puts together environment/target specific configuration and the target cluster. Multiple targets can exist which target the same cluster but with differing configuration (via args).

Each value found in the target definition is rendered with a simple Jinja2 context that only contains the target itself. The rendering process is retried 10 times until it finally succeeds, allowing you to reference the target itself in complex ways. This is especially useful when using dynamic targets .

Target entries have the following form:

targets:
...
  - name: <target_name>
    context: <context_name>
    args:
      arg1: <value1>
      arg2: <value2>
      ...
    images:
      - image: my-image
        resultImage: my-image:1.2.3
...

The following fields are allowed per target:

name

This field specifies the name of the target. The name must be unique. It is referred in all commands via the -t option.

context

This field specifies the kubectl context of the target cluster. The context must exist in the currently active kubeconfig. If this field is omitted, Kluctl will always use the currently active context.

args

This fields specifies a map of arguments to be passed to the deployment project when it is rendered. Allowed argument names are configured via deployment args .

The arguments specified in the dynamic target config have higher priority.

images

This field specifies a list of fixed images to be used by images.get_image(...) . The format is identical to the fixed images file .

The fixed images specified in the dynamic target config have higher priority.

1 - Dynamic Targets

Dynamically defined targets.

Targets can also be “dynamic”, meaning that additional configuration can be sourced from another git repository. This can be based on a single target repository and branch, or on a target repository and branch/ref pattern, resulting in multiple dynamic targets being created from one target definition.

Please note that a single entry in target might end up with multiple dynamic targets, meaning that the name must be made unique between these dynamic targets. This can be achieved by using templating in the name field. As an example, {{ target.targetConfig.ref }} can be used to set the target name to the branch name of the dynamic target.

Dynamic targets have the following form:

targets:
...
  - name: <dynamic_target_name>
    context: <cluster_name>
    args: ...
      arg1: <value1>
      arg2: <value2>
      ...
    targetConfig:
      project:
        url: <git-url>
      ref: <ref-name>
      refPattern: <regex-pattern>
      file: <config-file>
...

All fields known from normal targets are allowed. In addition, the targetConfig with following fields is available.

targetConfig

The presence of this field causes the target to become a dynamic target. It specifies where to look for dynamic targets and their addional configuration. It has the following form:

...
targets:
...
- name: <dynamic_target_name>
  ...
  targetConfig:
    project:
      url: <git-url>
    ref: <ref-name>
    refPattern: <regex-pattern>
...

project.url

This field specifies the git clone url of the target configuration project.

ref

This field specifies the branch or tag to use. If this field is specified, using refPattern is forbidden. This will result in one single dynamic target.

refPattern

This field specifies a regex pattern to use when looking for candidate branches and tags. If this is specified, using ref is forbidden. This will result in multiple dynamic targets. Each dynamic target will have ref set to the actual branch name it belong to. This allows using of {{ target.targetConfig.ref }} in all other target fields.

file

This field specifies the config file name to read externalized target config from.

Format of the target config

The target config file referenced in targetConfig must be of the following format:

args:
  arg1: value1
  arg2: value2
images:
  - image: registry.gitlab.com/my-group/my-project
    resultImage: registry.gitlab.com/my-group/my-project:1.1.0

args

An optional map of arguments, in the same format as in the normal target args .

The arguments specified here have higher priority.

images

An optional list of fixed images, in the same format as in the normal target images

Simple dynamic targets

A simplified form of dynamic targets is to store target config inside the same directory/project as the .kluctl.yaml. This can be done by omitting project, ref and refPattern from targetConfig and only specify file.