Skip to content

Latest commit

 

History

History
64 lines (44 loc) · 1.79 KB

README.md

File metadata and controls

64 lines (44 loc) · 1.79 KB

Namespace

Author: Nick Santos

Helper functions for creating Kubernetes namespaces and manipulating namespaces on Kubernetes objects.

Functions

namespace_yaml(name: str, annotations: List [str] = [], labels: List [str] = []): Blob

Returns YAML for a Kubernetes namespace.

namespace_create(name: str, allow_duplicates: boolean = False, annotations: List [str] = [], labels: List [str] = [])

Deploys a namespace to the cluster. Equivalent to

load('ext://namespace', 'namespace_yaml')
k8s_yaml(namespace_yaml('name'), allow_duplicates=False)

namespace_inject(objects: Union[str, Blob], namespace: str): Blob

Given YAML for Kubernetes objects, return new YAML with a different namespace.

Example Usage

For a fixed namespace:

load('ext://namespace', 'namespace_create', 'namespace_inject')
namespace_create('my-namespace')
k8s_yaml(namespace_inject(read_file('deployment.yaml'), 'my-namespace'))

For a user-specific namespace:

load('ext://namespace', 'namespace_create', 'namespace_inject')
ns = 'user-%s' % os.environ.get('USER', 'anonymous')
namespace_create(ns)
k8s_yaml(namespace_inject(read_file('deployment.yaml'), ns))

Attach annotations and labels

load('ext://namespace', 'namespace_create', 'namespace_inject')
namespace_create(
    'my-namespace',
    annotations=['kubernetes.io/metadata.name: my-namespace'],
    labels=['kubernetes.io/metadata.name: my-namespace']
)
k8s_yaml(namespace_inject(read_file('deployment.yaml'), 'my-namespace'))

Caveats

  • namespace_inject assumes all resources are namespaced-scoped. The behavior is undefined for cluster-scoped resources.

  • This extension doesn't do any validation to confirm that namespace names are valid. The behavior is undefined on invalid namespaces.