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.1.0.tar.gz
(11.0 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file shell_operator-0.1.0.tar.gz.
File metadata
- Download URL: shell_operator-0.1.0.tar.gz
- Upload date:
- Size: 11.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.3.1 CPython/3.10.7 Darwin/22.2.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f08f4850a4979331e78570d524fd7a1f2bfbdaedb45eaa7154e3a14bf1afde13
|
|
| MD5 |
6139345ddce50eefe0d29e8e7b6eff6e
|
|
| BLAKE2b-256 |
34f533874307627702bc35ff10d4062fbb7f48d7e2064f3271731cf086283c58
|
File details
Details for the file shell_operator-0.1.0-py3-none-any.whl.
File metadata
- Download URL: shell_operator-0.1.0-py3-none-any.whl
- Upload date:
- Size: 12.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.3.1 CPython/3.10.7 Darwin/22.2.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6df3fb38c3902fc46614be30095b9d242b2d25c93220f35b90c4a7fda4ba3140
|
|
| MD5 |
b2f241b00a98b11d2271130d6f1af153
|
|
| BLAKE2b-256 |
60a049eb0abad2800b33bb518db25ade2a8285d7c8f1c6c5515610a652ac9c1b
|