Code Monkey home page Code Monkey logo

kuttl's Introduction

KUTTL

lint unit test integration-test Go Report Card

KUbernetes Test TooL (KUTTL) provides a declarative approach to test Kubernetes Operators.

KUTTL is designed for testing operators, however it can declaratively test any kubernetes objects.

Getting Started

Please refer to the getting started guide documentation.

Resources

Initially Built under the KUDO project, we continue to use that channel for KUTTL.

Community Meetings

We have open community meetings every 2nd and 4th Wednesday of the month at 9:00 a.m. PST. (17:00 UTC)

Community, Events, Discussion, Contribution, and Support

Learn more on how to engage with the KUDO community on the community page.

Contributions

Please read the contributing guide for details around:

  1. Code of Conduct
  2. Code Culture
  3. Details on how to contribute

kuttl's People

Contributors

alenkacz avatar alifelan avatar aneumann82 avatar chhsia0 avatar croomes avatar davidebianchi avatar dependabot[bot] avatar eddycharly avatar erikgb avatar estroz avatar evenh avatar fhopfensperger avatar gberche-orange avatar gerred avatar haoxins avatar iblancasa avatar imusmanmalik avatar jbarrick-mesosphere avatar jlpedrosa avatar joejulian avatar jtucci avatar kensipe avatar nfnt avatar peres-richard avatar porridge avatar r3drun3 avatar redradrat avatar rishinair11 avatar takirala avatar zmalik avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

kuttl's Issues

Wait for default service account to exist in namespace before running test steps

What happened:

There is a race condition when creating namespaces in Kubernetes that if you create a Pod in the namespace before the ServiceAccount exists, it will fail.

We should resolve this for the tests by waiting for the default ServiceAccount to exist in created namespaces before continuing on to the test steps to prevent errors like:

            case.go:102: pods "influxdb-querier" is forbidden: error looking up service account kudo-test-lenient-lab/default: serviceaccount "default" not found

KUTTL CLI?

Should we have a kuttl plugin? seems useful.

KEP05: Pull Test-Tools into KUTTL

According to KEP-05:

Additionally, Operator-specific helper methods will be provided in the library that can be used by library users.

We will also endeavor to stay close to the API used by the kudo-cassandra-operator testing library to ensure that migration of existing tests is easy.

KEP05: CMD Utilities

According to KEP-05:

The cmd package should provide conveniences for running arbitrary commands (i.e. shelling out) from Go code in integration tests.

Current functionality:

  • Providing an Exec function that returns exit status, stdout and stderr
package cmd
func Exec(
  command string,
  arguments []string,
  environmentVariables map[string]string,
) (
  exitStatus int,
  stdout *bytes.Buffer,
  stderr *bytes.Buffer,
  error error,
)

CI and Test Infra

[ ] go run cmd/kubectl-kuttl/main.go test pkg/test/test_data/
[] CI setup to run tests and ^^ tests
[] update makefile for tests and integration-test
[] circle ci
[] goreleaser release
[] .git support for templates and PR defaults

test step - pod log output via API

this is a feature request, for the kuttl API to provide a means to obtain the Pod log when a test step executes a Pod, the API would let you get back the Pod log via the API call to execute a Test Step.

Our use case includes running custom container images within a Test Step, those images will need to produce log output in a particular format (e.g. v1alpha2 in our case), then we can aggregate or do other processing on the test log output, our test logs from the pods will show various kinds of feedback useful for the end-user (e.g. suggestions or error descriptions).

Command Retry

It would be worth added a retry to commands... this would retry to the command upon failure. Controls might include:

  • number of retries
  • amount of time to retry
  • timeout for retry
  • freq of retries

KUTTL CLI Should work without a TestSuite File

The CLI should function without a kuttl-test.yaml as long as all required details are provided

for instance k kuttl test --start-control-plane pkg/test/test_data/ should run without a file

Background Process Readiness Probe

When the BG process is started KUTTL moves forward with other commands (and tests).. however the commands could need the BG process to be ready to success. We do want to the process in the background however we need to know when it is live.

An example use case:

commands:
  - command: ./bin/kubectl-kudo init --crd-only	  - command: ./bin/kubectl-kudo init --crd-only
  - command: ./bin/manager
    background: true
  - command: ./bin/kubectl-kudo install --skip-instance ./repository/cassandra/3.11/operator/	  

The kudo install command will fail if manager isn't ready. We need manager to be "ready" before the install command.

KUDO Operator testing library

There should be a shared testing library that provides all necessary facilities for complex KUDO-based operators to have extensive and thorough integration tests.

Take a look at the kudo-cassandra-operator testing facilities to get a better understanding to how this differs from the current KUDO test harness, and provides functionality that is still not clear how to implement in the KUDO test harness, including a single verbose and useful test run output, useful for development and CI.

There's a private protokep for this in Google Drive.

KEP05: kubectl support

According to KEP-05:

The kubectl package should provide conveniences for interacting with a Kubernetes cluster as one would do via kubectl from the shell.

