diff --git a/doc/docs/coding.md b/doc/docs/coding.md index a1e00de..d039527 100644 --- a/doc/docs/coding.md +++ b/doc/docs/coding.md @@ -35,14 +35,6 @@ The `generator` package is where object struct are defined, and where the `Gener The generation is made by using a `HelmChart` object: ```golang -chart := NewChart(appName string) -``` - -Then, some processes are made to detect the "main app verion" (tag for the main service image), bootstrapping declared -ports in labels, managing links to bind containers in one pods... - -Then, a loop basically makes this: - ```golang for _, service := range project.Services { dep := NewDeployment(service) @@ -52,7 +44,6 @@ for _, service := range project.Services { Servicename: service.Name, } } -``` **A lot** of string manipulations are made by each `Yaml()` methods. This is where you find the complex and impacting operations. The `Yaml` methods **don't return a valid YAML content**. This is a Helm Chart Yaml content with template diff --git a/doc/docs/index.md b/doc/docs/index.md index 70acac9..4d02118 100644 --- a/doc/docs/index.md +++ b/doc/docs/index.md @@ -42,9 +42,7 @@ that is in your `PATH`. If you are a Linux user, you can use the "one line installation command" which will download the binary in your `$HOME/.local/bin` directory if it exists. -```bash sh <(curl -sSL https://raw.githubusercontent.com/metal3d/katenary/master/install.sh) -``` !!! Info "Upgrading is integrated to the `katenary` command" Katenary propose a `upgrade` subcommand to update the current binary to the latest stable release. @@ -61,21 +59,17 @@ sh <(curl -sSL https://raw.githubusercontent.com/metal3d/katenary/master/install But, note that the "master" branch is not the "stable" version. It's preferable to switch to a tag, or to use the releases. -```bash git clone https://github.com/metal3d/katenary.git cd katenary make build make install -``` `make install` copies `./katenary` binary to your user binary path (`~/.local/bin`) You can install it in other directory by changing the `PREFIX` variable. E.g.: -```bash make build sudo make install PREFIX=/usr/local -``` Check if everything is OK using `katenary version` and / or `katenary help` @@ -84,10 +78,8 @@ Check if everything is OK using `katenary version` and / or `katenary help` Katenary uses the very nice project named `cobra` to manage flags, argument and auto-completion. You can activate it with: -```bash # replace "bash" by "zsh" if needed source <(katenary completion bash) -``` Add this line in you `~/.profile` or `~/.bashrc` file to have completion at startup. diff --git a/doc/docs/packages/generator.md b/doc/docs/packages/generator.md index 82f9db8..fb824ec 100644 --- a/doc/docs/packages/generator.md +++ b/doc/docs/packages/generator.md @@ -6,7 +6,7 @@ import "katenary/generator" ``` -The generator package generates kubernetes objects from a compose file and transforms them into a helm chart. +The generator package generates kubernetes objects from a "compose" file and transforms them into a helm chart. The generator package is the core of katenary. It is responsible for generating kubernetes objects from a compose file and transforming them into a helm chart. Convertion manipulates Yaml representation of kubernetes object to add conditions, labels, annotations, etc. to the objects. It also create the values to be set to the values.yaml file. @@ -14,8 +14,6 @@ The generate.Convert\(\) create an HelmChart object and call "Generate\(\)" meth If you want to change or override the write behavior, you can use the HelmChart.Generate\(\) function and implement your own write function. This function returns the helm chart object containing all kubernetes objects and helm chart ingormation. It does not write the helm chart to the disk. -TODO: Manage cronjob \+ rbac TODO: create note.txt TODO: manage emptyDirs - ## Constants diff --git a/doc/docs/statics/icon.svg b/doc/docs/statics/icon.svg new file mode 100644 index 0000000..ca35f25 --- /dev/null +++ b/doc/docs/statics/icon.svg @@ -0,0 +1,121 @@ + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/doc/docs/statics/logo-bright.svg b/doc/docs/statics/logo-bright.svg index f1ef1ff..eb6da22 100644 --- a/doc/docs/statics/logo-bright.svg +++ b/doc/docs/statics/logo-bright.svg @@ -1,35 +1,121 @@ - - + xmlns:svg="http://www.w3.org/2000/svg" + xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" + xmlns:cc="http://creativecommons.org/ns#" + xmlns:dc="http://purl.org/dc/elements/1.1/"> + + + + image/svg+xml + + + + + id="defs211952" /> + + + + + + + + + + id="logo-group" + transform="translate(-331.21094,-211.65039)"> + d="m 773.83594,234.02344 c -0.4545,0.0375 -0.92821,0.1629 -1.40821,0.3789 -1.91999,0.864 -2.68851,2.68743 -1.72851,4.60743 l 21.4082,44.35351 0.0957,0.0957 -9.5996,21.02344 c -0.96,2.112 -0.28778,3.74342 1.82421,4.60742 0.576,0.288 1.15252,0.38477 1.72852,0.38477 1.248,0 2.2072,-0.76703 2.7832,-2.20703 l 31.10352,-68.35352 c 0.96,-2.112 0.28778,-3.64772 -1.82422,-4.51172 -2.112,-0.864 -3.64742,-0.28748 -4.60742,1.72852 l -17.85547,39.35937 -18.7207,-39.45507 c -0.648,-1.44 -1.83572,-2.12422 -3.19922,-2.01172 z" + style="font-size:96px;line-height:0;font-family:Comfortaa;-inkscape-font-specification:Comfortaa;fill:#ff7f2a;stroke-width:51.0236;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:0" + id="path9" /> + d="m 692.07617,233.63477 c -15.26398,0 -26.68945,11.51921 -26.68945,26.7832 0,15.26398 11.13594,26.68945 25.91992,26.68945 8.44799,0 15.64875,-3.84038 19.96875,-9.98437 v 5.85547 c 0,2.11199 1.53614,3.64843 3.74414,3.64843 2.112,0 3.74414,-1.53644 3.74414,-3.64843 v -22.56055 c -0.096,-15.26399 -11.51951,-26.7832 -26.6875,-26.7832 z m 0,6.7207 c 11.03999,0 19.39063,8.63851 19.39063,20.0625 0,11.42399 -8.35064,19.96875 -19.39063,19.96875 -11.03999,0 -19.48828,-8.54476 -19.48828,-19.96875 0,-11.42399 8.44829,-20.0625 19.48828,-20.0625 z" + style="font-size:96px;line-height:0;font-family:Comfortaa;-inkscape-font-specification:Comfortaa;fill:#ff7f2a;stroke-width:51.0236;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:0" + id="path8" /> + d="m 566.60352,233.63477 c -14.78399,0 -25.15235,11.13521 -25.15235,26.7832 0,15.64798 11.03981,26.68945 26.5918,26.68945 5.95199,0 13.24866,-2.59224 17.47265,-6.24023 1.536,-1.344 1.4406,-3.36079 -0.1914,-4.80078 -1.344,-1.056 -3.26508,-0.9606 -4.70508,0.1914 -2.784,2.4 -7.96818,4.22461 -12.57617,4.22461 -10.65599,0 -18.52799,-7.20007 -19.58399,-17.66406 h 38.78516 c 2.016,0 3.45508,-1.34338 3.45508,-3.35938 0,-15.07198 -9.59972,-25.82421 -24.0957,-25.82421 z m 0,6.62304 c 9.69599,0 16.22359,6.72003 17.18359,16.41602 h -35.13477 c 1.344,-9.69599 8.15919,-16.41602 17.95118,-16.41602 z" + style="font-size:96px;line-height:0;font-family:Comfortaa;-inkscape-font-specification:Comfortaa;fill:#ff7f2a;stroke-width:51.0236;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:0" + id="path7" /> + + + + + + + diff --git a/doc/docs/statics/logo-dark.svg b/doc/docs/statics/logo-dark.svg index 7f3ffa0..eb6da22 100644 --- a/doc/docs/statics/logo-dark.svg +++ b/doc/docs/statics/logo-dark.svg @@ -1,35 +1,121 @@ - - + xmlns:svg="http://www.w3.org/2000/svg" + xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" + xmlns:cc="http://creativecommons.org/ns#" + xmlns:dc="http://purl.org/dc/elements/1.1/"> + + + + image/svg+xml + + + + + id="defs211952" /> + + + + + + + + + + id="logo-group" + transform="translate(-331.21094,-211.65039)"> + d="m 773.83594,234.02344 c -0.4545,0.0375 -0.92821,0.1629 -1.40821,0.3789 -1.91999,0.864 -2.68851,2.68743 -1.72851,4.60743 l 21.4082,44.35351 0.0957,0.0957 -9.5996,21.02344 c -0.96,2.112 -0.28778,3.74342 1.82421,4.60742 0.576,0.288 1.15252,0.38477 1.72852,0.38477 1.248,0 2.2072,-0.76703 2.7832,-2.20703 l 31.10352,-68.35352 c 0.96,-2.112 0.28778,-3.64772 -1.82422,-4.51172 -2.112,-0.864 -3.64742,-0.28748 -4.60742,1.72852 l -17.85547,39.35937 -18.7207,-39.45507 c -0.648,-1.44 -1.83572,-2.12422 -3.19922,-2.01172 z" + style="font-size:96px;line-height:0;font-family:Comfortaa;-inkscape-font-specification:Comfortaa;fill:#ff7f2a;stroke-width:51.0236;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:0" + id="path9" /> + d="m 692.07617,233.63477 c -15.26398,0 -26.68945,11.51921 -26.68945,26.7832 0,15.26398 11.13594,26.68945 25.91992,26.68945 8.44799,0 15.64875,-3.84038 19.96875,-9.98437 v 5.85547 c 0,2.11199 1.53614,3.64843 3.74414,3.64843 2.112,0 3.74414,-1.53644 3.74414,-3.64843 v -22.56055 c -0.096,-15.26399 -11.51951,-26.7832 -26.6875,-26.7832 z m 0,6.7207 c 11.03999,0 19.39063,8.63851 19.39063,20.0625 0,11.42399 -8.35064,19.96875 -19.39063,19.96875 -11.03999,0 -19.48828,-8.54476 -19.48828,-19.96875 0,-11.42399 8.44829,-20.0625 19.48828,-20.0625 z" + style="font-size:96px;line-height:0;font-family:Comfortaa;-inkscape-font-specification:Comfortaa;fill:#ff7f2a;stroke-width:51.0236;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:0" + id="path8" /> + d="m 566.60352,233.63477 c -14.78399,0 -25.15235,11.13521 -25.15235,26.7832 0,15.64798 11.03981,26.68945 26.5918,26.68945 5.95199,0 13.24866,-2.59224 17.47265,-6.24023 1.536,-1.344 1.4406,-3.36079 -0.1914,-4.80078 -1.344,-1.056 -3.26508,-0.9606 -4.70508,0.1914 -2.784,2.4 -7.96818,4.22461 -12.57617,4.22461 -10.65599,0 -18.52799,-7.20007 -19.58399,-17.66406 h 38.78516 c 2.016,0 3.45508,-1.34338 3.45508,-3.35938 0,-15.07198 -9.59972,-25.82421 -24.0957,-25.82421 z m 0,6.62304 c 9.69599,0 16.22359,6.72003 17.18359,16.41602 h -35.13477 c 1.344,-9.69599 8.15919,-16.41602 17.95118,-16.41602 z" + style="font-size:96px;line-height:0;font-family:Comfortaa;-inkscape-font-specification:Comfortaa;fill:#ff7f2a;stroke-width:51.0236;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:0" + id="path7" /> + + + + + + + diff --git a/doc/docs/usage.md b/doc/docs/usage.md index 715d5f5..1808bdb 100644 --- a/doc/docs/usage.md +++ b/doc/docs/usage.md @@ -58,9 +58,7 @@ For more complete label usage, see [the labels page](labels.md). After having installed `katenary`, the standard usage is to call: -```bash katenary convert -``` It will search standard compose files in the current directory and try to create a helm chart in "chart" directory. @@ -71,9 +69,7 @@ It will search standard compose files in the current directory and try to create Of course, you can provide others files than the default with (cummulative) `-c` options: -```bash katenary convert -c file1.yaml -c file2.yaml -``` ## Some common labels to use @@ -90,7 +86,6 @@ to make you able to wait for a service to respond. But you'll probably need to a See this compose file: -```yaml version: "3" services: @@ -103,14 +98,12 @@ services: image: mariadb environment: MYSQL_ROOT_PASSWORD: foobar -``` In this case, `webapp` needs to know the `database` port because the `depends_on` points on it and Kubernetes has not (yet) solution to check the database startup. Katenary wants to create a `initContainer` to hit on the related service. So, instead of exposing the port in the compose definition, let's declare this to katenary with labels: -```yaml version: "3" services: @@ -126,14 +119,12 @@ services: labels: katenary.v3/ports: |- - 3306 -``` ### Declare ingresses It's very common to have an `Ingress` on web application to deploy on Kuberenetes. The `katenary.io/ingress` declare the port to bind. -```yaml # ... services: webapp: @@ -143,7 +134,6 @@ services: katenary.v3/ingress: |- port: 5050 hostname: myapp.example.com -``` Note that the port to bind is the one used by the container, not the used locally. This is because Katenary create a service to bind the container itself. @@ -156,7 +146,6 @@ example, to connect a PHP application to a database. With a compose file, there is no problem as Docker/Podman allows to resolve the name by container name: -```yaml services: webapp: image: php:7-apache @@ -165,13 +154,11 @@ services: database: image: mariadb -``` Katenary prefixes the services with `{{ .Release.Name }}` (to make it possible to install the application several times in a namespace), so you need to "remap" the environment variable to the right one. -```yaml services: webapp: image: php:7-apache @@ -183,13 +170,11 @@ services: database: image: mariadb -``` This label can be used to map others environment for any others reason. E.g. to change an informational environment variable. -```yaml services: webapp: @@ -199,7 +184,6 @@ services: labels: katenary.v3/mapenv: |- RUNNING: kubernetes -``` In the above example, `RUNNING` will be set to `kubernetes` when you'll deploy the application with helm, and it's `docker` for "podman" and "docker" executions. diff --git a/doc/fix.py b/doc/fix.py new file mode 100644 index 0000000..d9f6b84 --- /dev/null +++ b/doc/fix.py @@ -0,0 +1,48 @@ +""" Fix the markdown files to replace code blocs by lists when the code blocs are lists.""" + +import re +import sys +from typing import Tuple + +# get markdown bloc code +re_code = re.compile(r"```(.*?)```", re.DOTALL) + + +def fix(text: str) -> Tuple[str, bool]: + """Fix the markdown text to replace code blocs by lists when the code blocs are lists.""" + # in the text, get the code blocs + code_blocs = re_code.findall(text) + # for each code bloc, if lines begin by a "-", this is a list. So, + # make it a mkdocs list and remove the block code + fixed = False + for code in code_blocs: + lines = code.split("\n") + lines = [line.strip() for line in lines if line.strip()] + if all(line.startswith("-") for line in lines): + fixed = True + # make a mkdocs list + lines = [f"- {line[1:]}" for line in lines] + # replace the code bloc by the list + text = text.replace(f"```{code}```", "\n".join(lines)) + return text, fixed + + +def main(filename: str): + """Fix and rewrite the markdown file.""" + with open(filename, "r", encoding="utf-8") as f: + text = f.read() + content, fixed = fix(text) + + if not fixed: + return + + with open(sys.argv[1], "w", encoding="utf-8") as f: + f.write(content) + + +if __name__ == "__main__": + if len(sys.argv) != 2: + print("Usage: python fix.py ") + sys.exit(1) + + main(sys.argv[1]) diff --git a/doc/mkdocs.yml b/doc/mkdocs.yml index 3c7a813..475c4a5 100644 --- a/doc/mkdocs.yml +++ b/doc/mkdocs.yml @@ -3,7 +3,8 @@ docs_dir: ./docs theme: name: material custom_dir: overrides - logo: statics/logo-dark.svg + logo: statics/logo-bright.svg + favicon: statics/icon.svg palette: - scheme: slate toggle: @@ -28,7 +29,7 @@ extra_css: - statics/main.css extra_javascript: - statics/addons.js -copyright: Copyright © 2021 - 2023 - Katenary authors +copyright: Copyright © 2021 - 2024 - Katenary authors extra: generator: false social: diff --git a/generator/doc.go b/generator/doc.go index 095c2e7..333ac56 100644 --- a/generator/doc.go +++ b/generator/doc.go @@ -1,5 +1,5 @@ /* -The generator package generates kubernetes objects from a compose file and transforms them into a helm chart. +The generator package generates kubernetes objects from a "compose" file and transforms them into a helm chart. The generator package is the core of katenary. It is responsible for generating kubernetes objects from a compose file and transforming them into a helm chart. Convertion manipulates Yaml representation of kubernetes object to add conditions, labels, annotations, etc. to the objects. It also create the values to be set to @@ -10,9 +10,5 @@ It saves the helm chart in the given directory. If you want to change or override the write behavior, you can use the HelmChart.Generate() function and implement your own write function. This function returns the helm chart object containing all kubernetes objects and helm chart ingormation. It does not write the helm chart to the disk. - -TODO: Manage cronjob + rbac -TODO: create note.txt -TODO: manage emptyDirs */ package generator