k8s.base module

exception k8s.base.APIServerError(api_error)[source]

Bases: Exception

Raised when the API server returns an error event in the watch stream

classmethod match(event_json)[source]
class k8s.base.ApiMixIn[source]

Bases: object

ApiMixIn class for top level Models

Contains methods for working with the API

classmethod delete(name, namespace='default', **kwargs)[source]

Delete the named resource

classmethod delete_list(namespace='default', labels=None, delete_options=None, **kwargs)[source]
classmethod find(name='', namespace='default', labels=None)[source]

Find resources using label selection

Param:

str name: The name of the resource, as indicated by the app label

Param:

str namespace: The namespace to search in

Param:

dict labels: More advanced label selection (see below)

Returns:

A list of matching objects

When a labels dictionary is supplied, the name parameter is ignored. See the docs for _label_selector for more details

classmethod get(name, namespace='default')[source]

Get from API server if it exists

classmethod get_or_create(**kwargs)[source]

If exists, get from API, else create new instance

classmethod list(namespace='default')[source]

List all resources in given namespace

save()[source]

Save to API server, either update if existing, or create if new

save_status()[source]

Save status to API server, always updating

classmethod watch_list(namespace=None, resource_version=None, allow_bookmarks=False)[source]

Return a generator that yields WatchEvents of cls. If allowBookmarks is True, WatchBookmarks will also be yielded. It’s recommended to use the Watcher class instead of calling this directly, since it handles reconnects and resource versions.

class k8s.base.Equality(value='')[source]

Bases: LabelSelector

operator = '='

Operator used in selection query

class k8s.base.Exists[source]

Bases: LabelSelector

class k8s.base.In(value='')[source]

Bases: LabelSetSelector

operator = 'in'

Operator used in selection query

class k8s.base.Inequality(value='')[source]

Bases: LabelSelector

operator = '!='

Operator used in selection query

class k8s.base.LabelSelector(value='')[source]

Bases: object

Base for label select operations

operator = None

Operator used in selection query

class k8s.base.LabelSetSelector(value='')[source]

Bases: LabelSelector

class k8s.base.MetaModel(cls, bases, attrs)[source]

Bases: type

Metaclass for Model

Responsibilities:

  • Creating the _meta attribute, with url_template (if present), list of fields and for convenience, a list of field names.

  • Creates properties for name and namespace if the instance has a metadata field.

  • Mixes in ApiMixIn if the Model has a Meta attribute, indicating a top level Model (not to be confused with _meta).

class k8s.base.Model(new=True, **kwargs)[source]

Bases: object

A kubernetes Model object

Contains fields for each attribute in the API specification, and methods for export/import.

as_dict()[source]
classmethod from_dict(d)[source]
merge(other)[source]

merge sets each field in self to the value provided by other This is mostly equivalent to just replacing self with other, except read only fields in self are preserved.

update(other)

merge sets each field in self to the value provided by other This is mostly equivalent to just replacing self with other, except read only fields in self are preserved.

update_from_dict(d)[source]
class k8s.base.NotIn(value='')[source]

Bases: LabelSetSelector

operator = 'notin'

Operator used in selection query

class k8s.base.SelfModel[source]

Bases: object

Use SelfModel as Field.type to set Field.type to the model the Field was defined in during model instantiation.

This allows models to have fields with their own type. It is not possible to reference a class in its own attributes.

Example: ``` class MyModel(Model):

submodel = Field(SelfModel) # submodel gets the type MyModel

```

class k8s.base.WatchBaseEvent(event_json)[source]

Bases: ABC

Abstract base class for Watch events. Contains the resource version of the event as property resource_version.

has_object()[source]
resource_version
class k8s.base.WatchBookmark(event_json)[source]

Bases: WatchBaseEvent

Bookmark events, if enabled, are sent periodically by the API server. They only contain the resourceVersion of the event.

has_object()[source]
classmethod match(event_json)[source]
resource_version
class k8s.base.WatchEvent(event_json, cls)[source]

Bases: WatchBaseEvent

ADDED = 'ADDED'
DELETED = 'DELETED'
MODIFIED = 'MODIFIED'
has_object()[source]
resource_version