Wrapper for hooks for Deckhouse, Addon Operator, and Shell Operator by Flant
Project description
Deckhouse python library
Simplifies writing module hooks for Kubernetes operators:
- Deckhouse
- Addon Operator
- Shell Operator (values are unaccessible)
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 installmake 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
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 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
01ac547fdd52c99acfd1b1e789fdc92dbec95203576e7feeeafea691535c9047
|
|
| MD5 |
eccb3d52ccdc4bfc59dc3384ee8da581
|
|
| BLAKE2b-256 |
1b15289f6b78457b7512412fa2f0b367e8349bc0f40b5d5a9fab4663c6b464c3
|
Provenance
The following attestation bundles were made for deckhouse-0.4.11.tar.gz:
Publisher:
publish-to-pypi.yml on deckhouse/lib-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
deckhouse-0.4.11.tar.gz -
Subject digest:
01ac547fdd52c99acfd1b1e789fdc92dbec95203576e7feeeafea691535c9047 - Sigstore transparency entry: 152294660
- Sigstore integration time:
-
Permalink:
deckhouse/lib-python@a121e758848387c339553309ab08fcf73bd646cb -
Branch / Tag:
refs/tags/v0.4.11 - Owner: https://github.com/deckhouse
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-to-pypi.yml@a121e758848387c339553309ab08fcf73bd646cb -
Trigger Event:
release
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
393e407c36cc905f400875951052fcb75df667290edf8bb10cf598e53ef79ef3
|
|
| MD5 |
d8a83e337bf9dd6418a743a334e41d2c
|
|
| BLAKE2b-256 |
2fd741050d2bf8a99505c3f815369e33b617f59b0d3c8910dd1f74fb5a1647dc
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
deckhouse-0.4.11-py3-none-any.whl -
Subject digest:
393e407c36cc905f400875951052fcb75df667290edf8bb10cf598e53ef79ef3 - Sigstore transparency entry: 152294661
- Sigstore integration time:
-
Permalink:
deckhouse/lib-python@a121e758848387c339553309ab08fcf73bd646cb -
Branch / Tag:
refs/tags/v0.4.11 - Owner: https://github.com/deckhouse
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-to-pypi.yml@a121e758848387c339553309ab08fcf73bd646cb -
Trigger Event:
release
-
Statement type: