Python SDK for Shell Operator hooks
Project description
Shell Operator Python Framework
Simplifies writing shell-operator hooks in Python.
Install
pip install shell-operator
Sample hook
# hello.py
from shell_operator 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 shell_operator 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.repicas == 5
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
shell_operator-0.0.8.tar.gz
(10.0 kB
view hashes)
Built Distribution
Close
Hashes for shell_operator-0.0.8-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 87e5c692017e06127b108ddd1fb7a61096cbb643f14976f0c8545020193122ba |
|
MD5 | cff52f5a95352f21d05b7b18843af746 |
|
BLAKE2b-256 | c5f619c73cc04126a4f1e8f311b3d6b6194e74c12004f59f158c7b7282739e96 |