# Kubernator
Kubernator™ (Ktor™) is an integrated solution for the Kubernetes state management. It operates on directories,
processing their content via a collection of plugins, generating Kubernetes resources in the process, validating them,
transforming them and then applying against the Kubernetes cluster.
[![Gitter](https://img.shields.io/gitter/room/karellen/lobby?logo=gitter)](https://gitter.im/karellen/Lobby)
[![Build Status](https://img.shields.io/github/actions/workflow/status/karellen/kubernator/kubernator.yml?branch=master)](https://github.com/karellen/kubernator/actions/workflows/kubernator.yml)
[![Coverage Status](https://img.shields.io/coveralls/github/karellen/kubernator/master?logo=coveralls)](https://coveralls.io/r/karellen/kubernator?branch=master)
[![Kubernator Version](https://img.shields.io/pypi/v/kubernator?logo=pypi)](https://pypi.org/project/kubernator/)
[![Kubernator Python Versions](https://img.shields.io/pypi/pyversions/kubernator?logo=pypi)](https://pypi.org/project/kubernator/)
[![Kubernator Downloads Per Day](https://img.shields.io/pypi/dd/kubernator?logo=pypi)](https://pypi.org/project/kubernator/)
[![Kubernator Downloads Per Week](https://img.shields.io/pypi/dw/kubernator?logo=pypi)](https://pypi.org/project/kubernator/)
[![Kubernator Downloads Per Month](https://img.shields.io/pypi/dm/kubernator?logo=pypi)](https://pypi.org/project/kubernator/)
## Notices
### Beta Software
While fully functional in the current state and used in production, this software is in **BETA**. A lot of things
are expected to change rapidly, including main APIs, initialization procedures and some core features. Documentation at
this stage is basically non-existent.
### License
The product is licensed under the Apache License, Version 2.0. Please see LICENSE for further details.
### Warranties and Liability
Kubernator and its plugins are provided on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT,
MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of
using or redistributing Kubernator and assume any risks associated with doing so.
### Trademarks
"Kubernator" and "Ktor" are trademarks or registered trademarks of Express Systems USA, Inc and Karellen, Inc. All other
trademarks are property of their respective owners.
## Problem Statement
## Solution
## Using Kubernator with Docker
A simple example is as follows:
```
$ docker run --mount type=bind,source="$(pwd)",target=/root,readonly -t ghcr.io/karellen/kubernator:latest
```
## Using Kubernator on MacOS
```
$ brew install python3.11
$ pip3.11 install 'kubernator~=1.0.9'
$ kubernator --version
```
Please note, that some plugins (e.g. `awscli`, `eks`) may require additional volume mounts or environmental
variables to be passed for credentials and other external configuration.
## Mode of Operation
Kubernator is a command line utility. Upon startup and processing of the command line arguments and initializing
logging, Kubernator initializes plugins. Current plugins include:
0. Kubernator App
1. Terraform
2. kOps
3. Kubernetes
4. Helm
5. Template
The order of initialization matters as it's the order the plugin handlers are executed!
The entire application operates in the following stages by invoking each plugin's stage handler in sequence:
1. Plugin Init Stage
2. Pre-start script (if specified)
3. Plugin Start Stage
4. For each directory in the pipeline:
1. Plugin Before Directory Stage
2. If `.kubernator.py` is present in the directory:
1. Plugin Before Script Stage
2. `.kubernator.py` script
3. Plugin After Script Stage
3. Plugin After Directory Stage
5. Plugin End Stage
Each plugin individually plays a specific role and performs a specific function which will be described in a later
section.
## State/Context
There is a global state that is carried through as the application is running. It is a hierarchy of objects (`context`)
that follows the parent-child relationship as the application traverses the directory structure. For example, given the
directory structure `/a/b`, `/a/c`, and `/a/c/d` any value of the context set or modified in context scoped to
directory `/a` is visible in directories `/a/b`, `/a/c` and `/a/c/d`, while the same modified or set in `/a/b` is only
visible there, while one in `/a/c` is visible in `/a/c` and in `/a/c/d` but not `/a` or `/a/b`.
Additionally, there is a `context.globals` which is the top-most context that is available in all stages that are not
associated with the directory structure.
Note, that in cases where the directory structure traversal moves to remote directories (that are actualized by local
temporary directories), such remote directory structure enters the context hierarchy as a child of the directory in
which remote was registered.
Also note, that context carries not just data by references to essential functions.
In pre-start and `.kubernator.py` scripts the context is fully available as a global variable `ktor`.
### Plugins
#### Kubernator App Plugin
The role of the Kubernator App Plugin is to traverse the directory structure, expose essential functions through context
and to run Kubernator scripts.
In the *After Directory Stage* Kubernator app scans the directories immediately available in the current, sorts them in
the alphabetic order, excludes those matching any of the patterns in `context.app.excludes` and then queues up the
remaining directories in the order the match the patterns in `context.app.includes`.
Thus, for a directory content `/a/foo`, `/a/bal`, `/a/bar`, `/a/baz`, excludes `f*`, and includes `baz` and `*`, the
resulting queue of directories to traverse will be `/a/baz`, `/a/bal`, `/a/bar`.
Notice, that user can further interfere with processing order of the directory queue by asking Kubernator to walk
arbitrary paths, both local and remote.
##### Context
* `ktor.app.args`
> Namespace containing command line argument values
* `ktor.app.walk_local(*paths: Union[Path, str, bytes])`
> Immediately schedules the paths to be traversed after the current directory by adding them to the queue
> Relative path is relative to the current directory
* `ktor.app.walk_remote(repo, *path_prefixes: Union[Path, str, bytes])`
> Immediately schedules the path prefixes under the remote repo URL to be traversed after the current directory by
> adding them to the queue. Only Git URLs are currently supported.
> All absolute path prefixes are relativized based on the repository.
* `ktor.app.repository_credentials_provider(func: Callable)`
> Sets a repository credentials provider function `func` that sets/overwrites credentials for URLs being specified by
> `walk_remote`. The callable `func` accepts a single argument containing a parsed URL in a form of tuple. The `func`
> is expected to return a tuple of three elements representing URL schema, username and password. If the value should
> not be changed it should be None. To convert from `git://repo.com/hello` to HTTPS authentication one should write
> a function returning `("https", "username", "password")`. The best utility is achieved by logic that allows running
> the plan both in CI and local environments using different authentication mechanics in different environments.
#### Terraform
This is exclusively designed to pull the configuration options out of Terraform and to allow scripts and plugins to
utilize that data.
##### Context
* `ktor.tf`
> A dictionary containing the values from Terraform output
#### Kops
##### Context
#### Kubernetes
##### Context
#### Helm
##### Context
#### Templates
##### Context
## Examples
### Adding Remote Directory
```python
ktor.app.repository_credentials_provider(lambda r: ("ssh", "git", None))
ktor.app.walk_remote("git://repo.example.com/org/project?ref=dev", "/project")
```
### Adding Local Directory
```python
ktor.app.walk_local("/home/username/local-dir")
```
### Using Transformers
```python
def remove_replicas(resources, r: "K8SResource"):
if (r.group == "apps" and r.kind in ("StatefulSet", "Deployment")
and "replicas" in r.manifest["spec"]):
logger.warning("Resource %s in %s contains `replica` specification that will be removed. Use HPA!!!",
r, r.source)
del r.manifest["spec"]["replicas"]
ktor.k8s.add_transformer(remove_replicas)
```
Raw data
{
"_id": null,
"home_page": "https://github.com/karellen/kubernator",
"name": "kubernator",
"maintainer": "Karellen, Inc., Arcadiy Ivanov",
"docs_url": null,
"requires_python": ">=3.9",
"maintainer_email": "supervisor@karellen.co,arcadiy@karellen.co",
"keywords": "kubernetes k8s kube top provisioning kOps terraform tf AWS",
"author": "Express Systems USA, Inc.",
"author_email": null,
"download_url": "https://files.pythonhosted.org/packages/2d/19/b97015957779ada260b596415fb354e3fc409b60416e757066e5ae0805d8/kubernator-1.0.17.tar.gz",
"platform": null,
"description": "# Kubernator\n\nKubernator\u2122 (Ktor\u2122) is an integrated solution for the Kubernetes state management. It operates on directories,\nprocessing their content via a collection of plugins, generating Kubernetes resources in the process, validating them,\ntransforming them and then applying against the Kubernetes cluster.\n\n[![Gitter](https://img.shields.io/gitter/room/karellen/lobby?logo=gitter)](https://gitter.im/karellen/Lobby)\n[![Build Status](https://img.shields.io/github/actions/workflow/status/karellen/kubernator/kubernator.yml?branch=master)](https://github.com/karellen/kubernator/actions/workflows/kubernator.yml)\n[![Coverage Status](https://img.shields.io/coveralls/github/karellen/kubernator/master?logo=coveralls)](https://coveralls.io/r/karellen/kubernator?branch=master)\n\n[![Kubernator Version](https://img.shields.io/pypi/v/kubernator?logo=pypi)](https://pypi.org/project/kubernator/)\n[![Kubernator Python Versions](https://img.shields.io/pypi/pyversions/kubernator?logo=pypi)](https://pypi.org/project/kubernator/)\n[![Kubernator Downloads Per Day](https://img.shields.io/pypi/dd/kubernator?logo=pypi)](https://pypi.org/project/kubernator/)\n[![Kubernator Downloads Per Week](https://img.shields.io/pypi/dw/kubernator?logo=pypi)](https://pypi.org/project/kubernator/)\n[![Kubernator Downloads Per Month](https://img.shields.io/pypi/dm/kubernator?logo=pypi)](https://pypi.org/project/kubernator/)\n\n## Notices\n\n### Beta Software\n\nWhile fully functional in the current state and used in production, this software is in **BETA**. A lot of things\nare expected to change rapidly, including main APIs, initialization procedures and some core features. Documentation at\nthis stage is basically non-existent.\n\n### License\n\nThe product is licensed under the Apache License, Version 2.0. Please see LICENSE for further details.\n\n### Warranties and Liability\n\nKubernator and its plugins are provided on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either\nexpress or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT,\nMERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of\nusing or redistributing Kubernator and assume any risks associated with doing so.\n\n### Trademarks\n\n\"Kubernator\" and \"Ktor\" are trademarks or registered trademarks of Express Systems USA, Inc and Karellen, Inc. All other\ntrademarks are property of their respective owners.\n\n## Problem Statement\n\n## Solution\n\n## Using Kubernator with Docker\n\nA simple example is as follows:\n```\n$ docker run --mount type=bind,source=\"$(pwd)\",target=/root,readonly -t ghcr.io/karellen/kubernator:latest\n```\n\n## Using Kubernator on MacOS\n\n```\n$ brew install python3.11\n$ pip3.11 install 'kubernator~=1.0.9'\n$ kubernator --version\n```\n\nPlease note, that some plugins (e.g. `awscli`, `eks`) may require additional volume mounts or environmental\nvariables to be passed for credentials and other external configuration.\n\n## Mode of Operation\n\nKubernator is a command line utility. Upon startup and processing of the command line arguments and initializing\nlogging, Kubernator initializes plugins. Current plugins include:\n\n0. Kubernator App\n1. Terraform\n2. kOps\n3. Kubernetes\n4. Helm\n5. Template\n\nThe order of initialization matters as it's the order the plugin handlers are executed!\n\nThe entire application operates in the following stages by invoking each plugin's stage handler in sequence:\n\n1. Plugin Init Stage\n2. Pre-start script (if specified)\n3. Plugin Start Stage\n4. For each directory in the pipeline:\n 1. Plugin Before Directory Stage\n 2. If `.kubernator.py` is present in the directory:\n 1. Plugin Before Script Stage\n 2. `.kubernator.py` script\n 3. Plugin After Script Stage\n 3. Plugin After Directory Stage\n5. Plugin End Stage\n\nEach plugin individually plays a specific role and performs a specific function which will be described in a later\nsection.\n\n## State/Context\n\nThere is a global state that is carried through as the application is running. It is a hierarchy of objects (`context`)\nthat follows the parent-child relationship as the application traverses the directory structure. For example, given the\ndirectory structure `/a/b`, `/a/c`, and `/a/c/d` any value of the context set or modified in context scoped to\ndirectory `/a` is visible in directories `/a/b`, `/a/c` and `/a/c/d`, while the same modified or set in `/a/b` is only\nvisible there, while one in `/a/c` is visible in `/a/c` and in `/a/c/d` but not `/a` or `/a/b`.\n\nAdditionally, there is a `context.globals` which is the top-most context that is available in all stages that are not\nassociated with the directory structure.\n\nNote, that in cases where the directory structure traversal moves to remote directories (that are actualized by local\ntemporary directories), such remote directory structure enters the context hierarchy as a child of the directory in\nwhich remote was registered.\n\nAlso note, that context carries not just data by references to essential functions.\n\nIn pre-start and `.kubernator.py` scripts the context is fully available as a global variable `ktor`.\n\n### Plugins\n\n#### Kubernator App Plugin\n\nThe role of the Kubernator App Plugin is to traverse the directory structure, expose essential functions through context\nand to run Kubernator scripts.\n\nIn the *After Directory Stage* Kubernator app scans the directories immediately available in the current, sorts them in\nthe alphabetic order, excludes those matching any of the patterns in `context.app.excludes` and then queues up the\nremaining directories in the order the match the patterns in `context.app.includes`.\n\nThus, for a directory content `/a/foo`, `/a/bal`, `/a/bar`, `/a/baz`, excludes `f*`, and includes `baz` and `*`, the\nresulting queue of directories to traverse will be `/a/baz`, `/a/bal`, `/a/bar`.\n\nNotice, that user can further interfere with processing order of the directory queue by asking Kubernator to walk\narbitrary paths, both local and remote.\n\n##### Context\n\n* `ktor.app.args`\n > Namespace containing command line argument values\n* `ktor.app.walk_local(*paths: Union[Path, str, bytes])`\n > Immediately schedules the paths to be traversed after the current directory by adding them to the queue\n > Relative path is relative to the current directory\n* `ktor.app.walk_remote(repo, *path_prefixes: Union[Path, str, bytes])`\n > Immediately schedules the path prefixes under the remote repo URL to be traversed after the current directory by\n > adding them to the queue. Only Git URLs are currently supported.\n > All absolute path prefixes are relativized based on the repository.\n* `ktor.app.repository_credentials_provider(func: Callable)`\n > Sets a repository credentials provider function `func` that sets/overwrites credentials for URLs being specified by\n > `walk_remote`. The callable `func` accepts a single argument containing a parsed URL in a form of tuple. The `func`\n > is expected to return a tuple of three elements representing URL schema, username and password. If the value should\n > not be changed it should be None. To convert from `git://repo.com/hello` to HTTPS authentication one should write\n > a function returning `(\"https\", \"username\", \"password\")`. The best utility is achieved by logic that allows running\n > the plan both in CI and local environments using different authentication mechanics in different environments.\n\n#### Terraform\n\nThis is exclusively designed to pull the configuration options out of Terraform and to allow scripts and plugins to\nutilize that data.\n\n##### Context\n\n* `ktor.tf`\n > A dictionary containing the values from Terraform output\n\n#### Kops\n\n##### Context\n\n#### Kubernetes\n\n##### Context\n\n#### Helm\n\n##### Context\n\n#### Templates\n\n##### Context\n\n## Examples\n\n### Adding Remote Directory\n\n```python\nktor.app.repository_credentials_provider(lambda r: (\"ssh\", \"git\", None))\nktor.app.walk_remote(\"git://repo.example.com/org/project?ref=dev\", \"/project\")\n```\n\n### Adding Local Directory\n\n```python\nktor.app.walk_local(\"/home/username/local-dir\")\n```\n\n### Using Transformers\n\n```python\ndef remove_replicas(resources, r: \"K8SResource\"):\n if (r.group == \"apps\" and r.kind in (\"StatefulSet\", \"Deployment\")\n and \"replicas\" in r.manifest[\"spec\"]):\n logger.warning(\"Resource %s in %s contains `replica` specification that will be removed. Use HPA!!!\",\n r, r.source)\n del r.manifest[\"spec\"][\"replicas\"]\n\n\nktor.k8s.add_transformer(remove_replicas)\n```\n",
"bugtrack_url": null,
"license": "Apache License, Version 2.0",
"summary": "Kubernator is the a pluggable framework for K8S provisioning",
"version": "1.0.17",
"project_urls": {
"Bug Tracker": "https://github.com/karellen/kubernator/issues",
"Documentation": "https://github.com/karellen/kubernator/",
"Homepage": "https://github.com/karellen/kubernator",
"Source Code": "https://github.com/karellen/kubernator/"
},
"split_keywords": [
"kubernetes",
"k8s",
"kube",
"top",
"provisioning",
"kops",
"terraform",
"tf",
"aws"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "bd422187f4f14999c9de5b4688f352384940ff754f2219404c65e577335618bd",
"md5": "8c7f0c8d01558d98cc949f78ae3e6f6f",
"sha256": "ab995059572a46e26d55238628650d04e6c557e0ae955b36a0cd870cc40908ac"
},
"downloads": -1,
"filename": "kubernator-1.0.17-py3-none-any.whl",
"has_sig": false,
"md5_digest": "8c7f0c8d01558d98cc949f78ae3e6f6f",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.9",
"size": 69119,
"upload_time": "2024-09-13T23:37:58",
"upload_time_iso_8601": "2024-09-13T23:37:58.836167Z",
"url": "https://files.pythonhosted.org/packages/bd/42/2187f4f14999c9de5b4688f352384940ff754f2219404c65e577335618bd/kubernator-1.0.17-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "2d19b97015957779ada260b596415fb354e3fc409b60416e757066e5ae0805d8",
"md5": "8ac102e68fa702b98db4190279caa832",
"sha256": "2dd779400507f038d35480044a7fd70471b4818c815efc1b64f56420ea11a101"
},
"downloads": -1,
"filename": "kubernator-1.0.17.tar.gz",
"has_sig": false,
"md5_digest": "8ac102e68fa702b98db4190279caa832",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.9",
"size": 55284,
"upload_time": "2024-09-13T23:38:00",
"upload_time_iso_8601": "2024-09-13T23:38:00.085244Z",
"url": "https://files.pythonhosted.org/packages/2d/19/b97015957779ada260b596415fb354e3fc409b60416e757066e5ae0805d8/kubernator-1.0.17.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-09-13 23:38:00",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "karellen",
"github_project": "kubernator",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "kubernator"
}