Skip to main content

Wrapper for hooks for Deckhouse, Addon Operator, and Shell Operator by Flant

Project description

Deckhouse python library

Simplifies writing module hooks for Kubernetes operators:

NOTE:

  • The API is in alpha stage

Install

pip install deckhouse

Sample hook

# hello.py
from deckhouse import hook

def main(ctx: hook.Context):
    # Manipulate kubernetes state
    # ... object = { "kind" : "Pod", "apiVersion" : "v1", ... }
    ctx.kubernetes.create_or_update(object)

    # Export metrics
    # ... metric = { "name" : "power", "group": "my_hook", "set" : 9000, ... }
    ctx.metrics.collect(metric)

    # Use in-memory values for helm chart. Shell Operator does not support values, but Addon Operator and Deckhouse do.
    ctx.values.myModule.deployment.replicas = 5


if __name__ == "__main__":
    hook.run(main, configpath="hello.yaml") # 'config' arg is also supported for raw string
# hello.yaml
configVersion: v1
onStartup: 10

How to test

An example for pytest

# hello_test.py

from hello import main
from deckhouse import hook

# Inputs
#   initial_values = { ... }
#   binding_context = [ { ... } ]
# Outputs
#   expected_metrics = [ ... ]
#   expected_kube_operations = [ ... ]
#   expected_values_patches = [ ... ]
#   expected_values = { ... }

def test_hello():
    out = hook.testrun(main, binding_context, initial_values)

    assert out.metrics.data == expected_metrics
    assert out.kube_operations.data == expected_kube_operations
    assert out.values_patches.data == expected_values_patches

    assert out.values.myModule.deployment.replicas == 5

Development

  • Create virtual environment with python >= 3.8
  • Install poetry
  • poetry install
  • make test

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

deckhouse-0.4.11.tar.gz (13.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

deckhouse-0.4.11-py3-none-any.whl (16.3 kB view details)

Uploaded Python 3

File details

Details for the file deckhouse-0.4.11.tar.gz.

File metadata

  • Download URL: deckhouse-0.4.11.tar.gz
  • Upload date:
  • Size: 13.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for deckhouse-0.4.11.tar.gz
Algorithm Hash digest
SHA256 01ac547fdd52c99acfd1b1e789fdc92dbec95203576e7feeeafea691535c9047
MD5 eccb3d52ccdc4bfc59dc3384ee8da581
BLAKE2b-256 1b15289f6b78457b7512412fa2f0b367e8349bc0f40b5d5a9fab4663c6b464c3

See more details on using hashes here.

Provenance

The following attestation bundles were made for deckhouse-0.4.11.tar.gz:

Publisher: publish-to-pypi.yml on deckhouse/lib-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file deckhouse-0.4.11-py3-none-any.whl.

File metadata

  • Download URL: deckhouse-0.4.11-py3-none-any.whl
  • Upload date:
  • Size: 16.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for deckhouse-0.4.11-py3-none-any.whl
Algorithm Hash digest
SHA256 393e407c36cc905f400875951052fcb75df667290edf8bb10cf598e53ef79ef3
MD5 d8a83e337bf9dd6418a743a334e41d2c
BLAKE2b-256 2fd741050d2bf8a99505c3f815369e33b617f59b0d3c8910dd1f74fb5a1647dc

See more details on using hashes here.

Provenance

The following attestation bundles were made for deckhouse-0.4.11-py3-none-any.whl:

Publisher: publish-to-pypi.yml on deckhouse/lib-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page