Some fixes on "same-pod" and volumes + add some tests #82
@@ -14,7 +14,8 @@ effortlessly, saving you time and energy.
|
||||
🛠️ Simple automated CLI: Katenary handles the grunt work, generating everything needed for seamless service binding
|
||||
and Helm Chart creation.
|
||||
|
||||
💡 Effortless Efficiency: You only need to add labels when it's necessary to precise things. Then call `katenary convert` and let the magic happen.
|
||||
💡 Effortless Efficiency: You only need to add labels when it's necessary to precise things.
|
||||
Then call `katenary convert` and let the magic happen.
|
||||
|
||||
# What ?
|
||||
|
||||
@@ -158,7 +159,7 @@ services:
|
||||
katenary.v3/ingress: |-
|
||||
hostname: myapp.example.com
|
||||
port: 80
|
||||
katenary.v3/mapenv: |-
|
||||
katenary.v3/map-env: |-
|
||||
# make adaptations, DB_HOST environment is actually the service name
|
||||
DB_HOST: '{{ .Release.Name }}-database'
|
||||
|
||||
|
@@ -12,7 +12,7 @@ Since version v3, Katenary uses, in addition to `go-compose`, the `k8s` library
|
||||
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
|
||||
manipulation during the process. There are, also, some drawbacks using standard k8s packages that make 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.**
|
||||
@@ -59,9 +59,9 @@ its associated service are still created. They are deleted last, once the merge
|
||||
|
||||
## Conversion in "`generator`" package
|
||||
|
||||
The `generator` package is where object struct are defined, and where the `Generate()` function is written.
|
||||
The `generator` package is where object struct are defined, and where you can find the `Generate()` function.
|
||||
|
||||
The generation is made by using a `HelmChart` object:
|
||||
The generation fills `HelmChart` object using a loop:
|
||||
|
||||
```golang
|
||||
for _, service := range project.Services {
|
||||
@@ -75,7 +75,7 @@ for _, service := range project.Services {
|
||||
```
|
||||
|
||||
**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
|
||||
operations. The `Yaml` methods **don't return a valid YAML content**. This is a Helm Chart YAML content with template
|
||||
conditions, values and calls to helper templates.
|
||||
|
||||
> The `Yaml()` methods, in each object, need contribution, help, fixes, enhancements... They work, but there is a lot of
|
||||
@@ -92,11 +92,11 @@ For each source container linked to the destination:
|
||||
- we then copy the service port to the destination service
|
||||
- we finally remove the source service and deployment
|
||||
|
||||
> The configmap, secrets, variables... are kept.
|
||||
> The `Configmap`, secrets, variables... are kept.
|
||||
|
||||
It finaly computes the `helper` file.
|
||||
It finally computes the `helper` file.
|
||||
|
||||
## Convertion command
|
||||
## Conversion command
|
||||
|
||||
The `generator` works the same as described above. But the "convert" command makes some final steps:
|
||||
|
||||
|
@@ -1,11 +1,11 @@
|
||||
# Why those dependencies?
|
||||
|
||||
Katenary uses `compose-go` and several kubernetes official packages.
|
||||
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
|
||||
- that Katenary uses the "compose" struct exactly the same way `podman compose` or `docker copose` does
|
||||
- `github.com/spf13/cobra`: to parse command line arguments, subcommands and flags. It also generates completion for
|
||||
- that Katenary uses the "compose" struct exactly the same way `podman compose` or `docker copose` does
|
||||
- `github.com/spf13/cobra`: to parse command line arguments, sub-commands 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 its port number
|
||||
- `gopkg.in/yaml.v3`:
|
||||
|
@@ -23,7 +23,7 @@ Kompose is able to generate Helm charts, but [it could be not the case in future
|
||||
task, and we can confirm. Katenary takes a lot of time to be developed and maintained. This issue mentions Katenary as
|
||||
an alternative to Helm chart generation :smile:
|
||||
|
||||
The project is focused on Kubernetes manifests and proposes to use "kusomize" to adapt the manifests. Helm seems to be
|
||||
The project is focused on Kubernetes manifests and proposes to use "Kustomize" to adapt the manifests. Helm seems to be
|
||||
not the priority.
|
||||
|
||||
Anyway, before this decision, the Helm chart generation was not what we expected. We wanted to have a more complete
|
||||
@@ -41,7 +41,7 @@ your `docker-compose` files to Kubernetes manifests, but if you want to use Helm
|
||||
|
||||
## Why not using "one label" for all the configuration?
|
||||
|
||||
That was a dicsussion I had with my colleagues. The idea was to use a single label to store all the configuration.
|
||||
That was a discussion I had with my colleagues. The idea was to use a single label to store all the configuration.
|
||||
But, it's not a good idea.
|
||||
|
||||
Sometimes, you will have a long list of things to configure, like ports, ingress, dependencies, etc. It's better to have
|
||||
@@ -78,7 +78,8 @@ There is no reason to use Rust for this project.
|
||||
Yes, it's a possibility. But, it's not a priority. We have a lot of things to do before. We need to stabilize the
|
||||
project, to have a good documentation, to have a good test coverage, and to have a good community.
|
||||
|
||||
But, in a not so far future, we could have a GUI. The choice of [Fyne.io](https://fyne.io) is already made and we tested some concepts.
|
||||
But, in a not so far future, we could have a GUI. The choice of [Fyne.io](https://fyne.io) is already made, and we
|
||||
tested some concepts.
|
||||
|
||||
## I'm rich (or not), I want to help you. How can I do?
|
||||
|
||||
@@ -86,13 +87,13 @@ You can help us in many ways.
|
||||
|
||||
- The first things we really need, more than money, more than anything else, is to have feedback. If you use Katenary,
|
||||
if you have some issues, if you have some ideas, please open an issue on the [GitHub repository](https://github.com/metal3d/katenary).
|
||||
- The second things is to help us to fix issues. If you're a Go developper, or if you want to fix the documentation,
|
||||
- The second thing is to help us to fix issues. If you're a Go developer, or if you want to fix the documentation,
|
||||
your help is greatly appreciated.
|
||||
- And then, of course, we need money, or sponsors.
|
||||
|
||||
### If you're a company
|
||||
|
||||
We will be happy to communicate your help by putting your logo on the website and in the documentaiton. You can sponsor
|
||||
We will be happy to communicate your help by putting your logo on the website and in the documentation. You can sponsor
|
||||
us by giving us some money, or by giving us some time of your developers, or leaving us some time to work on the project.
|
||||
|
||||
### If you're an individual
|
||||
|
@@ -9,7 +9,7 @@
|
||||
Tired of manual conversions? Katenary harnesses the labels from your "compose" file to craft complete Helm Charts
|
||||
effortlessly, saving you time and energy.
|
||||
|
||||
🛠️ Simple autmated CLI: Katenary handles the grunt work, generating everything needed for seamless service binding
|
||||
🛠️ Simple automated CLI: Katenary handles the grunt work, generating everything needed for seamless service binding
|
||||
and Helm Chart creation.
|
||||
|
||||
💡 Effortless Efficiency: You only need to add labels when it's necessary to precise things. Then call `katenary convert`
|
||||
@@ -21,18 +21,18 @@ and let the magic happen.
|
||||
|
||||
# What is it?
|
||||
|
||||
Katenary is a tool made to help you to transform "compose" files (`compose.yaml`, `docker-compose.yml`, `podman-compose.yml`...) to
|
||||
complete and production ready [Helm Chart](https://helm.sh).
|
||||
Katenary is a tool made to help you to transform "compose" files (`compose.yaml`, `docker-compose.yml`,
|
||||
`podman-compose.yml`...) to complete and production ready [Helm Chart](https://helm.sh).
|
||||
|
||||
You'll be able to deploy your project in [:material-kubernetes: Kubernetes](https://kubernetes.io) in a few seconds
|
||||
(of course, more if you need to tweak with labels).
|
||||
|
||||
It uses your current file and optionnaly labels to configure the result.
|
||||
It uses your current file and optionally labels to configure the result.
|
||||
|
||||
It's an opensource project, under MIT licence, originally partially developped at [Smile](https://www.smile.eu).
|
||||
It's an open source project, under MIT license, originally partially developed at [Smile](https://www.smile.eu).
|
||||
|
||||
Today, it's partially developped in collaboration with [Klee Group](https://www.kleegroup.com). Note that Katenary is
|
||||
and **will stay an opensource and free (as freedom) project**. We are convinced that the best way to make it better is to
|
||||
Today, it's partially developed in collaboration with [Klee Group](https://www.kleegroup.com). Note that Katenary is
|
||||
and **will stay an open source and free (as freedom) project**. We are convinced that the best way to make it better is to
|
||||
share it with the community.
|
||||
|
||||
<div id="klee">
|
||||
@@ -46,9 +46,9 @@ code is hosted on the [:fontawesome-brands-github: Katenary GitHub Repository](h
|
||||
|
||||
## Install Katenary
|
||||
|
||||
Katenary is developped using the :fontawesome-brands-golang:{ .gopher } [Go](https://go.dev) language.
|
||||
Katenary is developed using the :fontawesome-brands-golang:{ .gopher } [Go](https://go.dev) language.
|
||||
The binary is statically linked, so you can simply download it from the [release
|
||||
page](https://github.com/metal3d/katenary/releases) of the project in GutHub.
|
||||
page](https://github.com/metal3d/katenary/releases) of the project in GitHub.
|
||||
|
||||
You need to select the right binary for your operating system and architecture, and copy the binary in a directory
|
||||
that is in your `PATH`.
|
||||
@@ -61,7 +61,7 @@ sh <(curl -sSL https://raw.githubusercontent.com/metal3d/katenary/master/install
|
||||
```
|
||||
|
||||
!!! Info "Upgrading is integrated to the `katenary` command"
|
||||
Katenary propose a `upgrade` subcommand to update the current binary to the latest stable release.
|
||||
Katenary propose a `upgrade` sub-command to update the current binary to the latest stable release.
|
||||
|
||||
Of course, you need to install Katenary once :smile:
|
||||
|
||||
@@ -122,18 +122,18 @@ Anyway, it's too late to change the name now :smile:
|
||||
## Special thanks to
|
||||
|
||||
I really want to thank all the contributors, testers, and of course, the authors of the packages and tools that are used
|
||||
in this project. There is too many to list here. Katenary can works because of all these people. Open source is a great
|
||||
in this project. There is too many to list here. Katenary can work because of all these people. Open source is a great
|
||||
thing! :heart:
|
||||
|
||||
!!! Edit "Special thanks"
|
||||
|
||||
**Katenary is built with:** <br />
|
||||
|
||||
<a href="https://go.dev" target="_blank">:fontawesome-brands-golang:{ .go-logo }</a>
|
||||
<a href="https://go.dev" target="_blank">:fontawesome-brands-golang:{ .go-logo }</a>
|
||||
|
||||
Go is an open source programming language that makes it easy to build simple, reliable, and efficient software. Because Docker, Podman,
|
||||
Kubernetes, and Helm are written in Go, Katenary is also written in Go and borrows packages from these projects to
|
||||
make it as efficient as possible.
|
||||
Go is an open source programming language that makes it easy to build simple, reliable, and efficient software.
|
||||
Because Docker, Podman, Kubernetes, and Helm are written in Go, Katenary is also written in Go and borrows packages
|
||||
from these projects to make it as efficient as possible.
|
||||
|
||||
Thanks to Kubernetes to provide [Kind](https://kind.sigs.k8s.io) that is used to test Katenary locally.
|
||||
|
||||
@@ -142,17 +142,17 @@ thing! :heart:
|
||||
Katenary can progress because of all these people. All contributions, as comments, issues, pull requests and
|
||||
feedbacks are welcome.
|
||||
|
||||
**Everything was also possible because of:** <br />
|
||||
**Everything was also possible because of:** <br />
|
||||
|
||||
<ul>
|
||||
<li><a href="https://helm.sh" target="_blank"><img src="https://helm.sh/img/helm.svg" style="height: 1rem"/>
|
||||
Helm</a> that is the main toppic of Katenary, Kubernetes is easier to use with it.</li>
|
||||
Helm</a> that is the main toppic of Katenary, Kubernetes is easier to use with it.</li>
|
||||
<li><a href="https://cobra.dev/"><img src="https://cobra.dev/home/logo.png" style="height: 1rem"/> Cobra</a> that
|
||||
makes command, subcommand and completion possible for Katenary with ease.</li>
|
||||
<li>Podman, Docker, Kubernetes that are the main tools that Katenary is made for.</li>
|
||||
</ul>
|
||||
|
||||
**Documentation is built with:** <br />
|
||||
**Documentation is built with:** <br />
|
||||
|
||||
<a href="https://www.mkdocs.org/" target="_blank">MkDocs</a> using <a
|
||||
href="https://squidfunk.github.io/mkdocs-material/" target="_blank">Material for MkDocs</a> theme template.
|
||||
|
@@ -7,22 +7,23 @@ Katenary will try to Unmarshal these labels.
|
||||
## Label list and types
|
||||
|
||||
<!-- 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 |
|
||||
| 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/exchange-volumes` | Add exchange volumes (empty directory on the node) to share data | list of objects |
|
||||
| `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 |
|
||||
|
||||
<!-- STOP_LABEL_DOC : do not remove this tag !-->
|
||||
|
||||
@@ -33,7 +34,7 @@ Katenary will try to Unmarshal these labels.
|
||||
|
||||
Add files to the configmap.
|
||||
|
||||
**Type**: `list of strings`
|
||||
**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
|
||||
@@ -59,11 +60,12 @@ labels:
|
||||
- ./conf.d
|
||||
```
|
||||
|
||||
|
||||
### katenary.v3/cronjob
|
||||
|
||||
Create a cronjob from the service.
|
||||
|
||||
**Type**: `object`
|
||||
**Type**: `object`
|
||||
|
||||
This adds a cronjob to the chart.
|
||||
|
||||
@@ -83,11 +85,12 @@ labels:
|
||||
schedule: "* */1 * * *" # or @hourly for example
|
||||
```
|
||||
|
||||
|
||||
### katenary.v3/dependencies
|
||||
|
||||
Add Helm dependencies to the service.
|
||||
|
||||
**Type**: `list of objects`
|
||||
**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
|
||||
@@ -129,11 +132,12 @@ labels:
|
||||
password: the secret password
|
||||
```
|
||||
|
||||
|
||||
### katenary.v3/description
|
||||
|
||||
Description of the service
|
||||
|
||||
**Type**: `string`
|
||||
**Type**: `string`
|
||||
|
||||
This replaces the default comment in values.yaml file to the given description.
|
||||
It is useful to document the service and configuration.
|
||||
@@ -149,11 +153,12 @@ labels:
|
||||
It can be multiline.
|
||||
```
|
||||
|
||||
|
||||
### katenary.v3/env-from
|
||||
|
||||
Add environment variables from antoher service.
|
||||
|
||||
**Type**: `list of strings`
|
||||
**Type**: `list of strings`
|
||||
|
||||
It adds environment variables from another service to the current service.
|
||||
|
||||
@@ -174,11 +179,55 @@ service2:
|
||||
- myservice1
|
||||
```
|
||||
|
||||
|
||||
### katenary.v3/exchange-volumes
|
||||
|
||||
Add exchange volumes (empty directory on the node) to share data
|
||||
|
||||
**Type**: `list of objects`
|
||||
|
||||
This label allows sharing data between containres. The volume is created in
|
||||
the node and mounted in the pod. It is useful to share data between containers
|
||||
in a "same pod" logic. For example to let PHP-FPM and Nginx share the same direcotory.
|
||||
|
||||
This will create:
|
||||
|
||||
- an `emptyDir` volume in the deployment
|
||||
- a `voumeMount` in the pod for **each container**
|
||||
- a `initContainer` for each definition
|
||||
|
||||
Fields:
|
||||
- name: the name of the volume (manadatory)
|
||||
- mountPath: the path where the volume is mounted in the pod (optional, default is `/opt`)
|
||||
- init: a command to run to initialize the volume with data (optional)
|
||||
|
||||
!!! Warning
|
||||
This is highly experimental. This is mainly useful when using the "same-pod" label.
|
||||
|
||||
**Example:**
|
||||
|
||||
```yaml
|
||||
nginx:
|
||||
# ...
|
||||
labels;
|
||||
katenary.v3/exchange-volumes: |-
|
||||
- name: php-fpm
|
||||
mountPath: /var/www/html
|
||||
php:
|
||||
# ...
|
||||
labels:
|
||||
katenary.v3/exchange-volumes: |-
|
||||
- name: php-fpm
|
||||
mountPath: /opt
|
||||
init: cp -ra /var/www/html/* /opt
|
||||
```
|
||||
|
||||
|
||||
### katenary.v3/health-check
|
||||
|
||||
Health check to be added to the deployment.
|
||||
|
||||
**Type**: `object`
|
||||
**Type**: `object`
|
||||
|
||||
Health check to be added to the deployment.
|
||||
|
||||
@@ -193,11 +242,12 @@ labels:
|
||||
port: 8080
|
||||
```
|
||||
|
||||
|
||||
### katenary.v3/ignore
|
||||
|
||||
Ignore the service
|
||||
|
||||
**Type**: `bool`
|
||||
**Type**: `bool`
|
||||
|
||||
Ingoring a service to not be exported in helm chart.
|
||||
|
||||
@@ -208,11 +258,12 @@ labels:
|
||||
katenary.v3/ignore: "true"
|
||||
```
|
||||
|
||||
|
||||
### katenary.v3/ingress
|
||||
|
||||
Ingress rules to be added to the service.
|
||||
|
||||
**Type**: `object`
|
||||
**Type**: `object`
|
||||
|
||||
Declare an ingress rule for the service. The port should be exposed or
|
||||
declared with `katenary.v3/ports`.
|
||||
@@ -226,17 +277,16 @@ labels:
|
||||
hostname: mywebsite.com (optional)
|
||||
```
|
||||
|
||||
|
||||
### katenary.v3/main-app
|
||||
|
||||
Mark the service as the main app.
|
||||
|
||||
**Type**: `bool`
|
||||
**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.
|
||||
considered to be the Chart appVersion and to be the defaultvalue in Pod
|
||||
container image attribute.
|
||||
|
||||
!!! Warning
|
||||
This label cannot be repeated in others services. If this label is
|
||||
@@ -254,11 +304,12 @@ ghost:
|
||||
katenary.v3/main-app: true
|
||||
```
|
||||
|
||||
|
||||
### katenary.v3/map-env
|
||||
|
||||
Map env vars from the service to the deployment.
|
||||
|
||||
**Type**: `object`
|
||||
**Type**: `object`
|
||||
|
||||
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
|
||||
@@ -281,11 +332,12 @@ labels:
|
||||
DB_HOST: '{{ include "__APP__.fullname" . }}-database'
|
||||
```
|
||||
|
||||
|
||||
### katenary.v3/ports
|
||||
|
||||
Ports to be added to the service.
|
||||
|
||||
**Type**: `list of uint32`
|
||||
**Type**: `list of uint32`
|
||||
|
||||
Only useful for services without exposed port. It is mandatory if the
|
||||
service is a dependency of another service.
|
||||
@@ -299,11 +351,12 @@ labels:
|
||||
- 8081
|
||||
```
|
||||
|
||||
|
||||
### katenary.v3/same-pod
|
||||
|
||||
Move the same-pod deployment to the target deployment.
|
||||
|
||||
**Type**: `string`
|
||||
**Type**: `string`
|
||||
|
||||
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.
|
||||
@@ -323,11 +376,12 @@ php:
|
||||
katenary.v3/same-pod: web
|
||||
```
|
||||
|
||||
|
||||
### katenary.v3/secrets
|
||||
|
||||
Env vars to be set as secrets.
|
||||
|
||||
**Type**: `list of string`
|
||||
**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.
|
||||
@@ -346,11 +400,12 @@ labels:
|
||||
- PASSWORD
|
||||
```
|
||||
|
||||
|
||||
### katenary.v3/values
|
||||
|
||||
Environment variables to be added to the values.yaml
|
||||
|
||||
**Type**: `list of string or map`
|
||||
**Type**: `list of string or map`
|
||||
|
||||
By default, all environment variables in the "env" and environment
|
||||
files are added to configmaps with the static values set. This label
|
||||
@@ -382,4 +437,5 @@ labels:
|
||||
It can be, of course, a multiline text.
|
||||
```
|
||||
|
||||
|
||||
<!-- STOP_DETAILED_DOC : do not remove this tag !-->
|
||||
|
@@ -23,7 +23,7 @@ var (
|
||||
|
||||
// Standard annotationss
|
||||
Annotations = map[string]string{
|
||||
labelName("version"): Version,
|
||||
labels.LabelName("version"): Version,
|
||||
}
|
||||
)
|
||||
```
|
||||
@@ -35,7 +35,7 @@ var Version = "master" // changed at compile time
|
||||
```
|
||||
|
||||
<a name="Convert"></a>
|
||||
## func [Convert](<https://github.com/metal3d/katenary/blob/develop/generator/converter.go#L91>)
|
||||
## func [Convert](<https://github.com/metal3d/katenary/blob/develop/generator/converter.go#L93>)
|
||||
|
||||
```go
|
||||
func Convert(config ConvertOptions, dockerComposeFile ...string)
|
||||
@@ -43,35 +43,8 @@ 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.
|
||||
|
||||
<a name="GetLabelHelp"></a>
|
||||
## func [GetLabelHelp](<https://github.com/metal3d/katenary/blob/develop/generator/katenaryLabels.go#L79>)
|
||||
|
||||
```go
|
||||
func GetLabelHelp(asMarkdown bool) string
|
||||
```
|
||||
|
||||
Generate the help for the labels.
|
||||
|
||||
<a name="GetLabelHelpFor"></a>
|
||||
## func [GetLabelHelpFor](<https://github.com/metal3d/katenary/blob/develop/generator/katenaryLabels.go#L88>)
|
||||
|
||||
```go
|
||||
func GetLabelHelpFor(labelname string, asMarkdown bool) string
|
||||
```
|
||||
|
||||
GetLabelHelpFor returns the help for a specific label.
|
||||
|
||||
<a name="GetLabelNames"></a>
|
||||
## func [GetLabelNames](<https://github.com/metal3d/katenary/blob/develop/generator/katenaryLabels.go#L63>)
|
||||
|
||||
```go
|
||||
func GetLabelNames() []string
|
||||
```
|
||||
|
||||
GetLabelNames returns a sorted list of all katenary label names.
|
||||
|
||||
<a name="GetLabels"></a>
|
||||
## func [GetLabels](<https://github.com/metal3d/katenary/blob/develop/generator/labels.go#L11>)
|
||||
## func [GetLabels](<https://github.com/metal3d/katenary/blob/develop/generator/labels.go#L12>)
|
||||
|
||||
```go
|
||||
func GetLabels(serviceName, appName string) map[string]string
|
||||
@@ -80,7 +53,7 @@ func GetLabels(serviceName, appName string) map[string]string
|
||||
GetLabels returns the labels for a service. It uses the appName to replace the \_\_replace\_\_ in the labels. This is used to generate the labels in the templates.
|
||||
|
||||
<a name="GetMatchLabels"></a>
|
||||
## func [GetMatchLabels](<https://github.com/metal3d/katenary/blob/develop/generator/labels.go#L24>)
|
||||
## func [GetMatchLabels](<https://github.com/metal3d/katenary/blob/develop/generator/labels.go#L25>)
|
||||
|
||||
```go
|
||||
func GetMatchLabels(serviceName, appName string) map[string]string
|
||||
@@ -89,7 +62,7 @@ func GetMatchLabels(serviceName, appName string) map[string]string
|
||||
GetMatchLabels returns the matchLabels for a service. It uses the appName to replace the \_\_replace\_\_ in the labels. This is used to generate the matchLabels in the templates.
|
||||
|
||||
<a name="Helper"></a>
|
||||
## func [Helper](<https://github.com/metal3d/katenary/blob/develop/generator/helper.go#L14>)
|
||||
## func [Helper](<https://github.com/metal3d/katenary/blob/develop/generator/helper.go#L15>)
|
||||
|
||||
```go
|
||||
func Helper(name string) string
|
||||
@@ -106,17 +79,17 @@ func NewCronJob(service types.ServiceConfig, chart *HelmChart, appName string) (
|
||||
|
||||
NewCronJob creates a new CronJob from a compose service. The appName is the name of the application taken from the project name.
|
||||
|
||||
<a name="Prefix"></a>
|
||||
## func [Prefix](<https://github.com/metal3d/katenary/blob/develop/generator/katenaryLabels.go#L233>)
|
||||
<a name="ToK8SYaml"></a>
|
||||
## func [ToK8SYaml](<https://github.com/metal3d/katenary/blob/develop/generator/utils.go#L90>)
|
||||
|
||||
```go
|
||||
func Prefix() string
|
||||
func ToK8SYaml(obj interface{}) ([]byte, error)
|
||||
```
|
||||
|
||||
|
||||
|
||||
<a name="UnWrapTPL"></a>
|
||||
## func [UnWrapTPL](<https://github.com/metal3d/katenary/blob/develop/generator/utils.go#L84>)
|
||||
## func [UnWrapTPL](<https://github.com/metal3d/katenary/blob/develop/generator/utils.go#L86>)
|
||||
|
||||
```go
|
||||
func UnWrapTPL(in []byte) []byte
|
||||
@@ -125,7 +98,7 @@ func UnWrapTPL(in []byte) []byte
|
||||
UnWrapTPL removes the line wrapping from a template.
|
||||
|
||||
<a name="ChartTemplate"></a>
|
||||
## type [ChartTemplate](<https://github.com/metal3d/katenary/blob/develop/generator/chart.go#L17-L20>)
|
||||
## type [ChartTemplate](<https://github.com/metal3d/katenary/blob/develop/generator/chart.go#L18-L21>)
|
||||
|
||||
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.
|
||||
|
||||
@@ -185,7 +158,7 @@ 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.
|
||||
|
||||
<a name="ConfigMap.AppendFile"></a>
|
||||
### func \(\*ConfigMap\) [AppendFile](<https://github.com/metal3d/katenary/blob/develop/generator/configMap.go#L201>)
|
||||
### func \(\*ConfigMap\) [AppendFile](<https://github.com/metal3d/katenary/blob/develop/generator/configMap.go#L200>)
|
||||
|
||||
```go
|
||||
func (c *ConfigMap) AppendFile(path string)
|
||||
@@ -194,7 +167,7 @@ func (c *ConfigMap) AppendFile(path string)
|
||||
|
||||
|
||||
<a name="ConfigMap.Filename"></a>
|
||||
### func \(\*ConfigMap\) [Filename](<https://github.com/metal3d/katenary/blob/develop/generator/configMap.go#L219>)
|
||||
### func \(\*ConfigMap\) [Filename](<https://github.com/metal3d/katenary/blob/develop/generator/configMap.go#L218>)
|
||||
|
||||
```go
|
||||
func (c *ConfigMap) Filename() string
|
||||
@@ -203,7 +176,7 @@ func (c *ConfigMap) Filename() string
|
||||
Filename returns the filename of the configmap. If the configmap is used for files, the filename contains the path.
|
||||
|
||||
<a name="ConfigMap.SetData"></a>
|
||||
### func \(\*ConfigMap\) [SetData](<https://github.com/metal3d/katenary/blob/develop/generator/configMap.go#L229>)
|
||||
### func \(\*ConfigMap\) [SetData](<https://github.com/metal3d/katenary/blob/develop/generator/configMap.go#L228>)
|
||||
|
||||
```go
|
||||
func (c *ConfigMap) SetData(data map[string]string)
|
||||
@@ -212,7 +185,7 @@ func (c *ConfigMap) SetData(data map[string]string)
|
||||
SetData sets the data of the configmap. It replaces the entire data.
|
||||
|
||||
<a name="ConfigMap.Yaml"></a>
|
||||
### func \(\*ConfigMap\) [Yaml](<https://github.com/metal3d/katenary/blob/develop/generator/configMap.go#L234>)
|
||||
### func \(\*ConfigMap\) [Yaml](<https://github.com/metal3d/katenary/blob/develop/generator/configMap.go#L233>)
|
||||
|
||||
```go
|
||||
func (c *ConfigMap) Yaml() ([]byte, error)
|
||||
@@ -232,7 +205,7 @@ type ConfigMapMount struct {
|
||||
```
|
||||
|
||||
<a name="ConvertOptions"></a>
|
||||
## type [ConvertOptions](<https://github.com/metal3d/katenary/blob/develop/generator/chart.go#L23-L32>)
|
||||
## type [ConvertOptions](<https://github.com/metal3d/katenary/blob/develop/generator/chart.go#L24-L33>)
|
||||
|
||||
ConvertOptions are the options to convert a compose project to a helm chart.
|
||||
|
||||
@@ -284,7 +257,7 @@ Yaml returns the yaml representation of the cronjob.
|
||||
Implements the Yaml interface.
|
||||
|
||||
<a name="CronJobValue"></a>
|
||||
## type [CronJobValue](<https://github.com/metal3d/katenary/blob/develop/generator/values.go#L108-L113>)
|
||||
## type [CronJobValue](<https://github.com/metal3d/katenary/blob/develop/generator/values.go#L113-L118>)
|
||||
|
||||
CronJobValue is a cronjob configuration that will be saved in values.yaml.
|
||||
|
||||
@@ -319,7 +292,7 @@ func NewFileMap(service types.ServiceConfig, appName, 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.
|
||||
|
||||
<a name="Deployment"></a>
|
||||
## type [Deployment](<https://github.com/metal3d/katenary/blob/develop/generator/deployment.go#L34-L42>)
|
||||
## type [Deployment](<https://github.com/metal3d/katenary/blob/develop/generator/deployment.go#L34-L43>)
|
||||
|
||||
Deployment is a kubernetes Deployment.
|
||||
|
||||
@@ -331,7 +304,7 @@ type Deployment struct {
|
||||
```
|
||||
|
||||
<a name="NewDeployment"></a>
|
||||
### func [NewDeployment](<https://github.com/metal3d/katenary/blob/develop/generator/deployment.go#L46>)
|
||||
### func [NewDeployment](<https://github.com/metal3d/katenary/blob/develop/generator/deployment.go#L47>)
|
||||
|
||||
```go
|
||||
func NewDeployment(service types.ServiceConfig, chart *HelmChart) *Deployment
|
||||
@@ -340,7 +313,7 @@ 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.
|
||||
|
||||
<a name="Deployment.AddContainer"></a>
|
||||
### func \(\*Deployment\) [AddContainer](<https://github.com/metal3d/katenary/blob/develop/generator/deployment.go#L111>)
|
||||
### func \(\*Deployment\) [AddContainer](<https://github.com/metal3d/katenary/blob/develop/generator/deployment.go#L113>)
|
||||
|
||||
```go
|
||||
func (d *Deployment) AddContainer(service types.ServiceConfig)
|
||||
@@ -349,7 +322,7 @@ func (d *Deployment) AddContainer(service types.ServiceConfig)
|
||||
AddContainer adds a container to the deployment.
|
||||
|
||||
<a name="Deployment.AddHealthCheck"></a>
|
||||
### func \(\*Deployment\) [AddHealthCheck](<https://github.com/metal3d/katenary/blob/develop/generator/deployment.go#L156>)
|
||||
### func \(\*Deployment\) [AddHealthCheck](<https://github.com/metal3d/katenary/blob/develop/generator/deployment.go#L158>)
|
||||
|
||||
```go
|
||||
func (d *Deployment) AddHealthCheck(service types.ServiceConfig, container *corev1.Container)
|
||||
@@ -358,7 +331,7 @@ func (d *Deployment) AddHealthCheck(service types.ServiceConfig, container *core
|
||||
|
||||
|
||||
<a name="Deployment.AddIngress"></a>
|
||||
### func \(\*Deployment\) [AddIngress](<https://github.com/metal3d/katenary/blob/develop/generator/deployment.go#L185>)
|
||||
### func \(\*Deployment\) [AddIngress](<https://github.com/metal3d/katenary/blob/develop/generator/deployment.go#L187>)
|
||||
|
||||
```go
|
||||
func (d *Deployment) AddIngress(service types.ServiceConfig, appName string) *Ingress
|
||||
@@ -366,8 +339,17 @@ func (d *Deployment) AddIngress(service types.ServiceConfig, appName string) *In
|
||||
|
||||
AddIngress adds an ingress to the deployment. It creates the ingress object.
|
||||
|
||||
<a name="Deployment.AddLegacyVolume"></a>
|
||||
### func \(\*Deployment\) [AddLegacyVolume](<https://github.com/metal3d/katenary/blob/develop/generator/deployment.go#L217>)
|
||||
|
||||
```go
|
||||
func (d *Deployment) AddLegacyVolume(name, kind string)
|
||||
```
|
||||
|
||||
|
||||
|
||||
<a name="Deployment.AddVolumes"></a>
|
||||
### func \(\*Deployment\) [AddVolumes](<https://github.com/metal3d/katenary/blob/develop/generator/deployment.go#L191>)
|
||||
### func \(\*Deployment\) [AddVolumes](<https://github.com/metal3d/katenary/blob/develop/generator/deployment.go#L193>)
|
||||
|
||||
```go
|
||||
func (d *Deployment) AddVolumes(service types.ServiceConfig, appName string)
|
||||
@@ -376,7 +358,7 @@ 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.
|
||||
|
||||
<a name="Deployment.BindFrom"></a>
|
||||
### func \(\*Deployment\) [BindFrom](<https://github.com/metal3d/katenary/blob/develop/generator/deployment.go#L215>)
|
||||
### func \(\*Deployment\) [BindFrom](<https://github.com/metal3d/katenary/blob/develop/generator/deployment.go#L238>)
|
||||
|
||||
```go
|
||||
func (d *Deployment) BindFrom(service types.ServiceConfig, binded *Deployment)
|
||||
@@ -384,8 +366,17 @@ func (d *Deployment) BindFrom(service types.ServiceConfig, binded *Deployment)
|
||||
|
||||
|
||||
|
||||
<a name="Deployment.BindMapFilesToContainer"></a>
|
||||
### func \(\*Deployment\) [BindMapFilesToContainer](<https://github.com/metal3d/katenary/blob/develop/generator/deployment.go#L375>)
|
||||
|
||||
```go
|
||||
func (d *Deployment) BindMapFilesToContainer(service types.ServiceConfig, secrets []string, appName string) (*corev1.Container, int)
|
||||
```
|
||||
|
||||
|
||||
|
||||
<a name="Deployment.DependsOn"></a>
|
||||
### func \(\*Deployment\) [DependsOn](<https://github.com/metal3d/katenary/blob/develop/generator/deployment.go#L243>)
|
||||
### func \(\*Deployment\) [DependsOn](<https://github.com/metal3d/katenary/blob/develop/generator/deployment.go#L266>)
|
||||
|
||||
```go
|
||||
func (d *Deployment) DependsOn(to *Deployment, servicename string) error
|
||||
@@ -394,7 +385,7 @@ func (d *Deployment) DependsOn(to *Deployment, servicename string) error
|
||||
DependsOn adds a initContainer to the deployment that will wait for the service to be up.
|
||||
|
||||
<a name="Deployment.Filename"></a>
|
||||
### func \(\*Deployment\) [Filename](<https://github.com/metal3d/katenary/blob/develop/generator/deployment.go#L269>)
|
||||
### func \(\*Deployment\) [Filename](<https://github.com/metal3d/katenary/blob/develop/generator/deployment.go#L297>)
|
||||
|
||||
```go
|
||||
func (d *Deployment) Filename() string
|
||||
@@ -402,17 +393,26 @@ func (d *Deployment) Filename() string
|
||||
|
||||
Filename returns the filename of the deployment.
|
||||
|
||||
<a name="Deployment.SetEnvFrom"></a>
|
||||
### func \(\*Deployment\) [SetEnvFrom](<https://github.com/metal3d/katenary/blob/develop/generator/deployment.go#L274>)
|
||||
<a name="Deployment.MountExchangeVolumes"></a>
|
||||
### func \(\*Deployment\) [MountExchangeVolumes](<https://github.com/metal3d/katenary/blob/develop/generator/deployment.go#L426>)
|
||||
|
||||
```go
|
||||
func (d *Deployment) SetEnvFrom(service types.ServiceConfig, appName string)
|
||||
func (d *Deployment) MountExchangeVolumes()
|
||||
```
|
||||
|
||||
|
||||
|
||||
<a name="Deployment.SetEnvFrom"></a>
|
||||
### func \(\*Deployment\) [SetEnvFrom](<https://github.com/metal3d/katenary/blob/develop/generator/deployment.go#L302>)
|
||||
|
||||
```go
|
||||
func (d *Deployment) SetEnvFrom(service types.ServiceConfig, appName string, samePod ...bool)
|
||||
```
|
||||
|
||||
SetEnvFrom sets the environment variables to a configmap. The configmap is created.
|
||||
|
||||
<a name="Deployment.Yaml"></a>
|
||||
### func \(\*Deployment\) [Yaml](<https://github.com/metal3d/katenary/blob/develop/generator/deployment.go#L367>)
|
||||
### func \(\*Deployment\) [Yaml](<https://github.com/metal3d/katenary/blob/develop/generator/deployment.go#L450>)
|
||||
|
||||
```go
|
||||
func (d *Deployment) Yaml() ([]byte, error)
|
||||
@@ -439,7 +439,7 @@ const (
|
||||
```
|
||||
|
||||
<a name="HelmChart"></a>
|
||||
## type [HelmChart](<https://github.com/metal3d/katenary/blob/develop/generator/chart.go#L36-L49>)
|
||||
## type [HelmChart](<https://github.com/metal3d/katenary/blob/develop/generator/chart.go#L37-L50>)
|
||||
|
||||
HelmChart is a Helm Chart representation. It contains all the tempaltes, values, versions, helpers...
|
||||
|
||||
@@ -462,7 +462,7 @@ type HelmChart struct {
|
||||
```
|
||||
|
||||
<a name="Generate"></a>
|
||||
### func [Generate](<https://github.com/metal3d/katenary/blob/develop/generator/generator.go#L28>)
|
||||
### func [Generate](<https://github.com/metal3d/katenary/blob/develop/generator/generator.go#L29>)
|
||||
|
||||
```go
|
||||
func Generate(project *types.Project) (*HelmChart, error)
|
||||
@@ -482,7 +482,7 @@ The Generate function will create the HelmChart object this way:
|
||||
- Merge the same\-pod services.
|
||||
|
||||
<a name="NewChart"></a>
|
||||
### func [NewChart](<https://github.com/metal3d/katenary/blob/develop/generator/chart.go#L52>)
|
||||
### func [NewChart](<https://github.com/metal3d/katenary/blob/develop/generator/chart.go#L53>)
|
||||
|
||||
```go
|
||||
func NewChart(name string) *HelmChart
|
||||
@@ -491,7 +491,7 @@ func NewChart(name string) *HelmChart
|
||||
NewChart creates a new empty chart with the given name.
|
||||
|
||||
<a name="HelmChart.SaveTemplates"></a>
|
||||
### func \(\*HelmChart\) [SaveTemplates](<https://github.com/metal3d/katenary/blob/develop/generator/chart.go#L67>)
|
||||
### func \(\*HelmChart\) [SaveTemplates](<https://github.com/metal3d/katenary/blob/develop/generator/chart.go#L68>)
|
||||
|
||||
```go
|
||||
func (chart *HelmChart) SaveTemplates(templateDir string)
|
||||
@@ -499,20 +499,6 @@ func (chart *HelmChart) SaveTemplates(templateDir string)
|
||||
|
||||
SaveTemplates the templates of the chart to the given directory.
|
||||
|
||||
<a name="Help"></a>
|
||||
## type [Help](<https://github.com/metal3d/katenary/blob/develop/generator/katenaryLabels.go#L55-L60>)
|
||||
|
||||
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"`
|
||||
}
|
||||
```
|
||||
|
||||
<a name="Ingress"></a>
|
||||
## type [Ingress](<https://github.com/metal3d/katenary/blob/develop/generator/ingress.go#L17-L20>)
|
||||
|
||||
@@ -535,7 +521,7 @@ func NewIngress(service types.ServiceConfig, Chart *HelmChart) *Ingress
|
||||
NewIngress creates a new Ingress from a compose service.
|
||||
|
||||
<a name="Ingress.Filename"></a>
|
||||
### func \(\*Ingress\) [Filename](<https://github.com/metal3d/katenary/blob/develop/generator/ingress.go#L121>)
|
||||
### func \(\*Ingress\) [Filename](<https://github.com/metal3d/katenary/blob/develop/generator/ingress.go#L122>)
|
||||
|
||||
```go
|
||||
func (ingress *Ingress) Filename() string
|
||||
@@ -544,7 +530,7 @@ func (ingress *Ingress) Filename() string
|
||||
|
||||
|
||||
<a name="Ingress.Yaml"></a>
|
||||
### func \(\*Ingress\) [Yaml](<https://github.com/metal3d/katenary/blob/develop/generator/ingress.go#L125>)
|
||||
### func \(\*Ingress\) [Yaml](<https://github.com/metal3d/katenary/blob/develop/generator/ingress.go#L126>)
|
||||
|
||||
```go
|
||||
func (ingress *Ingress) Yaml() ([]byte, error)
|
||||
@@ -553,7 +539,7 @@ func (ingress *Ingress) Yaml() ([]byte, error)
|
||||
|
||||
|
||||
<a name="IngressValue"></a>
|
||||
## type [IngressValue](<https://github.com/metal3d/katenary/blob/develop/generator/values.go#L24-L30>)
|
||||
## type [IngressValue](<https://github.com/metal3d/katenary/blob/develop/generator/values.go#L28-L35>)
|
||||
|
||||
IngressValue is a ingress configuration that will be saved in values.yaml.
|
||||
|
||||
@@ -564,39 +550,10 @@ type IngressValue struct {
|
||||
Path string `yaml:"path"`
|
||||
Class string `yaml:"class"`
|
||||
Enabled bool `yaml:"enabled"`
|
||||
TLS TLS `yaml:"tls"`
|
||||
}
|
||||
```
|
||||
|
||||
<a name="Label"></a>
|
||||
## type [Label](<https://github.com/metal3d/katenary/blob/develop/generator/katenaryLabels.go#L48>)
|
||||
|
||||
Label is a katenary label to find in compose files.
|
||||
|
||||
```go
|
||||
type Label = string
|
||||
```
|
||||
|
||||
<a name="LabelMainApp"></a>Known labels.
|
||||
|
||||
```go
|
||||
const (
|
||||
LabelMainApp Label = katenaryLabelPrefix + "/main-app"
|
||||
LabelValues Label = katenaryLabelPrefix + "/values"
|
||||
LabelSecrets Label = katenaryLabelPrefix + "/secrets"
|
||||
LabelPorts Label = katenaryLabelPrefix + "/ports"
|
||||
LabelIngress Label = katenaryLabelPrefix + "/ingress"
|
||||
LabelMapEnv Label = katenaryLabelPrefix + "/map-env"
|
||||
LabelHealthCheck Label = katenaryLabelPrefix + "/health-check"
|
||||
LabelSamePod Label = katenaryLabelPrefix + "/same-pod"
|
||||
LabelDescription Label = katenaryLabelPrefix + "/description"
|
||||
LabelIgnore Label = katenaryLabelPrefix + "/ignore"
|
||||
LabelDependencies Label = katenaryLabelPrefix + "/dependencies"
|
||||
LabelConfigMapFiles Label = katenaryLabelPrefix + "/configmap-files"
|
||||
LabelCronJob Label = katenaryLabelPrefix + "/cronjob"
|
||||
LabelEnvFrom Label = katenaryLabelPrefix + "/env-from"
|
||||
)
|
||||
```
|
||||
|
||||
<a name="PersistenceValue"></a>
|
||||
## type [PersistenceValue](<https://github.com/metal3d/katenary/blob/develop/generator/values.go#L16-L21>)
|
||||
|
||||
@@ -706,7 +663,7 @@ func (r *RoleBinding) Yaml() ([]byte, error)
|
||||
|
||||
|
||||
<a name="Secret"></a>
|
||||
## type [Secret](<https://github.com/metal3d/katenary/blob/develop/generator/secret.go#L23-L26>)
|
||||
## type [Secret](<https://github.com/metal3d/katenary/blob/develop/generator/secret.go#L22-L25>)
|
||||
|
||||
Secret is a kubernetes Secret.
|
||||
|
||||
@@ -720,7 +677,7 @@ type Secret struct {
|
||||
```
|
||||
|
||||
<a name="NewSecret"></a>
|
||||
### func [NewSecret](<https://github.com/metal3d/katenary/blob/develop/generator/secret.go#L29>)
|
||||
### func [NewSecret](<https://github.com/metal3d/katenary/blob/develop/generator/secret.go#L28>)
|
||||
|
||||
```go
|
||||
func NewSecret(service types.ServiceConfig, appName string) *Secret
|
||||
@@ -729,7 +686,7 @@ func NewSecret(service types.ServiceConfig, appName string) *Secret
|
||||
NewSecret creates a new Secret from a compose service
|
||||
|
||||
<a name="Secret.AddData"></a>
|
||||
### func \(\*Secret\) [AddData](<https://github.com/metal3d/katenary/blob/develop/generator/secret.go#L79>)
|
||||
### func \(\*Secret\) [AddData](<https://github.com/metal3d/katenary/blob/develop/generator/secret.go#L70>)
|
||||
|
||||
```go
|
||||
func (s *Secret) AddData(key, value string)
|
||||
@@ -738,7 +695,7 @@ func (s *Secret) AddData(key, value string)
|
||||
AddData adds a key value pair to the secret.
|
||||
|
||||
<a name="Secret.Filename"></a>
|
||||
### func \(\*Secret\) [Filename](<https://github.com/metal3d/katenary/blob/develop/generator/secret.go#L87>)
|
||||
### func \(\*Secret\) [Filename](<https://github.com/metal3d/katenary/blob/develop/generator/secret.go#L86>)
|
||||
|
||||
```go
|
||||
func (s *Secret) Filename() string
|
||||
@@ -747,7 +704,7 @@ func (s *Secret) Filename() string
|
||||
Filename returns the filename of the secret.
|
||||
|
||||
<a name="Secret.SetData"></a>
|
||||
### func \(\*Secret\) [SetData](<https://github.com/metal3d/katenary/blob/develop/generator/secret.go#L92>)
|
||||
### func \(\*Secret\) [SetData](<https://github.com/metal3d/katenary/blob/develop/generator/secret.go#L91>)
|
||||
|
||||
```go
|
||||
func (s *Secret) SetData(data map[string]string)
|
||||
@@ -756,7 +713,7 @@ func (s *Secret) SetData(data map[string]string)
|
||||
SetData sets the data of the secret.
|
||||
|
||||
<a name="Secret.Yaml"></a>
|
||||
### func \(\*Secret\) [Yaml](<https://github.com/metal3d/katenary/blob/develop/generator/secret.go#L99>)
|
||||
### func \(\*Secret\) [Yaml](<https://github.com/metal3d/katenary/blob/develop/generator/secret.go#L98>)
|
||||
|
||||
```go
|
||||
func (s *Secret) Yaml() ([]byte, error)
|
||||
@@ -765,7 +722,7 @@ func (s *Secret) Yaml() ([]byte, error)
|
||||
Yaml returns the yaml representation of the secret.
|
||||
|
||||
<a name="Service"></a>
|
||||
## type [Service](<https://github.com/metal3d/katenary/blob/develop/generator/service.go#L18-L21>)
|
||||
## type [Service](<https://github.com/metal3d/katenary/blob/develop/generator/service.go#L17-L20>)
|
||||
|
||||
Service is a kubernetes Service.
|
||||
|
||||
@@ -777,7 +734,7 @@ type Service struct {
|
||||
```
|
||||
|
||||
<a name="NewService"></a>
|
||||
### func [NewService](<https://github.com/metal3d/katenary/blob/develop/generator/service.go#L24>)
|
||||
### func [NewService](<https://github.com/metal3d/katenary/blob/develop/generator/service.go#L23>)
|
||||
|
||||
```go
|
||||
func NewService(service types.ServiceConfig, appName string) *Service
|
||||
@@ -786,7 +743,7 @@ func NewService(service types.ServiceConfig, appName string) *Service
|
||||
NewService creates a new Service from a compose service.
|
||||
|
||||
<a name="Service.AddPort"></a>
|
||||
### func \(\*Service\) [AddPort](<https://github.com/metal3d/katenary/blob/develop/generator/service.go#L53>)
|
||||
### func \(\*Service\) [AddPort](<https://github.com/metal3d/katenary/blob/develop/generator/service.go#L52>)
|
||||
|
||||
```go
|
||||
func (s *Service) AddPort(port types.ServicePortConfig, serviceName ...string)
|
||||
@@ -795,7 +752,7 @@ func (s *Service) AddPort(port types.ServicePortConfig, serviceName ...string)
|
||||
AddPort adds a port to the service.
|
||||
|
||||
<a name="Service.Filename"></a>
|
||||
### func \(\*Service\) [Filename](<https://github.com/metal3d/katenary/blob/develop/generator/service.go#L77>)
|
||||
### func \(\*Service\) [Filename](<https://github.com/metal3d/katenary/blob/develop/generator/service.go#L76>)
|
||||
|
||||
```go
|
||||
func (s *Service) Filename() string
|
||||
@@ -804,7 +761,7 @@ func (s *Service) Filename() string
|
||||
Filename returns the filename of the service.
|
||||
|
||||
<a name="Service.Yaml"></a>
|
||||
### func \(\*Service\) [Yaml](<https://github.com/metal3d/katenary/blob/develop/generator/service.go#L82>)
|
||||
### func \(\*Service\) [Yaml](<https://github.com/metal3d/katenary/blob/develop/generator/service.go#L81>)
|
||||
|
||||
```go
|
||||
func (s *Service) Yaml() ([]byte, error)
|
||||
@@ -842,8 +799,19 @@ func (r *ServiceAccount) Yaml() ([]byte, error)
|
||||
|
||||
|
||||
|
||||
<a name="TLS"></a>
|
||||
## type [TLS](<https://github.com/metal3d/katenary/blob/develop/generator/values.go#L23-L25>)
|
||||
|
||||
|
||||
|
||||
```go
|
||||
type TLS struct {
|
||||
Enabled bool `yaml:"enabled"`
|
||||
}
|
||||
```
|
||||
|
||||
<a name="Value"></a>
|
||||
## type [Value](<https://github.com/metal3d/katenary/blob/develop/generator/values.go#L33-L44>)
|
||||
## type [Value](<https://github.com/metal3d/katenary/blob/develop/generator/values.go#L38-L49>)
|
||||
|
||||
Value will be saved in values.yaml. It contains configuraiton for all deployment and services.
|
||||
|
||||
@@ -863,7 +831,7 @@ type Value struct {
|
||||
```
|
||||
|
||||
<a name="NewValue"></a>
|
||||
### func [NewValue](<https://github.com/metal3d/katenary/blob/develop/generator/values.go#L51>)
|
||||
### func [NewValue](<https://github.com/metal3d/katenary/blob/develop/generator/values.go#L56>)
|
||||
|
||||
```go
|
||||
func NewValue(service types.ServiceConfig, main ...bool) *Value
|
||||
@@ -874,7 +842,7 @@ NewValue creates a new Value from a compose service. The value contains the nece
|
||||
If \`main\` is true, the tag will be empty because it will be set in the helm chart appVersion.
|
||||
|
||||
<a name="Value.AddIngress"></a>
|
||||
### func \(\*Value\) [AddIngress](<https://github.com/metal3d/katenary/blob/develop/generator/values.go#L84>)
|
||||
### func \(\*Value\) [AddIngress](<https://github.com/metal3d/katenary/blob/develop/generator/values.go#L89>)
|
||||
|
||||
```go
|
||||
func (v *Value) AddIngress(host, path string)
|
||||
@@ -883,7 +851,7 @@ func (v *Value) AddIngress(host, path string)
|
||||
|
||||
|
||||
<a name="Value.AddPersistence"></a>
|
||||
### func \(\*Value\) [AddPersistence](<https://github.com/metal3d/katenary/blob/develop/generator/values.go#L94>)
|
||||
### func \(\*Value\) [AddPersistence](<https://github.com/metal3d/katenary/blob/develop/generator/values.go#L99>)
|
||||
|
||||
```go
|
||||
func (v *Value) AddPersistence(volumeName string)
|
||||
@@ -892,7 +860,7 @@ func (v *Value) AddPersistence(volumeName string)
|
||||
AddPersistence adds persistence configuration to the Value.
|
||||
|
||||
<a name="VolumeClaim"></a>
|
||||
## type [VolumeClaim](<https://github.com/metal3d/katenary/blob/develop/generator/volume.go#L19-L24>)
|
||||
## type [VolumeClaim](<https://github.com/metal3d/katenary/blob/develop/generator/volume.go#L18-L23>)
|
||||
|
||||
VolumeClaim is a kubernetes VolumeClaim. This is a PersistentVolumeClaim.
|
||||
|
||||
@@ -904,7 +872,7 @@ type VolumeClaim struct {
|
||||
```
|
||||
|
||||
<a name="NewVolumeClaim"></a>
|
||||
### func [NewVolumeClaim](<https://github.com/metal3d/katenary/blob/develop/generator/volume.go#L27>)
|
||||
### func [NewVolumeClaim](<https://github.com/metal3d/katenary/blob/develop/generator/volume.go#L26>)
|
||||
|
||||
```go
|
||||
func NewVolumeClaim(service types.ServiceConfig, volumeName, appName string) *VolumeClaim
|
||||
@@ -913,7 +881,7 @@ func NewVolumeClaim(service types.ServiceConfig, volumeName, appName string) *Vo
|
||||
NewVolumeClaim creates a new VolumeClaim from a compose service.
|
||||
|
||||
<a name="VolumeClaim.Filename"></a>
|
||||
### func \(\*VolumeClaim\) [Filename](<https://github.com/metal3d/katenary/blob/develop/generator/volume.go#L63>)
|
||||
### func \(\*VolumeClaim\) [Filename](<https://github.com/metal3d/katenary/blob/develop/generator/volume.go#L62>)
|
||||
|
||||
```go
|
||||
func (v *VolumeClaim) Filename() string
|
||||
@@ -922,7 +890,7 @@ func (v *VolumeClaim) Filename() string
|
||||
Filename returns the suggested filename for a VolumeClaim.
|
||||
|
||||
<a name="VolumeClaim.Yaml"></a>
|
||||
### func \(\*VolumeClaim\) [Yaml](<https://github.com/metal3d/katenary/blob/develop/generator/volume.go#L68>)
|
||||
### func \(\*VolumeClaim\) [Yaml](<https://github.com/metal3d/katenary/blob/develop/generator/volume.go#L67>)
|
||||
|
||||
```go
|
||||
func (v *VolumeClaim) Yaml() ([]byte, error)
|
||||
|
66
doc/docs/packages/generator/katenaryfile.md
Normal file
66
doc/docs/packages/generator/katenaryfile.md
Normal file
@@ -0,0 +1,66 @@
|
||||
<!-- Code generated by gomarkdoc. DO NOT EDIT -->
|
||||
|
||||
# katenaryfile
|
||||
|
||||
```go
|
||||
import "katenary/generator/katenaryfile"
|
||||
```
|
||||
|
||||
Package katenaryfile is a package for reading and writing katenary files.
|
||||
|
||||
A katenary file, named "katenary.yml" or "katenary.yaml", is a file where you can define the configuration of the conversion avoiding the use of labels in the compose file.
|
||||
|
||||
Formely, the file describe the same structure as in labels, and so that can be validated and completed by LSP. It also ease the use of katenary.
|
||||
|
||||
## func [GenerateSchema](<https://github.com/metal3d/katenary/blob/develop/generator/katenaryfile/main.go#L116>)
|
||||
|
||||
```go
|
||||
func GenerateSchema() string
|
||||
```
|
||||
|
||||
GenerateSchema generates the schema for the katenary.yaml file.
|
||||
|
||||
<a name="OverrideWithConfig"></a>
|
||||
## func [OverrideWithConfig](<https://github.com/metal3d/katenary/blob/develop/generator/katenaryfile/main.go#L48>)
|
||||
|
||||
```go
|
||||
func OverrideWithConfig(project *types.Project)
|
||||
```
|
||||
|
||||
OverrideWithConfig overrides the project with the katenary.yaml file. It will set the labels of the services with the values from the katenary.yaml file. It work in memory, so it will not modify the original project.
|
||||
|
||||
<a name="Service"></a>
|
||||
## type [Service](<https://github.com/metal3d/katenary/blob/develop/generator/katenaryfile/main.go#L27-L43>)
|
||||
|
||||
Service is a struct that contains the service configuration for katenary
|
||||
|
||||
```go
|
||||
type Service struct {
|
||||
MainApp *bool `json:"main-app,omitempty" jsonschema:"title=Is this service the main application"`
|
||||
Values []StringOrMap `json:"values,omitempty" jsonschema:"description=Environment variables to be set in values.yaml with or without a description"`
|
||||
Secrets *labelStructs.Secrets `json:"secrets,omitempty" jsonschema:"title=Secrets,description=Environment variables to be set as secrets"`
|
||||
Ports *labelStructs.Ports `json:"ports,omitempty" jsonschema:"title=Ports,description=Ports to be exposed in services"`
|
||||
Ingress *labelStructs.Ingress `json:"ingress,omitempty" jsonschema:"title=Ingress,description=Ingress configuration"`
|
||||
HealthCheck *labelStructs.HealthCheck `json:"health-check,omitempty" jsonschema:"title=Health Check,description=Health check configuration that respects the kubernetes api"`
|
||||
SamePod *string `json:"same-pod,omitempty" jsonschema:"title=Same Pod,description=Service that should be in the same pod"`
|
||||
Description *string `json:"description,omitempty" jsonschema:"title=Description,description=Description of the service that will be injected in the values.yaml file"`
|
||||
Ignore *bool `json:"ignore,omitempty" jsonschema:"title=Ignore,description=Ignore the service in the conversion"`
|
||||
Dependencies []labelStructs.Dependency `json:"dependencies,omitempty" jsonschema:"title=Dependencies,description=Services that should be injected in the Chart.yaml file"`
|
||||
ConfigMapFile *labelStructs.ConfigMapFile `json:"configmap-files,omitempty" jsonschema:"title=ConfigMap Files,description=Files that should be injected as ConfigMap"`
|
||||
MapEnv *labelStructs.MapEnv `json:"map-env,omitempty" jsonschema:"title=Map Env,description=Map environment variables to another value"`
|
||||
CronJob *labelStructs.CronJob `json:"cron-job,omitempty" jsonschema:"title=Cron Job,description=Cron Job configuration"`
|
||||
EnvFrom *labelStructs.EnvFrom `json:"env-from,omitempty" jsonschema:"title=Env From,description=Inject environment variables from another service"`
|
||||
ExchangeVolumes []*labelStructs.ExchangeVolume `json:"exchange-volumes,omitempty" jsonschema:"title=Exchange Volumes,description=Exchange volumes between services"`
|
||||
}
|
||||
```
|
||||
|
||||
<a name="StringOrMap"></a>
|
||||
## type [StringOrMap](<https://github.com/metal3d/katenary/blob/develop/generator/katenaryfile/main.go#L24>)
|
||||
|
||||
StringOrMap is a struct that can be either a string or a map of strings. It's a helper struct to unmarshal the katenary.yaml file and produce the schema
|
||||
|
||||
```go
|
||||
type StringOrMap any
|
||||
```
|
||||
|
||||
Generated by [gomarkdoc](<https://github.com/princjef/gomarkdoc>)
|
@@ -1,193 +0,0 @@
|
||||
<!-- Code generated by gomarkdoc. DO NOT EDIT -->
|
||||
|
||||
# labelStructs
|
||||
|
||||
```go
|
||||
import "katenary/generator/labelStructs"
|
||||
```
|
||||
|
||||
labelStructs is a package that contains the structs used to represent the labels in the yaml files.
|
||||
|
||||
## type [ConfigMapFile](<https://github.com/metal3d/katenary/blob/develop/generator/labelStructs/configMap.go#L5>)
|
||||
|
||||
|
||||
|
||||
```go
|
||||
type ConfigMapFile []string
|
||||
```
|
||||
|
||||
<a name="ConfigMapFileFrom"></a>
|
||||
### func [ConfigMapFileFrom](<https://github.com/metal3d/katenary/blob/develop/generator/labelStructs/configMap.go#L7>)
|
||||
|
||||
```go
|
||||
func ConfigMapFileFrom(data string) (ConfigMapFile, error)
|
||||
```
|
||||
|
||||
|
||||
|
||||
<a name="CronJob"></a>
|
||||
## type [CronJob](<https://github.com/metal3d/katenary/blob/develop/generator/labelStructs/cronJob.go#L5-L10>)
|
||||
|
||||
|
||||
|
||||
```go
|
||||
type CronJob struct {
|
||||
Image string `yaml:"image,omitempty"`
|
||||
Command string `yaml:"command"`
|
||||
Schedule string `yaml:"schedule"`
|
||||
Rbac bool `yaml:"rbac"`
|
||||
}
|
||||
```
|
||||
|
||||
<a name="CronJobFrom"></a>
|
||||
### func [CronJobFrom](<https://github.com/metal3d/katenary/blob/develop/generator/labelStructs/cronJob.go#L12>)
|
||||
|
||||
```go
|
||||
func CronJobFrom(data string) (*CronJob, error)
|
||||
```
|
||||
|
||||
|
||||
|
||||
<a name="Dependency"></a>
|
||||
## type [Dependency](<https://github.com/metal3d/katenary/blob/develop/generator/labelStructs/dependencies.go#L6-L12>)
|
||||
|
||||
Dependency is a dependency of a chart to other charts.
|
||||
|
||||
```go
|
||||
type Dependency struct {
|
||||
Values map[string]any `yaml:"-"`
|
||||
Name string `yaml:"name"`
|
||||
Version string `yaml:"version"`
|
||||
Repository string `yaml:"repository"`
|
||||
Alias string `yaml:"alias,omitempty"`
|
||||
}
|
||||
```
|
||||
|
||||
<a name="DependenciesFrom"></a>
|
||||
### func [DependenciesFrom](<https://github.com/metal3d/katenary/blob/develop/generator/labelStructs/dependencies.go#L15>)
|
||||
|
||||
```go
|
||||
func DependenciesFrom(data string) ([]Dependency, error)
|
||||
```
|
||||
|
||||
DependenciesFrom returns a slice of dependencies from the given string.
|
||||
|
||||
<a name="EnvFrom"></a>
|
||||
## type [EnvFrom](<https://github.com/metal3d/katenary/blob/develop/generator/labelStructs/envFrom.go#L5>)
|
||||
|
||||
|
||||
|
||||
```go
|
||||
type EnvFrom []string
|
||||
```
|
||||
|
||||
<a name="EnvFromFrom"></a>
|
||||
### func [EnvFromFrom](<https://github.com/metal3d/katenary/blob/develop/generator/labelStructs/envFrom.go#L8>)
|
||||
|
||||
```go
|
||||
func EnvFromFrom(data string) (EnvFrom, error)
|
||||
```
|
||||
|
||||
EnvFromFrom returns a EnvFrom from the given string.
|
||||
|
||||
<a name="Ingress"></a>
|
||||
## type [Ingress](<https://github.com/metal3d/katenary/blob/develop/generator/labelStructs/ingress.go#L5-L12>)
|
||||
|
||||
|
||||
|
||||
```go
|
||||
type Ingress struct {
|
||||
Port *int32 `yaml:"port,omitempty"`
|
||||
Annotations map[string]string `yaml:"annotations,omitempty"`
|
||||
Hostname string `yaml:"hostname"`
|
||||
Path string `yaml:"path"`
|
||||
Class string `yaml:"class"`
|
||||
Enabled bool `yaml:"enabled"`
|
||||
}
|
||||
```
|
||||
|
||||
<a name="IngressFrom"></a>
|
||||
### func [IngressFrom](<https://github.com/metal3d/katenary/blob/develop/generator/labelStructs/ingress.go#L15>)
|
||||
|
||||
```go
|
||||
func IngressFrom(data string) (*Ingress, error)
|
||||
```
|
||||
|
||||
IngressFrom creates a new Ingress from a compose service.
|
||||
|
||||
<a name="MapEnv"></a>
|
||||
## type [MapEnv](<https://github.com/metal3d/katenary/blob/develop/generator/labelStructs/mapenv.go#L5>)
|
||||
|
||||
|
||||
|
||||
```go
|
||||
type MapEnv map[string]string
|
||||
```
|
||||
|
||||
<a name="MapEnvFrom"></a>
|
||||
### func [MapEnvFrom](<https://github.com/metal3d/katenary/blob/develop/generator/labelStructs/mapenv.go#L8>)
|
||||
|
||||
```go
|
||||
func MapEnvFrom(data string) (MapEnv, error)
|
||||
```
|
||||
|
||||
MapEnvFrom returns a MapEnv from the given string.
|
||||
|
||||
<a name="Ports"></a>
|
||||
## type [Ports](<https://github.com/metal3d/katenary/blob/develop/generator/labelStructs/ports.go#L5>)
|
||||
|
||||
|
||||
|
||||
```go
|
||||
type Ports []uint32
|
||||
```
|
||||
|
||||
<a name="PortsFrom"></a>
|
||||
### func [PortsFrom](<https://github.com/metal3d/katenary/blob/develop/generator/labelStructs/ports.go#L8>)
|
||||
|
||||
```go
|
||||
func PortsFrom(data string) (Ports, error)
|
||||
```
|
||||
|
||||
PortsFrom returns a Ports from the given string.
|
||||
|
||||
<a name="Probe"></a>
|
||||
## type [Probe](<https://github.com/metal3d/katenary/blob/develop/generator/labelStructs/probes.go#L11-L14>)
|
||||
|
||||
|
||||
|
||||
```go
|
||||
type Probe struct {
|
||||
LivenessProbe *corev1.Probe `yaml:"livenessProbe,omitempty"`
|
||||
ReadinessProbe *corev1.Probe `yaml:"readinessProbe,omitempty"`
|
||||
}
|
||||
```
|
||||
|
||||
<a name="ProbeFrom"></a>
|
||||
### func [ProbeFrom](<https://github.com/metal3d/katenary/blob/develop/generator/labelStructs/probes.go#L16>)
|
||||
|
||||
```go
|
||||
func ProbeFrom(data string) (*Probe, error)
|
||||
```
|
||||
|
||||
|
||||
|
||||
<a name="Secrets"></a>
|
||||
## type [Secrets](<https://github.com/metal3d/katenary/blob/develop/generator/labelStructs/secrets.go#L5>)
|
||||
|
||||
|
||||
|
||||
```go
|
||||
type Secrets []string
|
||||
```
|
||||
|
||||
<a name="SecretsFrom"></a>
|
||||
### func [SecretsFrom](<https://github.com/metal3d/katenary/blob/develop/generator/labelStructs/secrets.go#L7>)
|
||||
|
||||
```go
|
||||
func SecretsFrom(data string) (Secrets, error)
|
||||
```
|
||||
|
||||
|
||||
|
||||
Generated by [gomarkdoc](<https://github.com/princjef/gomarkdoc>)
|
107
doc/docs/packages/generator/labels.md
Normal file
107
doc/docs/packages/generator/labels.md
Normal file
@@ -0,0 +1,107 @@
|
||||
<!-- Code generated by gomarkdoc. DO NOT EDIT -->
|
||||
|
||||
# labels
|
||||
|
||||
```go
|
||||
import "katenary/generator/labels"
|
||||
```
|
||||
|
||||
## Constants
|
||||
|
||||
<a name="KatenaryLabelPrefix"></a>
|
||||
|
||||
```go
|
||||
const KatenaryLabelPrefix = "katenary.v3"
|
||||
```
|
||||
|
||||
<a name="GetLabelHelp"></a>
|
||||
## func [GetLabelHelp](<https://github.com/metal3d/katenary/blob/develop/generator/labels/katenaryLabels.go#L86>)
|
||||
|
||||
```go
|
||||
func GetLabelHelp(asMarkdown bool) string
|
||||
```
|
||||
|
||||
Generate the help for the labels.
|
||||
|
||||
<a name="GetLabelHelpFor"></a>
|
||||
## func [GetLabelHelpFor](<https://github.com/metal3d/katenary/blob/develop/generator/labels/katenaryLabels.go#L95>)
|
||||
|
||||
```go
|
||||
func GetLabelHelpFor(labelname string, asMarkdown bool) string
|
||||
```
|
||||
|
||||
GetLabelHelpFor returns the help for a specific label.
|
||||
|
||||
<a name="GetLabelNames"></a>
|
||||
## func [GetLabelNames](<https://github.com/metal3d/katenary/blob/develop/generator/labels/katenaryLabels.go#L70>)
|
||||
|
||||
```go
|
||||
func GetLabelNames() []string
|
||||
```
|
||||
|
||||
GetLabelNames returns a sorted list of all katenary label names.
|
||||
|
||||
<a name="Prefix"></a>
|
||||
## func [Prefix](<https://github.com/metal3d/katenary/blob/develop/generator/labels/katenaryLabels.go#L223>)
|
||||
|
||||
```go
|
||||
func Prefix() string
|
||||
```
|
||||
|
||||
|
||||
|
||||
<a name="Help"></a>
|
||||
## type [Help](<https://github.com/metal3d/katenary/blob/develop/generator/labels/katenaryLabels.go#L62-L67>)
|
||||
|
||||
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"`
|
||||
}
|
||||
```
|
||||
|
||||
<a name="Label"></a>
|
||||
## type [Label](<https://github.com/metal3d/katenary/blob/develop/generator/labels/katenaryLabels.go#L55>)
|
||||
|
||||
Label is a katenary label to find in compose files.
|
||||
|
||||
```go
|
||||
type Label = string
|
||||
```
|
||||
|
||||
<a name="LabelMainApp"></a>Known labels.
|
||||
|
||||
```go
|
||||
const (
|
||||
LabelMainApp Label = KatenaryLabelPrefix + "/main-app"
|
||||
LabelValues Label = KatenaryLabelPrefix + "/values"
|
||||
LabelSecrets Label = KatenaryLabelPrefix + "/secrets"
|
||||
LabelPorts Label = KatenaryLabelPrefix + "/ports"
|
||||
LabelIngress Label = KatenaryLabelPrefix + "/ingress"
|
||||
LabelMapEnv Label = KatenaryLabelPrefix + "/map-env"
|
||||
LabelHealthCheck Label = KatenaryLabelPrefix + "/health-check"
|
||||
LabelSamePod Label = KatenaryLabelPrefix + "/same-pod"
|
||||
LabelDescription Label = KatenaryLabelPrefix + "/description"
|
||||
LabelIgnore Label = KatenaryLabelPrefix + "/ignore"
|
||||
LabelDependencies Label = KatenaryLabelPrefix + "/dependencies"
|
||||
LabelConfigMapFiles Label = KatenaryLabelPrefix + "/configmap-files"
|
||||
LabelCronJob Label = KatenaryLabelPrefix + "/cronjob"
|
||||
LabelEnvFrom Label = KatenaryLabelPrefix + "/env-from"
|
||||
LabelExchangeVolume Label = KatenaryLabelPrefix + "/exchange-volumes"
|
||||
)
|
||||
```
|
||||
|
||||
<a name="LabelName"></a>
|
||||
### func [LabelName](<https://github.com/metal3d/katenary/blob/develop/generator/labels/katenaryLabels.go#L57>)
|
||||
|
||||
```go
|
||||
func LabelName(name string) Label
|
||||
```
|
||||
|
||||
|
||||
|
||||
Generated by [gomarkdoc](<https://github.com/princjef/gomarkdoc>)
|
228
doc/docs/packages/generator/labels/labelStructs.md
Normal file
228
doc/docs/packages/generator/labels/labelStructs.md
Normal file
@@ -0,0 +1,228 @@
|
||||
<!-- Code generated by gomarkdoc. DO NOT EDIT -->
|
||||
|
||||
# labelStructs
|
||||
|
||||
```go
|
||||
import "katenary/generator/labels/labelStructs"
|
||||
```
|
||||
|
||||
labelStructs is a package that contains the structs used to represent the labels in the yaml files.
|
||||
|
||||
## type [ConfigMapFile](<https://github.com/metal3d/katenary/blob/develop/generator/labels/labelStructs/configMap.go#L5>)
|
||||
|
||||
|
||||
|
||||
```go
|
||||
type ConfigMapFile []string
|
||||
```
|
||||
|
||||
<a name="ConfigMapFileFrom"></a>
|
||||
### func [ConfigMapFileFrom](<https://github.com/metal3d/katenary/blob/develop/generator/labels/labelStructs/configMap.go#L7>)
|
||||
|
||||
```go
|
||||
func ConfigMapFileFrom(data string) (ConfigMapFile, error)
|
||||
```
|
||||
|
||||
|
||||
|
||||
<a name="CronJob"></a>
|
||||
## type [CronJob](<https://github.com/metal3d/katenary/blob/develop/generator/labels/labelStructs/cronJob.go#L5-L10>)
|
||||
|
||||
|
||||
|
||||
```go
|
||||
type CronJob struct {
|
||||
Image string `yaml:"image,omitempty" json:"image,omitempty"`
|
||||
Command string `yaml:"command" json:"command,omitempty"`
|
||||
Schedule string `yaml:"schedule" json:"schedule,omitempty"`
|
||||
Rbac bool `yaml:"rbac" json:"rbac,omitempty"`
|
||||
}
|
||||
```
|
||||
|
||||
<a name="CronJobFrom"></a>
|
||||
### func [CronJobFrom](<https://github.com/metal3d/katenary/blob/develop/generator/labels/labelStructs/cronJob.go#L12>)
|
||||
|
||||
```go
|
||||
func CronJobFrom(data string) (*CronJob, error)
|
||||
```
|
||||
|
||||
|
||||
|
||||
<a name="Dependency"></a>
|
||||
## type [Dependency](<https://github.com/metal3d/katenary/blob/develop/generator/labels/labelStructs/dependencies.go#L6-L12>)
|
||||
|
||||
Dependency is a dependency of a chart to other charts.
|
||||
|
||||
```go
|
||||
type Dependency struct {
|
||||
Values map[string]any `yaml:"-" json:"values,omitempty"`
|
||||
Name string `yaml:"name" json:"name"`
|
||||
Version string `yaml:"version" json:"version"`
|
||||
Repository string `yaml:"repository" json:"repository"`
|
||||
Alias string `yaml:"alias,omitempty" json:"alias,omitempty"`
|
||||
}
|
||||
```
|
||||
|
||||
<a name="DependenciesFrom"></a>
|
||||
### func [DependenciesFrom](<https://github.com/metal3d/katenary/blob/develop/generator/labels/labelStructs/dependencies.go#L15>)
|
||||
|
||||
```go
|
||||
func DependenciesFrom(data string) ([]Dependency, error)
|
||||
```
|
||||
|
||||
DependenciesFrom returns a slice of dependencies from the given string.
|
||||
|
||||
<a name="EnvFrom"></a>
|
||||
## type [EnvFrom](<https://github.com/metal3d/katenary/blob/develop/generator/labels/labelStructs/envFrom.go#L5>)
|
||||
|
||||
|
||||
|
||||
```go
|
||||
type EnvFrom []string
|
||||
```
|
||||
|
||||
<a name="EnvFromFrom"></a>
|
||||
### func [EnvFromFrom](<https://github.com/metal3d/katenary/blob/develop/generator/labels/labelStructs/envFrom.go#L8>)
|
||||
|
||||
```go
|
||||
func EnvFromFrom(data string) (EnvFrom, error)
|
||||
```
|
||||
|
||||
EnvFromFrom returns a EnvFrom from the given string.
|
||||
|
||||
<a name="ExchangeVolume"></a>
|
||||
## type [ExchangeVolume](<https://github.com/metal3d/katenary/blob/develop/generator/labels/labelStructs/exchangeVolume.go#L5-L10>)
|
||||
|
||||
|
||||
|
||||
```go
|
||||
type ExchangeVolume struct {
|
||||
Name string `yaml:"name" json:"name"`
|
||||
MountPath string `yaml:"mountPath" json:"mountPath"`
|
||||
Type string `yaml:"type,omitempty" json:"type,omitempty"`
|
||||
Init string `yaml:"init,omitempty" json:"init,omitempty"`
|
||||
}
|
||||
```
|
||||
|
||||
<a name="NewExchangeVolumes"></a>
|
||||
### func [NewExchangeVolumes](<https://github.com/metal3d/katenary/blob/develop/generator/labels/labelStructs/exchangeVolume.go#L12>)
|
||||
|
||||
```go
|
||||
func NewExchangeVolumes(data string) ([]*ExchangeVolume, error)
|
||||
```
|
||||
|
||||
|
||||
|
||||
<a name="HealthCheck"></a>
|
||||
## type [HealthCheck](<https://github.com/metal3d/katenary/blob/develop/generator/labels/labelStructs/probes.go#L11-L14>)
|
||||
|
||||
|
||||
|
||||
```go
|
||||
type HealthCheck struct {
|
||||
LivenessProbe *corev1.Probe `yaml:"livenessProbe,omitempty" json:"livenessProbe,omitempty"`
|
||||
ReadinessProbe *corev1.Probe `yaml:"readinessProbe,omitempty" json:"readinessProbe,omitempty"`
|
||||
}
|
||||
```
|
||||
|
||||
<a name="ProbeFrom"></a>
|
||||
### func [ProbeFrom](<https://github.com/metal3d/katenary/blob/develop/generator/labels/labelStructs/probes.go#L16>)
|
||||
|
||||
```go
|
||||
func ProbeFrom(data string) (*HealthCheck, error)
|
||||
```
|
||||
|
||||
|
||||
|
||||
<a name="Ingress"></a>
|
||||
## type [Ingress](<https://github.com/metal3d/katenary/blob/develop/generator/labels/labelStructs/ingress.go#L9-L17>)
|
||||
|
||||
|
||||
|
||||
```go
|
||||
type Ingress struct {
|
||||
Port *int32 `yaml:"port,omitempty" jsonschema:"nullable" json:"port,omitempty"`
|
||||
Annotations map[string]string `yaml:"annotations,omitempty" jsonschema:"nullable" json:"annotations,omitempty"`
|
||||
Hostname string `yaml:"hostname" json:"hostname,omitempty"`
|
||||
Path string `yaml:"path" json:"path,omitempty"`
|
||||
Class string `yaml:"class" json:"class,omitempty" jsonschema:"default:-"`
|
||||
Enabled bool `yaml:"enabled" json:"enabled,omitempty"`
|
||||
TLS *TLS `yaml:"tls,omitempty" json:"tls,omitempty"`
|
||||
}
|
||||
```
|
||||
|
||||
<a name="IngressFrom"></a>
|
||||
### func [IngressFrom](<https://github.com/metal3d/katenary/blob/develop/generator/labels/labelStructs/ingress.go#L20>)
|
||||
|
||||
```go
|
||||
func IngressFrom(data string) (*Ingress, error)
|
||||
```
|
||||
|
||||
IngressFrom creates a new Ingress from a compose service.
|
||||
|
||||
<a name="MapEnv"></a>
|
||||
## type [MapEnv](<https://github.com/metal3d/katenary/blob/develop/generator/labels/labelStructs/mapenv.go#L5>)
|
||||
|
||||
|
||||
|
||||
```go
|
||||
type MapEnv map[string]string
|
||||
```
|
||||
|
||||
<a name="MapEnvFrom"></a>
|
||||
### func [MapEnvFrom](<https://github.com/metal3d/katenary/blob/develop/generator/labels/labelStructs/mapenv.go#L8>)
|
||||
|
||||
```go
|
||||
func MapEnvFrom(data string) (MapEnv, error)
|
||||
```
|
||||
|
||||
MapEnvFrom returns a MapEnv from the given string.
|
||||
|
||||
<a name="Ports"></a>
|
||||
## type [Ports](<https://github.com/metal3d/katenary/blob/develop/generator/labels/labelStructs/ports.go#L5>)
|
||||
|
||||
|
||||
|
||||
```go
|
||||
type Ports []uint32
|
||||
```
|
||||
|
||||
<a name="PortsFrom"></a>
|
||||
### func [PortsFrom](<https://github.com/metal3d/katenary/blob/develop/generator/labels/labelStructs/ports.go#L8>)
|
||||
|
||||
```go
|
||||
func PortsFrom(data string) (Ports, error)
|
||||
```
|
||||
|
||||
PortsFrom returns a Ports from the given string.
|
||||
|
||||
<a name="Secrets"></a>
|
||||
## type [Secrets](<https://github.com/metal3d/katenary/blob/develop/generator/labels/labelStructs/secrets.go#L5>)
|
||||
|
||||
|
||||
|
||||
```go
|
||||
type Secrets []string
|
||||
```
|
||||
|
||||
<a name="SecretsFrom"></a>
|
||||
### func [SecretsFrom](<https://github.com/metal3d/katenary/blob/develop/generator/labels/labelStructs/secrets.go#L7>)
|
||||
|
||||
```go
|
||||
func SecretsFrom(data string) (Secrets, error)
|
||||
```
|
||||
|
||||
|
||||
|
||||
<a name="TLS"></a>
|
||||
## type [TLS](<https://github.com/metal3d/katenary/blob/develop/generator/labels/labelStructs/ingress.go#L5-L7>)
|
||||
|
||||
|
||||
|
||||
```go
|
||||
type TLS struct {
|
||||
Enabled bool `yaml:"enabled" json:"enabled,omitempty"`
|
||||
}
|
||||
```
|
||||
|
||||
Generated by [gomarkdoc](<https://github.com/princjef/gomarkdoc>)
|
@@ -8,6 +8,15 @@ import "katenary/utils"
|
||||
|
||||
Utils package provides some utility functions used in katenary. It defines some constants and functions used in the whole project.
|
||||
|
||||
## func [AsResourceName](<https://github.com/metal3d/katenary/blob/develop/utils/utils.go#L204>)
|
||||
|
||||
```go
|
||||
func AsResourceName(name string) string
|
||||
```
|
||||
|
||||
AsResourceName returns a resource name with underscores to respect the kubernetes naming convention. It's the opposite of FixedResourceName.
|
||||
|
||||
<a name="Confirm"></a>
|
||||
## func [Confirm](<https://github.com/metal3d/katenary/blob/develop/utils/utils.go#L174>)
|
||||
|
||||
```go
|
||||
|
@@ -106,3 +106,12 @@ h3[id*="katenaryio"] {
|
||||
z-index: 1;
|
||||
}
|
||||
}
|
||||
|
||||
#klee {
|
||||
filter: drop-shadow(0 0 16px var(--md-default-fg-color));
|
||||
text-align: center;
|
||||
padding: 1rem;
|
||||
}
|
||||
#klee svg {
|
||||
zoom: 2;
|
||||
}
|
||||
|
@@ -4,10 +4,77 @@ Basically, you can use `katenary` to transpose a docker-compose file (or any com
|
||||
`podman-compose` and `docker-compose`) to a configurable Helm Chart. This resulting helm chart can be installed with
|
||||
`helm` command to your Kubernetes cluster.
|
||||
|
||||
For very basic compose files, without any specific configuration, Katenary will create a working helm chart using the
|
||||
simple command line:
|
||||
|
||||
```bash
|
||||
katenary convert
|
||||
```
|
||||
|
||||
This will create a `chart` directory with the helm chart inside.
|
||||
|
||||
But, in general, you will need to add a few configuration to help Katenary to transpose the compose file to a working
|
||||
helm chart.
|
||||
|
||||
There are two ways to configure Katenary:
|
||||
|
||||
- Using the compose files, adding labels to the services
|
||||
- Using a specific file named `katenary.yaml`
|
||||
|
||||
The Katenary file `katenary.yaml` has benefits over the labels in the compose file:
|
||||
|
||||
- you can validate the configuration with a schema, and use completion in your editor
|
||||
- you separate the configuration and leave the compose file "intact"
|
||||
- the syntax is a bit simpler, instead of using `katenary.v3/xxx: |-" you can use`xxx: ...`
|
||||
|
||||
But: **this implies that you have to maintain two files if the compose file changes.**
|
||||
|
||||
For example. With "labels", you should do:
|
||||
|
||||
```yaml
|
||||
# in compose file
|
||||
services:
|
||||
webapp:
|
||||
image: php:7-apache
|
||||
ports:
|
||||
- 8080:80
|
||||
environment:
|
||||
DB_HOST: database
|
||||
labels:
|
||||
katenary.v3/ingress: |-
|
||||
hostname: myapp.example.com
|
||||
port: 8080
|
||||
katenary.v3/map-env: |-
|
||||
DB_HOST: "{{ .Release.Name }}-database"
|
||||
|
||||
```
|
||||
|
||||
Using a Katenary file, you can do:
|
||||
|
||||
```yaml
|
||||
# in compose file, no need to add labels
|
||||
services:
|
||||
webapp:
|
||||
image: php:7-apache
|
||||
ports:
|
||||
- 8080:80
|
||||
environment:
|
||||
DB_HOST: database
|
||||
|
||||
# in katenary.yaml
|
||||
webapp:
|
||||
ingress:
|
||||
hostname: myapp.example.com
|
||||
port: 8080
|
||||
|
||||
map-env:
|
||||
DB_HOST: "{{ .Release.Name }}-database"
|
||||
```
|
||||
|
||||
!!! Warning "YAML in multiline label"
|
||||
|
||||
Compose only accept text label. So, to put a complete YAML content in the target label, you need to use a pipe char (`|` or `|-`)
|
||||
and to **indent** your content.
|
||||
Compose only accept text label. So, to put a complete YAML content in the target label,
|
||||
you need to use a pipe char (`|` or `|-`) and to **indent** your content.
|
||||
|
||||
For example :
|
||||
|
||||
@@ -26,14 +93,15 @@ Basically, you can use `katenary` to transpose a docker-compose file (or any com
|
||||
Katenary transforms compose services this way:
|
||||
|
||||
- Takes the service and create a "Deployment" file
|
||||
- if a port is declared, Katenary creates a service (ClusterIP)
|
||||
- if a port is exposed, Katenary creates a service (NodePort)
|
||||
- environment variables will be stored inside a configMap
|
||||
- if a port is declared, Katenary creates a service (`ClusterIP`)
|
||||
- if a port is exposed, Katenary creates a service (`NodePort`)
|
||||
- environment variables will be stored inside a `ConfigMap`
|
||||
- image, tags, and ingresses configuration are also stored in `values.yaml` file
|
||||
- if named volumes are declared, Katenary create PersistentVolumeClaims - not enabled in values file
|
||||
- if named volumes are declared, Katenary create `PersistentVolumeClaims` - not enabled in values file
|
||||
- `depends_on` needs that the pointed service declared a port. If not, you can use labels to inform Katenary
|
||||
|
||||
For any other specific configuration, like binding local files as configMap, bind variables, add values with documentation, etc. You'll need to use labels.
|
||||
For any other specific configuration, like binding local files as `ConfigMap`, bind variables, add values with
|
||||
documentation, etc. You'll need to use labels.
|
||||
|
||||
Katenary can also configure containers grouping in pods, declare dependencies, ignore some services, force variables as
|
||||
secrets, mount files as `configMap`, and many others things. To adapt the helm chart generation, you will need to use
|
||||
@@ -100,7 +168,7 @@ services:
|
||||
|
||||
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:
|
||||
So, instead of exposing the port in the compose definition, let's declare this to Katenary with labels:
|
||||
|
||||
```yaml
|
||||
version: "3"
|
||||
|
@@ -59,4 +59,8 @@ nav:
|
||||
- Generator:
|
||||
- Index: packages/generator.md
|
||||
- ExtraFiles: packages/generator/extrafiles.md
|
||||
- LabelStructs: packages/generator/labelStructs.md
|
||||
- labels:
|
||||
- packages/generator/labels.md
|
||||
- LabelStructs: packages/generator/labels/labelStructs.md
|
||||
- KatenaryFile: packages/generator/katenaryfile.md
|
||||
|
||||
|
@@ -33,7 +33,7 @@ type ConvertOptions struct {
|
||||
}
|
||||
|
||||
// HelmChart is a Helm Chart representation. It contains all the
|
||||
// tempaltes, values, versions, helpers...
|
||||
// templates, values, versions, helpers...
|
||||
type HelmChart struct {
|
||||
Templates map[string]*ChartTemplate `yaml:"-"`
|
||||
Values map[string]any `yaml:"-"`
|
||||
@@ -209,10 +209,21 @@ func (chart *HelmChart) generateDeployment(service types.ServiceConfig, deployme
|
||||
// generate the cronjob if needed
|
||||
chart.setCronJob(service, appName)
|
||||
|
||||
if exchange, ok := service.Labels[labels.LabelExchangeVolume]; ok {
|
||||
// we need to add a volume and a mount point
|
||||
ex, err := labelStructs.NewExchangeVolumes(exchange)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, exchangeVolume := range ex {
|
||||
d.AddLegacyVolume("exchange-"+exchangeVolume.Name, exchangeVolume.Type)
|
||||
d.exchangesVolumes[service.Name] = exchangeVolume
|
||||
}
|
||||
}
|
||||
|
||||
// get the same-pod label if exists, add it to the list.
|
||||
// We later will copy some parts to the target deployment and remove this one.
|
||||
if samePod, ok := service.Labels[labels.LabelSamePod]; ok && samePod != "" {
|
||||
log.Printf("Found same-pod label for %s", service.Name)
|
||||
podToMerge[samePod] = &service
|
||||
}
|
||||
|
||||
|
@@ -24,17 +24,6 @@ const (
|
||||
FileMapUsageFiles // files in a configmap.
|
||||
)
|
||||
|
||||
// NewFileMap creates a new DataMap from a compose service. The appName is the name of the application taken from the project name.
|
||||
func NewFileMap(service types.ServiceConfig, appName, kind string) DataMap {
|
||||
switch kind {
|
||||
case "configmap":
|
||||
return NewConfigMap(service, appName, true)
|
||||
default:
|
||||
log.Fatalf("Unknown filemap kind: %s", kind)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// only used to check interface implementation
|
||||
var (
|
||||
_ DataMap = (*ConfigMap)(nil)
|
||||
@@ -109,14 +98,14 @@ func NewConfigMap(service types.ServiceConfig, appName string, forFile bool) *Co
|
||||
done[key] = true
|
||||
}
|
||||
}
|
||||
}
|
||||
for key, env := range service.Environment {
|
||||
_, isDropped := drop[key]
|
||||
_, isDone := done[key]
|
||||
if isDropped || isDone {
|
||||
continue
|
||||
for key, env := range service.Environment {
|
||||
_, isDropped := drop[key]
|
||||
_, isDone := done[key]
|
||||
if isDropped || isDone {
|
||||
continue
|
||||
}
|
||||
cm.AddData(key, *env)
|
||||
}
|
||||
cm.AddData(key, *env)
|
||||
}
|
||||
|
||||
return cm
|
||||
@@ -168,7 +157,6 @@ func (c *ConfigMap) AppendDir(path string) {
|
||||
if err != nil {
|
||||
log.Fatalf("Path %s does not exist\n", path)
|
||||
}
|
||||
log.Printf("Appending files from %s to configmap\n", path)
|
||||
// recursively read all files in the path and add them to the configmap
|
||||
if stat.IsDir() {
|
||||
files, err := os.ReadDir(path)
|
||||
|
@@ -1,6 +1,8 @@
|
||||
package generator
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"katenary/generator/labels"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
@@ -40,3 +42,34 @@ services:
|
||||
t.Errorf("Expected BAR to be baz, got %s", data["BAR"])
|
||||
}
|
||||
}
|
||||
|
||||
func TestMapEnv(t *testing.T) {
|
||||
composeFile := `
|
||||
services:
|
||||
web:
|
||||
image: nginx:1.29
|
||||
environment:
|
||||
FOO: bar
|
||||
labels:
|
||||
%[1]s/map-env: |-
|
||||
FOO: 'baz'
|
||||
`
|
||||
|
||||
composeFile = fmt.Sprintf(composeFile, labels.KatenaryLabelPrefix)
|
||||
tmpDir := setup(composeFile)
|
||||
defer teardown(tmpDir)
|
||||
|
||||
currentDir, _ := os.Getwd()
|
||||
os.Chdir(tmpDir)
|
||||
defer os.Chdir(currentDir)
|
||||
|
||||
output := internalCompileTest(t, "-s", "templates/web/configmap.yaml")
|
||||
configMap := v1.ConfigMap{}
|
||||
if err := yaml.Unmarshal([]byte(output), &configMap); err != nil {
|
||||
t.Errorf(unmarshalError, err)
|
||||
}
|
||||
data := configMap.Data
|
||||
if v, ok := data["FOO"]; !ok || v != "baz" {
|
||||
t.Errorf("Expected FOO to be baz, got %s", v)
|
||||
}
|
||||
}
|
||||
|
@@ -53,7 +53,7 @@ const imagePullSecretHelp = `
|
||||
# e.g.
|
||||
# pullSecrets:
|
||||
# - name: regcred
|
||||
# You are, for now, repsonsible for creating the secret.
|
||||
# You are, for now, responsible for creating the secret.
|
||||
`
|
||||
|
||||
const imagePullPolicyHelp = `# imagePullPolicy allows you to specify a policy to cache or always pull an image.
|
||||
@@ -397,23 +397,6 @@ func addMainTagAppDoc(values []byte, project *types.Project) []byte {
|
||||
return []byte(strings.Join(lines, "\n"))
|
||||
}
|
||||
|
||||
// addModeline adds a modeline to the values.yaml file to make sure that vim
|
||||
// will use the correct syntax highlighting.
|
||||
func addModeline(values []byte) []byte {
|
||||
modeline := "# vi" + "m: ft=helm.gotmpl.yaml"
|
||||
|
||||
// if the values ends by `{{- end }}` we need to add the modeline before
|
||||
lines := strings.Split(string(values), "\n")
|
||||
|
||||
if lines[len(lines)-1] == "{{- end }}" || lines[len(lines)-1] == "{{- end -}}" {
|
||||
lines = lines[:len(lines)-1]
|
||||
lines = append(lines, modeline, "{{- end }}")
|
||||
return []byte(strings.Join(lines, "\n"))
|
||||
}
|
||||
|
||||
return append(values, []byte(modeline)...)
|
||||
}
|
||||
|
||||
func addResourceHelp(values []byte) []byte {
|
||||
lines := strings.Split(string(values), "\n")
|
||||
for i, line := range lines {
|
||||
|
@@ -33,12 +33,13 @@ type ConfigMapMount struct {
|
||||
// Deployment is a kubernetes Deployment.
|
||||
type Deployment struct {
|
||||
*appsv1.Deployment `yaml:",inline"`
|
||||
chart *HelmChart `yaml:"-"`
|
||||
configMaps map[string]*ConfigMapMount `yaml:"-"`
|
||||
volumeMap map[string]string `yaml:"-"` // keep map of fixed named to original volume name
|
||||
service *types.ServiceConfig `yaml:"-"`
|
||||
defaultTag string `yaml:"-"`
|
||||
isMainApp bool `yaml:"-"`
|
||||
chart *HelmChart `yaml:"-"`
|
||||
configMaps map[string]*ConfigMapMount `yaml:"-"`
|
||||
volumeMap map[string]string `yaml:"-"` // keep map of fixed named to original volume name
|
||||
service *types.ServiceConfig `yaml:"-"`
|
||||
defaultTag string `yaml:"-"`
|
||||
isMainApp bool `yaml:"-"`
|
||||
exchangesVolumes map[string]*labelStructs.ExchangeVolume `yaml:"-"`
|
||||
}
|
||||
|
||||
// NewDeployment creates a new Deployment from a compose service. The appName is the name of the application taken from the project name.
|
||||
@@ -90,8 +91,9 @@ func NewDeployment(service types.ServiceConfig, chart *HelmChart) *Deployment {
|
||||
},
|
||||
},
|
||||
},
|
||||
configMaps: make(map[string]*ConfigMapMount),
|
||||
volumeMap: make(map[string]string),
|
||||
configMaps: make(map[string]*ConfigMapMount),
|
||||
volumeMap: make(map[string]string),
|
||||
exchangesVolumes: map[string]*labelStructs.ExchangeVolume{},
|
||||
}
|
||||
|
||||
// add containers
|
||||
@@ -212,6 +214,27 @@ func (d *Deployment) AddVolumes(service types.ServiceConfig, appName string) {
|
||||
}
|
||||
}
|
||||
|
||||
func (d *Deployment) AddLegacyVolume(name, kind string) {
|
||||
// ensure the volume is not present
|
||||
for _, v := range d.Spec.Template.Spec.Volumes {
|
||||
if v.Name == name {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// init
|
||||
if d.Spec.Template.Spec.Volumes == nil {
|
||||
d.Spec.Template.Spec.Volumes = []corev1.Volume{}
|
||||
}
|
||||
|
||||
d.Spec.Template.Spec.Volumes = append(d.Spec.Template.Spec.Volumes, corev1.Volume{
|
||||
Name: name,
|
||||
VolumeSource: corev1.VolumeSource{
|
||||
EmptyDir: &corev1.EmptyDirVolumeSource{},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func (d *Deployment) BindFrom(service types.ServiceConfig, binded *Deployment) {
|
||||
// find the volume in the binded deployment
|
||||
for _, bindedVolume := range binded.Spec.Template.Spec.Volumes {
|
||||
@@ -276,14 +299,27 @@ func (d *Deployment) Filename() string {
|
||||
}
|
||||
|
||||
// SetEnvFrom sets the environment variables to a configmap. The configmap is created.
|
||||
func (d *Deployment) SetEnvFrom(service types.ServiceConfig, appName string) {
|
||||
func (d *Deployment) SetEnvFrom(service types.ServiceConfig, appName string, samePod ...bool) {
|
||||
if len(service.Environment) == 0 {
|
||||
return
|
||||
}
|
||||
inSamePod := false
|
||||
if len(samePod) > 0 && samePod[0] {
|
||||
inSamePod = true
|
||||
}
|
||||
|
||||
drop := []string{}
|
||||
secrets := []string{}
|
||||
|
||||
defer func() {
|
||||
c, index := d.BindMapFilesToContainer(service, secrets, appName)
|
||||
if c == nil || index == -1 {
|
||||
log.Println("Container not found for service ", service.Name)
|
||||
return
|
||||
}
|
||||
d.Spec.Template.Spec.Containers[index] = *c
|
||||
}()
|
||||
|
||||
// secrets from label
|
||||
labelSecrets, err := labelStructs.SecretsFrom(service.Labels[labels.LabelSecrets])
|
||||
if err != nil {
|
||||
@@ -308,6 +344,10 @@ func (d *Deployment) SetEnvFrom(service types.ServiceConfig, appName string) {
|
||||
secrets = append(secrets, secret)
|
||||
}
|
||||
|
||||
if inSamePod {
|
||||
return
|
||||
}
|
||||
|
||||
// for each values from label "values", add it to Values map and change the envFrom
|
||||
// value to {{ .Values.<service>.<value> }}
|
||||
for _, value := range labelValues {
|
||||
@@ -330,10 +370,26 @@ func (d *Deployment) SetEnvFrom(service types.ServiceConfig, appName string) {
|
||||
for _, value := range drop {
|
||||
delete(service.Environment, value)
|
||||
}
|
||||
}
|
||||
|
||||
func (d *Deployment) BindMapFilesToContainer(service types.ServiceConfig, secrets []string, appName string) (*corev1.Container, int) {
|
||||
fromSources := []corev1.EnvFromSource{}
|
||||
|
||||
if len(service.Environment) > 0 {
|
||||
envSize := len(service.Environment)
|
||||
|
||||
for _, secret := range secrets {
|
||||
for k := range service.Environment {
|
||||
if k == secret {
|
||||
envSize--
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if envSize > 0 {
|
||||
if service.Name == "db" {
|
||||
log.Println("Service ", service.Name, " has environment variables")
|
||||
log.Println(service.Environment)
|
||||
}
|
||||
fromSources = append(fromSources, corev1.EnvFromSource{
|
||||
ConfigMapRef: &corev1.ConfigMapEnvSource{
|
||||
LocalObjectReference: corev1.LocalObjectReference{
|
||||
@@ -356,7 +412,7 @@ func (d *Deployment) SetEnvFrom(service types.ServiceConfig, appName string) {
|
||||
container, index := utils.GetContainerByName(service.Name, d.Spec.Template.Spec.Containers)
|
||||
if container == nil {
|
||||
utils.Warn("Container not found for service " + service.Name)
|
||||
return
|
||||
return nil, -1
|
||||
}
|
||||
|
||||
container.EnvFrom = append(container.EnvFrom, fromSources...)
|
||||
@@ -364,8 +420,30 @@ func (d *Deployment) SetEnvFrom(service types.ServiceConfig, appName string) {
|
||||
if container.Env == nil {
|
||||
container.Env = []corev1.EnvVar{}
|
||||
}
|
||||
return container, index
|
||||
}
|
||||
|
||||
d.Spec.Template.Spec.Containers[index] = *container
|
||||
func (d *Deployment) MountExchangeVolumes() {
|
||||
for name, ex := range d.exchangesVolumes {
|
||||
for i, c := range d.Spec.Template.Spec.Containers {
|
||||
c.VolumeMounts = append(c.VolumeMounts, corev1.VolumeMount{
|
||||
Name: "exchange-" + ex.Name,
|
||||
MountPath: ex.MountPath,
|
||||
})
|
||||
if len(ex.Init) > 0 && name == c.Name {
|
||||
d.Spec.Template.Spec.InitContainers = append(d.Spec.Template.Spec.InitContainers, corev1.Container{
|
||||
Command: []string{"/bin/sh", "-c", ex.Init},
|
||||
Image: c.Image,
|
||||
Name: "exhange-init-" + name,
|
||||
VolumeMounts: []corev1.VolumeMount{{
|
||||
Name: "exchange-" + ex.Name,
|
||||
MountPath: ex.MountPath,
|
||||
}},
|
||||
})
|
||||
}
|
||||
d.Spec.Template.Spec.Containers[i] = c
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Yaml returns the yaml representation of the deployment.
|
||||
@@ -405,7 +483,11 @@ func (d *Deployment) Yaml() ([]byte, error) {
|
||||
|
||||
if strings.Contains(volume, "mountPath: ") {
|
||||
spaces = strings.Repeat(" ", utils.CountStartingSpaces(volume))
|
||||
varName := d.volumeMap[volumeName]
|
||||
varName, ok := d.volumeMap[volumeName]
|
||||
if !ok {
|
||||
// this case happens when the volume is a "bind" volume comming from a "same-pod" service.
|
||||
continue
|
||||
}
|
||||
varName = strings.ReplaceAll(varName, "-", "_")
|
||||
content[line] = spaces + `{{- if .Values.` + serviceName + `.persistence.` + varName + `.enabled }}` + "\n" + volume
|
||||
changing = true
|
||||
@@ -581,10 +663,12 @@ func (d *Deployment) appendFileToConfigMap(service types.ServiceConfig, appName
|
||||
|
||||
func (d *Deployment) bindVolumes(volume types.ServiceVolumeConfig, isSamePod bool, tobind map[string]bool, service types.ServiceConfig, appName string) {
|
||||
container, index := utils.GetContainerByName(service.Name, d.Spec.Template.Spec.Containers)
|
||||
|
||||
defer func(d *Deployment, container *corev1.Container, index int) {
|
||||
d.Spec.Template.Spec.Containers[index] = *container
|
||||
}(d, container, index)
|
||||
if _, ok := tobind[volume.Source]; !isSamePod && volume.Type == "bind" && !ok {
|
||||
|
||||
if _, found := tobind[volume.Source]; !isSamePod && volume.Type == "bind" && !found {
|
||||
utils.Warn(
|
||||
"Bind volumes are not supported yet, " +
|
||||
"excepting for those declared as " +
|
||||
|
@@ -2,7 +2,7 @@
|
||||
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
|
||||
Conversion 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.
|
||||
|
@@ -79,6 +79,11 @@ func Generate(project *types.Project) (*HelmChart, error) {
|
||||
}
|
||||
}
|
||||
|
||||
// if we have built exchange volumes, we need to moint them in each deployment
|
||||
for _, d := range deployments {
|
||||
d.MountExchangeVolumes()
|
||||
}
|
||||
|
||||
// drop all "same-pod" deployments because the containers and volumes are already
|
||||
// in the target deployment
|
||||
for _, service := range podToMerge {
|
||||
@@ -87,6 +92,10 @@ func Generate(project *types.Project) (*HelmChart, error) {
|
||||
if target, ok := deployments[samepod]; ok {
|
||||
target.AddContainer(*service)
|
||||
target.BindFrom(*service, deployments[service.Name])
|
||||
target.SetEnvFrom(*service, appName, true)
|
||||
// copy all init containers
|
||||
initContainers := deployments[service.Name].Spec.Template.Spec.InitContainers
|
||||
target.Spec.Template.Spec.InitContainers = append(target.Spec.Template.Spec.InitContainers, initContainers...)
|
||||
delete(deployments, service.Name)
|
||||
} else {
|
||||
log.Printf("service %[1]s is declared as %[2]s, but %[2]s is not defined", service.Name, labels.LabelSamePod)
|
||||
@@ -146,7 +155,9 @@ func Generate(project *types.Project) (*HelmChart, error) {
|
||||
for _, s := range podToMerge {
|
||||
// get the target service
|
||||
target := services[s.Name]
|
||||
delete(chart.Templates, target.Filename())
|
||||
if target != nil {
|
||||
delete(chart.Templates, target.Filename())
|
||||
}
|
||||
}
|
||||
|
||||
// compute all needed resplacements in YAML templates
|
||||
@@ -272,7 +283,7 @@ func buildVolumes(service types.ServiceConfig, chart *HelmChart, deployments map
|
||||
}
|
||||
switch v.Type {
|
||||
case "volume":
|
||||
v.Source = strings.ReplaceAll(v.Source, "-", "_")
|
||||
v.Source = utils.AsResourceName(v.Source)
|
||||
pvc := NewVolumeClaim(service, v.Source, appName)
|
||||
|
||||
// if the service is integrated in another deployment, we need to add the volume
|
||||
|
@@ -51,9 +51,9 @@ func NewIngress(service types.ServiceConfig, Chart *HelmChart) *Ingress {
|
||||
|
||||
Chart.Values[service.Name].(*Value).Ingress = &IngressValue{
|
||||
Enabled: mapping.Enabled,
|
||||
Path: mapping.Path,
|
||||
Path: *mapping.Path,
|
||||
Host: mapping.Hostname,
|
||||
Class: mapping.Class,
|
||||
Class: *mapping.Class,
|
||||
Annotations: mapping.Annotations,
|
||||
TLS: TLS{Enabled: mapping.TLS.Enabled},
|
||||
}
|
||||
|
@@ -25,20 +25,21 @@ type StringOrMap any
|
||||
|
||||
// Service is a struct that contains the service configuration for katenary
|
||||
type Service struct {
|
||||
MainApp *bool `json:"main-app,omitempty" jsonschema:"title=Is this service the main application"`
|
||||
Values []StringOrMap `json:"values,omitempty" jsonschema:"description=Environment variables to be set in values.yaml with or without a description"`
|
||||
Secrets *labelStructs.Secrets `json:"secrets,omitempty" jsonschema:"title=Secrets,description=Environment variables to be set as secrets"`
|
||||
Ports *labelStructs.Ports `json:"ports,omitempty" jsonschema:"title=Ports,description=Ports to be exposed in services"`
|
||||
Ingress *labelStructs.Ingress `json:"ingress,omitempty" jsonschema:"title=Ingress,description=Ingress configuration"`
|
||||
HealthCheck *labelStructs.HealthCheck `json:"health-check,omitempty" jsonschema:"title=Health Check,description=Health check configuration that respects the kubernetes api"`
|
||||
SamePod *string `json:"same-pod,omitempty" jsonschema:"title=Same Pod,description=Service that should be in the same pod"`
|
||||
Description *string `json:"description,omitempty" jsonschema:"title=Description,description=Description of the service that will be injected in the values.yaml file"`
|
||||
Ignore *bool `json:"ignore,omitempty" jsonschema:"title=Ignore,description=Ignore the service in the conversion"`
|
||||
Dependencies []labelStructs.Dependency `json:"dependencies,omitempty" jsonschema:"title=Dependencies,description=Services that should be injected in the Chart.yaml file"`
|
||||
ConfigMapFile *labelStructs.ConfigMapFile `json:"configmap-files,omitempty" jsonschema:"title=ConfigMap Files,description=Files that should be injected as ConfigMap"`
|
||||
MapEnv *labelStructs.MapEnv `json:"map-env,omitempty" jsonschema:"title=Map Env,description=Map environment variables to another value"`
|
||||
CronJob *labelStructs.CronJob `json:"cron-job,omitempty" jsonschema:"title=Cron Job,description=Cron Job configuration"`
|
||||
EnvFrom *labelStructs.EnvFrom `json:"env-from,omitempty" jsonschema:"title=Env From,description=Inject environment variables from another service"`
|
||||
MainApp *bool `json:"main-app,omitempty" jsonschema:"title=Is this service the main application"`
|
||||
Values []StringOrMap `json:"values,omitempty" jsonschema:"description=Environment variables to be set in values.yaml with or without a description"`
|
||||
Secrets *labelStructs.Secrets `json:"secrets,omitempty" jsonschema:"title=Secrets,description=Environment variables to be set as secrets"`
|
||||
Ports *labelStructs.Ports `json:"ports,omitempty" jsonschema:"title=Ports,description=Ports to be exposed in services"`
|
||||
Ingress *labelStructs.Ingress `json:"ingress,omitempty" jsonschema:"title=Ingress,description=Ingress configuration"`
|
||||
HealthCheck *labelStructs.HealthCheck `json:"health-check,omitempty" jsonschema:"title=Health Check,description=Health check configuration that respects the kubernetes api"`
|
||||
SamePod *string `json:"same-pod,omitempty" jsonschema:"title=Same Pod,description=Service that should be in the same pod"`
|
||||
Description *string `json:"description,omitempty" jsonschema:"title=Description,description=Description of the service that will be injected in the values.yaml file"`
|
||||
Ignore *bool `json:"ignore,omitempty" jsonschema:"title=Ignore,description=Ignore the service in the conversion"`
|
||||
Dependencies []labelStructs.Dependency `json:"dependencies,omitempty" jsonschema:"title=Dependencies,description=Services that should be injected in the Chart.yaml file"`
|
||||
ConfigMapFile *labelStructs.ConfigMapFile `json:"configmap-files,omitempty" jsonschema:"title=ConfigMap Files,description=Files that should be injected as ConfigMap"`
|
||||
MapEnv *labelStructs.MapEnv `json:"map-env,omitempty" jsonschema:"title=Map Env,description=Map environment variables to another value"`
|
||||
CronJob *labelStructs.CronJob `json:"cron-job,omitempty" jsonschema:"title=Cron Job,description=Cron Job configuration"`
|
||||
EnvFrom *labelStructs.EnvFrom `json:"env-from,omitempty" jsonschema:"title=Env From,description=Inject environment variables from another service"`
|
||||
ExchangeVolumes []*labelStructs.ExchangeVolume `json:"exchange-volumes,omitempty" jsonschema:"title=Exchange Volumes,description=Exchange volumes between services"`
|
||||
}
|
||||
|
||||
// OverrideWithConfig overrides the project with the katenary.yaml file. It
|
||||
@@ -89,6 +90,7 @@ func OverrideWithConfig(project *types.Project) {
|
||||
getLabelContent(s.MapEnv, &project.Services[i], labels.LabelMapEnv)
|
||||
getLabelContent(s.CronJob, &project.Services[i], labels.LabelCronJob)
|
||||
getLabelContent(s.EnvFrom, &project.Services[i], labels.LabelEnvFrom)
|
||||
getLabelContent(s.ExchangeVolumes, &project.Services[i], labels.LabelExchangeVolume)
|
||||
}
|
||||
}
|
||||
fmt.Println(utils.IconInfo, "Katenary file loaded successfully, the services are now configured.")
|
||||
@@ -105,6 +107,19 @@ func getLabelContent(o any, service *types.ServiceConfig, labelName string) erro
|
||||
return err
|
||||
}
|
||||
val := strings.TrimSpace(string(c))
|
||||
if labelName == labels.LabelIngress {
|
||||
// special case, values must be set from some defaults
|
||||
ing, err := labelStructs.IngressFrom(val)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
return err
|
||||
}
|
||||
c, err := yaml.Marshal(ing)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
val = strings.TrimSpace(string(c))
|
||||
}
|
||||
|
||||
service.Labels[labelName] = val
|
||||
return nil
|
||||
|
119
generator/katenaryfile/main_test.go
Normal file
119
generator/katenaryfile/main_test.go
Normal file
@@ -0,0 +1,119 @@
|
||||
package katenaryfile
|
||||
|
||||
import (
|
||||
"katenary/generator/labels"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/compose-spec/compose-go/cli"
|
||||
)
|
||||
|
||||
func TestBuildSchema(t *testing.T) {
|
||||
sh := GenerateSchema()
|
||||
if len(sh) == 0 {
|
||||
t.Errorf("Expected schema to be defined")
|
||||
}
|
||||
}
|
||||
|
||||
func TestOverrideProjectWithKatenaryFile(t *testing.T) {
|
||||
composeContent := `
|
||||
services:
|
||||
webapp:
|
||||
image: nginx:latest
|
||||
`
|
||||
|
||||
katenaryfileContent := `
|
||||
webapp:
|
||||
ports:
|
||||
- 80
|
||||
`
|
||||
|
||||
// create /tmp/katenary-test-override directory, save the compose.yaml file
|
||||
tmpDir, err := os.MkdirTemp("", "katenary-test-override")
|
||||
if err != nil {
|
||||
t.Fatalf(err.Error())
|
||||
}
|
||||
composeFile := filepath.Join(tmpDir, "compose.yaml")
|
||||
katenaryFile := filepath.Join(tmpDir, "katenary.yaml")
|
||||
|
||||
os.MkdirAll(tmpDir, 0755)
|
||||
if err := os.WriteFile(composeFile, []byte(composeContent), 0644); err != nil {
|
||||
t.Log(err)
|
||||
}
|
||||
if err := os.WriteFile(katenaryFile, []byte(katenaryfileContent), 0644); err != nil {
|
||||
t.Log(err)
|
||||
}
|
||||
defer os.RemoveAll(tmpDir)
|
||||
|
||||
c, _ := os.ReadFile(composeFile)
|
||||
log.Println(string(c))
|
||||
|
||||
// chand dir to this directory
|
||||
os.Chdir(tmpDir)
|
||||
options, _ := cli.NewProjectOptions(nil,
|
||||
cli.WithWorkingDirectory(tmpDir),
|
||||
cli.WithDefaultConfigPath,
|
||||
)
|
||||
project, err := cli.ProjectFromOptions(options)
|
||||
|
||||
OverrideWithConfig(project)
|
||||
w := project.Services[0].Labels
|
||||
if v, ok := w[labels.LabelPorts]; !ok {
|
||||
t.Fatal("Expected ports to be defined", v)
|
||||
}
|
||||
}
|
||||
|
||||
func TestOverrideProjectWithIngress(t *testing.T) {
|
||||
composeContent := `
|
||||
services:
|
||||
webapp:
|
||||
image: nginx:latest
|
||||
`
|
||||
|
||||
katenaryfileContent := `
|
||||
webapp:
|
||||
ports:
|
||||
- 80
|
||||
ingress:
|
||||
port: 80
|
||||
`
|
||||
|
||||
// create /tmp/katenary-test-override directory, save the compose.yaml file
|
||||
tmpDir, err := os.MkdirTemp("", "katenary-test-override")
|
||||
if err != nil {
|
||||
t.Fatalf(err.Error())
|
||||
}
|
||||
composeFile := filepath.Join(tmpDir, "compose.yaml")
|
||||
katenaryFile := filepath.Join(tmpDir, "katenary.yaml")
|
||||
|
||||
os.MkdirAll(tmpDir, 0755)
|
||||
if err := os.WriteFile(composeFile, []byte(composeContent), 0644); err != nil {
|
||||
t.Log(err)
|
||||
}
|
||||
if err := os.WriteFile(katenaryFile, []byte(katenaryfileContent), 0644); err != nil {
|
||||
t.Log(err)
|
||||
}
|
||||
defer os.RemoveAll(tmpDir)
|
||||
|
||||
c, _ := os.ReadFile(composeFile)
|
||||
log.Println(string(c))
|
||||
|
||||
// chand dir to this directory
|
||||
os.Chdir(tmpDir)
|
||||
options, _ := cli.NewProjectOptions(nil,
|
||||
cli.WithWorkingDirectory(tmpDir),
|
||||
cli.WithDefaultConfigPath,
|
||||
)
|
||||
project, err := cli.ProjectFromOptions(options)
|
||||
|
||||
OverrideWithConfig(project)
|
||||
w := project.Services[0].Labels
|
||||
if v, ok := w[labels.LabelPorts]; !ok {
|
||||
t.Fatal("Expected ports to be defined", v)
|
||||
}
|
||||
if v, ok := w[labels.LabelIngress]; !ok {
|
||||
t.Fatal("Expected ingress to be defined", v)
|
||||
}
|
||||
}
|
14
generator/labels/help-template.md.tpl
Normal file
14
generator/labels/help-template.md.tpl
Normal file
@@ -0,0 +1,14 @@
|
||||
## {{ .KatenaryPrefix }}/{{ .Name }}
|
||||
|
||||
{{ .Help.Short }}
|
||||
|
||||
**Type**: `{{ .Help.Type }}`
|
||||
|
||||
{{ .Help.Long }}
|
||||
|
||||
**Example:**
|
||||
|
||||
```yaml
|
||||
{{ .Help.Example }}
|
||||
```
|
||||
|
9
generator/labels/help-template.tpl
Normal file
9
generator/labels/help-template.tpl
Normal file
@@ -0,0 +1,9 @@
|
||||
{{ .KatenaryPrefix }}/{{ .Name }}: {{ .Help.Short }}
|
||||
Type: {{ .Help.Type }}
|
||||
|
||||
{{ .Help.Long }}
|
||||
|
||||
Example:
|
||||
|
||||
{{ .Help.Example }}
|
||||
|
@@ -32,6 +32,7 @@ const (
|
||||
LabelConfigMapFiles Label = KatenaryLabelPrefix + "/configmap-files"
|
||||
LabelCronJob Label = KatenaryLabelPrefix + "/cronjob"
|
||||
LabelEnvFrom Label = KatenaryLabelPrefix + "/env-from"
|
||||
LabelExchangeVolume Label = KatenaryLabelPrefix + "/exchange-volumes"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -42,6 +43,12 @@ var (
|
||||
|
||||
// parsed yaml
|
||||
labelFullHelp map[string]Help
|
||||
|
||||
//go:embed help-template.tpl
|
||||
helpTemplatePlain string
|
||||
|
||||
//go:embed help-template.md.tpl
|
||||
helpTemplateMarkdown string
|
||||
)
|
||||
|
||||
// Label is a katenary label to find in compose files.
|
||||
@@ -95,9 +102,6 @@ func GetLabelHelpFor(labelname string, asMarkdown bool) string {
|
||||
help.Example = strings.TrimPrefix(help.Example, "\n")
|
||||
help.Short = strings.TrimPrefix(help.Short, "\n")
|
||||
|
||||
// get help template
|
||||
helpTemplate := getHelpTemplate(asMarkdown)
|
||||
|
||||
if asMarkdown {
|
||||
// enclose templates in backticks
|
||||
help.Long = regexp.MustCompile(`\{\{(.*?)\}\}`).ReplaceAllString(help.Long, "`{{$1}}`")
|
||||
@@ -110,6 +114,15 @@ func GetLabelHelpFor(labelname string, asMarkdown bool) string {
|
||||
help.Long = utils.WordWrap(help.Long, 80)
|
||||
}
|
||||
|
||||
// get help template
|
||||
var helpTemplate string
|
||||
switch asMarkdown {
|
||||
case true:
|
||||
helpTemplate = helpTemplateMarkdown
|
||||
case false:
|
||||
helpTemplate = helpTemplatePlain
|
||||
}
|
||||
|
||||
var buf bytes.Buffer
|
||||
template.Must(template.New("shorthelp").Parse(help.Long)).Execute(&buf, struct {
|
||||
KatenaryPrefix string
|
||||
@@ -207,29 +220,6 @@ func generateTableHeaderSeparator(maxNameLength, maxDescriptionLength, maxTypeLe
|
||||
)
|
||||
}
|
||||
|
||||
func getHelpTemplate(asMarkdown bool) string {
|
||||
if asMarkdown {
|
||||
return `## {{ .KatenaryPrefix }}/{{ .Name }}
|
||||
|
||||
{{ .Help.Short }}
|
||||
|
||||
**Type**: ` + "`" + `{{ .Help.Type }}` + "`" + `
|
||||
|
||||
{{ .Help.Long }}
|
||||
|
||||
**Example:**` + "\n\n```yaml\n" + `{{ .Help.Example }}` + "\n```\n"
|
||||
}
|
||||
|
||||
return `{{ .KatenaryPrefix }}/{{ .Name }}: {{ .Help.Short }}
|
||||
Type: {{ .Help.Type }}
|
||||
|
||||
{{ .Help.Long }}
|
||||
|
||||
Example:
|
||||
{{ .Help.Example }}
|
||||
`
|
||||
}
|
||||
|
||||
func Prefix() string {
|
||||
return KatenaryLabelPrefix
|
||||
}
|
||||
|
@@ -284,4 +284,41 @@
|
||||
{{ .KatenaryPrefix }}/env-from: |-
|
||||
- myservice1
|
||||
|
||||
"exchange-volumes":
|
||||
short: Add exchange volumes (empty directory on the node) to share data
|
||||
type: "list of objects"
|
||||
long: |-
|
||||
This label allows sharing data between containres. The volume is created in
|
||||
the node and mounted in the pod. It is useful to share data between containers
|
||||
in a "same pod" logic. For example to let PHP-FPM and Nginx share the same direcotory.
|
||||
|
||||
This will create:
|
||||
|
||||
- an `emptyDir` volume in the deployment
|
||||
- a `voumeMount` in the pod for **each container**
|
||||
- a `initContainer` for each definition
|
||||
|
||||
Fields:
|
||||
- name: the name of the volume (manadatory)
|
||||
- mountPath: the path where the volume is mounted in the pod (optional, default is `/opt`)
|
||||
- init: a command to run to initialize the volume with data (optional)
|
||||
|
||||
!!! Warning
|
||||
This is highly experimental. This is mainly useful when using the "same-pod" label.
|
||||
|
||||
example: |-
|
||||
nginx:
|
||||
# ...
|
||||
labels;
|
||||
{{ .KatenaryPrefix }}/exchange-volumes: |-
|
||||
- name: php-fpm
|
||||
mountPath: /var/www/html
|
||||
php:
|
||||
# ...
|
||||
labels:
|
||||
{{ .KatenaryPrefix }}/exchange-volumes: |-
|
||||
- name: php-fpm
|
||||
mountPath: /opt
|
||||
init: cp -ra /var/www/html/* /opt
|
||||
|
||||
# vim: ft=gotmpl.yaml
|
||||
|
20
generator/labels/labelStructs/exchangeVolume.go
Normal file
20
generator/labels/labelStructs/exchangeVolume.go
Normal file
@@ -0,0 +1,20 @@
|
||||
package labelStructs
|
||||
|
||||
import "gopkg.in/yaml.v3"
|
||||
|
||||
type ExchangeVolume struct {
|
||||
Name string `yaml:"name" json:"name"`
|
||||
MountPath string `yaml:"mountPath" json:"mountPath"`
|
||||
Type string `yaml:"type,omitempty" json:"type,omitempty"`
|
||||
Init string `yaml:"init,omitempty" json:"init,omitempty"`
|
||||
}
|
||||
|
||||
func NewExchangeVolumes(data string) ([]*ExchangeVolume, error) {
|
||||
mapping := []*ExchangeVolume{}
|
||||
|
||||
if err := yaml.Unmarshal([]byte(data), &mapping); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return mapping, nil
|
||||
}
|
@@ -1,17 +1,22 @@
|
||||
package labelStructs
|
||||
|
||||
import "gopkg.in/yaml.v3"
|
||||
import (
|
||||
"fmt"
|
||||
"katenary/utils"
|
||||
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
type TLS struct {
|
||||
Enabled bool `yaml:"enabled" json:"enabled,omitempty"`
|
||||
}
|
||||
|
||||
type Ingress struct {
|
||||
Port *int32 `yaml:"port,omitempty" jsonschema:"nullable" json:"port,omitempty"`
|
||||
Port *int32 `yaml:"port,omitempty" json:"port,omitempty"`
|
||||
Annotations map[string]string `yaml:"annotations,omitempty" jsonschema:"nullable" json:"annotations,omitempty"`
|
||||
Hostname string `yaml:"hostname" json:"hostname,omitempty"`
|
||||
Path string `yaml:"path" json:"path,omitempty"`
|
||||
Class string `yaml:"class" json:"class,omitempty" jsonschema:"default:-"`
|
||||
Path *string `yaml:"path,omitempty" json:"path,omitempty"`
|
||||
Class *string `yaml:"class,omitempty" json:"class,omitempty" jsonschema:"default:-"`
|
||||
Enabled bool `yaml:"enabled" json:"enabled,omitempty"`
|
||||
TLS *TLS `yaml:"tls,omitempty" json:"tls,omitempty"`
|
||||
}
|
||||
@@ -20,14 +25,17 @@ type Ingress struct {
|
||||
func IngressFrom(data string) (*Ingress, error) {
|
||||
mapping := Ingress{
|
||||
Hostname: "",
|
||||
Path: "/",
|
||||
Path: utils.StrPtr("/"),
|
||||
Enabled: false,
|
||||
Class: "-",
|
||||
Class: utils.StrPtr("-"),
|
||||
Port: nil,
|
||||
TLS: &TLS{Enabled: true},
|
||||
}
|
||||
if err := yaml.Unmarshal([]byte(data), &mapping); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if mapping.Port == nil {
|
||||
return nil, fmt.Errorf("port is required in ingress definition")
|
||||
}
|
||||
return &mapping, nil
|
||||
}
|
||||
|
@@ -1,6 +1,7 @@
|
||||
package generator
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"katenary/generator/labels"
|
||||
"os"
|
||||
@@ -44,3 +45,49 @@ services:
|
||||
t.Errorf("Expected BAR to be baz, got %s", data["BAR"])
|
||||
}
|
||||
}
|
||||
|
||||
func TestCreateSecretFromEnvironmentWithValue(t *testing.T) {
|
||||
composeFile := `
|
||||
services:
|
||||
web:
|
||||
image: nginx:1.29
|
||||
environment:
|
||||
- FOO=bar
|
||||
- BAR=baz
|
||||
labels:
|
||||
%[1]s/secrets: |-
|
||||
- BAR
|
||||
%[1]s/values: |-
|
||||
- BAR
|
||||
`
|
||||
composeFile = fmt.Sprintf(composeFile, labels.KatenaryLabelPrefix)
|
||||
tmpDir := setup(composeFile)
|
||||
defer teardown(tmpDir)
|
||||
|
||||
currentDir, _ := os.Getwd()
|
||||
os.Chdir(tmpDir)
|
||||
defer os.Chdir(currentDir)
|
||||
|
||||
force := false
|
||||
outputDir := "./chart"
|
||||
profiles := make([]string, 0)
|
||||
helmdepUpdate := true
|
||||
var appVersion *string
|
||||
chartVersion := "0.1.0"
|
||||
convertOptions := ConvertOptions{
|
||||
Force: force,
|
||||
OutputDir: outputDir,
|
||||
Profiles: profiles,
|
||||
HelmUpdate: helmdepUpdate,
|
||||
AppVersion: appVersion,
|
||||
ChartVersion: chartVersion,
|
||||
}
|
||||
Convert(convertOptions, "compose.yml")
|
||||
c, err := os.ReadFile("chart/values.yaml")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !bytes.Contains(c, []byte("BAR: baz")) {
|
||||
t.Errorf("Expected BAR to be baz, got %s", c)
|
||||
}
|
||||
}
|
||||
|
@@ -34,7 +34,7 @@ type IngressValue struct {
|
||||
TLS TLS `yaml:"tls"`
|
||||
}
|
||||
|
||||
// Value will be saved in values.yaml. It contains configuraiton for all deployment and services.
|
||||
// Value will be saved in values.yaml. It contains configuration for all deployment and services.
|
||||
type Value struct {
|
||||
Repository *RepositoryValue `yaml:"repository,omitempty"`
|
||||
Persistence map[string]*PersistenceValue `yaml:"persistence,omitempty"`
|
||||
|
@@ -191,3 +191,60 @@ volumes:
|
||||
t.Errorf("Expected volume name to be data: %v", dt)
|
||||
}
|
||||
}
|
||||
|
||||
func TestExchangeVolume(t *testing.T) {
|
||||
composeFile := `
|
||||
services:
|
||||
app1:
|
||||
image: nginx:1.29
|
||||
labels:
|
||||
%[1]s/exchange-volumes: |-
|
||||
- name: data
|
||||
mountPath: /var/www
|
||||
app2:
|
||||
image: foo:bar
|
||||
labels:
|
||||
%[1]s/same-pod: app1
|
||||
%[1]s/exchange-volumes: |-
|
||||
- name: data
|
||||
mountPath: /opt
|
||||
init: cp -r /var/www /opt
|
||||
`
|
||||
composeFile = fmt.Sprintf(composeFile, labels.KatenaryLabelPrefix)
|
||||
tmpDir := setup(composeFile)
|
||||
defer teardown(tmpDir)
|
||||
|
||||
currentDir, _ := os.Getwd()
|
||||
os.Chdir(tmpDir)
|
||||
defer os.Chdir(currentDir)
|
||||
output := internalCompileTest(t, "-s", "templates/app1/deployment.yaml")
|
||||
dt := v1.Deployment{}
|
||||
if err := yaml.Unmarshal([]byte(output), &dt); err != nil {
|
||||
t.Errorf(unmarshalError, err)
|
||||
}
|
||||
// the deployment should have a volume named "data"
|
||||
volumes := dt.Spec.Template.Spec.Volumes
|
||||
found := false
|
||||
for v := range volumes {
|
||||
if volumes[v].Name == "exchange-data" {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
t.Errorf("Expected volume name to be data: %v", volumes)
|
||||
}
|
||||
mounted := 0
|
||||
// we should have a volume mount for both containers
|
||||
containers := dt.Spec.Template.Spec.Containers
|
||||
for c := range containers {
|
||||
for _, vm := range containers[c].VolumeMounts {
|
||||
if vm.Name == "exchange-data" {
|
||||
mounted++
|
||||
}
|
||||
}
|
||||
}
|
||||
if mounted != 2 {
|
||||
t.Errorf("Expected 2 mounted volumes, got %d", mounted)
|
||||
}
|
||||
}
|
||||
|
@@ -6,7 +6,7 @@ sonar.go.tests.reportPaths=gotest.json
|
||||
sonar.go.coverage.reportPaths=coverprofile.out
|
||||
|
||||
# excludde
|
||||
sonar.exclusions=doc/**
|
||||
sonar.exclusions=doc/**,**/*_test.go
|
||||
sonar.coverage.exclusions=doc/**,**/*_test.go
|
||||
|
||||
# This is the name and version displayed in the SonarCloud UI.
|
||||
|
@@ -70,11 +70,6 @@ func Wrap(src, above, below string) string {
|
||||
return spaces + above + "\n" + src + "\n" + spaces + below
|
||||
}
|
||||
|
||||
// WrapBytes wraps a byte array with a byte array above and below. It will respect the indentation of the src string.
|
||||
func WrapBytes(src, above, below []byte) []byte {
|
||||
return []byte(Wrap(string(src), string(above), string(below)))
|
||||
}
|
||||
|
||||
// GetServiceNameByPort returns the service name for a port. It the service name is not found, it returns an empty string.
|
||||
func GetServiceNameByPort(port int) string {
|
||||
name := ""
|
||||
@@ -162,14 +157,6 @@ func WordWrap(text string, lineWidth int) string {
|
||||
return wordwrap.WrapString(text, uint(lineWidth))
|
||||
}
|
||||
|
||||
func MapKeys(m map[string]interface{}) []string {
|
||||
keys := make([]string, 0, len(m))
|
||||
for k := range m {
|
||||
keys = append(keys, k)
|
||||
}
|
||||
return keys
|
||||
}
|
||||
|
||||
// Confirm asks a question and returns true if the answer is y.
|
||||
func Confirm(question string, icon ...Icon) bool {
|
||||
if len(icon) > 0 {
|
||||
@@ -198,3 +185,9 @@ func EncodeBasicYaml(data any) ([]byte, error) {
|
||||
func FixedResourceName(name string) string {
|
||||
return strings.ReplaceAll(name, "_", "-")
|
||||
}
|
||||
|
||||
// AsResourceName returns a resource name with underscores to respect the kubernetes naming convention.
|
||||
// It's the opposite of FixedResourceName.
|
||||
func AsResourceName(name string) string {
|
||||
return strings.ReplaceAll(name, "-", "_")
|
||||
}
|
||||
|
Reference in New Issue
Block a user