apama.docker.kubernetes

Support for using Kubernetes and Rancher from PySys tests.

Pod(parent, data[, own, namespace])

Represents a Kubernetes pod.

Job(parent, data[, own, namespace])

Represents a Kubernetes job.

Service(parent, data[, namespace])

Represents a Kubernetes service.

NameSpace(parent, data[, namespace])

Represents a Kubernetes NameSpace.

Secret(parent, data[, namespace])

Represents a Kubernetes Secret.

PersistentVolume(parent, data[, namespace])

Represents a Kubernetes PersistentVolume.

PersistentVolumeClaim(parent, data[, namespace])

Represents a Kubernetes PersistentVolumeClaim.

Deployment(parent, data[, namespace])

Represents a Kubernetes Deployment.

StatefulSet(parent, data[, namespace])

Represents a Kubernetes StatefulSet.

Resource(parent, data[, namespace])

Helper class for working with Kubernetes objects.

Project(parent, cluster, data)

Represents a Rancher Project - A grouping mechanism in Rancher.

Cluster(parent, data, name)

Represents a Rancher Cluster - top level organisation for objects.

Project

class apama.docker.kubernetes.Project(parent, cluster, data)[source]

Bases: apama.docker.kubernetes.Resource

Represents a Rancher Project - A grouping mechanism in Rancher. Create using Project.fromContext

Record Cluster using existing mechanism

classmethod fromName(parent, cluster, name)[source]

Bending this to fit class hierarchy

classmethod fromUnique(parent, cluster, rootname)[source]

Create a namespace with a unique name

classmethod fromContext(parent, cluster)[source]

Create a project with a unique name

switch()[source]

Check Cluster and create project if needed - if not rancher then noop

Resource

class apama.docker.kubernetes.Resource(parent, data, namespace=None)[source]

Bases: apama.docker.framework.DockerHelper

Helper class for working with Kubernetes objects. Represents any resource within Kubernetes - pods, services etc.

Resources are created from a Kubernetes resource definition, either using createResource, or from a file using fromFile. fromFile will create multiple resources from a single file.

Create a resource object from a Parent and YAML

classmethod fromFile(parent, fileName, imageSubst=None, namespace=None)[source]

Create (multiple) resources from a single file, possibly substituting image names. Returns a list of Resource objects.

Parameters
  • parent – Reference to the parent PySys testcase

  • fileName – Path of the yaml file to read the resource definitions from, which will be passed to “kubectrl create -f <filename>”. Must be in UTF-8 encoding.

  • imageSubst – a map of search:replacement for strings to replace in image: stanzas

  • namespace – The Namespace to define these objects in

Returns

a list of Resource objects

classmethod createResource(parent, data, imageSubst=None, namespace=None)[source]

Create a resource from a YAML resource definition, possibly substituting image names.

Parameters
  • parent – Reference to the parent PySys testcase

  • data – The YAML content for a single resource, as a list of character strings representing each line. The “kind” dictionary value will be used to determine what class is instantiated.

  • imageSubst – a map of search:replacement for strings to replace in image: stanzas

  • namespace – The Namespace to define this objects in

:return a Resource object

classmethod createAll(resources, waitForRunning=True, timeout=240)[source]

Create all the specified resources, then wait for all of them to be running.

Parameters
  • resources – A dictionary string:Resource

  • waitForRunning – Set to false to not wait for all the resources

  • timeout – Maximum number of seconds to wait for each resource

getName()[source]

Return the name of this resource

create(waitForRunning=True, timeout=240)[source]

Create this resource within a Kubernetes node.

Parameters
  • waitForRunning – If True waits for the resource to be ready before returning.

  • timeout – Maximum number of seconds to wait for the resource to be ready.

waitForRunning(timeout=240)[source]

Overridden by subclasses. Waits until a resource is in the running state or timeout (seconds) occurs

Parameters

timeout – Maximum number of seconds to wait for the resource to be available

Job

class apama.docker.kubernetes.Job(parent, data, own=True, namespace=None)[source]

Bases: apama.docker.kubernetes.Resource

Represents a Kubernetes job. Provides controls to create and destroy the job, get the logs etc Create using Resource.fromFile

Create a job from a Parent and YAML

waitForRunning(timeout=240)[source]

Wait until the pod is in the running state

Parameters

timeout – Maximum number of seconds to wait for the resource to be available

log(logfile)[source]

Stream the Kubernetes logs (i.e. the stdout and stderr) for a resource that has been run.

Sends it live to two files, one for stdout, another for stderr.

Parameters

logfile – A named file prefix in the output directory. Suffixed with ‘.out’ and ‘.err’

cp(containerPath)[source]

‘docker cp’ a file out of the pod into your output directory

Parameters

containerPath – Absolute path of the file in the container. The file in your output directory will share its basename.

delete(timeout=600, graceperiod=0, force=True)[source]

Removes the job and waits for it to be removed.

Parameters

timeout – Maximum number of seconds to wait for the pod to be removed

Pod

class apama.docker.kubernetes.Pod(parent, data, own=True, namespace=None)[source]

Bases: apama.docker.kubernetes.Resource

Represents a Kubernetes pod. Provides controls to create and destroy the pod, get the logs etc Create using Resource.fromFile

Create a pod from a Parent and YAML

waitForRunning(timeout=240)[source]

Wait until the pod is in the running state

Parameters

timeout – Maximum number of seconds to wait for the resource to be available

log(logfile, once=False)[source]

