Skip to content

Create

The create operation lets you define resources that should be created in the Kubernetes cluster during the test step. These can be configurations, deployments, services, or any other Kubernetes resource.

Warning

If the resource to be created already exists in the cluster, the step will fail.

Reference documentation

The full structure of the Create is documented here.

Usage in Test

Below is an example of using create in a Test resource.

Using a file

apiVersion: chainsaw.kyverno.io/v1alpha1
kind: Test
metadata:
  name: example
spec:
  steps:
  - try:
    # ...
    - create:
        file: my-configmap.yaml
    # ...

Using an URL

```yaml apiVersion: chainsaw.kyverno.io/v1alpha1 kind: Test metadata: name: example spec: steps: - try: # ... - create: file: https://raw.githubusercontent.com/kyverno/chainsaw/main/testdata/resource/valid.yaml # ...

Using an inline resource

apiVersion: chainsaw.kyverno.io/v1alpha1
kind: Test
metadata:
  name: example
spec:
  steps:
  - try:
    # ...
    - create:
        resource:
          apiVersion: v1
          kind: ConfigMap
          metadata:
            name: chainsaw-quick-start
          data:
            foo: bar
    # ...

Usage in TestStep

Below is an example of using create in a TestStep resource.

Using a file

apiVersion: chainsaw.kyverno.io/v1alpha1
kind: TestStep
metadata:
  name: example
spec:
  try:
  # ...
  - create:
      file: my-configmap.yaml
  # ...

Using an URL

apiVersion: chainsaw.kyverno.io/v1alpha1
kind: TestStep
metadata:
  name: example
spec:
  try:
  # ...
  - create:
      file: https://raw.githubusercontent.com/kyverno/chainsaw/main/testdata/resource/valid.yaml
  # ...

Using an inline resource

apiVersion: chainsaw.kyverno.io/v1alpha1
kind: TestStep
metadata:
  name: example
spec:
  try:
  # ...
  - create:
      resource:
        apiVersion: v1
        kind: ConfigMap
        metadata:
          name: chainsaw-quick-start
        data:
          foo: bar
  # ...

Operation check

Below is an example of using an operation check.

With check

# ...
- apply:
    file: my-configmap.yaml
    expect:
    - match:
        # this check applies only if the match
        # statement below evaluates to `true`
        apiVersion: v1
        kind: ConfigMap
      check:
        # an error is expected, this will:
        # - succeed if the operation failed
        # - fail if the operation succeeded
        ($error != null): true
# ...

With check

# ...
- apply:
    resource:
      apiVersion: v1
      kind: ConfigMap
      metadata:
        name: chainsaw-quick-start
      data:
        foo: bar
    expect:
    - match:
        # this check applies only if the match
        # statement below evaluates to `true`
        apiVersion: v1
        kind: ConfigMap
      check:
        # an error is expected, this will:
        # - succeed if the operation failed
        # - fail if the operation succeeded
        ($error != null): true
# ...