Skip to content

Get

The get collector is used to list and print resources in the cluster.

Configuration

The full structure of the Get resource is documented here.

Single resource

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

Get pod in the test namespace

apiVersion: chainsaw.kyverno.io/v1alpha1
kind: Test
metadata:
  name: example
spec:
  steps:
  - try:
    # ...
    catch:
    - get:
        resource: pods
        name: my-pod
    # ...
    finally:
    - get:
        resource: pods
        name: my-pod
    # ...

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

Collect pod in a specific namespace

apiVersion: chainsaw.kyverno.io/v1alpha1
kind: Test
metadata:
  name: example
spec:
  steps:
  - try:
    # ...
    catch:
    - get:
        resource: pods
        name: my-pod
        namespace: foo
    # ...
    finally:
    - get:
        resource: pods
        name: my-pod
        namespace: foo
    # ...

All resources

If no name and namespace are specified, Chainsaw will retrieve all resources in the test namespace.

Collect all resources in the test namespace

apiVersion: chainsaw.kyverno.io/v1alpha1
kind: Test
metadata:
  name: example
spec:
  steps:
  - try:
    # ...
    catch:
    - get:
        resource: pods
    # ...
    finally:
    - get:
        resource: pods
    # ...

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

Collect all resources in a specific namespace

apiVersion: chainsaw.kyverno.io/v1alpha1
kind: Test
metadata:
  name: example
spec:
  steps:
  - try:
    # ...
    catch:
    - get:
        resource: pods
        namespace: foo
    # ...
    finally:
    - get:
        resource: pods
        namespace: foo
    # ...

Label selector

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

Collect resources using a label selector in the test namespace

apiVersion: chainsaw.kyverno.io/v1alpha1
kind: Test
metadata:
  name: example
spec:
  steps:
  - try:
    # ...
    catch:
    - get:
        resource: pods
        selector: app=my-app
    # ...
    finally:
    - get:
        resource: pods
        selector: app=my-app
    # ...

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

Collect resources using a label selector in a specific namespace

apiVersion: chainsaw.kyverno.io/v1alpha1
kind: Test
metadata:
  name: example
spec:
  steps:
  - try:
    # ...
    catch:
    - get:
        resource: pods
        selector: app=my-app
        namespace: foo
    # ...
    finally:
    - get:
        resource: pods
        selector: app=my-app
        namespace: foo
    # ...

Format

An optional format can be specified. Supported formats are json and yaml.

If format is not specified, results will be returned in text format.

Use json format

apiVersion: chainsaw.kyverno.io/v1alpha1
kind: Test
metadata:
  name: example
spec:
  steps:
  - try:
    # ...
    catch:
    - get:
        resource: pods
        format: json
    # ...
    finally:
    - get:
        resource: pods
        format: json
    # ...

Use yaml format

apiVersion: chainsaw.kyverno.io/v1alpha1
kind: Test
metadata:
  name: example
spec:
  steps:
  - try:
    # ...
    catch:
    - get:
        resource: pods
        format: yaml
    # ...
    finally:
    - get:
        resource: pods
        format: yaml
    # ...