Skip to content

Events

Collecting namespace events can help understand what happened inside the cluster.

Configuration

The full structure of the Events resource is documented here.

Single event

If a name is specified, Chainsaw will retrieve the specified event in the test namespace.

Collect event in the test namespace

apiVersion: chainsaw.kyverno.io/v1alpha1
kind: Test
metadata:
  name: example
spec:
  steps:
  - try:
    - apply:
        file: my-pod.yaml
    - assert:
        file: my-pod-assert.yaml
    catch:
    - events:
        name: my-event

If a namespace is specified, Chainsaw will retrieve the specified event in the specified namespace.

Collect event in the test namespace

apiVersion: chainsaw.kyverno.io/v1alpha1
kind: Test
metadata:
  name: example
spec:
  steps:
  - try:
    - apply:
        file: my-pod.yaml
    - assert:
        file: my-pod-assert.yaml
    catch:
    - events:
        name: my-event
        namespace: foo

All events

If no name and namespace is specified, Chainsaw will retrieve all events in the test namespace.

Collect all events in the test namespace

apiVersion: chainsaw.kyverno.io/v1alpha1
kind: Test
metadata:
  name: example
spec:
  steps:
  - try:
    - apply:
        file: my-pod.yaml
    - assert:
        file: my-pod-assert.yaml
    catch:
    - events: {}

On the other hand, if a namespace is specified, Chainsaw will retrieve all events in the specified namespace.

Collect all events in a specific namespace

apiVersion: chainsaw.kyverno.io/v1alpha1
kind: Test
metadata:
  name: example
spec:
  steps:
  - try:
    - apply:
        file: my-pod.yaml
    - assert:
        file: my-pod-assert.yaml
    catch:
    - events:
        namespace: foo

Label selector

An optional label selector can be configured to refine the events to be retrieved.

Collect events using a label selector in the test namespace

apiVersion: chainsaw.kyverno.io/v1alpha1
kind: Test
metadata:
  name: example
spec:
  steps:
  - try:
    - apply:
        file: my-pod.yaml
    - assert:
        file: my-pod-assert.yaml
    catch:
    - events:
        selector: app=my-app

If a namespace is specified, Chainsaw will retrieve events using the specified namespace.

Collect events using a label selector in a specific namespace

apiVersion: chainsaw.kyverno.io/v1alpha1
kind: Test
metadata:
  name: example
spec:
  steps:
  - try:
    - apply:
        file: my-pod.yaml
    - assert:
        file: my-pod-assert.yaml
    catch:
    - events:
        selector: app=my-app
        namespace: foo