3 Commits

Author SHA1 Message Date
9bd1ebb59a chore(doc) Regenerate doc code
All checks were successful
Build release binaries and packages / build-packages (amd64, windows) (push) Successful in 2m0s
Build release binaries and packages / build-packages (amd64, darwin) (push) Successful in 2m30s
Build release binaries and packages / build-packages (arm64, freebsd) (push) Successful in 3m1s
Build and push OCI image / build (push) Successful in 2m15s
Build release binaries and packages / build-packages (amd64, freebsd) (push) Successful in 4m55s
Build release binaries and packages / build-packages (amd64, linux) (push) Successful in 5m2s
Build release binaries and packages / build-packages (arm64, linux) (push) Successful in 2m48s
2025-09-23 12:34:05 +02:00
614a1df5ba fix(dependson): Fixes how depends-on are managed
All checks were successful
Go-Tests / tests (push) Successful in 2m41s
Go-Tests / sonar (push) Successful in 58s
- depends-on were not renamed
- static files were not well managed
- droping depends-on deployment to fast

fixes #174 and #173
2025-09-23 12:30:43 +02:00
f0436ebce1 fix(err): When Katenary fails, help message was displayed
This is because Cobra thought the command was not correct.
2025-09-23 12:28:58 +02:00
5 changed files with 41 additions and 28 deletions

View File

