Skip to content

Commit

Permalink
Standardization
Browse files Browse the repository at this point in the history
- changed variables that was uppercased, that's not OK for linters
- cleanup some documentation
- remove the "/" in label prefix, a function is now used to get the
  complete label (`labelName()`)
- some cleanup in tpl files, and so on...
  • Loading branch information
metal3d committed Apr 24, 2024
1 parent 98c7c6d commit f73d598
Show file tree
Hide file tree
Showing 22 changed files with 181 additions and 220 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ docker-compose*
.credentials
release.id
configs/
cover.*
cover*
.sq
katenary
./katenary
2 changes: 1 addition & 1 deletion cmd/katenary/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ func generateLabelHelpCommand() *cobra.Command {
If no label is specified, the help for all labels is printed.
If a label is specified, the help for this label is printed.
The name of the label must be specified without the prefix ` + generator.KATENARY_PREFIX + `.
The name of the label must be specified without the prefix ` + generator.Prefix() + `.
e.g.
kanetary help-labels
Expand Down
16 changes: 14 additions & 2 deletions doc/docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,27 @@ and let the magic happen.

# What is it?

Katenary is a tool made to help you to transform "compose" files (`docker-compose.yml`, `podman-compose.yml`...) to
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's an opensource project, under MIT licence, partially developped at [Smile](https://www.smile.eu). The project source
It's an opensource project, under MIT licence, originally partially developped 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
share it with the community.

<div id="klee">
![](./statics/klee.svg)
</div>

The main developer is [Patrice FERLET](https://github.com/metal3d).

The project source
code is hosted on the [:fontawesome-brands-github: Katenary GitHub Repository](https://github.com/metal3d/katenary).

## Install Katenary
Expand Down
30 changes: 15 additions & 15 deletions doc/docs/labels.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,22 @@ Katenary will try to Unmarshal these labels.
## Label list and types

<!-- START_LABEL_DOC : do not remove this tag !-->
| Label name | Description | Type |
| ----------------------------- | ------------------------------------------------------ | --------------------- |
| 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 |
| `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 |

<!-- STOP_LABEL_DOC : do not remove this tag !-->

Expand Down
120 changes: 43 additions & 77 deletions doc/docs/packages/generator.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,6 @@ The generate.Convert\(\) create an HelmChart object and call "Generate\(\)" meth

If you want to change or override the write behavior, you can use the HelmChart.Generate\(\) function and implement your own write function. This function returns the helm chart object containing all kubernetes objects and helm chart ingormation. It does not write the helm chart to the disk.

## Constants

<a name="KATENARY_PREFIX"></a>

```go
const KATENARY_PREFIX = "katenary.v3/"
```

## Variables

<a name="Annotations"></a>
Expand All @@ -31,7 +23,7 @@ var (

// Standard annotationss
Annotations = map[string]string{
KATENARY_PREFIX + "version": Version,
labelName("version"): Version,
}
)
```
Expand All @@ -52,7 +44,7 @@ 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#L66>)
## func [GetLabelHelp](<https://github.com/metal3d/katenary/blob/develop/generator/katenaryLabels.go#L74>)

```go
func GetLabelHelp(asMarkdown bool) string
Expand All @@ -61,7 +53,7 @@ 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#L142>)
## func [GetLabelHelpFor](<https://github.com/metal3d/katenary/blob/develop/generator/katenaryLabels.go#L150>)

```go
func GetLabelHelpFor(labelname string, asMarkdown bool) string
Expand All @@ -70,7 +62,7 @@ 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#L198>)
## func [GetLabelNames](<https://github.com/metal3d/katenary/blob/develop/generator/katenaryLabels.go#L206>)

```go
func GetLabelNames() []string
Expand All @@ -79,7 +71,7 @@ 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#L18>)
## func [GetLabels](<https://github.com/metal3d/katenary/blob/develop/generator/labels.go#L11>)

```go
func GetLabels(serviceName, appName string) map[string]string
Expand All @@ -88,7 +80,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#L31>)
## func [GetMatchLabels](<https://github.com/metal3d/katenary/blob/develop/generator/labels.go#L24>)

```go
func GetMatchLabels(serviceName, appName string) map[string]string
Expand All @@ -114,6 +106,15 @@ 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#L41>)

```go
func Prefix() string
```



<a name="ChartTemplate"></a>
## type [ChartTemplate](<https://github.com/metal3d/katenary/blob/develop/generator/chart.go#L16-L19>)

Expand Down Expand Up @@ -274,7 +275,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#L66-L71>)
## type [CronJobValue](<https://github.com/metal3d/katenary/blob/develop/generator/values.go#L50-L55>)

CronJobValue is a cronjob configuration that will be saved in values.yaml.

Expand Down Expand Up @@ -354,7 +355,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#L440>)
### func \(\*Deployment\) [AddHealthCheck](<https://github.com/metal3d/katenary/blob/develop/generator/deployment.go#L442>)

```go
func (d *Deployment) AddHealthCheck(service types.ServiceConfig, container *corev1.Container)
Expand All @@ -381,7 +382,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#L317>)
### func \(\*Deployment\) [BindFrom](<https://github.com/metal3d/katenary/blob/develop/generator/deployment.go#L319>)

```go
func (d *Deployment) BindFrom(service types.ServiceConfig, binded *Deployment)
Expand All @@ -399,7 +400,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#L623>)
### func \(\*Deployment\) [Filename](<https://github.com/metal3d/katenary/blob/develop/generator/deployment.go#L624>)

```go
func (d *Deployment) Filename() string
Expand All @@ -408,7 +409,7 @@ 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#L345>)
### func \(\*Deployment\) [SetEnvFrom](<https://github.com/metal3d/katenary/blob/develop/generator/deployment.go#L347>)

```go
func (d *Deployment) SetEnvFrom(service types.ServiceConfig, appName string)
Expand All @@ -417,7 +418,7 @@ func (d *Deployment) SetEnvFrom(service types.ServiceConfig, appName string)
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#L473>)
### func \(\*Deployment\) [Yaml](<https://github.com/metal3d/katenary/blob/develop/generator/deployment.go#L475>)

```go
func (d *Deployment) Yaml() ([]byte, error)
Expand Down Expand Up @@ -529,7 +530,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#L178>)
### func \(\*Ingress\) [Filename](<https://github.com/metal3d/katenary/blob/develop/generator/ingress.go#L177>)

```go
func (ingress *Ingress) Filename() string
Expand All @@ -538,7 +539,7 @@ func (ingress *Ingress) Filename() string


<a name="Ingress.Yaml"></a>
### func \(\*Ingress\) [Yaml](<https://github.com/metal3d/katenary/blob/develop/generator/ingress.go#L137>)
### func \(\*Ingress\) [Yaml](<https://github.com/metal3d/katenary/blob/develop/generator/ingress.go#L136>)

```go
func (ingress *Ingress) Yaml() ([]byte, error)
Expand Down Expand Up @@ -570,42 +571,24 @@ Label is a katenary label to find in compose files.
type Label = string
```

<a name="LABEL_MAIN_APP"></a>Known labels.
<a name="LabelMainApp"></a>Known labels.

```go
const (
LABEL_MAIN_APP Label = KATENARY_PREFIX + "main-app"
LABEL_VALUES Label = KATENARY_PREFIX + "values"
LABEL_SECRETS Label = KATENARY_PREFIX + "secrets"
LABEL_PORTS Label = KATENARY_PREFIX + "ports"
LABEL_INGRESS Label = KATENARY_PREFIX + "ingress"
LABEL_MAP_ENV Label = KATENARY_PREFIX + "map-env"
LABEL_HEALTHCHECK Label = KATENARY_PREFIX + "health-check"
LABEL_SAME_POD Label = KATENARY_PREFIX + "same-pod"
LABEL_DESCRIPTION Label = KATENARY_PREFIX + "description"
LABEL_IGNORE Label = KATENARY_PREFIX + "ignore"
LABEL_DEPENDENCIES Label = KATENARY_PREFIX + "dependencies"
LABEL_CM_FILES Label = KATENARY_PREFIX + "configmap-files"
LABEL_CRONJOB Label = KATENARY_PREFIX + "cronjob"
LABEL_ENV_FROM Label = KATENARY_PREFIX + "env-from"
)
```

<a name="LabelType"></a>
## type [LabelType](<https://github.com/metal3d/katenary/blob/develop/generator/labels.go#L9>)

LabelType identifies the type of label to generate in objects. TODO: is this still needed?

```go
type LabelType uint8
```

<a name="DeploymentLabel"></a>

```go
const (
DeploymentLabel LabelType = iota
ServiceLabel
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"
)
```

Expand Down Expand Up @@ -855,26 +838,9 @@ func (r *ServiceAccount) Yaml() ([]byte, error)


<a name="Value"></a>
## type [Value](<https://github.com/metal3d/katenary/blob/develop/generator/values.go#L52-L63>)
## type [Value](<https://github.com/metal3d/katenary/blob/develop/generator/values.go#L36-L47>)

Value will be saved in values.yaml. It contains configuraiton for all deployment and services. The content will be lile:

```
name_of_component:
repository:
image: image_name
tag: image_tag
persistence:
enabled: true
storageClass: storage_class_name
ingress:
enabled: true
host: host_name
path: path_name
environment:
ENV_VAR_1: value_1
ENV_VAR_2: value_2
```
Value will be saved in values.yaml. It contains configuraiton for all deployment and services.

```go
type Value struct {
Expand All @@ -892,7 +858,7 @@ type Value struct {
```

<a name="NewValue"></a>
### func [NewValue](<https://github.com/metal3d/katenary/blob/develop/generator/values.go#L78>)
### func [NewValue](<https://github.com/metal3d/katenary/blob/develop/generator/values.go#L62>)

```go
func NewValue(service types.ServiceConfig, main ...bool) *Value
Expand All @@ -903,7 +869,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#L117>)
### func \(\*Value\) [AddIngress](<https://github.com/metal3d/katenary/blob/develop/generator/values.go#L101>)

```go
func (v *Value) AddIngress(host, path string)
Expand All @@ -912,7 +878,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#L105>)
### func \(\*Value\) [AddPersistence](<https://github.com/metal3d/katenary/blob/develop/generator/values.go#L89>)

```go
func (v *Value) AddPersistence(volumeName string)
Expand Down
6 changes: 3 additions & 3 deletions generator/configMap.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func NewConfigMap(service types.ServiceConfig, appName string) *ConfigMap {
}

// get the secrets from the labels
if v, ok := service.Labels[LABEL_SECRETS]; ok {
if v, ok := service.Labels[LabelSecrets]; ok {
err := yaml.Unmarshal([]byte(v), &secrets)
if err != nil {
log.Fatal(err)
Expand All @@ -87,7 +87,7 @@ func NewConfigMap(service types.ServiceConfig, appName string) *ConfigMap {
}
}
// get the label values from the labels
varDescriptons := utils.GetValuesFromLabel(service, LABEL_VALUES)
varDescriptons := utils.GetValuesFromLabel(service, LabelValues)
for value := range varDescriptons {
labelValues = append(labelValues, value)
}
Expand All @@ -104,7 +104,7 @@ func NewConfigMap(service types.ServiceConfig, appName string) *ConfigMap {
}

// remove the variables that are already defined in the environment
if l, ok := service.Labels[LABEL_MAP_ENV]; ok {
if l, ok := service.Labels[LabelMapEnv]; ok {
envmap := make(map[string]string)
if err := goyaml.Unmarshal([]byte(l), &envmap); err != nil {
log.Fatal("Error parsing map-env", err)
Expand Down
Loading

0 comments on commit f73d598

Please sign in to comment.