deckhouse


Namedeckhouse JSON
Version 0.4.9 PyPI version JSON
download
home_page
SummaryWrapper for hooks for Deckhouse, Addon Operator, and Shell Operator by Flant
upload_time2023-10-02 14:27:50
maintainer
docs_urlNone
authorEugene Shevchenko
requires_python>=3.8,<4.0
licenseApache-2.0
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Deckhouse python library

Simplifies writing module hooks for Kubernetes 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 unaccessible)

**NOTE**:
- The API is in alpha stage


## Install

```bash
pip install deckhouse
```

## Sample hook

```python
# 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
```

```yaml
# hello.yaml
configVersion: v1
onStartup: 10
```

## How to test

An example for pytest

```python
# 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](https://python-poetry.org/docs/#installation)
- `poetry install`
- `make test`


            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "deckhouse",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8,<4.0",
    "maintainer_email": "",
    "keywords": "",
    "author": "Eugene Shevchenko",
    "author_email": "evgeny.shevchenko@flant.com",
    "download_url": "https://files.pythonhosted.org/packages/0e/36/105b7abaadb2925bbf62045ec318eaa4e5735c8db97bda8f564ae14be21a/deckhouse-0.4.9.tar.gz",
    "platform": null,
    "description": "# Deckhouse python library\n\nSimplifies writing module hooks for Kubernetes 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 unaccessible)\n\n**NOTE**:\n- The API is in alpha stage\n\n\n## Install\n\n```bash\npip install deckhouse\n```\n\n## Sample hook\n\n```python\n# hello.py\nfrom deckhouse 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 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.replicas == 5\n```\n\n## Development\n\n- Create virtual environment with python >= 3.8\n- [Install poetry](https://python-poetry.org/docs/#installation)\n- `poetry install`\n- `make test`\n\n",
    "bugtrack_url": null,
    "license": "Apache-2.0",
    "summary": "Wrapper for hooks for Deckhouse, Addon Operator, and Shell Operator by Flant",
    "version": "0.4.9",
    "project_urls": null,
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "cae8fa1086ce7bbea1f9346fe79513f65d69b83f804c580ce0435cfe0f9811c9",
                "md5": "2a6ab64f88d1e9b50ada0398b8205a67",
                "sha256": "f9a70e44810ea3c30821c2ece498ba4743dd6495b09e3b7a2e7bc98fb16ef3c6"
            },
            "downloads": -1,
            "filename": "deckhouse-0.4.9-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "2a6ab64f88d1e9b50ada0398b8205a67",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8,<4.0",
            "size": 13767,
            "upload_time": "2023-10-02T14:27:48",
            "upload_time_iso_8601": "2023-10-02T14:27:48.682853Z",
            "url": "https://files.pythonhosted.org/packages/ca/e8/fa1086ce7bbea1f9346fe79513f65d69b83f804c580ce0435cfe0f9811c9/deckhouse-0.4.9-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "0e36105b7abaadb2925bbf62045ec318eaa4e5735c8db97bda8f564ae14be21a",
                "md5": "58ed99e8a855be516b858bf3a62efdb0",
                "sha256": "99d00de3dff40ea3fde2b3b9da1b1e73e24ad5f5642ed1f14161d5b721e92d7d"
            },
            "downloads": -1,
            "filename": "deckhouse-0.4.9.tar.gz",
            "has_sig": false,
            "md5_digest": "58ed99e8a855be516b858bf3a62efdb0",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8,<4.0",
            "size": 11297,
            "upload_time": "2023-10-02T14:27:50",
            "upload_time_iso_8601": "2023-10-02T14:27:50.237946Z",
            "url": "https://files.pythonhosted.org/packages/0e/36/105b7abaadb2925bbf62045ec318eaa4e5735c8db97bda8f564ae14be21a/deckhouse-0.4.9.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-10-02 14:27:50",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "deckhouse"
}
        
Elapsed time: 0.11664s