@@ -146,11 +146,11 @@ func generateConvertCommand() *cobra.Command {
convertCmd := &cobra.Command{ convertCmd := &cobra.Command{
Use: "convert", Use: "convert",
Short: "Converts a docker-compose file to a Helm Chart", Short: "Converts a docker-compose file to a Helm Chart",
RunE: func(cmd *cobra.Command, args []string) error { Run: func(cmd *cobra.Command, args []string) {
if len(strings.TrimSpace(givenAppVersion)) > 0 { if len(strings.TrimSpace(givenAppVersion)) > 0 {
appVersion = &givenAppVersion appVersion = &givenAppVersion
} }
return generator.Convert(generator.ConvertOptions{ if err := generator.Convert(generator.ConvertOptions{
Force: force, Force: force,
OutputDir: outputDir, OutputDir: outputDir,
Profiles: profiles, Profiles: profiles,
@@ -159,7 +159,9 @@ func generateConvertCommand() *cobra.Command {
ChartVersion: chartVersion, ChartVersion: chartVersion,
Icon: icon, Icon: icon,
EnvFiles: envFiles, EnvFiles: envFiles,
}, dockerComposeFile...) }, dockerComposeFile...); err != nil {
os.Exit(1)
}
}, },
} }

View File

@@ -349,7 +349,7 @@ func (d *Deployment) AddIngress(service types.ServiceConfig, appName string) *In
AddIngress adds an ingress to the deployment. It creates the ingress object. AddIngress adds an ingress to the deployment. It creates the ingress object.
<a name="Deployment.AddLegacyVolume"></a> <a name="Deployment.AddLegacyVolume"></a>
### func \(\*Deployment\) [AddLegacyVolume](<https://repo.katenary.io/Katenary/katenary/blob/master/internal/generator/deployment.go#L223>) ### func \(\*Deployment\) [AddLegacyVolume](<https://repo.katenary.io/Katenary/katenary/blob/master/internal/generator/deployment.go#L216>)
```go ```go
func (d *Deployment) AddLegacyVolume(name, kind string) func (d *Deployment) AddLegacyVolume(name, kind string)
@@ -367,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. 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> <a name="Deployment.BindFrom"></a>
### func \(\*Deployment\) [BindFrom](<https://repo.katenary.io/Katenary/katenary/blob/master/internal/generator/deployment.go#L244>) ### func \(\*Deployment\) [BindFrom](<https://repo.katenary.io/Katenary/katenary/blob/master/internal/generator/deployment.go#L237>)
```go ```go
func (d *Deployment) BindFrom(service types.ServiceConfig, binded *Deployment) func (d *Deployment) BindFrom(service types.ServiceConfig, binded *Deployment)
@@ -376,7 +376,7 @@ func (d *Deployment) BindFrom(service types.ServiceConfig, binded *Deployment)
<a name="Deployment.BindMapFilesToContainer"></a> <a name="Deployment.BindMapFilesToContainer"></a>
### func \(\*Deployment\) [BindMapFilesToContainer](<https://repo.katenary.io/Katenary/katenary/blob/master/internal/generator/deployment.go#L378>) ### func \(\*Deployment\) [BindMapFilesToContainer](<https://repo.katenary.io/Katenary/katenary/blob/master/internal/generator/deployment.go#L372>)
```go ```go
func (d *Deployment) BindMapFilesToContainer(service types.ServiceConfig, secrets []string, appName string) (*corev1.Container, int) func (d *Deployment) BindMapFilesToContainer(service types.ServiceConfig, secrets []string, appName string) (*corev1.Container, int)
@@ -385,7 +385,7 @@ func (d *Deployment) BindMapFilesToContainer(service types.ServiceConfig, secret
<a name="Deployment.DependsOn"></a> <a name="Deployment.DependsOn"></a>
### func \(\*Deployment\) [DependsOn](<https://repo.katenary.io/Katenary/katenary/blob/master/internal/generator/deployment.go#L272>) ### func \(\*Deployment\) [DependsOn](<https://repo.katenary.io/Katenary/katenary/blob/master/internal/generator/deployment.go#L265>)
```go ```go
func (d *Deployment) DependsOn(to *Deployment, servicename string) error func (d *Deployment) DependsOn(to *Deployment, servicename string) error
@@ -394,7 +394,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. DependsOn adds a initContainer to the deployment that will wait for the service to be up.
<a name="Deployment.Filename"></a> <a name="Deployment.Filename"></a>
### func \(\*Deployment\) [Filename](<https://repo.katenary.io/Katenary/katenary/blob/master/internal/generator/deployment.go#L303>) ### func \(\*Deployment\) [Filename](<https://repo.katenary.io/Katenary/katenary/blob/master/internal/generator/deployment.go#L297>)
```go ```go
func (d *Deployment) Filename() string func (d *Deployment) Filename() string
@@ -403,7 +403,7 @@ func (d *Deployment) Filename() string
Filename returns the filename of the deployment. Filename returns the filename of the deployment.
<a name="Deployment.MountExchangeVolumes"></a> <a name="Deployment.MountExchangeVolumes"></a>
### func \(\*Deployment\) [MountExchangeVolumes](<https://repo.katenary.io/Katenary/katenary/blob/master/internal/generator/deployment.go#L429>) ### func \(\*Deployment\) [MountExchangeVolumes](<https://repo.katenary.io/Katenary/katenary/blob/master/internal/generator/deployment.go#L423>)
```go ```go
func (d *Deployment) MountExchangeVolumes() func (d *Deployment) MountExchangeVolumes()
@@ -412,7 +412,7 @@ func (d *Deployment) MountExchangeVolumes()
<a name="Deployment.SetEnvFrom"></a> <a name="Deployment.SetEnvFrom"></a>
### func \(\*Deployment\) [SetEnvFrom](<https://repo.katenary.io/Katenary/katenary/blob/master/internal/generator/deployment.go#L308>) ### func \(\*Deployment\) [SetEnvFrom](<https://repo.katenary.io/Katenary/katenary/blob/master/internal/generator/deployment.go#L302>)
```go ```go
func (d *Deployment) SetEnvFrom(service types.ServiceConfig, appName string, samePod ...bool) func (d *Deployment) SetEnvFrom(service types.ServiceConfig, appName string, samePod ...bool)
@@ -421,7 +421,7 @@ func (d *Deployment) SetEnvFrom(service types.ServiceConfig, appName string, sam
SetEnvFrom sets the environment variables to a configmap. The configmap is created. SetEnvFrom sets the environment variables to a configmap. The configmap is created.
<a name="Deployment.Yaml"></a> <a name="Deployment.Yaml"></a>
### func \(\*Deployment\) [Yaml](<https://repo.katenary.io/Katenary/katenary/blob/master/internal/generator/deployment.go#L453>) ### func \(\*Deployment\) [Yaml](<https://repo.katenary.io/Katenary/katenary/blob/master/internal/generator/deployment.go#L447>)
```go ```go
func (d *Deployment) Yaml() ([]byte, error) func (d *Deployment) Yaml() ([]byte, error)
@@ -471,7 +471,7 @@ type HelmChart struct {
``` ```
<a name="Generate"></a> <a name="Generate"></a>
### func [Generate](<https://repo.katenary.io/Katenary/katenary/blob/master/internal/generator/generator.go#L32>) ### func [Generate](<https://repo.katenary.io/Katenary/katenary/blob/master/internal/generator/generator.go#L33>)
```go ```go
func Generate(project *types.Project) (*HelmChart, error) func Generate(project *types.Project) (*HelmChart, error)

View File

@@ -130,7 +130,7 @@ func Convert(config ConvertOptions, dockerComposeFile ...string) error {
// parse the compose files // parse the compose files
project, err := parser.Parse(config.Profiles, config.EnvFiles, dockerComposeFile...) project, err := parser.Parse(config.Profiles, config.EnvFiles, dockerComposeFile...)
if err != nil { if err != nil {
fmt.Println(err) logger.Failure("Cannot parse compose files", err.Error())
return err return err
} }

View File

@@ -208,15 +208,8 @@ func (d *Deployment) AddVolumes(service types.ServiceConfig, appName string) {
} }
} }
isSamePod := false
if v, ok := service.Labels[labels.LabelSamePod]; !ok {
isSamePod = false
} else {
isSamePod = v != ""
}
for _, volume := range service.Volumes { for _, volume := range service.Volumes {
d.bindVolumes(volume, isSamePod, tobind, service, appName) d.bindVolumes(volume, tobind, service, appName)
} }
} }
@@ -272,6 +265,7 @@ func (d *Deployment) BindFrom(service types.ServiceConfig, binded *Deployment) {
func (d *Deployment) DependsOn(to *Deployment, servicename string) error { func (d *Deployment) DependsOn(to *Deployment, servicename string) error {
// Add a initContainer with busybox:latest using netcat to check if the service is up // Add a initContainer with busybox:latest using netcat to check if the service is up
// it will wait until the service responds to all ports // it will wait until the service responds to all ports
logger.Info("Adding dependency from ", d.service.Name, " to ", to.service.Name)
for _, container := range to.Spec.Template.Spec.Containers { for _, container := range to.Spec.Template.Spec.Containers {
commands := []string{} commands := []string{}
if len(container.Ports) == 0 { if len(container.Ports) == 0 {
@@ -670,14 +664,14 @@ 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) { func (d *Deployment) bindVolumes(volume types.ServiceVolumeConfig, tobind map[string]bool, service types.ServiceConfig, appName string) {
container, index := utils.GetContainerByName(service.ContainerName, d.Spec.Template.Spec.Containers) container, index := utils.GetContainerByName(service.ContainerName, d.Spec.Template.Spec.Containers)
defer func(d *Deployment, container *corev1.Container, index int) { defer func(d *Deployment, container *corev1.Container, index int) {
d.Spec.Template.Spec.Containers[index] = *container d.Spec.Template.Spec.Containers[index] = *container
}(d, container, index) }(d, container, index)
if _, found := tobind[volume.Source]; !isSamePod && volume.Type == "bind" && !found { if _, found := tobind[volume.Source]; volume.Type == "bind" && !found {
logger.Warn( logger.Warn(
"Bind volumes are not supported yet, " + "Bind volumes are not supported yet, " +
"excepting for those declared as " + "excepting for those declared as " +

View File

@@ -9,6 +9,7 @@ import (
"katenary.io/internal/generator/labels" "katenary.io/internal/generator/labels"
"katenary.io/internal/generator/labels/labelstructs" "katenary.io/internal/generator/labels/labelstructs"
"katenary.io/internal/logger"
"katenary.io/internal/utils" "katenary.io/internal/utils"
"github.com/compose-spec/compose-go/types" "github.com/compose-spec/compose-go/types"
@@ -99,6 +100,7 @@ func Generate(project *types.Project) (*HelmChart, error) {
// drop all "same-pod" deployments because the containers and volumes are already // drop all "same-pod" deployments because the containers and volumes are already
// in the target deployment // in the target deployment
drops := []string{}
for _, service := range podToMerge { for _, service := range podToMerge {
if samepod, ok := service.Labels[labels.LabelSamePod]; ok && samepod != "" { if samepod, ok := service.Labels[labels.LabelSamePod]; ok && samepod != "" {
// move this deployment volumes to the target deployment // move this deployment volumes to the target deployment
@@ -109,9 +111,11 @@ func Generate(project *types.Project) (*HelmChart, error) {
// copy all init containers // copy all init containers
initContainers := deployments[service.Name].Spec.Template.Spec.InitContainers initContainers := deployments[service.Name].Spec.Template.Spec.InitContainers
target.Spec.Template.Spec.InitContainers = append(target.Spec.Template.Spec.InitContainers, initContainers...) target.Spec.Template.Spec.InitContainers = append(target.Spec.Template.Spec.InitContainers, initContainers...)
delete(deployments, service.Name) drops = append(drops, service.Name)
} else { } else {
log.Printf("service %[1]s is declared as %[2]s, but %[2]s is not defined", service.Name, labels.LabelSamePod) err := fmt.Errorf("service %s is declared as %s, but %s is not defined", service.Name, labels.LabelSamePod, samepod)
logger.Failure(err.Error())
return nil, err
} }
} }
} }
@@ -122,13 +126,18 @@ func Generate(project *types.Project) (*HelmChart, error) {
if dep, ok := deployments[d]; ok { if dep, ok := deployments[d]; ok {
err := deployments[s.Name].DependsOn(dep, d) err := deployments[s.Name].DependsOn(dep, d)
if err != nil { if err != nil {
log.Printf("error creating init container for service %[1]s: %[2]s", s.Name, err) logger.Info(fmt.Sprintf("error creating init container for service %[1]s: %[2]s", s.Name, err))
} }
} else { } else {
log.Printf("service %[1]s depends on %[2]s, but %[2]s is not defined", s.Name, d) err := fmt.Errorf("service %[1]s depends on %[2]s, but %[2]s is not defined", s.Name, d)
logger.Failure(err.Error())
return nil, err
} }
} }
} }
for _, name := range drops {
delete(deployments, name)
}
// it's now time to get "value-from", before makeing the secrets and configmaps! // it's now time to get "value-from", before makeing the secrets and configmaps!
for _, s := range project.Services { for _, s := range project.Services {
chart.setEnvironmentValuesFrom(s, deployments) chart.setEnvironmentValuesFrom(s, deployments)
@@ -226,6 +235,7 @@ func fixResourceNames(project *types.Project) error {
s.Labels[labels.LabelSamePod] = fixed s.Labels[labels.LabelSamePod] = fixed
project.Services[j] = s project.Services[j] = s
} }
// also, the value-from label should be updated // also, the value-from label should be updated
if valuefrom, ok := s.Labels[labels.LabelValuesFrom]; ok { if valuefrom, ok := s.Labels[labels.LabelValuesFrom]; ok {
vf, err := labelstructs.GetValueFrom(valuefrom) vf, err := labelstructs.GetValueFrom(valuefrom)
@@ -244,8 +254,15 @@ func fixResourceNames(project *types.Project) error {
} }
} }
service.Name = fixed service.Name = fixed
project.Services[i] = service
} }
// rename depends_on
for _, d := range service.GetDependencies() {
depname := utils.AsResourceName(d)
dep := service.DependsOn[d]
delete(service.DependsOn, d)
service.DependsOn[depname] = dep
}
project.Services[i] = service
} }
return nil return nil
} }