package kubectl
func Exec(
  namespaceName string,
  containerName string,
  command string,
  argvuments []string,
  environmentVariables map[string]string,
) error

Kill of Background Processes Failing

The newly added technique to start a background process is working in testing but leaves the process running after exit. It isn't clear yet why... theories:

  1. the process exits too quickly for the kill to take place
  2. the process is a grandchild (not a child) which go doesn't kill (frankly we may need to support killing all child and grandchild processes anyway.

for ref: https://medium.com/@felixge/killing-a-child-process-and-all-of-its-children-in-go-54079af94773

Extended Assert Capabilities

Asserts today are easy for YAML or K8s objects... however there are users wanting to do a regex match against pod logs. Is there a way to make this easier?

or at a min, allow a command used for assertion that can be repeat for each test.

perhaps there is something more here... pull and logging a pod log to test might be useful.

KUTTL Shouldn't Panic for Bad TestSuite File

for a bad kuttl-test.yaml for with kuttl v0.1.0 the kuttl cli panics... please don't

to duplicate... change apiVersion: kudo.dev/v1beta1 to apiVersion: kuttl.dev/v1beta1

we should probably also switch to kuttl.dev

Add "script" setting to commands that runs as a bash script

We should add a new setting to the commands struct called script that accepts a bash script as a string that we run. When running the script, we can set the $NAMESPACE and $KUBECONFIG variables. This will allow users to more easily write scripts inline when necessary.

apiVersion: kudo.dev/v1alpha1
kind: TestStep
commands:
- script: until ! kubectl get pod --namespace $NAMESPACE my-pod; do sleep 1; done

Fix Readme Doc

We need a contribs doc...

in it we need to make sure devs are aware that we are dependent on kubebuilder... along with other dependents and requirements to get started.

Test harness should support asserting that a specific number of a resource exist when listing

What would you like to be added:

In the test harness, you can match objects without specifying a name, for example:

apiVersion: v1
kind: Pod
metadata:
  labels:
    app: nginx
status:
  state: READY

It should be possible to specify how many objects match.

Why is this needed:

This can be used to verify that a certain number of pods are ready or a certain number of plan executions exist.

Easy way to Repeat Asserts for Each Test

Need a way to define an assertion that is true for every test in the testsuite

we will need to be clear if this is every teststep or every test... perhaps configurable.

User should be able to define a yaml assertion that is tested for each test and not need to repeat that for every test configuration. This is part of the spirit of the composability KEP.

Command Aliases

Perhaps it could be useful to define command aliases for a testsuite for long pathed commands that are repeated.

example:

commands:
- command: ../../../bin/dispatch -n dispatch-tasks serviceaccount create multi-namespace

Better CRD Support

currently it is possible to specify a CRD dir in TestSuite after which there is a CRD wait.
It is also documented that a CRD could be the result of a TestStep with a pattern to follow to "wait" via an Assert.

It would be good to support a way to waiting other that TestSuite. It would be good to support CRD via a command exec from TestSuite.