Stream the Kubernetes logs (i.e. the stdout and stderr) for a resource that has been run.

Sends it live to two files, one for stdout, another for stderr.

Parameters

logfile – A named file prefix in the output directory. Suffixed with ‘.out’ and ‘.err’

cp(containerPath)[source]

‘docker cp’ a file out of the pod into your output directory

Parameters

containerPath – Absolute path of the file in the container. The file in your output directory will share its basename.

expose()[source]

Expose the port(s) of the pod on the host

getExternalPort(port)[source]

Return the port on the Kube node which corresponds to the given internal port. Exposes the ports if not already exposed.

delete(timeout=600, graceperiod=0, force=True)[source]

Removes the pod and waits for it to be removed.

Parameters

timeout – Maximum number of seconds to wait for the pod to be removed

Service

class apama.docker.kubernetes.Service(parent, data, namespace=None)[source]

Bases: apama.docker.kubernetes.Resource

Represents a Kubernetes service. Provides controls to create and destroy the pod, get the logs etc. Create using Resource.fromFile

Create a service from a Parent and YAML

delete(timeout=600, graceperiod=0, force=True)[source]

Removes the service and waits for it to be removed.

Parameters

timeout – Maximum number of seconds to wait for the service to be removed

log(logfile)[source]

Stream the Kubernetes logs (i.e. the stdout and stderr) for a resource that has been run.

Sends it live to two files, one for stdout, another for stderr.

Parameters

logfile – A named file prefix in the output directory. Suffixed with ‘.out’ and ‘.err’

NameSpace

class apama.docker.kubernetes.NameSpace(parent, data, namespace=None)[source]

Bases: apama.docker.kubernetes.Resource

Represents a Kubernetes NameSpace. Create using Resource.fromFile or NameSpace.fromName or NameSpace.fromRandom

Create a namespace from a Parent and YAML

classmethod fromName(parent, name)[source]

Create a named namespace

classmethod fromUnique(parent)[source]

Create a namespace with a unique name

createInProject(project)[source]

Create the namespace under the suppied project - noop if not rancher

delete(timeout=600, graceperiod=0, force=True)[source]

Removes the namespace and waits for it to be removed.

Parameters

timeout – Maximum number of seconds to wait for the volume to be removed

Secret

class apama.docker.kubernetes.Secret(parent, data, namespace=None)[source]

Bases: apama.docker.kubernetes.Resource

Represents a Kubernetes Secret.

Create using Resource.fromFils

Create a secret from a Parent and YAML

delete(timeout=600, graceperiod=0, force=True)[source]

Removes the secret and waits for it to be removed.

Parameters

timeout – Maximum number of seconds to wait for the secret to be removed

PersistentVolume

class apama.docker.kubernetes.PersistentVolume(parent, data, namespace=None)[source]

Bases: apama.docker.kubernetes.Resource

Represents a Kubernetes PersistentVolume. Create using Resource.fromFile

Create a volume from a Parent and YAML

delete(timeout=600, graceperiod=0, force=True)[source]

Removes the volume and waits for it to be removed.

Parameters

timeout – Maximum number of seconds to wait for the volume to be removed

PersistentVolumeClaim

class apama.docker.kubernetes.PersistentVolumeClaim(parent, data, namespace=None)[source]

Bases: apama.docker.kubernetes.Resource

Represents a Kubernetes PersistentVolumeClaim. Create using Resource.fromFile

Create a claim from a Parent and YAML

delete(timeout=600, graceperiod=0, force=True)[source]

Removes the claim and waits for it to be removed.

Parameters

timeout – Maximum number of seconds to wait for the claim to be removed

Deployment

class apama.docker.kubernetes.Deployment(parent, data, namespace=None)[source]

Bases: apama.docker.kubernetes.Resource

Represents a Kubernetes Deployment. Create using Resource.fromFile

Create a deployment from a Parent and YAML

waitForRunning(timeout=240)[source]

Wait until the deployment and all its pods are in the running state

Parameters

timeout – Maximum number of seconds to wait for each pod to be available.

getPods()[source]

Get all the pods associated with this deployment

delete(timeout=600, graceperiod=0, force=True)[source]

Removes the deployment and waits for it to be removed.

Parameters

timeout – Maximum number of seconds to wait for the deployment to be removed

StatefulSet

class apama.docker.kubernetes.StatefulSet(parent, data, namespace=None)[source]

Bases: apama.docker.kubernetes.Resource

Represents a Kubernetes StatefulSet. Create using Resource.fromFile

Create a statefulset from a Parent and YAML

waitForRunning(timeout=240)[source]

Wait until the statefulset and all its pods are in the running state

Parameters

timeout – Maximum number of seconds to wait for each pod to be available.

getPods()[source]

Get all the pods associated with this statefulset

delete(timeout=600, graceperiod=0, force=True)[source]

Removes the statefulset and waits for it to be removed.

Parameters

timeout – Maximum number of seconds to wait for the statefulset to be removed

Cluster

class apama.docker.kubernetes.Cluster(parent, data, name)[source]

Bases: apama.docker.kubernetes.Resource

Represents a Rancher Cluster - top level organisation for objects. Also provides a hook for determining cluster health and availability. Create using Cluster.fromName

Record Cluster using existing mechanism

classmethod fromName(parent, name)[source]

Bending this to fit class hierarchy

delete(timeout=600, graceperiod=0, force=True)[source]

Cluster is Read-Only