You are on page 1of 7

KubeLibrary

Library scope: TEST


Named arguments: supported

Introduction
KubeLibrary is a Robot Framework test library for Kubernetes.

The approach taken by this library is to provide easy to access kubernetes objects
representation that can be then accessed to define highlevel keywords for tests.

Kubeconfigs
By default ~/.kube/config is used. Kubeconfig location can also be passed by setting
KUBECONFIG environment variable or as Library argument.

*** Settings ***


Library KubeLibrary /path/to/kubeconfig

In cluster execution
If tests are supposed to be executed from within cluster, KubeLibrary can be
configured to use standard token authentication. Just set incluster parameter to True.
If True then kubeconfigs are not used, even if provided.

*** Settings ***


Library KubeLibrary None True

Importing
Arguments Documentation
KubeLibrary can be configured with several optional
arguments.

• kube_config: Path pointing to kubeconfig of target


kube_config=None,
Kubernetes cluster.
incluster=False,
• incuster: Default False. Indicates if used from within
cert_validation=True
k8s cluster. Overrides kubeconfig.
• cert_validation: Default True. Can be set to False
for self-signed certificates.

Shortcuts
List style: Compact Expanded
Assert Container Has Env Vars
Assert Pod Has Annotations
Assert Pod Has Labels
Filter Containers Images
Filter Containers Resources
Filter Pods Containers By Name
Filter Pods Containers Statuses By Name
Filter Pods Names
Get Configmaps In Namespace
Get Deployments In Namespace
Get Endpoints In Namespace
Get Healthy Nodes Count
Get Jobs In Namespace
Get Kubelet Version
Get Namespaces
Get Pod Logs
Get Pod Names In Namespace
Get Pod Status In Namespace
Get Pods In Namespace
Get Pvc Capacity
Get Pvc In Namespace
Get Service Details In Namespace
Get Services In Namespace
K8s Api Ping
Reload Config

Keywords
Keywor
Arguments Documentation
d
Assert container has env vars.

Assert Returns True/False


Containe container,
r Has env_vars_json • container: Container object.
Env Vars • env_var_json: JSON representing env vars i.e.:
{"EXAMPLE_VAR": "examplevalue"}

Assert pod has annotations.

Assert Returns True/False


pod,
Pod Has
annotations_js
Annotati • pod: Pod object.
on
ons • annotations_json: JSON representing
annotations
Assert pod has labels.

Assert Returns True/False


pod,
Pod Has
labels_json
Labels • pod: Pod object.
• labels_json: JSON representing labels

Filters container images for given lists of containers.


Filter
Returns list of images.
Containe containers
rs Images
• containers: List of containers

Filters container resources for given lists of containers.


Filter
Containe
Returns list of resources.
rs containers
Resource
• containers: List of containers
s

Filters pods containers by name for given list of pods.


Filter
Pods
pods, Returns lists of containers (flattens).
Containe
name_pattern
rs By
• pods: List of pods objects
Name

Filters pods containers statuses by container name for


Filter
given list of pods.
Pods
Containe pods,
Returns lists of containers statuses.
rs name_pattern
Statuses
• pods: List of pods objects
By Name

Filter pod names for list of pods.


Filter
Returns list of strings.
Pods pods
Names
• pods: List of pods objects

Gets configmaps matching pattern in given namespace.


Get
Can be optionally filtered by label. e.g.
Configm name_pattern,
label_selector=label_key=label_value
aps In namespace,
Namespa label_selector=
Returns list of configmaps.
ce
• name_pattern: configmap name pattern to check
• namespace: Namespace to check

Gets deployments matching pattern in given namespace.

Can be optionally filtered by label. e.g.


Get label_selector=label_key=label_value
Deploym name_pattern,
ents In namespace, Returns list of deployments.
Namespa label_selector=
ce • name_pattern: deployment name pattern to
check
• namespace: Namespace to check

Gets endpoint details in given namespace.

Returns Endpoint object representation. Can be accessed


using

Get
pod-
Endpoint Shou
name, name
s In ld ${endpoint_details.subsets[0].addresses[0].
namespace -
Namespa Matc target_ref.name}
1234
ce h
56

• name: Name of endpoint.


• namespace: Namespace to check

Counts node with KubeletReady and status True.


Get
Can be optionally filtered by label. e.g.
Healthy
label_selector= label_selector=label_key=label_value
Nodes
Count
Can be used to check number of healthy nodes. Can be
used as prerequisite in tests.
Gets jobs matching pattern in given namespace.

Can be optionally filtered by label. e.g.


Get Jobs label_selector=label_key=label_value
name_pattern,
In
namespace,
Namespa Returns list of jobs.
label_selector=
ce
• name_pattern: job name pattern to check
• namespace: Namespace to check

Get
Gets list of kubelet versions on each node.
Kubelet label_selector=
Version
Can be optionally filtered by label. e.g.
label_selector=label_key=label_value

Returns list of strings.


Gets a list of available namespaces.
Get
Can be optionally filtered by label. e.g.
Namespa label_selector=
label_selector=label_key=label_value
ces
Returns list of namespaces.
Gets container logs of given pod in given namespace.

Returns logs.
name,
Get Pod
namespace,
Logs • name: Pod name to check
container
• namespace: Namespace to check
• container: Container to check

Gets pod name matching pattern in given namespace.

Can be optionally filtered by label. e.g.


Get Pod label_selector=label_key=label_value
name_pattern,
Names In
namespace,
Namespa Returns list of strings.
label_selector=
ce
• name_pattern: Pod name pattern to check
• namespace: Namespace to check

Gets pod status in given namespace.


Get Pod
Status In name,
• name: Name of pod.
Namespa namespace
• namespace: Namespace to check
ce

Gets pods matching pattern in given namespace.

Can be optionally filtered by label. e.g.


Get Pods label_selector=label_key=label_value
name_pattern,
In
namespace,
Namespa Returns list of pods.
label_selector=
ce
• name_pattern: Pod name pattern to check
• namespace: Namespace to check

Get Pvc name, Gets PVC details in given namespace.


Capacity namespace
Returns PVC object representation. Can be accessed
using

Should Be Equal As
${pvc.status.capacity.storage} 1Gi
strings

• name: Name of PVC.


• namespace: Namespace to check

Gets pvcs in given namespace.

Can be optionally filtered by label. e.g.


Get Pvc
label_selector=label_key=label_value
In namespace,
Namespa label_selector=
Returns list of strings.
ce
• namespace: Namespace to check

Gets service details in given namespace.

Returns Service object representation. Can be accessed


Get using
Service
Details name, Should Be
In namespace Equal As ${service_details.spec.ports[0].port} 8080
Namespa integers
ce
• name: Name of service.
• namespace: Namespace to check

Gets services in given namespace.

Get Can be optionally filtered by label. e.g.


Services label_selector=label_key=label_value
namespace,
In
label_selector=
Namespa Returns list of strings.
ce
• namespace: Namespace to check

Performs GET on /api/v1/ for simple check of API


availability.
K8s Api
Ping
Returns tuple of (response data, response status, response
headers). Can be used as prerequisite in tests.
Reload the KubeLibrary to be configured with different
optional arguments. This can be used to connect to a
different cluster during the same test.
kube_config=
None,
• kube_config: Path pointing to kubeconfig of
Reload incluster=False
target Kubernetes cluster.
Config ,
• incuster: Default False. Indicates if used from
cert_validation
within k8s cluster. Overrides kubeconfig.
=True
• cert_validation: Default True. Can be set to
False for self-signed certificates.

Altogether 25 keywords.
Generated by Libdoc on 2020-09-19 23:19:58.

You might also like