Name | deckhouse-sdk JSON |
Version |
0.4.3
JSON |
| download |
home_page | |
Summary | Python SDK for Shell Operator hooks |
upload_time | 2023-02-02 14:51:25 |
maintainer | |
docs_url | None |
author | Eugene Shevchenko |
requires_python | >=3.7.2,<4.0.0 |
license | Apache-2.0 |
keywords |
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# Deckhouse module SDK
Deckhouse module SDK simplifies writing module hooks for operators:
- [Deckhouse](https://github.com/deckhouse/deckhouse)
- [Addon Operator](https://github.com/flant/addon-operator)
- [Shell Operator](https://github.com/flant/shell-operator) (values are unaccessable)
**NOTE**:
- The API is in alpha stage
## Install
```bash
pip install deckhouse-sdk
```
## Sample hook
```python
# hello.py
from deckhouse_sdk 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
```
```yaml
# hello.yaml
configVersion: v1
onStartup: 10
```
## How to test
An example for pytest
```python
# hello_test.py
from hello import main
from deckhouse_sdk 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
```
Raw data
{
"_id": null,
"home_page": "",
"name": "deckhouse-sdk",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.7.2,<4.0.0",
"maintainer_email": "",
"keywords": "",
"author": "Eugene Shevchenko",
"author_email": "evgeny.shevchenko@flant.com",
"download_url": "https://files.pythonhosted.org/packages/9f/c6/f74268f7fbfbf817864f6f86eae486c6c44bbe410e75f505aef34104cd79/deckhouse_sdk-0.4.3.tar.gz",
"platform": null,
"description": "# Deckhouse module SDK\n\nDeckhouse module SDK simplifies writing module hooks for operators:\n\n- [Deckhouse](https://github.com/deckhouse/deckhouse)\n- [Addon Operator](https://github.com/flant/addon-operator)\n- [Shell Operator](https://github.com/flant/shell-operator) (values are unaccessable)\n\n**NOTE**:\n- The API is in alpha stage\n\n\n## Install\n\n```bash\npip install deckhouse-sdk\n```\n\n## Sample hook\n\n```python\n# hello.py\nfrom deckhouse_sdk import hook\n\ndef main(ctx: hook.Context):\n # Manipulate kubernetes state\n # ... object = { \"kind\" : \"Pod\", \"apiVersion\" : \"v1\", ... }\n ctx.kubernetes.create_or_update(object)\n\n # Export metrics\n # ... metric = { \"name\" : \"power\", \"group\": \"my_hook\", \"set\" : 9000, ... }\n ctx.metrics.collect(metric)\n\n # Use in-memory values for helm chart. Shell Operator does not support values, but Addon Operator and Deckhouse do.\n ctx.values.myModule.deployment.replicas = 5\n\n\nif __name__ == \"__main__\":\n hook.run(main, configpath=\"hello.yaml\") # 'config' arg is also supported for raw string\n```\n\n```yaml\n# hello.yaml\nconfigVersion: v1\nonStartup: 10\n```\n\n## How to test\n\nAn example for pytest\n\n```python\n# hello_test.py\n\nfrom hello import main\nfrom deckhouse_sdk import hook\n\n# Inputs\n# initial_values = { ... }\n# binding_context = [ { ... } ]\n# Outputs\n# expected_metrics = [ ... ]\n# expected_kube_operations = [ ... ]\n# expected_values_patches = [ ... ]\n# expected_values = { ... }\n\ndef test_hello():\n out = hook.testrun(main, binding_context, initial_values)\n\n assert out.metrics.data == expected_metrics\n assert out.kube_operations.data == expected_kube_operations\n assert out.values_patches.data == expected_values_patches\n\n assert out.values.myModule.deployment.repicas == 5\n```\n",
"bugtrack_url": null,
"license": "Apache-2.0",
"summary": "Python SDK for Shell Operator hooks",
"version": "0.4.3",
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "6cc712b2cbf56873af06b3c84b67a46653cb1f7aef09a66ba04f5327dcab9c3a",
"md5": "83f082ab5b32cbbdc6ab18f95cad4f15",
"sha256": "fddc458440627e24a0ea3370030da480a824930937c14e740e830dba1dae49c1"
},
"downloads": -1,
"filename": "deckhouse_sdk-0.4.3-py3-none-any.whl",
"has_sig": false,
"md5_digest": "83f082ab5b32cbbdc6ab18f95cad4f15",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.7.2,<4.0.0",
"size": 13714,
"upload_time": "2023-02-02T14:51:23",
"upload_time_iso_8601": "2023-02-02T14:51:23.187767Z",
"url": "https://files.pythonhosted.org/packages/6c/c7/12b2cbf56873af06b3c84b67a46653cb1f7aef09a66ba04f5327dcab9c3a/deckhouse_sdk-0.4.3-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "9fc6f74268f7fbfbf817864f6f86eae486c6c44bbe410e75f505aef34104cd79",
"md5": "4ffb3d58aaf96e14c1e7c1228b28cd19",
"sha256": "d598b741a7a77e83b33bd7871151a467ac753e1316ae44cf15d283dbfab4c76b"
},
"downloads": -1,
"filename": "deckhouse_sdk-0.4.3.tar.gz",
"has_sig": false,
"md5_digest": "4ffb3d58aaf96e14c1e7c1228b28cd19",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.7.2,<4.0.0",
"size": 11705,
"upload_time": "2023-02-02T14:51:25",
"upload_time_iso_8601": "2023-02-02T14:51:25.822456Z",
"url": "https://files.pythonhosted.org/packages/9f/c6/f74268f7fbfbf817864f6f86eae486c6c44bbe410e75f505aef34104cd79/deckhouse_sdk-0.4.3.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-02-02 14:51:25",
"github": false,
"gitlab": false,
"bitbucket": false,
"lcname": "deckhouse-sdk"
}