Skip to content

test with kuttl

Masato Naka edited this page Nov 17, 2021 · 1 revision

A declarative testing framework for Kubernetes Operators.

Prerequisite

  • Kubernetes Cluster
  • kubectl

Version

kubectl-kuttl -v
kubectl-kuttl version 0.11.1
KUTTL Version: version.Info{GitVersion:"0.11.1", GitCommit:"25776a2", BuildDate:"2021-08-09T15:18:32Z", GoVersion:"go1.16.6", Compiler:"gc", Platform:"darwin/amd64"}

Basics

  1. Install kuttl plugin

    kubectl krew install kuttl
    
  2. Run kuttl test

    Run tests against the Kubernetes cluster with default kubeconfig:

    kubectl kuttl test ./bundle/tests/scorecard/kuttl
    
    kubectl kuttl test ./bundle/tests/scorecard/kuttl
    
    2021/09/20 13:07:17 running without a 'kuttl-test.yaml' configuration
    2021/09/20 13:07:17 kutt-test config testdirs is overridden with args: [ ./bundle/tests/scorecard/kuttl ]
    === RUN   kuttl
        harness.go:457: starting setup
        harness.go:248: running tests using configured kubeconfig.
        harness.go:285: Successful connection to cluster at: https://kubernetes.docker.internal:6443
        harness.go:353: running tests
        harness.go:74: going to run test suite with timeout of 30 seconds for each step
        harness.go:365: testsuite: ./bundle/tests/scorecard/kuttl has 1 tests
    === RUN   kuttl/harness
    === RUN   kuttl/harness/with-valid-mysql
    === PAUSE kuttl/harness/with-valid-mysql
    === CONT  kuttl/harness/with-valid-mysql
        logger.go:42: 13:07:19 | with-valid-mysql | Creating namespace: kuttl-test-becoming-liger
        logger.go:42: 13:07:19 | with-valid-mysql/0-mysql-deployment | starting test step 0-mysql-deployment
        logger.go:42: 13:07:20 | with-valid-mysql/0-mysql-deployment | Deployment:kuttl-test-becoming-liger/mysql created
        logger.go:42: 13:07:20 | with-valid-mysql/0-mysql-deployment | Service:kuttl-test-becoming-liger/mysql created
        logger.go:42: 13:07:22 | with-valid-mysql/0-mysql-deployment | test step completed 0-mysql-deployment
        logger.go:42: 13:07:22 | with-valid-mysql | with-valid-mysql events from ns kuttl-test-becoming-liger:
        logger.go:42: 13:07:22 | with-valid-mysql | 2021-09-20 13:07:20 +0900 JST   Normal  Pod mysql-5fd4b796b6-tr7wx      Binding      Scheduled       Successfully assigned kuttl-test-becoming-liger/mysql-5fd4b796b6-tr7wx to docker-desktop        default-scheduler
        logger.go:42: 13:07:22 | with-valid-mysql | 2021-09-20 13:07:20 +0900 JST   Normal  ReplicaSet.apps mysql-5fd4b796b6    SuccessfulCreate Created pod: mysql-5fd4b796b6-tr7wx
        logger.go:42: 13:07:22 | with-valid-mysql | 2021-09-20 13:07:20 +0900 JST   Normal  Deployment.apps mysql           ScalingReplicaSet    Scaled up replica set mysql-5fd4b796b6 to 1
        logger.go:42: 13:07:22 | with-valid-mysql | 2021-09-20 13:07:21 +0900 JST   Normal  Pod mysql-5fd4b796b6-tr7wx.spec.containers{mysql}            Pulled  Container image "mysql:5.7" already present on machine
        logger.go:42: 13:07:22 | with-valid-mysql | 2021-09-20 13:07:21 +0900 JST   Normal  Pod mysql-5fd4b796b6-tr7wx.spec.containers{mysql}            Created Created container mysql
        logger.go:42: 13:07:22 | with-valid-mysql | 2021-09-20 13:07:21 +0900 JST   Normal  Pod mysql-5fd4b796b6-tr7wx.spec.containers{mysql}            Started Started container mysql
        logger.go:42: 13:07:22 | with-valid-mysql | Deleting namespace: kuttl-test-becoming-liger
    === CONT  kuttl
        harness.go:399: run tests finished
        harness.go:508: cleaning up
        harness.go:563: removing temp folder: ""
    --- PASS: kuttl (5.00s)
        --- PASS: kuttl/harness (0.00s)
            --- PASS: kuttl/harness/with-valid-mysql (2.85s)
    PASS
    

    Run tests against kind cluster:

    kubectl kuttl test --start-kind=true ./bundle/tests/scorecard/kuttl
    
Clone this wiki locally