Skip to content

Delete

The delete operation defines resources that should be deleted from a Kubernetes cluster.

Warning

The propagation policy is forced to Background because some types default to Orphan (this is the case for unmanaged jobs for example) and we don't want to let dangling pods run in the cluster after cleanup.

Configuration

The full structure of Delete is documented here.

Features

Supported features
Bindings support ✅
Outputs support ❌
Templating support ✅
Operation checks support ✅

Propagation policy

The deletion propagation policy can be overriden for the specific operation using the deletionPropagationPolicy field.

When the deletionPropagationPolicy is not specified it is inherited from the configuration, test, or test step.

Look at the configuration section for details about supported values and how this affects execution.

Examples

apiVersion: chainsaw.kyverno.io/v1alpha1
kind: Test
metadata:
  name: example
spec:
  steps:
  - try:
    - delete:
        # specify reference inline
        ref:
          apiVersion: v1
          kind: Pod
          namespace: default
          name: my-test-pod
---
apiVersion: chainsaw.kyverno.io/v1alpha1
kind: Test
metadata:
  name: example
spec:
  steps:
  - try:
    - delete:
        # use a file
        file: my-configmap.yaml

Operation check

apiVersion: chainsaw.kyverno.io/v1alpha1
kind: Test
metadata:
  name: example
spec:
  steps:
  - try:
    - delete:
        ref:
          apiVersion: v1
          kind: Pod
          namespace: default
          name: my-test-pod
        expect:
        - match:
            # this check applies only if the match
            # statement below evaluates to `true`
            apiVersion: v1
            kind: Pod
            metadata:
              namespace: default
              name: my-test-pod
          check:
            # an error is expected, this will:
            # - succeed if the operation failed
            # - fail if the operation succeeded
            ($error != null): true