Skip to content

Commit

Permalink
Add CRDs reflecting kuttl configuration files to provide coding assis…
Browse files Browse the repository at this point in the history
…tance in IDEs (#376)

Fixes #372

Signed-off-by: Guillaume Berche <guillaume.berche@orange.com>
  • Loading branch information
gberche-orange authored Aug 26, 2022
1 parent 5f709d5 commit e37b284
Show file tree
Hide file tree
Showing 7 changed files with 464 additions and 0 deletions.
19 changes: 19 additions & 0 deletions crds/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
This directory contains CRD files for the kuttl configuration files.

## Use of CRD files for kuttl

While there is no currently available K8S controller to handle the kuttl configuration files,
the CRD definitions may be handy for kuttl users to leverage coding assistance for K8S CRs in
their favorite IDE.

For intellij IDEA, refer to https://www.jetbrains.com/help/idea/kubernetes.html#crd for instructions
on how to load the CRD files either from:
- a local clone on your desktop
- remote github raw url pointing to the kuttl repository
- from a K8S cluster where you'd register the CRDs (by running `kubectl apply -f <crd_file.yaml>`

## Maintaining CRD files

In order to leverage IDE supports for Json schema, the json schema were extracted into distinct files and manually inlined into the CRD files.

Future possible automated include use of [carvel ytt](https://carvel.dev/ytt/), see sample usage at https://github.com/crossplane/crossplane/issues/3197#issuecomment-1191479570
7 changes: 7 additions & 0 deletions crds/testassert-json-schema.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
description: The TestAssert object can be used to specify settings for a test step's assert and must be specified in the test step's assert YAML.
type: object
properties:
timeout:
description: Number of seconds that the test is allowed to run for
type: integer
default: 30
23 changes: 23 additions & 0 deletions crds/testassert_crd.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
name: testasserts.kuttl.dev
spec:
group: kuttl.dev
names:
kind: TestAssert
plural: testasserts
scope: Namespaced
versions:
- name: v1beta1
served: true # served as to allow IDEs to remotely load them and offer coding assistance
storage: true
schema:
openAPIV3Schema: #! inlined from teststep-json-schema.yaml where authoring is made easier. See https://github.com/crossplane/crossplane/issues/3197#issuecomment-1191479570 for details
description: The TestAssert object can be used to specify settings for a test step's assert and must be specified in the test step's assert YAML.
type: object
properties:
timeout:
description: Number of seconds that the test is allowed to run for
type: integer
default: 30
73 changes: 73 additions & 0 deletions crds/teststep-json-schema.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
description: The TestStep object can be used to specify settings for a test step and can be specified in any test step YAML
type: object
properties:
delete:
description: |
A list of objects to delete, if they do not already exist, at the beginning of the test step.
The test harness will wait for the objects to be successfully deleted before applying the objects in the step.
type: array
items:
type: object
apiVersion:
type: string
description: The Kubernetes API version of the objects to delete.
kind:
description: The Kubernetes kind of the objects to delete.
type: string
name:
description: |
If specified, the name of the object to delete.
If not specified, all objects that match the specified labels will be deleted.
type: string
namespace:
description: The namespace of the objects to delete.
type: string
labels:
description: |
If specified, a label selector to use when looking up objects to delete.
If both labels and name are unspecified, then all resources of the specified kind in the namespace will be deleted.
type: object



index:
description: Override the test step's index.
type: integer
commands:
description: Commands to run prior at the beginning of the test step.
type: array
items:
description: The Command object is used to enable running commands in tests
type: object
properties:
command:
description: The command and argument to run as a string.
type: string
script:
description: |
Allows a shell script to run
- namespaced and command should not be used with script.
- namespaced is ignored and command is an error.
- env expansion is depended upon the shell but ENV is passed to the runtime env.
type: string
namespaced:
description: |
If set, the --namespace flag will be appended to the command with the namespace to use
(the test namespace for a test step or "default" for the test suite).
type: boolean
ignoreFailure:
description: If set, failures will be ignored.
type: boolean
background:
description: |
If this command is to be started in the background.
These are only support in TestSuites.
type: boolean
skipLogOutput:
description: |
If set, the output from the command is not logged.
Useful for sensitive logs or to reduce noise.
type: boolean
timeout:
description: Override the TestSuite timeout for this command (in seconds).
type: integer
86 changes: 86 additions & 0 deletions crds/teststep_crd.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
name: teststeps.kuttl.dev
spec:
group: kuttl.dev
names:
kind: TestStep
plural: teststeps
scope: Namespaced
versions:
- name: v1beta1
served: true # served as to allow IDEs to remotely load them and offer coding assistance
storage: true
schema:
openAPIV3Schema: #! inlined from teststep-json-schema.yaml where authoring is made easier. See https://github.com/crossplane/crossplane/issues/3197#issuecomment-1191479570 for details
description: The TestStep object can be used to specify settings for a test step and can be specified in any test step YAML
type: object
properties:
delete:
description: |
A list of objects to delete, if they do not already exist, at the beginning of the test step.
The test harness will wait for the objects to be successfully deleted before applying the objects in the step.
type: array
items:
type: object
apiVersion:
type: string
description: The Kubernetes API version of the objects to delete.
kind:
description: The Kubernetes kind of the objects to delete.
type: string
name:
description: |
If specified, the name of the object to delete.
If not specified, all objects that match the specified labels will be deleted.
type: string
namespace:
description: The namespace of the objects to delete.
type: string
labels:
description: |
If specified, a label selector to use when looking up objects to delete.
If both labels and name are unspecified, then all resources of the specified kind in the namespace will be deleted.
type: object
index:
description: Override the test step's index.
type: integer
commands:
description: Commands to run prior at the beginning of the test step.
type: array
items:
description: The Command object is used to enable running commands in tests
type: object
properties:
command:
description: The command and argument to run as a string.
type: string
script:
description: |
Allows a shell script to run
- namespaced and command should not be used with script.
- namespaced is ignored and command is an error.
- env expansion is depended upon the shell but ENV is passed to the runtime env.
type: string
namespaced:
description: |
If set, the --namespace flag will be appended to the command with the namespace to use
(the test namespace for a test step or "default" for the test suite).
type: boolean
ignoreFailure:
description: If set, failures will be ignored.
type: boolean
background:
description: |
If this command is to be started in the background.
These are only support in TestSuites.
type: boolean
skipLogOutput:
description: |
If set, the output from the command is not logged.
Useful for sensitive logs or to reduce noise.
type: boolean
timeout:
description: Override the TestSuite timeout for this command (in seconds).
type: integer
120 changes: 120 additions & 0 deletions crds/testsuite-json-schema.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
description: |
The TestSuite object specifies the settings for the entire test suite and should live in the test suite
configuration file (kuttl-test.yaml by default, or --config)
type: object
properties:
crdDir:
description: Path to CRDs to install before running tests. KUTTL waits for CRDs to be available prior to starting tests.
type: string
manifestDirs:
description: Paths to manifests to install before running tests.
type: array
items:
type: string
testDirs:
description: Directories containing test cases to run.
type: array
items:
type: string
startControlPlane:
description: Whether or not to start a local etcd and kubernetes API server for the tests.
type: boolean
default: false
startKIND:
description: Whether or not to start a local kind cluster for the tests.
type: boolean
default: false
kindNodeCache:
description: If set, each node defined in the kind configuration will have a docker volume mounted into it to persist pulled container images across test runs
type: boolean
default: false
kindConfig:
description: Path to the KIND configuration file to use.
type: boolean
kindContext:
description: KIND context to use.
type: string
default: "kind"
skipDelete:
description: If set, do not delete the resources after running the tests (implies SkipClusterDelete).
type: boolean
default: false
skipClusterDelete:
description: If set, do not delete the mocked control plane or kind cluster.
type: boolean
default: false
timeout:
description: Override the default timeout of 30 seconds (in seconds).
type: integer
default: 30
parallel:
description: The maximum number of tests to run at once.
type: integer
default: 8
artifactsDir:
description: The directory to output artifacts to (current working directory if not specified).
type: string
default: "."
commands:
description: Commands to run prior to running the tests.
type: array
items:
description: The Command object is used to enable running commands in tests
type: object
properties:
command:
description: The command and argument to run as a string.
type: string
script:
description: |
Allows a shell script to run
- namespaced and command should not be used with script.
- namespaced is ignored and command is an error.
- env expansion is depended upon the shell but ENV is passed to the runtime env.
type: string
namespaced:
description: |
If set, the --namespace flag will be appended to the command with the namespace to use
(the test namespace for a test step or "default" for the test suite).
type: boolean
ignoreFailure:
description: If set, failures will be ignored.
type: boolean
background:
description: |
If this command is to be started in the background.
These are only support in TestSuites.
type: boolean
skipLogOutput:
description: |
If set, the output from the command is not logged.
Useful for sensitive logs or to reduce noise.
type: boolean
timeout:
description: Override the TestSuite timeout for this command (in seconds).
type: integer
kindContainers:
description: List of Docker images to load into the KIND cluster once it is started.
type: array
items:
type: string
default: []
reportFormat:
description: |
Determines the report format. If empty, no report is generated. One of: JSON, XML.
type: string
reportName:
description: The name of report to create. This field is not used unless reportFormat is set.
default: "kuttl-test"
type: string
namespace:
description: |
The namespace to use for tests. This namespace will be created if it does not exist
and removed if it was created (unless skipDelete is set).
If no namespace is set, one will be auto-generated.
type: string
suppress:
description: Suppresses log collection of the specified types. Currently only events is supported.
type: array
items:
type: string
Loading

0 comments on commit e37b284

Please sign in to comment.