Go to Katenary V3
This is the next-gen of Katenary
This commit is contained in:
72
doc/docs/coding.md
Normal file
72
doc/docs/coding.md
Normal file
@@ -0,0 +1,72 @@
|
||||
# How Katenary works behind the scene
|
||||
|
||||
This section is for developers who want to take part in Katenary. Here we describe how it works and the expected principles.
|
||||
|
||||
## A few important points
|
||||
|
||||
Katenary is developed in Go. The version currently supported is 1.20. For reasons of readability, the `any` type is preferred to `interface{}`.
|
||||
|
||||
Since version v3, Katenary uses, in addition to `go-compose`, the `k8s` library to generate objects that are guaranteed to work before transformation. Katenary adds Helm syntax entries to add loops, transformations and conditions.
|
||||
|
||||
We really try to follow best practices and code principles. But, Katenary needs a lot of workarounds and string manipulation during the process. There are, also, some drawbacks using standard k8s packages that makes a lot of type checks when generating the objects. We need to finalize the values after object generation.
|
||||
|
||||
**This makes the coding a bit harder than simply converting from YAML to YAML.**
|
||||
|
||||
> If Katenary only generated YAML objects, the algorithms would be much simpler and would require less generation work.
|
||||
|
||||
## General principle
|
||||
|
||||
During conversion, the `generator` package is primarily responsible for creating "objects". The principle is to generate one `Deployment` per `compose` service. If the container coming from "compose" exposes ports (explicitly), then a service is created.
|
||||
|
||||
If the declaration of a container is to be integrated into another pod (via the `same-pod` label), this `Deployment` and its associated service are still created. They are deleted last, once the merge has been completed.
|
||||
|
||||
## Conversion in "`generator`" package
|
||||
|
||||
The `generator` package is where object struct are defined, and where the `Generate()` function is written.
|
||||
|
||||
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)
|
||||
y, _ := dep.Yaml()
|
||||
chart.Templates[dep.Filename()] = &ChartTemplate{
|
||||
Content: y,
|
||||
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 conditions, vamues and calls to helper templates.
|
||||
|
||||
> The `Yaml()` methods, in each object, need contribution, help, fixes, enhancements...
|
||||
> They work, but there is a lot of complexity. Please, create issues, pull-requests and conversation in the GitHub repository.
|
||||
|
||||
The final step, before sending all templates to chart, is to bind the containers inside the same pod where it's specified.
|
||||
|
||||
For each source container linked to the destination:
|
||||
|
||||
- we get the deployment of the source
|
||||
- we copy the container to the destination deployment
|
||||
- we get the associated service (if any)
|
||||
- we then copy the service port to the destination service
|
||||
- we finally remove the source service and deployment
|
||||
|
||||
> The configmap, secrets, variables... are kept.
|
||||
|
||||
It finaly computes the `helper` file.
|
||||
|
||||
## Convertion command
|
||||
|
||||
The `generator` works the same as described above. But the "convert" command makes some final steps:
|
||||
|
||||
- generate `values.yaml` and `Chart.yaml` files from the `HelmChart` object
|
||||
- add comments to the `values.yaml` files
|
||||
- add comments to the `Chart.yaml` files
|
15
doc/docs/dependencies.md
Normal file
15
doc/docs/dependencies.md
Normal file
@@ -0,0 +1,15 @@
|
||||
# Why those dependencies?
|
||||
|
||||
Katenary uses `compose-go` and several kubernetes official packages.
|
||||
|
||||
- `github.com/compose-spec/compose-go`: to parse compose files. It ensures that:
|
||||
- the project respects the "compose" specification
|
||||
- katenary uses the "compose" struct exactly the same way that podman-compose or docker does
|
||||
- `github.com/spf13/cobra`: to parse command line arguments, subcommands and flags. It also generates completion for bash, zsh, fish and powershell.
|
||||
- `github.com/thediveo/netdb`: to get the standard names of a service from it's port number
|
||||
- `gopkg.in/yaml.v3`:
|
||||
- to generate `Chart.yaml` and `values.yaml` files (only)
|
||||
- to parse Katenary labels in the compose file
|
||||
- `k8s.io/api` and `k8s.io/apimachinery` to create Kubernetes objects
|
||||
- `sigs.k8s.io/yaml`: to generate Katenary yaml files
|
||||
|
@@ -1,358 +1,384 @@
|
||||
# Using labels
|
||||
# Labels documentation
|
||||
|
||||
Katenary proposes labels to specify adaptation to provide to the Helm Chart. All labels are declared in the help message using:
|
||||
Katenary proposes labels to set in `compose.yaml` files (or override files) to configure the Helm Chart generation. Because it is sometimes needed to have structured values, it is necessary to use the Yaml syntax. While compose labels are string, we can use `|` to use Yaml multilines as value.
|
||||
|
||||
```text
|
||||
$ katenary show-labels
|
||||
Katenary will try to Unmarshal these labels.
|
||||
|
||||
# Labels
|
||||
katenary.io/ignore : ignore the container, it will not yied any object in the helm chart (bool)
|
||||
katenary.io/secret-vars : secret variables to push on a secret file (coma separated)
|
||||
katenary.io/secret-envfiles : set the given file names as a secret instead of configmap (coma separated)
|
||||
katenary.io/mapenv : map environment variable to a template string (yaml style, object)
|
||||
katenary.io/ports : set the ports to assign on the container in pod + expose as a service (coma separated)
|
||||
katenary.io/container-ports : set the ports to assign on the contaienr in pod but avoid service (coma separated)
|
||||
katenary.io/ingress : set the port to expose in an ingress (coma separated)
|
||||
katenary.io/configmap-volumes : specifies that the volumes points on a configmap (coma separated)
|
||||
katenary.io/same-pod : specifies that the pod should be deployed in the same pod than the
|
||||
given service name (string)
|
||||
katenary.io/volume-from : specifies that the volumes to be mounted from the given service (yaml style)
|
||||
katenary.io/empty-dirs : specifies that the given volume names should be "emptyDir" instead of
|
||||
persistentVolumeClaim (coma separated)
|
||||
katenary.io/crontabs : specifies a cronjobs to create (yaml style, array) - this will create a
|
||||
cronjob, a service account, a role and a rolebinding to start the command with "kubectl"
|
||||
The form is the following:
|
||||
- command: the command to run
|
||||
schedule: the schedule to run the command (e.g. "@daily" or "*/1 * * * *")
|
||||
image: the image to use for the command (default to "bitnami/kubectl")
|
||||
allPods: true if you want to run the command on all pods (default to false)
|
||||
katenary.io/healthcheck : specifies that the container should be monitored by a healthcheck,
|
||||
**it overrides the docker-compose healthcheck**.
|
||||
You can use these form of label values:
|
||||
-> http://[ignored][:port][/path] to specify an http healthcheck
|
||||
-> tcp://[ignored]:port to specify a tcp healthcheck
|
||||
-> other string is condidered as a "command" healthcheck
|
||||
```
|
||||
## Label list and types
|
||||
|
||||
## healthcheck
|
||||
<!-- START_LABEL_DOC : do not remove this tag !-->
|
||||
| Label name | Description | Type |
|
||||
| ----------------------------- | ------------------------------------------------------ | --------------------- |
|
||||
| `katenary.v3/configmap-files` | Add files to the configmap. | list of strings |
|
||||
| `katenary.v3/cronjob` | Create a cronjob from the service. | object |
|
||||
| `katenary.v3/dependencies` | Add Helm dependencies to the service. | list of objects |
|
||||
| `katenary.v3/description` | Description of the service | string |
|
||||
| `katenary.v3/env-from` | Add environment variables from antoher service. | list of strings |
|
||||
| `katenary.v3/health-check` | Health check to be added to the deployment. | object |
|
||||
| `katenary.v3/ignore` | Ignore the service | bool |
|
||||
| `katenary.v3/ingress` | Ingress rules to be added to the service. | object |
|
||||
| `katenary.v3/main-app` | Mark the service as the main app. | bool |
|
||||
| `katenary.v3/map-env` | Map env vars from the service to the deployment. | object |
|
||||
| `katenary.v3/ports` | Ports to be added to the service. | list of uint32 |
|
||||
| `katenary.v3/same-pod` | Move the same-pod deployment to the target deployment. | string |
|
||||
| `katenary.v3/secrets` | Env vars to be set as secrets. | list of string |
|
||||
| `katenary.v3/values` | Environment variables to be added to the values.yaml | list of string or map |
|
||||
|
||||
HealthCheck label defines how to make LivenessProbe on Kubernetes.
|
||||
<!-- STOP_LABEL_DOC : do not remove this tag !-->
|
||||
|
||||
## Detailed description
|
||||
|
||||
<!-- START_DETAILED_DOC : do not remove this tag !-->
|
||||
### katenary.v3/configmap-files
|
||||
|
||||
Add files to the configmap.
|
||||
|
||||
**Type**: `list of strings`
|
||||
|
||||
It makes a file or directory to be converted to one or more ConfigMaps
|
||||
and mounted in the pod. The file or directory is relative to the
|
||||
service directory.
|
||||
|
||||
If it is a directory, all files inside it are added to the ConfigMap.
|
||||
|
||||
If the directory as subdirectories, so one configmap per subpath are created.
|
||||
|
||||
!!! Warning
|
||||
This overrides the compose file healthcheck
|
||||
It is not intended to be used to store an entire project in configmaps.
|
||||
It is intended to be used to store configuration files that are not managed
|
||||
by the application, like nginx configuration files. Keep in mind that your
|
||||
project sources should be stored in an application image or in a storage.
|
||||
|
||||
**Example:**
|
||||
|
||||
```yaml
|
||||
volumes
|
||||
- ./conf.d:/etc/nginx/conf.d
|
||||
labels:
|
||||
katenary.v3/configmap-files: |-
|
||||
- ./conf.d
|
||||
```
|
||||
|
||||
### katenary.v3/cronjob
|
||||
|
||||
Create a cronjob from the service.
|
||||
|
||||
**Type**: `object`
|
||||
|
||||
This adds a cronjob to the chart.
|
||||
|
||||
The label value is a YAML object with the following attributes:
|
||||
- command: the command to be executed
|
||||
- schedule: the cron schedule (cron format or @every where "every" is a
|
||||
duration like 1h30m, daily, hourly...)
|
||||
- rbac: false (optionnal), if true, it will create a role, a rolebinding and
|
||||
a serviceaccount to make your cronjob able to connect the Kubernetes API
|
||||
|
||||
**Example:**
|
||||
|
||||
```yaml
|
||||
labels:
|
||||
katenary.v3/cronjob: |-
|
||||
command: echo "hello world"
|
||||
schedule: "* */1 * * *" # or @hourly for example
|
||||
```
|
||||
|
||||
### katenary.v3/dependencies
|
||||
|
||||
Add Helm dependencies to the service.
|
||||
|
||||
**Type**: `list of objects`
|
||||
|
||||
Set the service to be, actually, a Helm dependency. This means that the
|
||||
service will not be exported as template. The dependencies are added to
|
||||
the Chart.yaml file and the values are added to the values.yaml file.
|
||||
|
||||
It's a list of objects with the following attributes:
|
||||
|
||||
- name: the name of the dependency
|
||||
- repository: the repository of the dependency
|
||||
- alias: the name of the dependency in values.yaml (optional)
|
||||
- values: the values to be set in values.yaml (optional)
|
||||
|
||||
!!! Info
|
||||
The hostname is set to "localhost" by convention, but Katenary will ignore the hostname in tcp and http tests because it will create a LivenessProbe.
|
||||
Katenary doesn't update the helm depenedencies by default.
|
||||
|
||||
Use `--helm-update` (or `-u`) flag to update the dependencies.
|
||||
|
||||
example: <code>katenary convert -u</code>
|
||||
|
||||
Some example of usage:
|
||||
By setting an alias, it is possible to change the name of the dependency
|
||||
in values.yaml.
|
||||
|
||||
**Example:**
|
||||
|
||||
```yaml
|
||||
services:
|
||||
mariadb:
|
||||
image: mariadb
|
||||
labels:
|
||||
katenary.io/healthcheck: tcp://localhost:3306
|
||||
labels:
|
||||
katenary.v3/dependencies: |-
|
||||
- name: mariadb
|
||||
repository: oci://registry-1.docker.io/bitnamicharts
|
||||
|
||||
webapp:
|
||||
image: nginx
|
||||
labels:
|
||||
katenary.io/healthcheck: http://localhost:80
|
||||
## optional, it changes the name of the section in values.yaml
|
||||
# alias: mydatabase
|
||||
|
||||
example:
|
||||
image: yourimage
|
||||
labels:
|
||||
katenary.io/healthcheck: "test -f /opt/installed"
|
||||
## optional, it adds the values to values.yaml
|
||||
values:
|
||||
auth:
|
||||
database: mydatabasename
|
||||
username: myuser
|
||||
password: the secret password
|
||||
```
|
||||
|
||||
## crontabs
|
||||
### katenary.v3/description
|
||||
|
||||
Crontabs label proposes to create a complete CronTab object with needed RBAC to make it possible to run command inside the pod(s) with `kubectl`. Katenary will make the job for you. You only need to provide the command(s) to call.
|
||||
Description of the service
|
||||
|
||||
It's a YAML array in multiline label.
|
||||
**Type**: `string`
|
||||
|
||||
This replaces the default comment in values.yaml file to the given description.
|
||||
It is useful to document the service and configuration.
|
||||
|
||||
The value can be set with a documentation in multiline format.
|
||||
|
||||
**Example:**
|
||||
|
||||
```yaml
|
||||
services:
|
||||
mariadb:
|
||||
image: mariadb
|
||||
labels:
|
||||
katenary.io/crontabs: |
|
||||
- command: mysqldump -B myapp -uroot -p$${MYSQL_ROOT_PASSWORD} > dump.sql
|
||||
schedule: "@every 1h"
|
||||
```
|
||||
The object is:
|
||||
```
|
||||
command: Command to run
|
||||
schedule: the cron form schedule string
|
||||
allPods: boolean (default false) to activate the cront on each pod
|
||||
image: image name to use (default is bitnami/kubectl)
|
||||
with corresponding tag to your kubernetes version
|
||||
labels:
|
||||
katenary.v3/description: |-
|
||||
This is a description of the service.
|
||||
It can be multiline.
|
||||
```
|
||||
|
||||
## empty-dirs
|
||||
### katenary.v3/env-from
|
||||
|
||||
You sometime don't need to create a PersistentVolumeClaim. For example when a volume in your compose file is actually made to share the data between 2 or more containers.
|
||||
Add environment variables from antoher service.
|
||||
|
||||
In this case, an "emptyDir" volume is appreciated.
|
||||
**Type**: `list of strings`
|
||||
|
||||
It adds environment variables from another service to the current service.
|
||||
|
||||
**Example:**
|
||||
|
||||
```yaml
|
||||
services:
|
||||
webapp:
|
||||
image: nginx
|
||||
volumes:
|
||||
- websource:/var/www/html
|
||||
labels:
|
||||
# sources is actually an empty directory on the node
|
||||
katenary.io/empty-dirs: websource
|
||||
service1:
|
||||
image: nginx:1.19
|
||||
environment:
|
||||
FOO: bar
|
||||
|
||||
php:
|
||||
image: php:7-fpm
|
||||
volumes:
|
||||
- sources:/var/www/html
|
||||
labels:
|
||||
# in the same pod than webapp
|
||||
katenary.io/same-pod: webapp
|
||||
# see the corresponding section, get the volume
|
||||
# fro webapp
|
||||
katenary.io/volume-from: |
|
||||
sources:
|
||||
webapp: websource
|
||||
service2:
|
||||
image: php:7.4-fpm
|
||||
labels:
|
||||
# get the congigMap from service1 where FOO is
|
||||
# defined inside this service too
|
||||
katenary.v3/env-from: |-
|
||||
- myservice1
|
||||
```
|
||||
|
||||
## volume-from
|
||||
### katenary.v3/health-check
|
||||
|
||||
We see this in the [empty-dir](#empty-dir) section, this label defines that the corresponding volume should be shared in this pod.
|
||||
Health check to be added to the deployment.
|
||||
|
||||
**Type**: `object`
|
||||
|
||||
Health check to be added to the deployment.
|
||||
|
||||
**Example:**
|
||||
|
||||
```yaml
|
||||
services:
|
||||
webapp:
|
||||
image: nginx
|
||||
volumes:
|
||||
- datasource:/var/www/html
|
||||
|
||||
app:
|
||||
image: php
|
||||
volumes:
|
||||
- data:/opt/data
|
||||
labels:
|
||||
katenary.io/volume-from: |
|
||||
# data in this container...
|
||||
data:
|
||||
# ... correspond to "datasource" in "webapp" container
|
||||
webapp: datasource
|
||||
labels:
|
||||
katenary.v3/health-check: |-
|
||||
httpGet:
|
||||
path: /health
|
||||
port: 8080
|
||||
```
|
||||
|
||||
This implies that the declared volume in "webapp" will be mounted to "app" pods.
|
||||
### katenary.v3/ignore
|
||||
|
||||
Ignore the service
|
||||
|
||||
**Type**: `bool`
|
||||
|
||||
Ingoring a service to not be exported in helm chart.
|
||||
|
||||
**Example:**
|
||||
|
||||
```yaml
|
||||
labels:
|
||||
katenary.v3/ignore: "true"
|
||||
```
|
||||
|
||||
### katenary.v3/ingress
|
||||
|
||||
Ingress rules to be added to the service.
|
||||
|
||||
**Type**: `object`
|
||||
|
||||
Declare an ingress rule for the service. The port should be exposed or
|
||||
declared with `katenary.v3/ports`.
|
||||
|
||||
**Example:**
|
||||
|
||||
```yaml
|
||||
labels:
|
||||
katenary.v3/ingress: |-
|
||||
port: 80
|
||||
hostname: mywebsite.com (optional)
|
||||
```
|
||||
|
||||
### katenary.v3/main-app
|
||||
|
||||
Mark the service as the main app.
|
||||
|
||||
**Type**: `bool`
|
||||
|
||||
This makes the service to be the main application. Its image tag is
|
||||
considered to be the
|
||||
|
||||
Chart appVersion and to be the defaultvalue in Pod container
|
||||
image attribute.
|
||||
|
||||
!!! Warning
|
||||
This is possible with Kubernetes volumes restrictions. So, it works in these cases:
|
||||
This label cannot be repeated in others services. If this label is
|
||||
set in more than one service as true, Katenary will return an error.
|
||||
|
||||
- if the volume class is Read Write Many
|
||||
- or if you mount the volume in the same pod (so in the same node)
|
||||
- and/or the volume is an emptyDir
|
||||
|
||||
|
||||
## same-pod
|
||||
|
||||
It's sometimes important and/or necessary to declare that 2 services are in the same pod. For example, using PHP-FPM and NGinx. In this case, you can declare that both services are in the same pod.
|
||||
|
||||
You must declare this label only on "supplementary" services and always use the same master service for the entire pod declaration.
|
||||
**Example:**
|
||||
|
||||
```yaml
|
||||
services:
|
||||
web:
|
||||
image: nginx
|
||||
|
||||
php:
|
||||
image: php:8-fpm
|
||||
labels:
|
||||
katenary.io/same-pod: web
|
||||
ghost:
|
||||
image: ghost:1.25.5
|
||||
labels:
|
||||
# The chart is now named ghost, and the appVersion is 1.25.5.
|
||||
# In Deployment, the image attribute is set to ghost:1.25.5 if
|
||||
# you don't change the "tag" attribute in values.yaml
|
||||
katenary.v3/main-app: true
|
||||
```
|
||||
|
||||
The above example will create a `web` deployment, the PHP container is added in the `web` pod.
|
||||
### katenary.v3/map-env
|
||||
|
||||
## configmap-volumes
|
||||
Map env vars from the service to the deployment.
|
||||
|
||||
This label proposes to declare a file or directory where content is actually static and can be mounted as configMap volume.
|
||||
**Type**: `object`
|
||||
|
||||
It's a comma separated label, you can declare several volumes.
|
||||
Because you may need to change the variable for Kubernetes, this label
|
||||
forces the value to another. It is also particullary helpful to use a template
|
||||
value instead. For example, you could bind the value to a service name
|
||||
with Helm attributes:
|
||||
`{{ tpl .Release.Name . }}`.
|
||||
|
||||
For example, in `static/index.html`:
|
||||
If you use `__APP__` in the value, it will be replaced by the Chart name.
|
||||
|
||||
```html
|
||||
<html>
|
||||
<body>Hello</body>
|
||||
</html>
|
||||
```
|
||||
|
||||
And a compose file (snippet):
|
||||
**Example:**
|
||||
|
||||
```yaml
|
||||
serivces:
|
||||
web:
|
||||
image: nginx
|
||||
volumes:
|
||||
- ./static:/usr/share/nginx/html:z
|
||||
labels:
|
||||
katenary.io/configmap-volumes: ./statics
|
||||
env:
|
||||
DB_HOST: database
|
||||
RUNNING: docker
|
||||
OTHER: value
|
||||
labels:
|
||||
katenary.v3/map-env: |-
|
||||
RUNNING: kubernetes
|
||||
DB_HOST: '{{ include "__APP__.fullname" . }}-database'
|
||||
```
|
||||
|
||||
What will make Katenary:
|
||||
### katenary.v3/ports
|
||||
|
||||
- create a configmap containing the "index.html" file as data
|
||||
- declare the volume in the `web` deployment file
|
||||
- mount the configmap in `/usr/share/nginx/html` directory of the container
|
||||
Ports to be added to the service.
|
||||
|
||||
## ingress
|
||||
**Type**: `list of uint32`
|
||||
|
||||
Declare which port to use to create an ingress. The hostname will be declared in `values.yaml` file.
|
||||
Only useful for services without exposed port. It is mandatory if the
|
||||
service is a dependency of another service.
|
||||
|
||||
**Example:**
|
||||
|
||||
```yaml
|
||||
serivces:
|
||||
web:
|
||||
image: nginx
|
||||
ports:
|
||||
- 8080:80
|
||||
labels:
|
||||
katenary.io/ingress: 80
|
||||
labels:
|
||||
katenary.v3/ports: |-
|
||||
- 8080
|
||||
- 8081
|
||||
```
|
||||
|
||||
!!! Info
|
||||
A port **must** be declared, in `ports` section or with `katenary.io/ports` label. This to force the creation of a `Service`.
|
||||
### katenary.v3/same-pod
|
||||
|
||||
## ports and container-ports
|
||||
Move the same-pod deployment to the target deployment.
|
||||
|
||||
It's sometimes not mandatory to declare a port in compose file, or maybe you want to avoid to expose them in the compose file. But Katenary will sometimes need to know the ports to create service, for example to allow `depends_on` directive.
|
||||
**Type**: `string`
|
||||
|
||||
In this case, you can declare the ports in the corresponding label:
|
||||
This will make the service to be included in another service pod. Some services
|
||||
must work together in the same pod, like a sidecar or a proxy or nginx + php-fpm.
|
||||
|
||||
Note that volume and VolumeMount are copied from the source to the target
|
||||
deployment.
|
||||
|
||||
**Example:**
|
||||
|
||||
```yaml
|
||||
serivces:
|
||||
web:
|
||||
image: nginx
|
||||
labels:
|
||||
katenary.io/ports: 80,443
|
||||
web:
|
||||
image: nginx:1.19
|
||||
|
||||
php:
|
||||
image: php:7.4-fpm
|
||||
labels:
|
||||
katenary.v3/same-pod: web
|
||||
```
|
||||
|
||||
This will leave Katenary creating the service to open these ports to others pods.
|
||||
### katenary.v3/secrets
|
||||
|
||||
Sometimes, you need to have `containerPort` in pods but **avoid the service declaration**, so you can use this label:
|
||||
Env vars to be set as secrets.
|
||||
|
||||
**Type**: `list of string`
|
||||
|
||||
This label allows setting the environment variables as secrets. The variable
|
||||
is removed from the environment and added to a secret object.
|
||||
|
||||
The variable can be set to the `katenary.v3/values` too,
|
||||
so the secret value can be configured in values.yaml
|
||||
|
||||
**Example:**
|
||||
|
||||
```yaml
|
||||
services:
|
||||
php:
|
||||
image: php:8-fpm
|
||||
labels:
|
||||
katenary.io/container-ports: 9000
|
||||
env:
|
||||
PASSWORD: a very secret password
|
||||
NOT_A_SECRET: a public value
|
||||
labels:
|
||||
katenary.v3/secrets: |-
|
||||
- PASSWORD
|
||||
```
|
||||
|
||||
That will only declare the container port in the pod, but not in the service.
|
||||
### katenary.v3/values
|
||||
|
||||
!!! Info
|
||||
It's very useful when you need to declare ports in conjonction with `same-pod`. Katenary would create a service with all the pods ports inside. The `container-ports` label will make the ports to be ignored in the service creation.
|
||||
Environment variables to be added to the values.yaml
|
||||
|
||||
## mapenv
|
||||
**Type**: `list of string or map`
|
||||
|
||||
Environment variables are working great for your compose stack but you sometimes need to change them in Helm. This label allows you to remap the value for Helm.
|
||||
By default, all environment variables in the "env" and environment
|
||||
files are added to configmaps with the static values set. This label
|
||||
allows to add environment variables to the values.yaml file.
|
||||
|
||||
For example, when you use an environment variable to point on another service.
|
||||
Note that the value inside the configmap is `{{ tpl vaname . }}`, so
|
||||
you can set the value to a template that will be rendered with the
|
||||
values.yaml file.
|
||||
|
||||
The value can be set with a documentation. This may help to understand
|
||||
the purpose of the variable.
|
||||
|
||||
**Example:**
|
||||
|
||||
```yaml
|
||||
serivces:
|
||||
php:
|
||||
image: php
|
||||
environment:
|
||||
DB_HOST: database
|
||||
|
||||
database:
|
||||
image: mariadb
|
||||
labels:
|
||||
katenary.io/ports: 3306
|
||||
env:
|
||||
FOO: bar
|
||||
DB_NAME: mydb
|
||||
TO_CONFIGURE: something that can be changed in values.yaml
|
||||
A_COMPLEX_VALUE: example
|
||||
labels:
|
||||
katenary.v3/values: |-
|
||||
# simple values, set as is in values.yaml
|
||||
- TO_CONFIGURE
|
||||
# complex values, set as a template in values.yaml with a documentation
|
||||
- A_COMPLEX_VALUE: |-
|
||||
This is the documentation for the variable to
|
||||
configure in values.yaml.
|
||||
It can be, of course, a multiline text.
|
||||
```
|
||||
|
||||
The above example will break when you'll start it in Kubernetes because the `database` service will not be named like this, it will be renamed to `{{ .Release.Name }}-database`. So, you can declare the rewrite:
|
||||
|
||||
```yaml
|
||||
services:
|
||||
php:
|
||||
image: php
|
||||
environment:
|
||||
DB_HOST: database
|
||||
labels:
|
||||
katenary.io/mapenv: |
|
||||
DB_HOST: "{{ .Release.Name }}"-database
|
||||
database:
|
||||
image: mariadb
|
||||
labels:
|
||||
katenary.io/ports: 3306
|
||||
|
||||
```
|
||||
|
||||
It's also useful when you want to change a variable value to another when you deploy on Kubernetes.
|
||||
|
||||
## secret-envfiles
|
||||
|
||||
Katenary binds all "environemnt files" to config maps. But some of these files can be bound as sercrets.
|
||||
|
||||
In this case, declare the files as is:
|
||||
|
||||
```yaml
|
||||
services:
|
||||
app:
|
||||
image: #...
|
||||
env_file:
|
||||
- ./env/whatever
|
||||
- ./env/sensitives
|
||||
labels:
|
||||
katenary.io/secret-envfiles: ./env/sensitives
|
||||
```
|
||||
|
||||
## secret-vars
|
||||
|
||||
If you have some environemnt variables to declare as secret, you can list them in the `secret-vars` label.
|
||||
|
||||
```yaml
|
||||
services:
|
||||
database:
|
||||
image: mariadb
|
||||
environemnt:
|
||||
MYSQL_PASSWORD: foobar
|
||||
MYSQL_ROOT_PASSWORD: longpasswordhere
|
||||
MYSQL_USER: john
|
||||
MYSQL_DATABASE: appdb
|
||||
labels:
|
||||
katenary.io/secret-vars: MYSQL_ROOT_PASSWORD,MYSQL_PASSWORD
|
||||
```
|
||||
|
||||
## ignore
|
||||
|
||||
Simply ignore the service to not be exported in the Helm Chart.
|
||||
|
||||
```yaml
|
||||
serivces:
|
||||
|
||||
# this service is able to answer HTTP
|
||||
# on port 5000
|
||||
webapp:
|
||||
image: myapp
|
||||
labels:
|
||||
# declare the port
|
||||
katenary.io/ports: 5000
|
||||
# the ingress controller is a web proxy, so...
|
||||
katenary.io/ingress: 5000
|
||||
|
||||
|
||||
# with local Docker, I want to access my webapp
|
||||
# with "myapp.locahost" so I use a nice proxy on
|
||||
# port 80
|
||||
proxy:
|
||||
image: quay.io/pathwae/proxy
|
||||
ports:
|
||||
- 80:80
|
||||
environemnt:
|
||||
CONFIG: |
|
||||
myapp.localhost: webapp:5000
|
||||
labels:
|
||||
# I don't need it in Helm, it's only
|
||||
# for local test!
|
||||
katenary.io/ignore: true
|
||||
```
|
||||
<!-- STOP_DETAILED_DOC : do not remove this tag !-->
|
||||
|
8
doc/docs/packages/cmd/katenary.md
Normal file
8
doc/docs/packages/cmd/katenary.md
Normal file
@@ -0,0 +1,8 @@
|
||||
<!-- Code generated by gomarkdoc. DO NOT EDIT -->
|
||||
|
||||
# katenary
|
||||
|
||||
``` go
|
||||
import "katenary/cmd/katenary"
|
||||
```
|
||||
|
893
doc/docs/packages/generator.md
Normal file
893
doc/docs/packages/generator.md
Normal file
@@ -0,0 +1,893 @@
|
||||
<!-- Code generated by gomarkdoc. DO NOT EDIT -->
|
||||
|
||||
# generator
|
||||
|
||||
``` go
|
||||
import "katenary/generator"
|
||||
```
|
||||
|
||||
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.
|
||||
|
||||
The generate.Convert() create an HelmChart object and call “Generate()”
|
||||
method to convert from a compose file to a helm chart. 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
|
||||
|
||||
## Constants
|
||||
|
||||
``` go
|
||||
const KATENARY_PREFIX = "katenary.v3/"
|
||||
```
|
||||
|
||||
## Variables
|
||||
|
||||
``` go
|
||||
var (
|
||||
|
||||
// Standard annotationss
|
||||
Annotations = map[string]string{
|
||||
KATENARY_PREFIX + "version": Version,
|
||||
}
|
||||
)
|
||||
```
|
||||
|
||||
Version is the version of katenary. It is set at compile time.
|
||||
|
||||
``` go
|
||||
var Version = "master" // changed at compile time
|
||||
```
|
||||
|
||||
## func Convert
|
||||
|
||||
``` go
|
||||
func Convert(config ConvertOptions, dockerComposeFile ...string)
|
||||
```
|
||||
|
||||
Convert a compose (docker, podman…) project to a helm chart. It calls
|
||||
Generate() to generate the chart and then write it to the disk.
|
||||
|
||||
## func GetLabelHelp
|
||||
|
||||
``` go
|
||||
func GetLabelHelp(asMarkdown bool) string
|
||||
```
|
||||
|
||||
Generate the help for the labels.
|
||||
|
||||
## func GetLabelHelpFor
|
||||
|
||||
``` go
|
||||
func GetLabelHelpFor(labelname string, asMarkdown bool) string
|
||||
```
|
||||
|
||||
GetLabelHelpFor returns the help for a specific label.
|
||||
|
||||
## func GetLabelNames
|
||||
|
||||
``` go
|
||||
func GetLabelNames() []string
|
||||
```
|
||||
|
||||
GetLabelNames returns a sorted list of all katenary label names.
|
||||
|
||||
## func GetLabels
|
||||
|
||||
``` go
|
||||
func GetLabels(serviceName, appName string) map[string]string
|
||||
```
|
||||
|
||||
## func GetMatchLabels
|
||||
|
||||
``` go
|
||||
func GetMatchLabels(serviceName, appName string) map[string]string
|
||||
```
|
||||
|
||||
## func Helper
|
||||
|
||||
``` go
|
||||
func Helper(name string) string
|
||||
```
|
||||
|
||||
Helper returns the \_helpers.tpl file for a chart.
|
||||
|
||||
## func NewCronJob
|
||||
|
||||
``` go
|
||||
func NewCronJob(service types.ServiceConfig, chart *HelmChart, appName string) (*CronJob, *RBAC)
|
||||
```
|
||||
|
||||
NewCronJob creates a new CronJob from a compose service. The appName is
|
||||
the name of the application taken from the project name.
|
||||
|
||||
## type ChartTemplate
|
||||
|
||||
ChartTemplate is a template of a chart. It contains the content of the
|
||||
template and the name of the service. This is used internally to
|
||||
generate the templates.
|
||||
|
||||
TODO: maybe we can set it private.
|
||||
|
||||
``` go
|
||||
type ChartTemplate struct {
|
||||
Content []byte
|
||||
Servicename string
|
||||
}
|
||||
```
|
||||
|
||||
## type ConfigMap
|
||||
|
||||
ConfigMap is a kubernetes ConfigMap. Implements the DataMap interface.
|
||||
|
||||
``` go
|
||||
type ConfigMap struct {
|
||||
*corev1.ConfigMap
|
||||
// contains filtered or unexported fields
|
||||
}
|
||||
```
|
||||
|
||||
### func NewConfigMap
|
||||
|
||||
``` go
|
||||
func NewConfigMap(service types.ServiceConfig, appName string) *ConfigMap
|
||||
```
|
||||
|
||||
NewConfigMap creates a new ConfigMap from a compose service. The appName
|
||||
is the name of the application taken from the project name. The
|
||||
ConfigMap is filled by environment variables and labels “map-env”.
|
||||
|
||||
### func NewConfigMapFromFiles
|
||||
|
||||
``` go
|
||||
func NewConfigMapFromFiles(service types.ServiceConfig, appName string, path string) *ConfigMap
|
||||
```
|
||||
|
||||
NewConfigMapFromFiles creates a new ConfigMap from a compose service.
|
||||
This path is the path to the file or directory. If the path is a
|
||||
directory, all files in the directory are added to the ConfigMap. Each
|
||||
subdirectory are ignored. Note that the Generate() function will create
|
||||
the subdirectories ConfigMaps.
|
||||
|
||||
### func (*ConfigMap) AddData
|
||||
|
||||
``` go
|
||||
func (c *ConfigMap) AddData(key string, value string)
|
||||
```
|
||||
|
||||
AddData adds a key value pair to the configmap. Append or overwrite the
|
||||
value if the key already exists.
|
||||
|
||||
### func (*ConfigMap) AppendDir
|
||||
|
||||
``` go
|
||||
func (c *ConfigMap) AppendDir(path string)
|
||||
```
|
||||
|
||||
AddFile adds files from given path to the configmap. It is not
|
||||
recursive, to add all files in a directory, you need to call this
|
||||
function for each subdirectory.
|
||||
|
||||
### func (*ConfigMap) Filename
|
||||
|
||||
``` go
|
||||
func (c *ConfigMap) Filename() string
|
||||
```
|
||||
|
||||
Filename returns the filename of the configmap. If the configmap is used
|
||||
for files, the filename contains the path.
|
||||
|
||||
### func (*ConfigMap) SetData
|
||||
|
||||
``` go
|
||||
func (c *ConfigMap) SetData(data map[string]string)
|
||||
```
|
||||
|
||||
SetData sets the data of the configmap. It replaces the entire data.
|
||||
|
||||
### func (*ConfigMap) Yaml
|
||||
|
||||
``` go
|
||||
func (c *ConfigMap) Yaml() ([]byte, error)
|
||||
```
|
||||
|
||||
Yaml returns the yaml representation of the configmap
|
||||
|
||||
## type ConvertOptions
|
||||
|
||||
ConvertOptions are the options to convert a compose project to a helm
|
||||
chart.
|
||||
|
||||
``` go
|
||||
type ConvertOptions struct {
|
||||
Force bool // Force the chart directory deletion if it already exists.
|
||||
OutputDir string // The output directory of the chart.
|
||||
Profiles []string // Profile to use for the conversion.
|
||||
HelmUpdate bool // If true, the "helm dep update" command will be run after the chart generation.
|
||||
AppVersion *string // Set the chart "appVersion" field. If nil, the version will be set to 0.1.0.
|
||||
ChartVersion string // Set the chart "version" field.
|
||||
}
|
||||
```
|
||||
|
||||
## type CronJob
|
||||
|
||||
CronJob is a kubernetes CronJob.
|
||||
|
||||
``` go
|
||||
type CronJob struct {
|
||||
*batchv1.CronJob
|
||||
// contains filtered or unexported fields
|
||||
}
|
||||
```
|
||||
|
||||
### func (*CronJob) Filename
|
||||
|
||||
``` go
|
||||
func (c *CronJob) Filename() string
|
||||
```
|
||||
|
||||
Filename returns the filename of the cronjob.
|
||||
|
||||
Implements the Yaml interface.
|
||||
|
||||
### func (*CronJob) Yaml
|
||||
|
||||
``` go
|
||||
func (c *CronJob) Yaml() ([]byte, error)
|
||||
```
|
||||
|
||||
Yaml returns the yaml representation of the cronjob.
|
||||
|
||||
Implements the Yaml interface.
|
||||
|
||||
## type CronJobValue
|
||||
|
||||
CronJobValue is a cronjob configuration that will be saved in
|
||||
values.yaml.
|
||||
|
||||
``` go
|
||||
type CronJobValue struct {
|
||||
Repository *RepositoryValue `yaml:"repository,omitempty"`
|
||||
Environment map[string]any `yaml:"environment,omitempty"`
|
||||
ImagePullPolicy string `yaml:"imagePullPolicy,omitempty"`
|
||||
Schedule string `yaml:"schedule"`
|
||||
}
|
||||
```
|
||||
|
||||
## type DataMap
|
||||
|
||||
DataMap is a kubernetes ConfigMap or Secret. It can be used to add data
|
||||
to the ConfigMap or Secret.
|
||||
|
||||
``` go
|
||||
type DataMap interface {
|
||||
SetData(map[string]string)
|
||||
AddData(string, string)
|
||||
}
|
||||
```
|
||||
|
||||
### func NewFileMap
|
||||
|
||||
``` go
|
||||
func NewFileMap(service types.ServiceConfig, appName string, kind string) DataMap
|
||||
```
|
||||
|
||||
NewFileMap creates a new DataMap from a compose service. The appName is
|
||||
the name of the application taken from the project name.
|
||||
|
||||
## type Dependency
|
||||
|
||||
Dependency is a dependency of a chart to other charts.
|
||||
|
||||
``` go
|
||||
type Dependency struct {
|
||||
Name string `yaml:"name"`
|
||||
Version string `yaml:"version"`
|
||||
Repository string `yaml:"repository"`
|
||||
Alias string `yaml:"alias,omitempty"`
|
||||
Values map[string]any `yaml:"-"` // do not export to Chart.yaml
|
||||
}
|
||||
```
|
||||
|
||||
## type Deployment
|
||||
|
||||
Deployment is a kubernetes Deployment.
|
||||
|
||||
``` go
|
||||
type Deployment struct {
|
||||
*appsv1.Deployment `yaml:",inline"`
|
||||
// contains filtered or unexported fields
|
||||
}
|
||||
```
|
||||
|
||||
### func NewDeployment
|
||||
|
||||
``` go
|
||||
func NewDeployment(service types.ServiceConfig, chart *HelmChart) *Deployment
|
||||
```
|
||||
|
||||
NewDeployment creates a new Deployment from a compose service. The
|
||||
appName is the name of the application taken from the project name. It
|
||||
also creates the Values map that will be used to create the values.yaml
|
||||
file.
|
||||
|
||||
### func (*Deployment) AddContainer
|
||||
|
||||
``` go
|
||||
func (d *Deployment) AddContainer(service types.ServiceConfig)
|
||||
```
|
||||
|
||||
AddContainer adds a container to the deployment.
|
||||
|
||||
### func (*Deployment) AddHealthCheck
|
||||
|
||||
``` go
|
||||
func (d *Deployment) AddHealthCheck(service types.ServiceConfig, container *corev1.Container)
|
||||
```
|
||||
|
||||
### func (*Deployment) AddIngress
|
||||
|
||||
``` go
|
||||
func (d *Deployment) AddIngress(service types.ServiceConfig, appName string) *Ingress
|
||||
```
|
||||
|
||||
AddIngress adds an ingress to the deployment. It creates the ingress
|
||||
object.
|
||||
|
||||
### func (*Deployment) AddVolumes
|
||||
|
||||
``` go
|
||||
func (d *Deployment) AddVolumes(service types.ServiceConfig, appName string)
|
||||
```
|
||||
|
||||
AddVolumes adds a volume to the deployment. It does not create the PVC,
|
||||
it only adds the volumes to the deployment. If the volume is a bind
|
||||
volume it will warn the user that it is not supported yet.
|
||||
|
||||
### func (*Deployment) BindFrom
|
||||
|
||||
``` go
|
||||
func (d *Deployment) BindFrom(service types.ServiceConfig, binded *Deployment)
|
||||
```
|
||||
|
||||
### func (*Deployment) DependsOn
|
||||
|
||||
``` go
|
||||
func (d *Deployment) DependsOn(to *Deployment) error
|
||||
```
|
||||
|
||||
DependsOn adds a initContainer to the deployment that will wait for the
|
||||
service to be up.
|
||||
|
||||
### func (*Deployment) Filename
|
||||
|
||||
``` go
|
||||
func (d *Deployment) Filename() string
|
||||
```
|
||||
|
||||
### func (*Deployment) SetEnvFrom
|
||||
|
||||
``` go
|
||||
func (d *Deployment) SetEnvFrom(service types.ServiceConfig, appName string)
|
||||
```
|
||||
|
||||
SetEnvFrom sets the environment variables to a configmap. The configmap
|
||||
is created.
|
||||
|
||||
### func (*Deployment) Yaml
|
||||
|
||||
``` go
|
||||
func (d *Deployment) Yaml() ([]byte, error)
|
||||
```
|
||||
|
||||
Yaml returns the yaml representation of the deployment.
|
||||
|
||||
## type FileMapUsage
|
||||
|
||||
FileMapUsage is the usage of the filemap.
|
||||
|
||||
``` go
|
||||
type FileMapUsage uint8
|
||||
```
|
||||
|
||||
FileMapUsage constants.
|
||||
|
||||
``` go
|
||||
const (
|
||||
FileMapUsageConfigMap FileMapUsage = iota // pure configmap for key:values.
|
||||
FileMapUsageFiles // files in a configmap.
|
||||
)
|
||||
```
|
||||
|
||||
## type HelmChart
|
||||
|
||||
HelmChart is a Helm Chart representation. It contains all the tempaltes,
|
||||
values, versions, helpers…
|
||||
|
||||
``` go
|
||||
type HelmChart struct {
|
||||
Name string `yaml:"name"`
|
||||
ApiVersion string `yaml:"apiVersion"`
|
||||
Version string `yaml:"version"`
|
||||
AppVersion string `yaml:"appVersion"`
|
||||
Description string `yaml:"description"`
|
||||
Dependencies []Dependency `yaml:"dependencies,omitempty"`
|
||||
Templates map[string]*ChartTemplate `yaml:"-"` // do not export to yaml
|
||||
Helper string `yaml:"-"` // do not export to yaml
|
||||
Values map[string]any `yaml:"-"` // do not export to yaml
|
||||
VolumeMounts map[string]any `yaml:"-"` // do not export to yaml
|
||||
// contains filtered or unexported fields
|
||||
}
|
||||
```
|
||||
|
||||
### func Generate
|
||||
|
||||
``` go
|
||||
func Generate(project *types.Project) (*HelmChart, error)
|
||||
```
|
||||
|
||||
Generate a chart from a compose project. This does not write files to
|
||||
disk, it only creates the HelmChart object.
|
||||
|
||||
The Generate function will create the HelmChart object this way:
|
||||
|
||||
1. Detect the service port name or leave the port number if not found.
|
||||
|
||||
2. Create a deployment for each service that are not ingnore.
|
||||
|
||||
3. Create a service and ingresses for each service that has ports
|
||||
and/or declared ingresses.
|
||||
|
||||
4. Create a PVC or Configmap volumes for each volume.
|
||||
|
||||
5. Create init containers for each service which has dependencies to
|
||||
other services.
|
||||
|
||||
6. Create a chart dependencies.
|
||||
|
||||
7. Create a configmap and secrets from the environment variables.
|
||||
|
||||
8. Merge the same-pod services.
|
||||
|
||||
### func NewChart
|
||||
|
||||
``` go
|
||||
func NewChart(name string) *HelmChart
|
||||
```
|
||||
|
||||
NewChart creates a new empty chart with the given name.
|
||||
|
||||
## type Help
|
||||
|
||||
Help is the documentation of a label.
|
||||
|
||||
``` go
|
||||
type Help struct {
|
||||
Short string `yaml:"short"`
|
||||
Long string `yaml:"long"`
|
||||
Example string `yaml:"example"`
|
||||
Type string `yaml:"type"`
|
||||
}
|
||||
```
|
||||
|
||||
## type Ingress
|
||||
|
||||
``` go
|
||||
type Ingress struct {
|
||||
*networkv1.Ingress
|
||||
// contains filtered or unexported fields
|
||||
}
|
||||
```
|
||||
|
||||
### func NewIngress
|
||||
|
||||
``` go
|
||||
func NewIngress(service types.ServiceConfig, Chart *HelmChart) *Ingress
|
||||
```
|
||||
|
||||
NewIngress creates a new Ingress from a compose service.
|
||||
|
||||
### func (*Ingress) Filename
|
||||
|
||||
``` go
|
||||
func (ingress *Ingress) Filename() string
|
||||
```
|
||||
|
||||
### func (*Ingress) Yaml
|
||||
|
||||
``` go
|
||||
func (ingress *Ingress) Yaml() ([]byte, error)
|
||||
```
|
||||
|
||||
## type IngressValue
|
||||
|
||||
IngressValue is a ingress configuration that will be saved in
|
||||
values.yaml.
|
||||
|
||||
``` go
|
||||
type IngressValue struct {
|
||||
Enabled bool `yaml:"enabled"`
|
||||
Host string `yaml:"host"`
|
||||
Path string `yaml:"path"`
|
||||
Class string `yaml:"class"`
|
||||
Annotations map[string]string `yaml:"annotations"`
|
||||
}
|
||||
```
|
||||
|
||||
## type Label
|
||||
|
||||
Label is a katenary label to find in compose files.
|
||||
|
||||
``` go
|
||||
type Label = string
|
||||
```
|
||||
|
||||
Known labels.
|
||||
|
||||
``` go
|
||||
const (
|
||||
LABEL_MAIN_APP Label = KATENARY_PREFIX + "main-app"
|
||||
LABEL_VALUES Label = KATENARY_PREFIX + "values"
|
||||
LABEL_SECRETS Label = KATENARY_PREFIX + "secrets"
|
||||
LABEL_PORTS Label = KATENARY_PREFIX + "ports"
|
||||
LABEL_INGRESS Label = KATENARY_PREFIX + "ingress"
|
||||
LABEL_MAP_ENV Label = KATENARY_PREFIX + "map-env"
|
||||
LABEL_HEALTHCHECK Label = KATENARY_PREFIX + "health-check"
|
||||
LABEL_SAME_POD Label = KATENARY_PREFIX + "same-pod"
|
||||
LABEL_DESCRIPTION Label = KATENARY_PREFIX + "description"
|
||||
LABEL_IGNORE Label = KATENARY_PREFIX + "ignore"
|
||||
LABEL_DEPENDENCIES Label = KATENARY_PREFIX + "dependencies"
|
||||
LABEL_CM_FILES Label = KATENARY_PREFIX + "configmap-files"
|
||||
LABEL_CRONJOB Label = KATENARY_PREFIX + "cronjob"
|
||||
LABEL_ENV_FROM Label = KATENARY_PREFIX + "env-from"
|
||||
)
|
||||
```
|
||||
|
||||
## type LabelType
|
||||
|
||||
LabelType identifies the type of label to generate in objects. TODO: is
|
||||
this still needed?
|
||||
|
||||
``` go
|
||||
type LabelType uint8
|
||||
```
|
||||
|
||||
``` go
|
||||
const (
|
||||
DeploymentLabel LabelType = iota
|
||||
ServiceLabel
|
||||
)
|
||||
```
|
||||
|
||||
## type PersistenceValue
|
||||
|
||||
PersistenceValue is a persistence configuration that will be saved in
|
||||
values.yaml.
|
||||
|
||||
``` go
|
||||
type PersistenceValue struct {
|
||||
Enabled bool `yaml:"enabled"`
|
||||
StorageClass string `yaml:"storageClass"`
|
||||
Size string `yaml:"size"`
|
||||
AccessMode []string `yaml:"accessMode"`
|
||||
}
|
||||
```
|
||||
|
||||
## type RBAC
|
||||
|
||||
RBAC is a kubernetes RBAC containing a role, a rolebinding and an
|
||||
associated serviceaccount.
|
||||
|
||||
``` go
|
||||
type RBAC struct {
|
||||
RoleBinding *RoleBinding
|
||||
Role *Role
|
||||
ServiceAccount *ServiceAccount
|
||||
}
|
||||
```
|
||||
|
||||
### func NewRBAC
|
||||
|
||||
``` go
|
||||
func NewRBAC(service types.ServiceConfig, appName string) *RBAC
|
||||
```
|
||||
|
||||
NewRBAC creates a new RBAC from a compose service. The appName is the
|
||||
name of the application taken from the project name.
|
||||
|
||||
## type RepositoryValue
|
||||
|
||||
RepositoryValue is a docker repository image and tag that will be saved
|
||||
in values.yaml.
|
||||
|
||||
``` go
|
||||
type RepositoryValue struct {
|
||||
Image string `yaml:"image"`
|
||||
Tag string `yaml:"tag"`
|
||||
}
|
||||
```
|
||||
|
||||
## type Role
|
||||
|
||||
Role is a kubernetes Role.
|
||||
|
||||
``` go
|
||||
type Role struct {
|
||||
*rbacv1.Role
|
||||
// contains filtered or unexported fields
|
||||
}
|
||||
```
|
||||
|
||||
### func (*Role) Filename
|
||||
|
||||
``` go
|
||||
func (r *Role) Filename() string
|
||||
```
|
||||
|
||||
### func (*Role) Yaml
|
||||
|
||||
``` go
|
||||
func (r *Role) Yaml() ([]byte, error)
|
||||
```
|
||||
|
||||
## type RoleBinding
|
||||
|
||||
RoleBinding is a kubernetes RoleBinding.
|
||||
|
||||
``` go
|
||||
type RoleBinding struct {
|
||||
*rbacv1.RoleBinding
|
||||
// contains filtered or unexported fields
|
||||
}
|
||||
```
|
||||
|
||||
### func (*RoleBinding) Filename
|
||||
|
||||
``` go
|
||||
func (r *RoleBinding) Filename() string
|
||||
```
|
||||
|
||||
### func (*RoleBinding) Yaml
|
||||
|
||||
``` go
|
||||
func (r *RoleBinding) Yaml() ([]byte, error)
|
||||
```
|
||||
|
||||
## type Secret
|
||||
|
||||
Secret is a kubernetes Secret.
|
||||
|
||||
Implements the DataMap interface.
|
||||
|
||||
``` go
|
||||
type Secret struct {
|
||||
*corev1.Secret
|
||||
// contains filtered or unexported fields
|
||||
}
|
||||
```
|
||||
|
||||
### func NewSecret
|
||||
|
||||
``` go
|
||||
func NewSecret(service types.ServiceConfig, appName string) *Secret
|
||||
```
|
||||
|
||||
NewSecret creates a new Secret from a compose service
|
||||
|
||||
### func (*Secret) AddData
|
||||
|
||||
``` go
|
||||
func (s *Secret) AddData(key string, value string)
|
||||
```
|
||||
|
||||
AddData adds a key value pair to the secret.
|
||||
|
||||
### func (*Secret) Filename
|
||||
|
||||
``` go
|
||||
func (s *Secret) Filename() string
|
||||
```
|
||||
|
||||
Filename returns the filename of the secret.
|
||||
|
||||
### func (*Secret) SetData
|
||||
|
||||
``` go
|
||||
func (s *Secret) SetData(data map[string]string)
|
||||
```
|
||||
|
||||
SetData sets the data of the secret.
|
||||
|
||||
### func (*Secret) Yaml
|
||||
|
||||
``` go
|
||||
func (s *Secret) Yaml() ([]byte, error)
|
||||
```
|
||||
|
||||
Yaml returns the yaml representation of the secret.
|
||||
|
||||
## type Service
|
||||
|
||||
Service is a kubernetes Service.
|
||||
|
||||
``` go
|
||||
type Service struct {
|
||||
*v1.Service `yaml:",inline"`
|
||||
// contains filtered or unexported fields
|
||||
}
|
||||
```
|
||||
|
||||
### func NewService
|
||||
|
||||
``` go
|
||||
func NewService(service types.ServiceConfig, appName string) *Service
|
||||
```
|
||||
|
||||
NewService creates a new Service from a compose service.
|
||||
|
||||
### func (*Service) AddPort
|
||||
|
||||
``` go
|
||||
func (s *Service) AddPort(port types.ServicePortConfig, serviceName ...string)
|
||||
```
|
||||
|
||||
AddPort adds a port to the service.
|
||||
|
||||
### func (*Service) Filename
|
||||
|
||||
``` go
|
||||
func (s *Service) Filename() string
|
||||
```
|
||||
|
||||
Filename returns the filename of the service.
|
||||
|
||||
### func (*Service) Yaml
|
||||
|
||||
``` go
|
||||
func (s *Service) Yaml() ([]byte, error)
|
||||
```
|
||||
|
||||
Yaml returns the yaml representation of the service.
|
||||
|
||||
## type ServiceAccount
|
||||
|
||||
ServiceAccount is a kubernetes ServiceAccount.
|
||||
|
||||
``` go
|
||||
type ServiceAccount struct {
|
||||
*corev1.ServiceAccount
|
||||
// contains filtered or unexported fields
|
||||
}
|
||||
```
|
||||
|
||||
### func (*ServiceAccount) Filename
|
||||
|
||||
``` go
|
||||
func (r *ServiceAccount) Filename() string
|
||||
```
|
||||
|
||||
### func (*ServiceAccount) Yaml
|
||||
|
||||
``` go
|
||||
func (r *ServiceAccount) Yaml() ([]byte, error)
|
||||
```
|
||||
|
||||
## type Value
|
||||
|
||||
Value will be saved in values.yaml. It contains configuraiton for all
|
||||
deployment and services. The content will be lile:
|
||||
|
||||
name_of_component:
|
||||
repository:
|
||||
image: image_name
|
||||
tag: image_tag
|
||||
persistence:
|
||||
enabled: true
|
||||
storageClass: storage_class_name
|
||||
ingress:
|
||||
enabled: true
|
||||
host: host_name
|
||||
path: path_name
|
||||
environment:
|
||||
ENV_VAR_1: value_1
|
||||
ENV_VAR_2: value_2
|
||||
|
||||
``` go
|
||||
type Value struct {
|
||||
Repository *RepositoryValue `yaml:"repository,omitempty"`
|
||||
Persistence map[string]*PersistenceValue `yaml:"persistence,omitempty"`
|
||||
Ingress *IngressValue `yaml:"ingress,omitempty"`
|
||||
ImagePullPolicy string `yaml:"imagePullPolicy,omitempty"`
|
||||
Environment map[string]any `yaml:"environment,omitempty"`
|
||||
Replicas *uint32 `yaml:"replicas,omitempty"`
|
||||
CronJob *CronJobValue `yaml:"cronjob,omitempty"`
|
||||
}
|
||||
```
|
||||
|
||||
### func NewValue
|
||||
|
||||
``` go
|
||||
func NewValue(service types.ServiceConfig, main ...bool) *Value
|
||||
```
|
||||
|
||||
NewValue creates a new Value from a compose service. The value contains
|
||||
the necessary information to deploy the service (image, tag, replicas,
|
||||
etc.).
|
||||
|
||||
If \`main\` is true, the tag will be empty because it will be set in the
|
||||
helm chart appVersion.
|
||||
|
||||
### func (*Value) AddIngress
|
||||
|
||||
``` go
|
||||
func (v *Value) AddIngress(host, path string)
|
||||
```
|
||||
|
||||
### func (*Value) AddPersistence
|
||||
|
||||
``` go
|
||||
func (v *Value) AddPersistence(volumeName string)
|
||||
```
|
||||
|
||||
AddPersistence adds persistence configuration to the Value.
|
||||
|
||||
## type VolumeClaim
|
||||
|
||||
VolumeClaim is a kubernetes VolumeClaim. This is a
|
||||
PersistentVolumeClaim.
|
||||
|
||||
``` go
|
||||
type VolumeClaim struct {
|
||||
*v1.PersistentVolumeClaim
|
||||
// contains filtered or unexported fields
|
||||
}
|
||||
```
|
||||
|
||||
### func NewVolumeClaim
|
||||
|
||||
``` go
|
||||
func NewVolumeClaim(service types.ServiceConfig, volumeName, appName string) *VolumeClaim
|
||||
```
|
||||
|
||||
NewVolumeClaim creates a new VolumeClaim from a compose service.
|
||||
|
||||
### func (*VolumeClaim) Filename
|
||||
|
||||
``` go
|
||||
func (v *VolumeClaim) Filename() string
|
||||
```
|
||||
|
||||
Filename returns the suggested filename for a VolumeClaim.
|
||||
|
||||
### func (*VolumeClaim) Yaml
|
||||
|
||||
``` go
|
||||
func (v *VolumeClaim) Yaml() ([]byte, error)
|
||||
```
|
||||
|
||||
Yaml marshals a VolumeClaim into yaml.
|
||||
|
||||
## type Yaml
|
||||
|
||||
Yaml is a kubernetes object that can be converted to yaml.
|
||||
|
||||
``` go
|
||||
type Yaml interface {
|
||||
Yaml() ([]byte, error)
|
||||
Filename() string
|
||||
}
|
||||
```
|
||||
|
||||
Generated by [gomarkdoc](https://github.com/princjef/gomarkdoc)
|
28
doc/docs/packages/generator/extrafiles.md
Normal file
28
doc/docs/packages/generator/extrafiles.md
Normal file
@@ -0,0 +1,28 @@
|
||||
<!-- Code generated by gomarkdoc. DO NOT EDIT -->
|
||||
|
||||
# extrafiles
|
||||
|
||||
``` go
|
||||
import "katenary/generator/extrafiles"
|
||||
```
|
||||
|
||||
extrafiles package provides function to generate the Chart files that
|
||||
are not objects. Like README.md and notes.txt…
|
||||
|
||||
## func NotesFile
|
||||
|
||||
``` go
|
||||
func NotesFile() string
|
||||
```
|
||||
|
||||
NoteTXTFile returns the content of the note.txt file.
|
||||
|
||||
## func ReadMeFile
|
||||
|
||||
``` go
|
||||
func ReadMeFile(charname, description string, values map[string]any) string
|
||||
```
|
||||
|
||||
ReadMeFile returns the content of the README.md file.
|
||||
|
||||
Generated by [gomarkdoc](https://github.com/princjef/gomarkdoc)
|
20
doc/docs/packages/parser.md
Normal file
20
doc/docs/packages/parser.md
Normal file
@@ -0,0 +1,20 @@
|
||||
<!-- Code generated by gomarkdoc. DO NOT EDIT -->
|
||||
|
||||
# parser
|
||||
|
||||
``` go
|
||||
import "katenary/parser"
|
||||
```
|
||||
|
||||
Parser package is a wrapper around compose-go to parse compose files.
|
||||
|
||||
## func Parse
|
||||
|
||||
``` go
|
||||
func Parse(profiles []string, dockerComposeFile ...string) (*types.Project, error)
|
||||
```
|
||||
|
||||
Parse compose files and return a project. The project is parsed with
|
||||
dotenv, osenv and profiles.
|
||||
|
||||
Generated by [gomarkdoc](https://github.com/princjef/gomarkdoc)
|
55
doc/docs/packages/update.md
Normal file
55
doc/docs/packages/update.md
Normal file
@@ -0,0 +1,55 @@
|
||||
<!-- Code generated by gomarkdoc. DO NOT EDIT -->
|
||||
|
||||
# update
|
||||
|
||||
``` go
|
||||
import "katenary/update"
|
||||
```
|
||||
|
||||
Update package is used to check if a new version of katenary is
|
||||
available.
|
||||
|
||||
## Variables
|
||||
|
||||
``` go
|
||||
var Version = "master" // reset by cmd/main.go
|
||||
```
|
||||
|
||||
## func DownloadFile
|
||||
|
||||
``` go
|
||||
func DownloadFile(url, exe string) error
|
||||
```
|
||||
|
||||
DownloadFile will download a url to a local file. It also ensure that
|
||||
the file is executable.
|
||||
|
||||
## func DownloadLatestVersion
|
||||
|
||||
``` go
|
||||
func DownloadLatestVersion(assets []Asset) error
|
||||
```
|
||||
|
||||
DownloadLatestVersion will download the latest version of katenary.
|
||||
|
||||
## type Asset
|
||||
|
||||
Asset is a github asset from release url.
|
||||
|
||||
``` go
|
||||
type Asset struct {
|
||||
Name string `json:"name"`
|
||||
URL string `json:"browser_download_url"`
|
||||
}
|
||||
```
|
||||
|
||||
### func CheckLatestVersion
|
||||
|
||||
``` go
|
||||
func CheckLatestVersion() (string, []Asset, error)
|
||||
```
|
||||
|
||||
CheckLatestVersion check katenary latest version from release and
|
||||
propose to download it
|
||||
|
||||
Generated by [gomarkdoc](https://github.com/princjef/gomarkdoc)
|
187
doc/docs/packages/utils.md
Normal file
187
doc/docs/packages/utils.md
Normal file
@@ -0,0 +1,187 @@
|
||||
<!-- Code generated by gomarkdoc. DO NOT EDIT -->
|
||||
|
||||
# utils
|
||||
|
||||
``` go
|
||||
import "katenary/utils"
|
||||
```
|
||||
|
||||
Utils package provides some utility functions used in katenary. It
|
||||
defines some constants and functions used in the whole project.
|
||||
|
||||
## Constants
|
||||
|
||||
Icons used in katenary.
|
||||
|
||||
``` go
|
||||
const (
|
||||
IconSuccess Icon = "✅"
|
||||
IconFailure = "❌"
|
||||
IconWarning = "⚠️'"
|
||||
IconNote = "📝"
|
||||
IconWorld = "🌐"
|
||||
IconPlug = "🔌"
|
||||
IconPackage = "📦"
|
||||
IconCabinet = "🗄️"
|
||||
IconInfo = "❕"
|
||||
IconSecret = "🔒"
|
||||
IconConfig = "🔧"
|
||||
IconDependency = "🔗"
|
||||
)
|
||||
```
|
||||
|
||||
## func CountStartingSpaces
|
||||
|
||||
``` go
|
||||
func CountStartingSpaces(line string) int
|
||||
```
|
||||
|
||||
CountStartingSpaces counts the number of spaces at the beginning of a
|
||||
string.
|
||||
|
||||
## func GetContainerByName
|
||||
|
||||
``` go
|
||||
func GetContainerByName(name string, containers []corev1.Container) (*corev1.Container, int)
|
||||
```
|
||||
|
||||
GetContainerByName returns a container by name and its index in the
|
||||
array. It returns nil, -1 if not found.
|
||||
|
||||
## func GetKind
|
||||
|
||||
``` go
|
||||
func GetKind(path string) (kind string)
|
||||
```
|
||||
|
||||
GetKind returns the kind of the resource from the file path.
|
||||
|
||||
## func GetServiceNameByPort
|
||||
|
||||
``` go
|
||||
func GetServiceNameByPort(port int) string
|
||||
```
|
||||
|
||||
GetServiceNameByPort returns the service name for a port. It the service
|
||||
name is not found, it returns an empty string.
|
||||
|
||||
## func GetValuesFromLabel
|
||||
|
||||
``` go
|
||||
func GetValuesFromLabel(service types.ServiceConfig, LabelValues string) map[string]*EnvConfig
|
||||
```
|
||||
|
||||
GetValuesFromLabel returns a map of values from a label.
|
||||
|
||||
## func HashComposefiles
|
||||
|
||||
``` go
|
||||
func HashComposefiles(files []string) (string, error)
|
||||
```
|
||||
|
||||
HashComposefiles returns a hash of the compose files.
|
||||
|
||||
## func Int32Ptr
|
||||
|
||||
``` go
|
||||
func Int32Ptr(i int32) *int32
|
||||
```
|
||||
|
||||
Int32Ptr returns a pointer to an int32.
|
||||
|
||||
## func MapKeys
|
||||
|
||||
``` go
|
||||
func MapKeys(m map[string]interface{}) []string
|
||||
```
|
||||
|
||||
## func PathToName
|
||||
|
||||
``` go
|
||||
func PathToName(path string) string
|
||||
```
|
||||
|
||||
PathToName converts a path to a kubernetes complient name.
|
||||
|
||||
## func StrPtr
|
||||
|
||||
``` go
|
||||
func StrPtr(s string) *string
|
||||
```
|
||||
|
||||
StrPtr returns a pointer to a string.
|
||||
|
||||
## func TplName
|
||||
|
||||
``` go
|
||||
func TplName(serviceName, appname string, suffix ...string) string
|
||||
```
|
||||
|
||||
TplName returns the name of the kubernetes resource as a template
|
||||
string. It is used in the templates and defined in \_helper.tpl file.
|
||||
|
||||
## func TplValue
|
||||
|
||||
``` go
|
||||
func TplValue(serviceName, variable string, pipes ...string) string
|
||||
```
|
||||
|
||||
GetContainerByName returns a container by name and its index in the
|
||||
array.
|
||||
|
||||
## func Warn
|
||||
|
||||
``` go
|
||||
func Warn(msg ...interface{})
|
||||
```
|
||||
|
||||
Warn prints a warning message
|
||||
|
||||
## func WordWrap
|
||||
|
||||
``` go
|
||||
func WordWrap(text string, lineWidth int) string
|
||||
```
|
||||
|
||||
WordWrap wraps a string to a given line width. Warning: it may break the
|
||||
string. You need to check the result.
|
||||
|
||||
## func Wrap
|
||||
|
||||
``` go
|
||||
func Wrap(src, above, below string) string
|
||||
```
|
||||
|
||||
Wrap wraps a string with a string above and below. It will respect the
|
||||
indentation of the src string.
|
||||
|
||||
## func WrapBytes
|
||||
|
||||
``` go
|
||||
func WrapBytes(src, above, below []byte) []byte
|
||||
```
|
||||
|
||||
WrapBytes wraps a byte array with a byte array above and below. It will
|
||||
respect the indentation of the src string.
|
||||
|
||||
## type EnvConfig
|
||||
|
||||
EnvConfig is a struct to hold the description of an environment
|
||||
variable.
|
||||
|
||||
``` go
|
||||
type EnvConfig struct {
|
||||
Description string
|
||||
Service types.ServiceConfig
|
||||
}
|
||||
```
|
||||
|
||||
## type Icon
|
||||
|
||||
Icon is a unicode icon
|
||||
|
||||
``` go
|
||||
type Icon string
|
||||
```
|
||||
|
||||
Generated by [gomarkdoc](https://github.com/princjef/gomarkdoc)
|
@@ -27,7 +27,7 @@ button.md-clipboard:hover::after {
|
||||
|
||||
article a,
|
||||
article a:visited {
|
||||
color: var(--md-code-hl-number-color);
|
||||
color: var(--md-code-hl-number-color) !important;
|
||||
}
|
||||
|
||||
.md-center {
|
||||
@@ -53,3 +53,15 @@ pre code.hljs {
|
||||
background-color: var(--code-bg-color);
|
||||
color: var(--code-fg-color);
|
||||
}
|
||||
|
||||
table tbody code {
|
||||
text-align: left;
|
||||
white-space: nowrap;
|
||||
font-size: 1em !important;
|
||||
background-color: transparent !important;
|
||||
color: var(--md-code-hl-special-color) !important;
|
||||
}
|
||||
|
||||
h3[id*="katenaryio"] {
|
||||
color: var(--md-code-hl-special-color);
|
||||
}
|
||||
|
@@ -18,8 +18,8 @@ markdown_extensions:
|
||||
- admonition
|
||||
- attr_list
|
||||
- pymdownx.emoji:
|
||||
emoji_generator: !!python/name:materialx.emoji.to_svg
|
||||
emoji_index: !!python/name:materialx.emoji.twemoji
|
||||
emoji_index: !!python/name:material.extensions.emoji.twemoji
|
||||
emoji_generator: !!python/name:material.extensions.emoji.to_svg
|
||||
- pymdownx.highlight:
|
||||
anchor_linenums: true
|
||||
use_pygments: false
|
||||
@@ -28,7 +28,7 @@ extra_css:
|
||||
- statics/main.css
|
||||
extra_javascript:
|
||||
- statics/addons.js
|
||||
copyright: Copyright © 2021 - 2022 - Katenary authors
|
||||
copyright: Copyright © 2021 - 2023 - Katenary authors
|
||||
extra:
|
||||
generator: false
|
||||
social:
|
||||
@@ -38,3 +38,12 @@ nav:
|
||||
- "Home": index.md
|
||||
- usage.md
|
||||
- labels.md
|
||||
- Behind the scene:
|
||||
- coding.md
|
||||
- dependencies.md
|
||||
- Go Packages:
|
||||
- packages/generator.md
|
||||
- packages/parser.md
|
||||
- packages/update.md
|
||||
- packages/utils.md
|
||||
- packages/generator/extrafiles.md
|
||||
|
@@ -1,4 +1,4 @@
|
||||
mkdocs==1.3.0
|
||||
mkdocs>=1.3.0
|
||||
Jinja2>=2.10.2
|
||||
MarkupSafe>=2.0
|
||||
pymdown-extensions>=9.5
|
||||
|
Reference in New Issue
Block a user