Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Unreleased
+++++++++++++++++++++++++++++++++++

* New rule set :doc:`rules/dag` to validate DAG templates and their tasks.
* Redesign :doc:`rules/workflow-variable` to improve validation of Argo workflow variable references:
* Redesign :doc:`rules/variable` to improve validation of Argo workflow variable references:

* Rule ``VAR001`` has been renamed to :rule:`var101`.
* Rule ``VAR002`` has been renamed to :rule:`var201`.
Expand Down
2 changes: 1 addition & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,9 @@ For more information on how to use Tugboat, runs its help command:
rules/manifest-errors
rules/step
rules/template
rules/variable
rules/workflow
rules/workflow-template
rules/workflow-variable

.. toctree::
:hidden:
Expand Down
4 changes: 2 additions & 2 deletions docs/rules/dag.rst
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ Code ``DAG`` is used for errors related to the `DAG`_ in a `template`_.
.. rule:: DAG301 Invalid parameter reference

A task input parameter contains a reference that cannot be resolved.
This rule builds on :rule:`VAR002` but narrows the report to the task argument where the typo or mismatch occurs.
This rule builds on :rule:`VAR201` but narrows the report to the task argument where the typo or mismatch occurs.

.. rule:: DAG302 Invalid artifact reference

Expand Down Expand Up @@ -357,7 +357,7 @@ Code ``DAG`` is used for errors related to the `DAG`_ in a `template`_.

.. code-block:: yaml
:caption: ❌ Example manifest that violates this rule
:emphasize-lines: 18
:emphasize-lines: 12

apiVersion: argoproj.io/v1alpha1
kind: Workflow
Expand Down
4 changes: 2 additions & 2 deletions docs/rules/step.rst
Original file line number Diff line number Diff line change
Expand Up @@ -149,14 +149,14 @@ Code ``STP`` is used for errors related to the `steps`_ in a `template`_.

Found invalid parameter reference in the step input parameter.

This rule is a variation of :rule:`VAR002`.
This rule is a variation of :rule:`VAR201`.
It is triggered when a step input parameter references an invalid objective.

.. rule:: STP302 Invalid artifact reference

Found invalid artifact reference in the step input artifact.

This rule is a variation of :rule:`VAR002`.
This rule is a variation of :rule:`VAR201`.
It is triggered when a step input artifact references an invalid objective.

.. code-block:: yaml
Expand Down
2 changes: 1 addition & 1 deletion docs/rules/template.rst
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ Rules

Found invalid parameter reference in the template input parameter.

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

.. code-block:: yaml
Expand Down
2 changes: 1 addition & 1 deletion docs/rules/variable.rst
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ The code ``VAR`` identifies potential issues with `workflow variables`_, includi
When a tag contains only a simple variable name (e.g., ``{{ foo }}``), it is unlikely to be an Argo variable.

.. code-block:: yaml
:emphasize-lines: 14
:emphasize-lines: 11

apiVersion: argoproj.io/v1alpha1
kind: Workflow
Expand Down
74 changes: 0 additions & 74 deletions docs/rules/workflow-variable.rst

This file was deleted.

4 changes: 2 additions & 2 deletions docs/violations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ The comment may include the rule codes (separated by commas) for the violations

The comment should be placed on the same line as the section where the violation occurs, or the parent level of the section.

The following example demonstrates how to ignore :rule:`var002` in the Argo workflow manifest.
The following example demonstrates how to ignore :rule:`var202` in the Argo workflow manifest.
We want to ignore this violation because the template file is intended to be a Jinja template, rather than an Argo tag template.

.. code-block:: yaml
Expand All @@ -47,7 +47,7 @@ We want to ignore this violation because the template file is intended to be a J
- name: template
path: /tmp/template.j2
raw:
data: | # noqa: TPL202; this is a Jinja template
data: | # noqa: VAR202; this is a Jinja template
Hello {{name}}
- name: data
path: /tmp/data.json
Expand Down
51 changes: 25 additions & 26 deletions tests/analyzers/test_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,37 @@


def test_analyze_template(diagnoses_logger):
diagnoses = analyze_yaml_stream(MANIFEST_INVALID_REFERENCE)
diagnoses = analyze_yaml_stream(
"""
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
name: test
spec:
entrypoint: main
templates:
- name: main
script:
image: busybox
source: |
echo "{{ inputs.parameters.foo }}"
resources:
requests:
memory: 100Gi
cpu: "1.5"
limits:
memory: 10Gi
cpu: 1000m
"""
)
diagnoses_logger(diagnoses)