If possible we should:

  1. define a publicly exposed wait function for CRDs which were created (perhaps this is only supported via API ... it would be great to support declaratively
  2. provide a way in TestSuite to define CRD via a command. so a k kudo init --crd-only could be used to define the CRD (which would wait)
  3. We should support the CRD command in a TestStep as well.

Assert at End of TestSuite Setup (Before Tests)

A great strategy for "ensuring" a controller or resources is to have a step 0 assert of that instance running
see kudobuilder/kudo#1473
test/e2e/cli-install-uninstall/00-assert.yaml

apiVersion: v1
kind: Pod
metadata:
  labels:
    app: kudo-manager
    control-plane: controller-manager
  namespace: kudo-system
status:
   phase: Running 

Assuming you may want this as a precondition on all tests... it would be great to assert this at the end of TestSuite setup prior to tests.

Document CLI env flags override TestSuite file

The kuttl cli overrides the testsuite file... with the exception of the test env. (this is a require to fix that).

If the kuttl-test.yaml has a configuration for startControlPlane: true and the cli is started with --start-kind.... the cli override should start kind.

Perhaps we should have an override that allows to point at a cluster (currently it is the default that is selected if nothing is provided).

KEP05: K8S CRUD Support

The k8s package should provide conveniences for interacting with Kubernetes objects.

  • Partial CRUD functionality for namespaces
  • CRUD functionality for all useful Kubernetes objects
  • Current known use-cases:
  • Creating and deleting namespaces during test runs

This should likely include WaitFor functions

package k8s
func Init(kubectlOptions *kubectl.KubectlOptions) error
func CreateNamespace(namespaceName string) error
func DeleteNamespace(namespaceName string) error

Ease Create Configmap

seeing projects is commonly looking for a configmap for a teststep
example

apiVersion: kudo.dev/v1alpha1
kind: TestStep
commands:
- command: 'kubectl create configmap example-cm --from-file=../../jobs/tensorflow.py -n tensorflow-testing'

looks like a need for create, from file, from values with a namespace

Fix kind cluster discovery

There are two issues with the built-in kind cluster functionality (that are likely related):

  1. If a cluster has no containers running but has not been deleted (e.g., kind delete cluster was not ran and --skip-cluster-delete was set), kuttl will still attempt to use it and hang forever.
  2. When the kind cluster is already running, kuttl will not detect it and attempt to start a new cluster.

These may be regressions related to the kind version bump from 0.5.1 to 0.7.0 as upstream kind changed a lot of the API and how kind clusters are managed.

test step - allow namespace outside of of kubectl command

  • I have a TestStep that calls kubectl, I'm wanting the TestStep to use a namespace for running that kubectl command...is this possible? so far, I have to add the --namespace onto the kubectl command string itself to have it run within that namespace.
apiVersion: kudo.dev/v1alpha1
kind: TestStep
delete:
- apiVersion: v1
  kind: ConfigMap
  name: my-static-test
  namespace: rq
kubectl:
- create configmap my-static-test --from-file=bundle=/tmp/bundle.zip --namespace=rq

Setup KUTTL Website

kuttl.io / kuttl.dev either.. both... it would be nice to have this in place prior to April 1

Add the new KUTTL to KUDO

KUDO needs to use this new dependency

  • needs to be added for kudo test
  • inject kudo manager into the tests (with designed approach)

The `timeout` parameter is only applied to the assertion part of the step

What happened:
While working on a test that includes a webhook, I noticed that timeout parameter is not used when the test step fails in the apply-phase:

    harness.go:66: going to run test suite with timeout of 3000000 seconds for each step
    --- FAIL: kudo/harness (0.02s)
        --- FAIL: kudo/harness/terminal-failed-job (7.67s)
            logger.go:37: 14:51:05 | terminal-failed-job | Ignoring failjob-operator as it does not match file name regexp: ^(\d+)-([^.]+)(.yaml)?$
            logger.go:37: 14:51:05 | terminal-failed-job | Ignoring job-timeout-operator as it does not match file name regexp: ^(\d+)-([^.]+)(.yaml)?$
            logger.go:37: 14:51:05 | terminal-failed-job | Creating namespace: kudo-test-heroic-dodo
            logger.go:37: 14:51:05 | terminal-failed-job/0-install | starting test step 0-install
            logger.go:37: 14:51:05 | terminal-failed-job/0-install | running command:  {kubectl kudo install --instance failjob-operator-instance ./failjob-operator %!s(bool=true) %!s(bool=false) %!s(bool=false)}
            logger.go:37: 14:51:12 | terminal-failed-job/0-install | Error: failed to install instance failjob-operator-instance: installing Instance: Internal error occurred: failed calling webhook "instance-admission.kudo.dev": Post https://kudo-controller-manager-service.kudo-system.svc:443/admit-kudo-dev-v1beta1-instance?timeout=30s: dial tcp 10.103.201.124:443: connect: connection refused

            logger.go:37: 14:51:12 | terminal-failed-job/0-install | operator.kudo.dev/v1beta1/failjob-operator created
                operatorversion.kudo.dev/v1beta1/failjob-operator-0.1.0 created

            case.go:156: exit status 255
            case.go:159: failed in step 0-install

The code suggests that the timeout is only respected during the assertion phase of the step. I often use the timeout to "pause" the execution of the failing step and look into the cluster (using kubectl). A number of k8s admission controllers might reject applied resources so it might be beneficial to extend timeout to the whole step and not just the assertion phase.

What you expected to happen:
The timeout should be applied to the whole step.

How to reproduce it (as minimally and precisely as possible):
Using any step command that fails (e.g. false)

Anything else we need to know?:

Environment:

  • Kubernetes version (use kubectl version):
  • KUTTL version (use kubectl kuttl version):
  • Cloud provider or hardware configuration:
  • OS (e.g. from /etc/os-release):
  • Kernel (e.g. uname -a):
  • Install tools:
  • Others:

Test harness should support watching objects rather than polling

Currently, the test harness polls for object state when tests are running which offers opportunity for races (and is likely more inefficient). For example, to test delete steps in KUDO properly, we need to be able verify that a Job is created and is completed before it gets deleted, without racing KUDO, if we poll, there is a chance we can miss the Job before KUDO deletes it.

Support --namespace flag

KUTTL currently always creates namespaces for each test step, but some users may want to run their tests in a specific namespace or target an existing deployment. This would also be useful for running kudo test in less privileged environments where it is unable to create namespaces.

It is possible today to target static namespaces by specifying them on any commands or manifests, but it would be useful to add a --namespace flag to kudo test that controls the namespace used.

For example, if --namespace is set on kudo test, instead of creating namespaces for each test step and using the created namespace as the default for each resource, kudo test will set the default namespace to the --namespace flag and use that instead.

Add gracePeriod or timeout to error steps

What would you like to be added:

Add a gracePeriod or timeout to the error teststep type.

Why is this needed:

I have a controller that migrates one type of object to another. I want to be able to specify that after some time, my original object no longer exists. Currently I cannot do that as it may take some amount of time for the controller to pick up the original object, create the derived object, and remove the original. Currently, the error teststep would fail immediately as the original object will likely still exist.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.