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.9.tar.gz (11.3 kB view details)

Uploaded Source

Built Distribution

deckhouse-0.4.9-py3-none-any.whl (13.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: deckhouse-0.4.9.tar.gz
  • Upload date:
  • Size: 11.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.2 CPython/3.11.5

File hashes

Hashes for deckhouse-0.4.9.tar.gz
Algorithm Hash digest
SHA256 99d00de3dff40ea3fde2b3b9da1b1e73e24ad5f5642ed1f14161d5b721e92d7d
MD5 58ed99e8a855be516b858bf3a62efdb0
BLAKE2b-256 0e36105b7abaadb2925bbf62045ec318eaa4e5735c8db97bda8f564ae14be21a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: deckhouse-0.4.9-py3-none-any.whl
  • Upload date:
  • Size: 13.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.2 CPython/3.11.5

File hashes

Hashes for deckhouse-0.4.9-py3-none-any.whl
Algorithm Hash digest
SHA256 f9a70e44810ea3c30821c2ece498ba4743dd6495b09e3b7a2e7bc98fb16ef3c6
MD5 2a6ab64f88d1e9b50ada0398b8205a67
BLAKE2b-256 cae8fa1086ce7bbea1f9346fe79513f65d69b83f804c580ce0435cfe0f9811c9

See more details on using hashes here.

Supported by

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