Template Rules (TPL)

Code TPL is used for errors specifically related to the template, the reusable and composable unit of execution in a workflow or workflow template.

Coverage

Argo Workflows offers various types of templates. However, Tugboat currently supports only a few of them:

Rules

TPL101 Duplicate template names

The workflow or workflow template contains multiple templates with the same name.

In the following example, the template hello is duplicated:

apiVersion: argoproj.io/v1alpha1
kind: WorkflowTemplate
metadata:
  name: demo
spec:
  templates:
    - name: hello
      container:
        image: alpine:latest
    - name: hello
      container:
        image: busybox:latest

TPL102 Duplicate input parameter names

The template contains multiple input parameters (<template>.inputs.parameters) with the same name.

apiVersion: argoproj.io/v1alpha1
kind: WorkflowTemplate
metadata:
  name: demo
spec:
  templates:
    - name: main
      inputs:
        parameters:
          - name: data
          - name: data
      ...

TPL103 Duplicate input artifact names

The template contains multiple input artifacts (<template>.inputs.artifacts) with the same name.

apiVersion: argoproj.io/v1alpha1
kind: WorkflowTemplate
metadata:
  name: demo
spec:
  templates:
    - name: main
      inputs:
        artifacts:
          - name: data
            path: /data/foo
          - name: data
            path: /data/bar
      ...

TPL104 Duplicate output parameter names

The template contains multiple output parameters (<template>.outputs.parameters) with the same name.

apiVersion: argoproj.io/v1alpha1
kind: WorkflowTemplate
metadata:
  name: demo
spec:
  templates:
     - name: main
       ...
       outputs:
         parameters:
           - name: message
             valueFrom:
               path: /tmp/message.txt
           - name: message
             valueFrom:
               path: /tmp/msg.txt

TPL105 Duplicate output artifact names

The template contains multiple output artifacts (<template>.outputs.artifacts) with the same name.

apiVersion: argoproj.io/v1alpha1
kind: WorkflowTemplate
metadata:
  name: demo
spec:
  templates:
     - name: main
       ...
       outputs:
         artifacts:
           - name: data
             path: /data/foo
           - name: data
             path: /data/bar

TPL201 Invalid parameter reference

Found invalid parameter reference in the template input parameter.

This rule is a variation of VAR002 Misused reference. It is triggered when a template input parameter references an invalid objective:

apiVersion: argoproj.io/v1alpha1
kind: WorkflowTemplate
metadata:
  name: demo
spec:
  templates:
    - name: main
      inputs:
        parameters:
          - name: data
            value: "{{ inputs.parameters.invalid }}"

TPL202 Improper use of raw artifact field

This rule is triggered when a raw artifact in the input arguments references something other than a parameter. Raw artifacts are designed to accept only parameter references, but users often mistakenly try to reference artifacts in this field.

The purpose of this rule is to identify such cases where artifacts are incorrectly referenced. However, it is important to note that this rule is not limited to detecting artifact references - it also flags other types of invalid references that do not conform to the expected parameter format.

For example, the following code demonstrates a scenario where this rule would be triggered:

apiVersion: argoproj.io/v1alpha1
kind: WorkflowTemplate
metadata:
  name: demo
spec:
  templates:
    - name: main
      inputs:
        artifacts:
          - name: data
            raw:
              data: |-
                {{ inputs.artifacts.any }}

TPL301 Invalid metric name

This rule is triggered when a metric name in a template is invalid.

Argo Workflows provides metrics in both Prometheus and OpenTelemetry formats. As a result, it must comply with the naming rules of both formats. This means metric names must begin with a letter and can only contain letters, numbers, and underscores (_).

apiVersion: argoproj.io/v1alpha1
kind: WorkflowTemplate
metadata:
  name: demo
spec:
  templates:
    - name: main
      container:
        image: alpine:latest
        command: ["true"]
      metrics:
        prometheus:
          - name: invalid-metric-name
            help: This is an invalid metric name
            counter:
              value: "1"

TPL302 Invalid metric label name

This rule is triggered when a metric label name in a template is invalid.

Prometheus label names must start with an alphabetic character and can only contain alphanumeric characters and underscores (_).

apiVersion: argoproj.io/v1alpha1
kind: WorkflowTemplate
metadata:
  name: demo
spec:
  templates:
    - name: main
      container:
        image: alpine:latest
        command: ["true"]
      metrics:
        prometheus:
          - name: demo_count
            help: This is an invalid metric name
            labels:
              - key: invalid-label-name
                value: demo_value
            counter:
              value: "1"

TPL303 Redundant metric label

Prometheus metric labels with an empty value are treated the same as labels that are not defined. This rule is triggered when a metric label in a template has an empty value.

apiVersion: argoproj.io/v1alpha1
kind: WorkflowTemplate
metadata:
  name: demo
spec:
  templates:
    - name: main
      container:
        image: alpine:latest
        command: ["true"]
      metrics:
        prometheus:
          - name: demo_count
            help: This is an invalid metric name
            labels:
              - key: demo_label
                value: ""
            counter:
              value: "1"

TPL304 Request resource exceeds the limit

This rule is triggered when a template’s requests for resources (e.g., memory or CPU) are greater than the corresponding resource limits.

The rule checks the resource requests in the template and compares them against the value from limits defined in the same template. If the requested resources exceed the defined limits, this rule is triggered.

apiVersion: argoproj.io/v1alpha1
kind: WorkflowTemplate
metadata:
  name: demo
spec:
  templates:
    - name: main
      container:
        image: alpine:latest
        resources:
          requests:
            memory: 100Gi
            cpu: "1.5"
          limits:
            memory: 10Gi
            cpu: 1000m