Skip to content

Commit

Permalink
Use real types to parse labels
Browse files Browse the repository at this point in the history
We were using `yaml.Unmarshal` on basic types or inline structs. This
was not efficient and not clear to defined what we expect in labels.
We now use types to unmarshal the labels.

Only the `values` label is, at this time, parsed by GetValuesFromLabel
because this `utils` function is clearly a special case.
  • Loading branch information
metal3d committed Apr 24, 2024
1 parent 0aa7023 commit d01a35e
Show file tree
Hide file tree
Showing 23 changed files with 435 additions and 138 deletions.
75 changes: 30 additions & 45 deletions doc/docs/packages/generator.md
Original file line number Diff line number Diff line change
Expand Up @@ -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#L37>)
## func [Convert](<https://github.com/metal3d/katenary/blob/develop/generator/converter.go#L38>)

```go
func Convert(config ConvertOptions, dockerComposeFile ...string)
Expand Down Expand Up @@ -116,7 +116,7 @@ func Prefix() string


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

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.

Expand Down Expand Up @@ -151,7 +151,7 @@ func NewConfigMap(service types.ServiceConfig, appName string) *ConfigMap
NewConfigMap creates a new ConfigMap from a compose service. The appName is the name of the application taken from the project name. The ConfigMap is filled by environment variables and labels "map\-env".

<a name="NewConfigMapFromDirectory"></a>
### func [NewConfigMapFromDirectory](<https://github.com/metal3d/katenary/blob/develop/generator/configMap.go#L133>)
### func [NewConfigMapFromDirectory](<https://github.com/metal3d/katenary/blob/develop/generator/configMap.go#L130>)

```go
func NewConfigMapFromDirectory(service types.ServiceConfig, appName string, path string) *ConfigMap
Expand All @@ -160,7 +160,7 @@ func NewConfigMapFromDirectory(service types.ServiceConfig, appName string, path
NewConfigMapFromDirectory creates a new ConfigMap from a compose service. This path is the path to the file or directory. If the path is a directory, all files in the directory are added to the ConfigMap. Each subdirectory are ignored. Note that the Generate\(\) function will create the subdirectories ConfigMaps.

<a name="ConfigMap.AddData"></a>
### func \(\*ConfigMap\) [AddData](<https://github.com/metal3d/katenary/blob/develop/generator/configMap.go#L169>)
### func \(\*ConfigMap\) [AddData](<https://github.com/metal3d/katenary/blob/develop/generator/configMap.go#L166>)

```go
func (c *ConfigMap) AddData(key string, value string)
Expand All @@ -169,7 +169,7 @@ func (c *ConfigMap) AddData(key string, value string)
AddData adds a key value pair to the configmap. Append or overwrite the value if the key already exists.

<a name="ConfigMap.AppendDir"></a>
### func \(\*ConfigMap\) [AppendDir](<https://github.com/metal3d/katenary/blob/develop/generator/configMap.go#L175>)
### func \(\*ConfigMap\) [AppendDir](<https://github.com/metal3d/katenary/blob/develop/generator/configMap.go#L172>)

```go
func (c *ConfigMap) AppendDir(path string)
Expand All @@ -178,7 +178,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#L211>)
### func \(\*ConfigMap\) [AppendFile](<https://github.com/metal3d/katenary/blob/develop/generator/configMap.go#L208>)

```go
func (c *ConfigMap) AppendFile(path string)
Expand All @@ -187,7 +187,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#L229>)
### func \(\*ConfigMap\) [Filename](<https://github.com/metal3d/katenary/blob/develop/generator/configMap.go#L226>)

```go
func (c *ConfigMap) Filename() string
Expand All @@ -196,7 +196,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#L164>)
### func \(\*ConfigMap\) [SetData](<https://github.com/metal3d/katenary/blob/develop/generator/configMap.go#L161>)

```go
func (c *ConfigMap) SetData(data map[string]string)
Expand All @@ -205,7 +205,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#L239>)
### func \(\*ConfigMap\) [Yaml](<https://github.com/metal3d/katenary/blob/develop/generator/configMap.go#L236>)

```go
func (c *ConfigMap) Yaml() ([]byte, error)
Expand All @@ -214,7 +214,7 @@ func (c *ConfigMap) Yaml() ([]byte, error)
Yaml returns the yaml representation of the configmap

<a name="ConfigMapMount"></a>
## type [ConfigMapMount](<https://github.com/metal3d/katenary/blob/develop/generator/deployment.go#L28-L31>)
## type [ConfigMapMount](<https://github.com/metal3d/katenary/blob/develop/generator/deployment.go#L29-L32>)



Expand All @@ -225,7 +225,7 @@ type ConfigMapMount struct {
```

<a name="ConvertOptions"></a>
## type [ConvertOptions](<https://github.com/metal3d/katenary/blob/develop/generator/chart.go#L53-L60>)
## type [ConvertOptions](<https://github.com/metal3d/katenary/blob/develop/generator/chart.go#L46-L53>)

ConvertOptions are the options to convert a compose project to a helm chart.

Expand Down Expand Up @@ -253,7 +253,7 @@ type CronJob struct {
```

<a name="CronJob.Filename"></a>
### func \(\*CronJob\) [Filename](<https://github.com/metal3d/katenary/blob/develop/generator/cronJob.go#L125>)
### func \(\*CronJob\) [Filename](<https://github.com/metal3d/katenary/blob/develop/generator/cronJob.go#L115>)

```go
func (c *CronJob) Filename() string
Expand All @@ -264,7 +264,7 @@ Filename returns the filename of the cronjob.
Implements the Yaml interface.

<a name="CronJob.Yaml"></a>
### func \(\*CronJob\) [Yaml](<https://github.com/metal3d/katenary/blob/develop/generator/cronJob.go#L132>)
### func \(\*CronJob\) [Yaml](<https://github.com/metal3d/katenary/blob/develop/generator/cronJob.go#L122>)

```go
func (c *CronJob) Yaml() ([]byte, error)
Expand Down Expand Up @@ -309,23 +309,8 @@ func NewFileMap(service types.ServiceConfig, appName string, kind string) DataMa

NewFileMap creates a new DataMap from a compose service. The appName is the name of the application taken from the project name.

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

Dependency is a dependency of a chart to other charts.

```go
type Dependency struct {
Name string `yaml:"name"`
Version string `yaml:"version"`
Repository string `yaml:"repository"`
Alias string `yaml:"alias,omitempty"`
Values map[string]any `yaml:"-"` // do not export to Chart.yaml
}
```

<a name="Deployment"></a>
## type [Deployment](<https://github.com/metal3d/katenary/blob/develop/generator/deployment.go#L34-L41>)
## type [Deployment](<https://github.com/metal3d/katenary/blob/develop/generator/deployment.go#L35-L42>)

Deployment is a kubernetes Deployment.

Expand All @@ -337,7 +322,7 @@ type Deployment struct {
```

<a name="NewDeployment"></a>
### func [NewDeployment](<https://github.com/metal3d/katenary/blob/develop/generator/deployment.go#L45>)
### func [NewDeployment](<https://github.com/metal3d/katenary/blob/develop/generator/deployment.go#L46>)

```go
func NewDeployment(service types.ServiceConfig, chart *HelmChart) *Deployment
Expand All @@ -346,7 +331,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#L135>)
### func \(\*Deployment\) [AddContainer](<https://github.com/metal3d/katenary/blob/develop/generator/deployment.go#L136>)

```go
func (d *Deployment) AddContainer(service types.ServiceConfig)
Expand All @@ -355,7 +340,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#L442>)
### func \(\*Deployment\) [AddHealthCheck](<https://github.com/metal3d/katenary/blob/develop/generator/deployment.go#L440>)

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

```go
func (d *Deployment) AddIngress(service types.ServiceConfig, appName string) *Ingress
Expand All @@ -373,7 +358,7 @@ 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.AddVolumes"></a>
### func \(\*Deployment\) [AddVolumes](<https://github.com/metal3d/katenary/blob/develop/generator/deployment.go#L187>)
### func \(\*Deployment\) [AddVolumes](<https://github.com/metal3d/katenary/blob/develop/generator/deployment.go#L188>)

```go
func (d *Deployment) AddVolumes(service types.ServiceConfig, appName string)
Expand All @@ -382,7 +367,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#L319>)
### func \(\*Deployment\) [BindFrom](<https://github.com/metal3d/katenary/blob/develop/generator/deployment.go#L320>)

```go
func (d *Deployment) BindFrom(service types.ServiceConfig, binded *Deployment)
Expand All @@ -391,7 +376,7 @@ func (d *Deployment) BindFrom(service types.ServiceConfig, binded *Deployment)


<a name="Deployment.DependsOn"></a>
### func \(\*Deployment\) [DependsOn](<https://github.com/metal3d/katenary/blob/develop/generator/deployment.go#L109>)
### func \(\*Deployment\) [DependsOn](<https://github.com/metal3d/katenary/blob/develop/generator/deployment.go#L110>)

```go
func (d *Deployment) DependsOn(to *Deployment, servicename string) error
Expand All @@ -400,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#L624>)
### func \(\*Deployment\) [Filename](<https://github.com/metal3d/katenary/blob/develop/generator/deployment.go#L618>)

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

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

```go
func (d *Deployment) Yaml() ([]byte, error)
Expand All @@ -445,7 +430,7 @@ const (
```

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

HelmChart is a Helm Chart representation. It contains all the tempaltes, values, versions, helpers...

Expand All @@ -456,7 +441,7 @@ type HelmChart struct {
Version string `yaml:"version"`
AppVersion string `yaml:"appVersion"`
Description string `yaml:"description"`
Dependencies []Dependency `yaml:"dependencies,omitempty"`
Dependencies []labelStructs.Dependency `yaml:"dependencies,omitempty"`
Templates map[string]*ChartTemplate `yaml:"-"` // do not export to yaml
Helper string `yaml:"-"` // do not export to yaml
Values map[string]any `yaml:"-"` // do not export to yaml
Expand All @@ -466,7 +451,7 @@ type HelmChart struct {
```

<a name="Generate"></a>
### func [Generate](<https://github.com/metal3d/katenary/blob/develop/generator/generator.go#L34>)
### func [Generate](<https://github.com/metal3d/katenary/blob/develop/generator/generator.go#L33>)

```go
func Generate(project *types.Project) (*HelmChart, error)
Expand All @@ -486,7 +471,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#L38>)
### func [NewChart](<https://github.com/metal3d/katenary/blob/develop/generator/chart.go#L31>)

```go
func NewChart(name string) *HelmChart
Expand Down Expand Up @@ -530,7 +515,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#L177>)
### func \(\*Ingress\) [Filename](<https://github.com/metal3d/katenary/blob/develop/generator/ingress.go#L163>)

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


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

```go
func (ingress *Ingress) Yaml() ([]byte, error)
Expand Down
Loading

0 comments on commit d01a35e

Please sign in to comment.