kyverno / chainsaw

Declarative K8s e2e testing
https://kyverno.github.io/chainsaw/
Apache License 2.0
269 stars 41 forks source link

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

Open lantingchiang opened 4 months ago

lantingchiang commented 4 months ago

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

welcome[bot] commented 4 months ago

Thanks for opening your first issue here! Be sure to follow the issue template!

chipzoller commented 4 months ago

Transferred to Chainsaw, not a Kyverno core issue.

eddycharly commented 4 months ago

Thanks for reporting, we could do something specific to override the namespace but a generic solution would be better 🤔