chainsaw icon indicating copy to clipboard operation
chainsaw copied to clipboard

[Feature] Allow overriding yaml files used in the `apply` operation of a test step

Open lantingchiang opened this issue 9 months ago • 3 comments

Problem Statement

If I have a test like the following:

apiVersion: chainsaw.kyverno.io/v1alpha1
kind: Test
metadata:
  name: test-basic-resource-creation-succeeds
spec:
  steps:
    - name: basic-pod-creation-should-succeed
      try:
        - apply:
            file: ../resources-always-pass/pods.yaml
        - assert:
            resource:
              apiVersion: v1
              kind: Pod
              metadata:
                name: basic-pod

where pods.yaml contains a pod manifest with metatdata.namespace specified. I would like to remove the namespace field or override it so that it gets created in the ephemeral namespace that chainsaw creates. The reason why I'm not directly removing metadata.namespace from pods.yaml is because the same manifest is used for other things.

Solution Description

There should be options to override fields from yaml files that are referenced in the apply operation. For example, I should be able to specify

apiVersion: chainsaw.kyverno.io/v1alpha1
kind: Test
metadata:
  name: test-basic-resource-creation-succeeds
spec:
  steps:
    - name: basic-pod-creation-should-succeed
      try:
        - apply:
            file: ../resources-always-pass/pods.yaml
            overrides:
              path: metadata.namespace
              value: ($namespace)
        - assert:
            resource:
              apiVersion: v1
              kind: Pod
              metadata:
                name: basic-pod

to override the key, or

apiVersion: chainsaw.kyverno.io/v1alpha1
kind: Test
metadata:
  name: test-basic-resource-creation-succeeds
spec:
  steps:
    - name: basic-pod-creation-should-succeed
      try:
        - apply:
            file: ../resources-always-pass/pods.yaml
            overrides:
              path: metadata.namespace
              value: null
        - assert:
            resource:
              apiVersion: v1
              kind: Pod
              metadata:
                name: basic-pod

to remove the key

Alternatives

No response

Additional Context

No response

Slack discussion

https://kubernetes.slack.com/archives/C067LUFL43U/p1715011398814629

Research

  • [X] I have read and followed the documentation AND the troubleshooting guide.
  • [X] I have searched other issues in this repository and mine is not recorded.

lantingchiang avatar May 08 '24 13:05 lantingchiang