Skip to main content

Kubernetes library for Robot Framework

Project description


CircleCI Build StatusPyPIPyPi downloadsGitHub LicenseSlack

RobotFramework library for testing Kubernetes cluster

Quick start

# install library itself
pip install robotframework-kubelibrary

export KUBECONFIG=~/.kube/config

# run example tests
pip install robotframework-requests
git clone
cd KubeLibrary
robot -e prerelease testcases

Example testcase

Pods in kube-system are ok
    [Documentation]  Test if all pods in kube-system initiated correctly and are running or succeeded
    [Tags]    cluster    smoke
    Given kubernetes API responds
    When getting all pods in  "kube-system"
    Then all pods in "kube-system" are running or succeeded

Grafana has correct version
    [Documentation]  Test if Grafana container image is in correct version
    [Tags]    grafana
    Given kubernetes API responds
    When accessing "grafana-" excluding "svclb" container images version in "default"
    Then "grafana/grafana:6.5.0" version is used

More examples in testcases/ directory.

To see all the tests passing execute below commands.


Library docs

Cluster Tests

# run cluster tests
robot -i cluster -e prerelease testcases/

Grafana Tests

helm repo add grafana
helm repo update
helm install grafana grafana/grafana -f testcases/grafana/values.yaml

# run grafana tests
export KLIB_POD_PATTERN='grafana.*'
export KLIB_POD_ANNOTATIONS='{"kubelibrary":"testing"}'
export KLIB_POD_NAMESPACE=default

robot -i grafana -e prerelease testcases/

Octopus Tests

git clone
helm install octopus octopus/chart/octopus/

# run octopus tests
export KLIB_POD_PATTERN='octopus.*'
export KLIB_POD_LABELS='{"app":"octopus"}'
export KLIB_ENV_VARS='{"SECRET_NAME":"webhook-server-secret"}'
export KLIB_POD_NAMESPACE=default

robot -i octopus -e prerelease testcases/

Other Tests

These tests require the kubelib-test helm-chart to be installed in your test cluster.

# run other library tests
export KLIB_POD_PATTERN='busybox.*'
export KLIB_POD_NAMESPACE=kubelib-tests
export KLIB_POD_LABELS='job-name=busybox-job'

kubectl create namespace $KLIB_POD_NAMESPACE
kubectl label namespaces kubelib-tests test=test
helm install kubelib-test ./test-objects-chart -n $KLIB_POD_NAMESPACE

robot -i other -e prerelease testcases/

Multi Cluster Tests

These tests require more than one cluster and utilize KinD as a setup. Download KinD and install it.

# Create Test Cluster 1
kind create cluster --kubeconfig ./cluster1-conf --name kind-cluster-1

# Create namespace in Test Cluster 1
kubectl create namespace test-ns-1 --context kind-kind-cluster-1 --kubeconfig ./cluster1-conf
# For bearer token auth
kubectl apply -f testcases/reload-config/sa.yaml
MYSA_TOKEN_SECRET=$(kubectl get sa mysa -o jsonpath="{.secrets[0].name}")
export K8S_TOKEN=$(kubectl get secret $MYSA_TOKEN_SECRET --template={{.data.token}} | base64 -d)
kubectl get secret $MYSA_TOKEN_SECRET -o jsonpath="{\.crt}" | base64 -d > ca.crt
export K8S_API_URL=$(kubectl config view -o jsonpath='{.clusters[0].cluster.server}')
export K8S_CA_CRT=./ca.crt

# Create Test Cluster 2
kind create cluster --kubeconfig ./cluster2-conf --name kind-cluster-2

# Create namespace in Test Cluster 2
kubectl create namespace test-ns-2 --context kind-kind-cluster-2 --kubeconfig ./cluster2-conf

robot -i reload-config -e prerelease testcases/

# Clean up
kind delete cluster --name kind-cluster-1
kind delete cluster --name kind-cluster-2

Keywords documentation

Keywords documentation can be found in docs/.

Further reading

DevOps spiral article on KubeLibrary

KubeLibrary: Testing Kubernetes with RobotFramework | Humanitec

RobotFramework User Guide


# clone repo
git clone
cd KubeLibrary

# create virtualenv
virtualenv .venv
. .venv/bin/activate
pip install -r requirements

Create keyword and test file, import KubeLibrary using below to point to library under development.

*** Settings ***

Library    ../src/KubeLibrary/

For development cluster you can use k3s/k3d as described in DevOps spiral article on K3d and skaffold.

Generate docs

    # To generate keyword documentation a connection
    # to a cluster is not necessary. Skip to load a
    # cluster configuration.
    # Set the variable local for the libdoc call only
    python -m robot.libdoc src/KubeLibrary/ docs/index.html

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

robotframework-kubelibrary-0.7.0.tar.gz (21.1 kB view hashes)

Uploaded source

Built Distribution

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page