assert (
IsPartialModel(
{
"code": "VAR002",
"code": "VAR201",
"loc": ("spec", "templates", 0, "script", "source"),
"input": "{{ inputs.parameters.foo }}",
"input": "inputs.parameters.foo",
}
)
in diagnoses
Expand Down Expand Up @@ -54,29 +76,6 @@ def test_analyze_template(diagnoses_logger):
)


MANIFEST_INVALID_REFERENCE = """
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
name: test
spec:
entrypoint: main
templates:
- name: main
script:
image: busybox
source: |
echo "{{ inputs.parameters.foo }}"
resources:
requests:
memory: 100Gi
cpu: "1.5"
limits:
memory: 10Gi
cpu: 1000m
"""


def test_check_input_artifacts(diagnoses_logger):
diagnoses = analyze_yaml_stream(MANIFEST_MISSING_INPUT_PATH)
diagnoses_logger(diagnoses)
Expand Down
12 changes: 6 additions & 6 deletions tests/analyzers/test_metrics.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from dirty_equals import IsPartialDict

from tests.dirty_equals import ContainsSubStrings
from tests.dirty_equals import HasSubstring
from tugboat.analyzers.metrics import check_prometheus
from tugboat.references import Context
from tugboat.schemas.metrics import Prometheus
Expand Down Expand Up @@ -46,7 +46,7 @@ def test_invalid_metric_name_1(self):
{
"code": "internal:invalid-metric-name",
"loc": ("name",),
"msg": ContainsSubStrings("Metric name 'test/metric' is invalid."),
"msg": HasSubstring("Metric name 'test/metric' is invalid."),
"input": "test/metric",
}
),
Expand All @@ -70,7 +70,7 @@ def test_invalid_metric_name_2(self):
{
"code": "internal:invalid-metric-name",
"loc": ("name",),
"msg": ContainsSubStrings("Metric name is too long."),
"msg": HasSubstring("Metric name is too long."),
"input": NAME,
}
),
Expand Down Expand Up @@ -98,7 +98,7 @@ def test_invalid_label_names(self):
{
"code": "internal:invalid-metric-label-name",
"loc": ("labels", 0, "key"),
"msg": ContainsSubStrings(
"msg": HasSubstring(
"Label name 'test/label' in metric 'test_metric' is invalid."
),
"input": "test/label",
Expand All @@ -108,7 +108,7 @@ def test_invalid_label_names(self):
{
"code": "internal:invalid-metric-label-name",
"loc": ("labels", 1, "key"),
"msg": ContainsSubStrings(
"msg": HasSubstring(
"Label name '__reserved' in metric 'test_metric' is invalid."
),
"input": "__reserved",
Expand All @@ -118,7 +118,7 @@ def test_invalid_label_names(self):
{
"code": "internal:invalid-metric-label-value",
"loc": ("labels", 2, "value"),
"msg": ContainsSubStrings(
"msg": HasSubstring(
"Label value for label 'valid_label' in metric 'test_metric' is empty."
),
},
Expand Down
35 changes: 17 additions & 18 deletions tests/analyzers/test_step.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,36 +342,35 @@ def test_check_referenced_template(caplog: pytest.LogCaptureFixture, diagnoses_l


def test_check_fields_references(diagnoses_logger):
diagnoses = analyze_yaml_stream(MANIFEST_FIELDS_REFERENCES)
diagnoses = analyze_yaml_stream(
"""
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: exit-handler-step-level-
spec:
entrypoint: main
templates:
- name: main
steps:
- - name: hello
when: "{{ count }} > 0"
template: print-message
"""
)
diagnoses_logger(diagnoses)

assert (
IsPartialModel(
{
"code": "VAR002",
"code": "VAR202",
"loc": ("spec", "templates", 0, "steps", 0, 0, "when"),
}
)
in diagnoses
)


MANIFEST_FIELDS_REFERENCES = """
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: exit-handler-step-level-
spec:
entrypoint: main
templates:
- name: main
steps:
- - name: hello
when: "{{ count }} > 0"
template: print-message
"""


def test_check_inline_template(diagnoses_logger):
diagnoses = analyze_yaml_stream(MANIFEST_INLINE_TEMPLATE)
diagnoses_logger(diagnoses)
Expand Down
Loading