From 0de7102b2b10a7ab42de02a8cdf6e79cece9a0c2 Mon Sep 17 00:00:00 2001 From: Patrice Ferlet Date: Fri, 5 Sep 2025 10:09:28 +0200 Subject: [PATCH 01/15] fix(build): Version prefix should be "v" In version.go, we check the "v" or "release-" prefix. Without this one, the version is built from "build info". --- .gitea/workflows/build-and-package.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitea/workflows/build-and-package.yaml b/.gitea/workflows/build-and-package.yaml index 5e4f3be..7be2dc3 100644 --- a/.gitea/workflows/build-and-package.yaml +++ b/.gitea/workflows/build-and-package.yaml @@ -67,7 +67,7 @@ jobs: echo "Building binary version $VERSION" mkdir -p dist GOARCH=${{ matrix.goarch }} GOOS=${{ matrix.goos }}\ - go build -ldflags="-X 'repo.katenary.io/katenary/katenary/internal/generator.Version=$VERSION'" \ + go build -ldflags="-X 'repo.katenary.io/katenary/katenary/internal/generator.Version=v$VERSION'" \ -trimpath -o dist/katenary-${{ matrix.goos }}-${{ matrix.goarch }} ./cmd/katenary - name: Package (Linux) From 03b4d5c7147fe84822f255819d45299a3eb5c25e Mon Sep 17 00:00:00 2001 From: Patrice Ferlet Date: Sun, 14 Sep 2025 23:23:11 +0200 Subject: [PATCH 02/15] fix(volume) File from project root failed When mounting one file from the root of the project (e.g. ./file.txt), the volume name is empty. In this case, we generate the volume name from the subpath. --- internal/generator/configMap_test.go | 19 +++++++++++++++++-- internal/generator/generator.go | 5 +++++ internal/generator/tools_test.go | 11 ++++++++++- 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/internal/generator/configMap_test.go b/internal/generator/configMap_test.go index 48e3ae0..0e83ef8 100644 --- a/internal/generator/configMap_test.go +++ b/internal/generator/configMap_test.go @@ -10,6 +10,7 @@ import ( "katenary.io/internal/generator/labels" "github.com/compose-spec/compose-go/types" + appv1 "k8s.io/api/apps/v1" v1 "k8s.io/api/core/v1" "sigs.k8s.io/yaml" ) @@ -117,9 +118,15 @@ services: io.WriteString(fooFp, fooTxt) fooFp.Close() - output := internalCompileTest(t, "-s", "templates/web/statics/configmap.yaml") + cmOutput := internalCompileTestForce(t, "-s", "templates/web/statics/configmap.yaml") + depOutput := internalCompileTestForce(t, "-s", "templates/web/deployment.yaml") + configMap := v1.ConfigMap{} - if err := yaml.Unmarshal([]byte(output), &configMap); err != nil { + if err := yaml.Unmarshal([]byte(cmOutput), &configMap); err != nil { + t.Errorf(unmarshalError, err) + } + deployment := appv1.Deployment{} + if err := yaml.Unmarshal([]byte(depOutput), &deployment); err != nil { t.Errorf(unmarshalError, err) } if configMap.Data == nil { @@ -130,4 +137,12 @@ services: if !valid.MatchString(configMap.Name) { t.Errorf("ConfigMap name %s is not valid", configMap.Name) } + + // the volume mount should be named "configmap-" + if deployment.Spec.Template.Spec.Volumes[0].Name != deployment.Spec.Template.Spec.Containers[0].VolumeMounts[0].Name { + t.Errorf("Expected volume name to be %s, got %s", + deployment.Spec.Template.Spec.Containers[0].VolumeMounts[0].Name, + deployment.Spec.Template.Spec.Volumes[0].Name, + ) + } } diff --git a/internal/generator/generator.go b/internal/generator/generator.go index 7fa5b9e..6c9f48f 100644 --- a/internal/generator/generator.go +++ b/internal/generator/generator.go @@ -278,6 +278,7 @@ func addStaticVolumes(deployments map[string]*Deployment, service types.ServiceC if y, err = config.configMap.Yaml(); err != nil { log.Fatal(err) } + // add the configmap to the chart d.chart.Templates[config.configMap.Filename()] = &ChartTemplate{ Content: y, @@ -285,6 +286,10 @@ func addStaticVolumes(deployments map[string]*Deployment, service types.ServiceC } // add the moint path to the container for _, m := range config.mountPath { + // volumeName can be empty, in this case we generate a name + if volumeName == "" { + volumeName = utils.PathToName(m.subPath) + } container.VolumeMounts = append(container.VolumeMounts, corev1.VolumeMount{ Name: utils.PathToName(volumeName), MountPath: m.mountPath, diff --git a/internal/generator/tools_test.go b/internal/generator/tools_test.go index fa22caa..aeb6730 100644 --- a/internal/generator/tools_test.go +++ b/internal/generator/tools_test.go @@ -29,13 +29,22 @@ func teardown(tmpDir string) { } } +// internalCompileTestForce is like internalCompileTest but with the force option enabled to rewrite the chart. +func internalCompileTestForce(t *testing.T, options ...string) string { + return compileTest(t, true, options...) +} + +// internalCompileTest is like compileTest but without the force option enabled to rewrite the chart. func internalCompileTest(t *testing.T, options ...string) string { + return compileTest(t, false, options...) +} + +func compileTest(t *testing.T, force bool, options ...string) string { _, err := parser.Parse(nil, nil, "compose.yml") if err != nil { t.Fatalf("Failed to parse the project: %s", err) } - force := false outputDir := "./chart" profiles := make([]string, 0) helmdepUpdate := true From 9472952d654424842f22c63430e6ede7780f61ff Mon Sep 17 00:00:00 2001 From: Patrice Ferlet Date: Sun, 14 Sep 2025 23:43:42 +0200 Subject: [PATCH 03/15] feat(tests): Verbose test coverage --- .gitea/workflows/go-test.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitea/workflows/go-test.yaml b/.gitea/workflows/go-test.yaml index a994de6..70df3a3 100644 --- a/.gitea/workflows/go-test.yaml +++ b/.gitea/workflows/go-test.yaml @@ -34,6 +34,7 @@ jobs: run: | go vet ./... go test -coverprofile=coverprofile.out -json -v ./... > gotest.json + go tool cover -func=coverprofile.out # - uses: actions/upload-artifact@v4 - name: Upload artifact uses: christopherhx/gitea-upload-artifact@v4 From debe43ce34a87f43b95ca06bf4489b4b4949604e Mon Sep 17 00:00:00 2001 From: Patrice Ferlet Date: Mon, 15 Sep 2025 13:02:54 +0200 Subject: [PATCH 04/15] chore(tests): enhance output - use a better logger separation - use tags not not overload the CI output - removed lot of log.Println/Fatal/Error --- .gitea/workflows/go-test.yaml | 3 +- internal/generator/chart.go | 38 ++++++++++--------- internal/generator/configMap.go | 3 +- internal/generator/converter.go | 28 +++++++------- internal/generator/deployment.go | 15 ++++---- internal/generator/extrafiles/readme_test.go | 1 - internal/generator/generator.go | 1 - internal/generator/katenaryfile/main.go | 7 ++-- internal/generator/katenaryfile/main_test.go | 28 +++++--------- internal/generator/volume_test.go | 3 -- internal/{utils/icons.go => logger/logger.go} | 30 +++++++++++---- internal/logger/printer.go | 12 ++++++ internal/logger/printer_ci.go | 9 +++++ internal/utils/utils.go | 5 ++- 14 files changed, 106 insertions(+), 77 deletions(-) rename internal/{utils/icons.go => logger/logger.go} (53%) create mode 100644 internal/logger/printer.go create mode 100644 internal/logger/printer_ci.go diff --git a/.gitea/workflows/go-test.yaml b/.gitea/workflows/go-test.yaml index 70df3a3..58f054d 100644 --- a/.gitea/workflows/go-test.yaml +++ b/.gitea/workflows/go-test.yaml @@ -33,7 +33,8 @@ jobs: - name: Launch Test run: | go vet ./... - go test -coverprofile=coverprofile.out -json -v ./... > gotest.json + go test -tags ci -coverprofile=coverprofile.out -v ./... + go test -tags ci -coverprofile=coverprofile.out -json -v ./... > gotest.json go tool cover -func=coverprofile.out # - uses: actions/upload-artifact@v4 - name: Upload artifact diff --git a/internal/generator/chart.go b/internal/generator/chart.go index 804c165..50dfc9a 100644 --- a/internal/generator/chart.go +++ b/internal/generator/chart.go @@ -11,6 +11,7 @@ import ( "katenary.io/internal/generator/labels" "katenary.io/internal/generator/labels/labelstructs" + "katenary.io/internal/logger" "katenary.io/internal/utils" "github.com/compose-spec/compose-go/types" @@ -77,36 +78,36 @@ func (chart *HelmChart) SaveTemplates(templateDir string) { // t = addModeline(t) kind := utils.GetKind(name) - var icon utils.Icon + var icon logger.Icon switch kind { case "deployment": - icon = utils.IconPackage + icon = logger.IconPackage case "service": - icon = utils.IconPlug + icon = logger.IconPlug case "ingress": - icon = utils.IconWorld + icon = logger.IconWorld case "volumeclaim": - icon = utils.IconCabinet + icon = logger.IconCabinet case "configmap": - icon = utils.IconConfig + icon = logger.IconConfig case "secret": - icon = utils.IconSecret + icon = logger.IconSecret default: - icon = utils.IconInfo + icon = logger.IconInfo } servicename := template.Servicename if err := os.MkdirAll(filepath.Join(templateDir, servicename), utils.DirectoryPermission); err != nil { - fmt.Println(utils.IconFailure, err) + logger.Failure(err.Error()) os.Exit(1) } - fmt.Println(icon, "Creating", kind, servicename) + logger.Log(icon, "Creating ", kind, " ", name) // if the name is a path, create the directory if strings.Contains(name, string(filepath.Separator)) { name = filepath.Join(templateDir, name) err := os.MkdirAll(filepath.Dir(name), utils.DirectoryPermission) if err != nil { - fmt.Println(utils.IconFailure, err) + logger.Failure(err.Error()) os.Exit(1) } } else { @@ -116,14 +117,14 @@ func (chart *HelmChart) SaveTemplates(templateDir string) { } f, err := os.Create(name) if err != nil { - fmt.Println(utils.IconFailure, err) + fmt.Println(logger.IconFailure, err) os.Exit(1) } defer f.Close() if _, err := f.Write(t); err != nil { - log.Fatal("error writing template file:", err) + logger.Failure("error wrting template file: ", err.Error()) + os.Exit(1) } - } } @@ -144,14 +145,15 @@ func (chart *HelmChart) generateConfigMapsAndSecrets(project *types.Project) err if v, ok := s.Labels[labels.LabelSecrets]; ok { list, err := labelstructs.SecretsFrom(v) if err != nil { - log.Fatal("error unmarshaling secrets label:", err) + logger.Failure("error unmarshaling secrets label:", err) + os.Exit(1) } for _, secret := range list { if secret == "" { continue } if _, ok := s.Environment[secret]; !ok { - fmt.Printf("%s secret %s not found in environment", utils.IconWarning, secret) + fmt.Printf("%s secret %s not found in environment", logger.IconWarning, secret) continue } secretsVar[secret] = s.Environment[secret] @@ -195,7 +197,7 @@ func (chart *HelmChart) generateDeployment(service types.ServiceConfig, deployme // isgnored service if isIgnored(service) { - fmt.Printf("%s Ignoring service %s\n", utils.IconInfo, service.Name) + logger.Info("Ignoring service ", service.Name) return nil } @@ -305,7 +307,7 @@ func (chart *HelmChart) setDependencies(service types.ServiceConfig) (bool, erro } for _, dep := range d { - fmt.Printf("%s Adding dependency to %s\n", utils.IconDependency, dep.Name) + logger.Log(logger.IconDependency, "Adding dependency to ", dep.Name) chart.Dependencies = append(chart.Dependencies, dep) name := dep.Name if dep.Alias != "" { diff --git a/internal/generator/configMap.go b/internal/generator/configMap.go index ca7438b..b8a497f 100644 --- a/internal/generator/configMap.go +++ b/internal/generator/configMap.go @@ -11,6 +11,7 @@ import ( "katenary.io/internal/generator/labels" "katenary.io/internal/generator/labels/labelstructs" + "katenary.io/internal/logger" "katenary.io/internal/utils" "github.com/compose-spec/compose-go/types" @@ -178,7 +179,7 @@ func (c *ConfigMap) AppendDir(path string) error { } for _, file := range files { if file.IsDir() { - utils.Warn("Subdirectories are ignored for the moment, skipping", filepath.Join(path, file.Name())) + logger.Warn("Subdirectories are ignored for the moment, skipping", filepath.Join(path, file.Name())) continue } path := filepath.Join(path, file.Name()) diff --git a/internal/generator/converter.go b/internal/generator/converter.go index c0243e1..6526b0f 100644 --- a/internal/generator/converter.go +++ b/internal/generator/converter.go @@ -16,6 +16,7 @@ import ( "katenary.io/internal/generator/katenaryfile" "katenary.io/internal/generator/labels" "katenary.io/internal/generator/labels/labelstructs" + "katenary.io/internal/logger" "katenary.io/internal/parser" "katenary.io/internal/utils" @@ -111,12 +112,13 @@ func Convert(config ConvertOptions, dockerComposeFile ...string) error { currentDir, _ := os.Getwd() // go to the root of the project if err := os.Chdir(filepath.Dir(dockerComposeFile[0])); err != nil { - fmt.Println(utils.IconFailure, err) + logger.Failure(err.Error()) return err } defer func() { if err := os.Chdir(currentDir); err != nil { // after the generation, go back to the original directory - log.Fatal(err) + logger.Failure(err.Error()) + os.Exit(1) } }() @@ -134,7 +136,7 @@ func Convert(config ConvertOptions, dockerComposeFile ...string) error { // check older version of labels if err := checkOldLabels(project); err != nil { - fmt.Println(utils.IconFailure, err) + logger.Failure(err.Error()) return err } @@ -147,7 +149,7 @@ func Convert(config ConvertOptions, dockerComposeFile ...string) error { if _, err := os.Stat(config.OutputDir); err == nil { overwrite := utils.Confirm( "The chart directory "+config.OutputDir+" already exists, do you want to overwrite it?", - utils.IconWarning, + logger.IconWarning, ) if !overwrite { fmt.Println("Aborting") @@ -399,7 +401,7 @@ func addMainTagAppDoc(values []byte, project *types.Project) []byte { } else if v == "false" || v == "no" || v == "0" { continue } else { - fmt.Printf("%s Adding main tag app doc %s\n", utils.IconConfig, service.Name) + logger.Log(logger.IconConfig, "Adding main tag app doc for service", service.Name) } lines = addMainAppDoc(lines, service) @@ -579,15 +581,15 @@ func buildValues(chart *HelmChart, project *types.Project, valuesPath string) { func callHelmUpdate(config ConvertOptions) { executeAndHandleError := func(fn func(ConvertOptions) error, config ConvertOptions, message string) { if err := fn(config); err != nil { - fmt.Println(utils.IconFailure, err) + logger.Failure("Helm command failed, please check the output above", err.Error()) os.Exit(1) } - fmt.Println(utils.IconSuccess, message) + logger.Success(message) } if config.HelmUpdate { executeAndHandleError(helmUpdate, config, "Helm dependencies updated") executeAndHandleError(helmLint, config, "Helm chart linted") - fmt.Println(utils.IconSuccess, "Helm chart created successfully") + logger.Success("Helm chart created successfully") } } @@ -627,7 +629,7 @@ func removeUnwantedLines(values []byte) []byte { func writeContent(path string, content []byte) { f, err := os.Create(path) if err != nil { - fmt.Println(utils.IconFailure, err) + logger.Failure("Cannot create file "+path, err.Error()) os.Exit(1) } defer f.Close() @@ -640,10 +642,10 @@ func writeContent(path string, content []byte) { // helmLint runs "helm lint" on the output directory. func helmLint(config ConvertOptions) error { - fmt.Println(utils.IconInfo, "Linting...") + logger.Info("Linting...") helm, err := exec.LookPath("helm") if err != nil { - fmt.Println(utils.IconFailure, err) + logger.Failure("Helm is not installed or not in your PATH", err.Error()) os.Exit(1) } cmd := exec.Command(helm, "lint", config.OutputDir) @@ -655,10 +657,10 @@ func helmLint(config ConvertOptions) error { // helmUpdate runs "helm dependency update" on the output directory. func helmUpdate(config ConvertOptions) error { // lookup for "helm" binary - fmt.Println(utils.IconInfo, "Updating helm dependencies...") + logger.Info("Updating helm dependencies...") helm, err := exec.LookPath("helm") if err != nil { - fmt.Println(utils.IconFailure, err) + fmt.Println(logger.IconFailure, err) os.Exit(1) } // run "helm dependency update" diff --git a/internal/generator/deployment.go b/internal/generator/deployment.go index 675bbbd..a1fc677 100644 --- a/internal/generator/deployment.go +++ b/internal/generator/deployment.go @@ -11,6 +11,7 @@ import ( "katenary.io/internal/generator/labels" "katenary.io/internal/generator/labels/labelstructs" + "katenary.io/internal/logger" "katenary.io/internal/utils" "github.com/compose-spec/compose-go/types" @@ -119,7 +120,7 @@ func (d *Deployment) AddContainer(service types.ServiceConfig) { for _, port := range service.Ports { name := utils.GetServiceNameByPort(int(port.Target)) if name == "" { - utils.Warn("Port name not found for port ", port.Target, " in service ", service.Name, ". Using port number instead") + logger.Warn("Port name not found for port ", port.Target, " in service ", service.Name, ". Using port number instead") name = fmt.Sprintf("port-%d", port.Target) } ports = append(ports, corev1.ContainerPort{ @@ -274,7 +275,7 @@ func (d *Deployment) DependsOn(to *Deployment, servicename string) error { for _, container := range to.Spec.Template.Spec.Containers { commands := []string{} if len(container.Ports) == 0 { - utils.Warn("No ports found for service ", + logger.Warn("No ports found for service ", servicename, ". You should declare a port in the service or use "+ labels.LabelPorts+ @@ -340,7 +341,7 @@ func (d *Deployment) SetEnvFrom(service types.ServiceConfig, appName string, sam _, ok := service.Environment[secret] if !ok { drop = append(drop, secret) - utils.Warn("Secret " + secret + " not found in service " + service.Name + " - skpped") + logger.Warn("Secret " + secret + " not found in service " + service.Name + " - skpped") continue } secrets = append(secrets, secret) @@ -357,7 +358,7 @@ func (d *Deployment) SetEnvFrom(service types.ServiceConfig, appName string, sam val, ok := service.Environment[value] if !ok { drop = append(drop, value) - utils.Warn("Environment variable " + value + " not found in service " + service.Name + " - skpped") + logger.Warn("Environment variable " + value + " not found in service " + service.Name + " - skpped") continue } if d.chart.Values[service.Name].(*Value).Environment == nil { @@ -413,7 +414,7 @@ func (d *Deployment) BindMapFilesToContainer(service types.ServiceConfig, secret container, index := utils.GetContainerByName(service.ContainerName, d.Spec.Template.Spec.Containers) if container == nil { - utils.Warn("Container not found for service " + service.Name) + logger.Warn("Container not found for service " + service.Name) return nil, -1 } @@ -677,7 +678,7 @@ func (d *Deployment) bindVolumes(volume types.ServiceVolumeConfig, isSamePod boo }(d, container, index) if _, found := tobind[volume.Source]; !isSamePod && volume.Type == "bind" && !found { - utils.Warn( + logger.Warn( "Bind volumes are not supported yet, " + "excepting for those declared as " + labels.LabelConfigMapFiles + @@ -688,7 +689,7 @@ func (d *Deployment) bindVolumes(volume types.ServiceVolumeConfig, isSamePod boo } if container == nil { - utils.Warn("Container not found for volume", volume.Source) + logger.Warn("Container not found for volume", volume.Source) return } diff --git a/internal/generator/extrafiles/readme_test.go b/internal/generator/extrafiles/readme_test.go index e819872..b386e59 100644 --- a/internal/generator/extrafiles/readme_test.go +++ b/internal/generator/extrafiles/readme_test.go @@ -15,7 +15,6 @@ func TestReadMeFile_Basic(t *testing.T) { } result := ReadMeFile("testchart", "A test chart", values) - t.Logf("Generated README content:\n%s", result) paramerRegExp := regexp.MustCompile(`\|\s+` + "`" + `(.*?)` + "`" + `\s+\|\s+` + "`" + `(.*?)` + "`" + `\s+\|`) matches := paramerRegExp.FindAllStringSubmatch(result, -1) if len(matches) != 3 { diff --git a/internal/generator/generator.go b/internal/generator/generator.go index 6c9f48f..7548e03 100644 --- a/internal/generator/generator.go +++ b/internal/generator/generator.go @@ -233,7 +233,6 @@ func fixResourceNames(project *types.Project) error { return err } for varname, bind := range *vf { - log.Printf("service %s, varname %s, bind %s", service.Name, varname, bind) bind := strings.ReplaceAll(bind, service.Name, fixed) (*vf)[varname] = bind } diff --git a/internal/generator/katenaryfile/main.go b/internal/generator/katenaryfile/main.go index de120c3..ed72216 100644 --- a/internal/generator/katenaryfile/main.go +++ b/internal/generator/katenaryfile/main.go @@ -3,7 +3,6 @@ package katenaryfile import ( "bytes" "encoding/json" - "fmt" "log" "os" "reflect" @@ -11,7 +10,7 @@ import ( "katenary.io/internal/generator/labels" "katenary.io/internal/generator/labels/labelstructs" - "katenary.io/internal/utils" + "katenary.io/internal/logger" "github.com/compose-spec/compose-go/types" "github.com/invopop/jsonschema" @@ -60,7 +59,7 @@ func OverrideWithConfig(project *types.Project) { // no katenary file found return } - fmt.Println(utils.IconInfo, "Using katenary file", yamlFile) + logger.Info("Using katenary file", yamlFile) services := make(map[string]Service) fp, err := os.Open(yamlFile) @@ -102,7 +101,7 @@ func OverrideWithConfig(project *types.Project) { mustGetLabelContent(s.ValuesFrom, &project.Services[i], labels.LabelValuesFrom) } } - fmt.Println(utils.IconInfo, "Katenary file loaded successfully, the services are now configured.") + logger.Info("Katenary file loaded successfully, the services are now configured.") } func getLabelContent(o any, service *types.ServiceConfig, labelName string) error { diff --git a/internal/generator/katenaryfile/main_test.go b/internal/generator/katenaryfile/main_test.go index 7df48a5..bef7da4 100644 --- a/internal/generator/katenaryfile/main_test.go +++ b/internal/generator/katenaryfile/main_test.go @@ -1,7 +1,6 @@ package katenaryfile import ( - "log" "os" "path/filepath" "testing" @@ -39,18 +38,15 @@ webapp: 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 { + os.MkdirAll(tmpDir, 0o755) + if err := os.WriteFile(composeFile, []byte(composeContent), 0o644); err != nil { t.Log(err) } - if err := os.WriteFile(katenaryFile, []byte(katenaryfileContent), 0644); err != nil { + if err := os.WriteFile(katenaryFile, []byte(katenaryfileContent), 0o644); 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, @@ -92,18 +88,15 @@ webapp: 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 { + os.MkdirAll(tmpDir, 0o755) + if err := os.WriteFile(composeFile, []byte(composeContent), 0o644); err != nil { t.Log(err) } - if err := os.WriteFile(katenaryFile, []byte(katenaryfileContent), 0644); err != nil { + if err := os.WriteFile(katenaryFile, []byte(katenaryfileContent), 0o644); 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, @@ -150,18 +143,15 @@ webapp: 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 { + os.MkdirAll(tmpDir, 0o755) + if err := os.WriteFile(composeFile, []byte(composeContent), 0o644); err != nil { t.Log(err) } - if err := os.WriteFile(katenaryFile, []byte(katenaryfileContent), 0644); err != nil { + if err := os.WriteFile(katenaryFile, []byte(katenaryfileContent), 0o644); 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, diff --git a/internal/generator/volume_test.go b/internal/generator/volume_test.go index 8357504..53c1614 100644 --- a/internal/generator/volume_test.go +++ b/internal/generator/volume_test.go @@ -5,7 +5,6 @@ import ( "image" "image/color" "image/png" - "log" "os" "path/filepath" "testing" @@ -173,7 +172,6 @@ services: ` composeFile = fmt.Sprintf(composeFile, labels.KatenaryLabelPrefix) tmpDir := setup(composeFile) - log.Println(tmpDir) defer teardown(tmpDir) os.Mkdir(filepath.Join(tmpDir, "images"), utils.DirectoryPermission) @@ -243,7 +241,6 @@ services: ` composeFile = fmt.Sprintf(composeFile, labels.KatenaryLabelPrefix) tmpDir := setup(composeFile) - log.Println(tmpDir) defer teardown(tmpDir) os.Mkdir(filepath.Join(tmpDir, "images"), utils.DirectoryPermission) diff --git a/internal/utils/icons.go b/internal/logger/logger.go similarity index 53% rename from internal/utils/icons.go rename to internal/logger/logger.go index 2a2a38d..0cc0993 100644 --- a/internal/utils/icons.go +++ b/internal/logger/logger.go @@ -1,6 +1,5 @@ -package utils - -import "fmt" +// Package logger provides simple logging functions with icons and colors. +package logger // Icon is a unicode icon type Icon string @@ -21,11 +20,28 @@ const ( IconDependency Icon = "🔗" ) +const reset = "\033[0m" + +func Info(msg ...any) { + message("", IconInfo, msg...) +} + // Warn prints a warning message func Warn(msg ...any) { orange := "\033[38;5;214m" - reset := "\033[0m" - fmt.Print(IconWarning, orange, " ") - fmt.Print(msg...) - fmt.Println(reset) + message(orange, IconWarning, msg...) +} + +func Success(msg ...any) { + green := "\033[38;5;34m" + message(green, IconSuccess, msg...) +} + +func Failure(msg ...any) { + red := "\033[38;5;196m" + message(red, IconFailure, msg...) +} + +func Log(icon Icon, msg ...any) { + message("", icon, msg...) } diff --git a/internal/logger/printer.go b/internal/logger/printer.go new file mode 100644 index 0000000..699f6d5 --- /dev/null +++ b/internal/logger/printer.go @@ -0,0 +1,12 @@ +//go:build !ci +// +build !ci + +package logger + +import "fmt" + +func message(color string, icon Icon, msg ...any) { + fmt.Print(icon, " ", color) + fmt.Print(msg...) + fmt.Println(reset) +} diff --git a/internal/logger/printer_ci.go b/internal/logger/printer_ci.go new file mode 100644 index 0000000..abeeb66 --- /dev/null +++ b/internal/logger/printer_ci.go @@ -0,0 +1,9 @@ +//go:build ci +// +build ci + +package logger + +// CI should be no-op +func message(color string, icon Icon, msg ...any) { + // no-op +} diff --git a/internal/utils/utils.go b/internal/utils/utils.go index 9f082f3..4e6030b 100644 --- a/internal/utils/utils.go +++ b/internal/utils/utils.go @@ -12,6 +12,7 @@ import ( "github.com/thediveo/netdb" "gopkg.in/yaml.v3" corev1 "k8s.io/api/core/v1" + "katenary.io/internal/logger" ) // DirectoryPermission is the default values for permissions apply to created directories. @@ -64,7 +65,7 @@ func GetKind(path string) (kind string) { } else { kind = strings.Split(path, ".")[1] } - return + return kind } // Wrap wraps a string with a string above and below. It will respect the indentation of the src string. @@ -161,7 +162,7 @@ func WordWrap(text string, lineWidth int) string { } // Confirm asks a question and returns true if the answer is y. -func Confirm(question string, icon ...Icon) bool { +func Confirm(question string, icon ...logger.Icon) bool { if len(icon) > 0 { fmt.Printf("%s %s [y/N] ", icon[0], question) } else { From e3cad1e5617c0126e09ebcf6a55174bfc66289d0 Mon Sep 17 00:00:00 2001 From: Patrice Ferlet Date: Mon, 15 Sep 2025 13:31:31 +0200 Subject: [PATCH 05/15] chore(tests): Test only when it's necessary Pushing documentation, README.md or install.sh should not launch go test --- .gitea/workflows/go-test.yaml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.gitea/workflows/go-test.yaml b/.gitea/workflows/go-test.yaml index 58f054d..fa1369c 100644 --- a/.gitea/workflows/go-test.yaml +++ b/.gitea/workflows/go-test.yaml @@ -5,10 +5,18 @@ on: types: - opened - edited + paths-ignore: + - "doc/**" + - "README.md" + - "*.sh" push: branches: - "master" - "main" + paths-ignore: + - "doc/**" + - "README.md" + - "*.sh" env: SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} From f3c1bf39fecbba979c9f064364570fc0be04f648 Mon Sep 17 00:00:00 2001 From: Patrice Ferlet Date: Mon, 15 Sep 2025 13:36:22 +0200 Subject: [PATCH 06/15] chore(doc): Document code --- doc/docs/packages/internal/generator.md | 64 +++++++------- .../internal/generator/katenaryfile.md | 8 +- doc/docs/packages/internal/logger.md | 83 +++++++++++++++++++ doc/docs/packages/internal/utils.md | 73 ++++------------ internal/logger/logger.go | 6 +- 5 files changed, 142 insertions(+), 92 deletions(-) create mode 100644 doc/docs/packages/internal/logger.md diff --git a/doc/docs/packages/internal/generator.md b/doc/docs/packages/internal/generator.md index 2633692..0fe06c1 100644 --- a/doc/docs/packages/internal/generator.md +++ b/doc/docs/packages/internal/generator.md @@ -35,7 +35,7 @@ var Version = "master" // changed at compile time ``` -## func [Convert]() +## func [Convert]() ```go func Convert(config ConvertOptions, dockerComposeFile ...string) error @@ -107,7 +107,7 @@ func UnWrapTPL(in []byte) []byte UnWrapTPL removes the line wrapping from a template. -## type [ChartTemplate]() +## type [ChartTemplate]() ChartTemplate is a template of a chart. It contains the content of the template and the name of the service. This is used internally to generate the templates. @@ -119,7 +119,7 @@ type ChartTemplate struct { ``` -## type [ConfigMap]() +## type [ConfigMap]() ConfigMap is a kubernetes ConfigMap. Implements the DataMap interface. @@ -131,7 +131,7 @@ type ConfigMap struct { ``` -### func [NewConfigMap]() +### func [NewConfigMap]() ```go func NewConfigMap(service types.ServiceConfig, appName string, forFile bool) *ConfigMap @@ -140,7 +140,7 @@ func NewConfigMap(service types.ServiceConfig, appName string, forFile bool) *Co NewConfigMap creates a new ConfigMap from a compose service. The appName is the name of the application taken from the project name. The ConfigMap is filled by environment variables and labels "map\-env". -### func [NewConfigMapFromDirectory]() +### func [NewConfigMapFromDirectory]() ```go func NewConfigMapFromDirectory(service types.ServiceConfig, appName, path string) *ConfigMap @@ -149,7 +149,7 @@ func NewConfigMapFromDirectory(service types.ServiceConfig, appName, path string 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. -### func \(\*ConfigMap\) [AddBinaryData]() +### func \(\*ConfigMap\) [AddBinaryData]() ```go func (c *ConfigMap) AddBinaryData(key string, value []byte) @@ -158,7 +158,7 @@ func (c *ConfigMap) AddBinaryData(key string, value []byte) AddBinaryData adds binary data to the configmap. Append or overwrite the value if the key already exists. -### func \(\*ConfigMap\) [AddData]() +### func \(\*ConfigMap\) [AddData]() ```go func (c *ConfigMap) AddData(key, value string) @@ -167,7 +167,7 @@ func (c *ConfigMap) AddData(key, value string) AddData adds a key value pair to the configmap. Append or overwrite the value if the key already exists. -### func \(\*ConfigMap\) [AppendDir]() +### func \(\*ConfigMap\) [AppendDir]() ```go func (c *ConfigMap) AppendDir(path string) error @@ -176,7 +176,7 @@ func (c *ConfigMap) AppendDir(path string) error AppendDir adds files from given path to the configmap. It is not recursive, to add all files in a directory, you need to call this function for each subdirectory. -### func \(\*ConfigMap\) [AppendFile]() +### func \(\*ConfigMap\) [AppendFile]() ```go func (c *ConfigMap) AppendFile(path string) error @@ -185,7 +185,7 @@ func (c *ConfigMap) AppendFile(path string) error -### func \(\*ConfigMap\) [Filename]() +### func \(\*ConfigMap\) [Filename]() ```go func (c *ConfigMap) Filename() string @@ -194,7 +194,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. -### func \(\*ConfigMap\) [SetData]() +### func \(\*ConfigMap\) [SetData]() ```go func (c *ConfigMap) SetData(data map[string]string) @@ -203,7 +203,7 @@ func (c *ConfigMap) SetData(data map[string]string) SetData sets the data of the configmap. It replaces the entire data. -### func \(\*ConfigMap\) [Yaml]() +### func \(\*ConfigMap\) [Yaml]() ```go func (c *ConfigMap) Yaml() ([]byte, error) @@ -212,7 +212,7 @@ func (c *ConfigMap) Yaml() ([]byte, error) Yaml returns the yaml representation of the configmap -## type [ConfigMapMount]() +## type [ConfigMapMount]() @@ -223,7 +223,7 @@ type ConfigMapMount struct { ``` -## type [ConvertOptions]() +## type [ConvertOptions]() ConvertOptions are the options to convert a compose project to a helm chart. @@ -301,7 +301,7 @@ type DataMap interface { ``` -## type [Deployment]() +## type [Deployment]() Deployment is a kubernetes Deployment. @@ -313,7 +313,7 @@ type Deployment struct { ``` -### func [NewDeployment]() +### func [NewDeployment]() ```go func NewDeployment(service types.ServiceConfig, chart *HelmChart) *Deployment @@ -322,7 +322,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. -### func \(\*Deployment\) [AddContainer]() +### func \(\*Deployment\) [AddContainer]() ```go func (d *Deployment) AddContainer(service types.ServiceConfig) @@ -331,7 +331,7 @@ func (d *Deployment) AddContainer(service types.ServiceConfig) AddContainer adds a container to the deployment. -### func \(\*Deployment\) [AddHealthCheck]() +### func \(\*Deployment\) [AddHealthCheck]() ```go func (d *Deployment) AddHealthCheck(service types.ServiceConfig, container *corev1.Container) @@ -340,7 +340,7 @@ func (d *Deployment) AddHealthCheck(service types.ServiceConfig, container *core -### func \(\*Deployment\) [AddIngress]() +### func \(\*Deployment\) [AddIngress]() ```go func (d *Deployment) AddIngress(service types.ServiceConfig, appName string) *Ingress @@ -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. -### func \(\*Deployment\) [AddLegacyVolume]() +### func \(\*Deployment\) [AddLegacyVolume]() ```go func (d *Deployment) AddLegacyVolume(name, kind string) @@ -358,7 +358,7 @@ func (d *Deployment) AddLegacyVolume(name, kind string) -### func \(\*Deployment\) [AddVolumes]() +### func \(\*Deployment\) [AddVolumes]() ```go func (d *Deployment) AddVolumes(service types.ServiceConfig, appName 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. -### func \(\*Deployment\) [BindFrom]() +### func \(\*Deployment\) [BindFrom]() ```go func (d *Deployment) BindFrom(service types.ServiceConfig, binded *Deployment) @@ -376,7 +376,7 @@ func (d *Deployment) BindFrom(service types.ServiceConfig, binded *Deployment) -### func \(\*Deployment\) [BindMapFilesToContainer]() +### func \(\*Deployment\) [BindMapFilesToContainer]() ```go 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 -### func \(\*Deployment\) [DependsOn]() +### func \(\*Deployment\) [DependsOn]() ```go 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. -### func \(\*Deployment\) [Filename]() +### func \(\*Deployment\) [Filename]() ```go func (d *Deployment) Filename() string @@ -403,7 +403,7 @@ func (d *Deployment) Filename() string Filename returns the filename of the deployment. -### func \(\*Deployment\) [MountExchangeVolumes]() +### func \(\*Deployment\) [MountExchangeVolumes]() ```go func (d *Deployment) MountExchangeVolumes() @@ -412,7 +412,7 @@ func (d *Deployment) MountExchangeVolumes() -### func \(\*Deployment\) [SetEnvFrom]() +### func \(\*Deployment\) [SetEnvFrom]() ```go 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. -### func \(\*Deployment\) [Yaml]() +### func \(\*Deployment\) [Yaml]() ```go func (d *Deployment) Yaml() ([]byte, error) @@ -430,7 +430,7 @@ func (d *Deployment) Yaml() ([]byte, error) Yaml returns the yaml representation of the deployment. -## type [FileMapUsage]() +## type [FileMapUsage]() FileMapUsage is the usage of the filemap. @@ -448,7 +448,7 @@ const ( ``` -## type [HelmChart]() +## type [HelmChart]() HelmChart is a Helm Chart representation. It contains all the templates, values, versions, helpers... @@ -491,7 +491,7 @@ The Generate function will create the HelmChart object this way: - Merge the same\-pod services. -### func [NewChart]() +### func [NewChart]() ```go func NewChart(name string) *HelmChart @@ -500,7 +500,7 @@ func NewChart(name string) *HelmChart NewChart creates a new empty chart with the given name. -### func \(\*HelmChart\) [SaveTemplates]() +### func \(\*HelmChart\) [SaveTemplates]() ```go func (chart *HelmChart) SaveTemplates(templateDir string) diff --git a/doc/docs/packages/internal/generator/katenaryfile.md b/doc/docs/packages/internal/generator/katenaryfile.md index f6fb81c..214133a 100644 --- a/doc/docs/packages/internal/generator/katenaryfile.md +++ b/doc/docs/packages/internal/generator/katenaryfile.md @@ -12,7 +12,7 @@ A katenary file, named "katenary.yml" or "katenary.yaml", is a file where you ca 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]() +## func [GenerateSchema]() ```go func GenerateSchema() string @@ -21,7 +21,7 @@ func GenerateSchema() string GenerateSchema generates the schema for the katenary.yaml file. -## func [OverrideWithConfig]() +## func [OverrideWithConfig]() ```go func OverrideWithConfig(project *types.Project) @@ -30,7 +30,7 @@ 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. -## type [Service]() +## type [Service]() Service is a struct that contains the service configuration for katenary @@ -56,7 +56,7 @@ type Service struct { ``` -## type [StringOrMap]() +## type [StringOrMap]() 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 diff --git a/doc/docs/packages/internal/logger.md b/doc/docs/packages/internal/logger.md new file mode 100644 index 0000000..c1151ab --- /dev/null +++ b/doc/docs/packages/internal/logger.md @@ -0,0 +1,83 @@ + + +# logger + +```go +import "katenary.io/internal/logger" +``` + +Package logger provides simple logging functions with icons and colors. + +## func [Failure]() + +```go +func Failure(msg ...any) +``` + +Failure prints a failure message. + + +## func [Info]() + +```go +func Info(msg ...any) +``` + +Info prints an informational message. + + +## func [Log]() + +```go +func Log(icon Icon, msg ...any) +``` + +Log prints a message with a custom icon. + + +## func [Success]() + +```go +func Success(msg ...any) +``` + +Success prints a success message. + + +## func [Warn]() + +```go +func Warn(msg ...any) +``` + +Warn prints a warning message. + + +## type [Icon]() + +Icon is a unicode icon + +```go +type Icon string +``` + +Icons used in katenary. + +```go +const ( + IconSuccess Icon = "✅" + IconFailure Icon = "❌" + IconWarning Icon = "❕" + IconNote Icon = "📝" + IconWorld Icon = "🌐" + IconPlug Icon = "🔌" + IconPackage Icon = "📦" + IconCabinet Icon = "🗄️" + IconInfo Icon = "🔵" + IconSecret Icon = "🔒" + IconConfig Icon = "🔧" + IconDependency Icon = "🔗" +) +``` + +Generated by [gomarkdoc]() diff --git a/doc/docs/packages/internal/utils.md b/doc/docs/packages/internal/utils.md index c24a866..a2f27bd 100644 --- a/doc/docs/packages/internal/utils.md +++ b/doc/docs/packages/internal/utils.md @@ -17,7 +17,7 @@ const DirectoryPermission = 0o755 ``` -## func [AsResourceName]() +## func [AsResourceName]() ```go func AsResourceName(name string) string @@ -26,16 +26,16 @@ func AsResourceName(name string) string AsResourceName returns a resource name with underscores to respect the kubernetes naming convention. It's the opposite of FixedResourceName. -## func [Confirm]() +## func [Confirm]() ```go -func Confirm(question string, icon ...Icon) bool +func Confirm(question string, icon ...logger.Icon) bool ``` Confirm asks a question and returns true if the answer is y. -## func [CountStartingSpaces]() +## func [CountStartingSpaces]() ```go func CountStartingSpaces(line string) int @@ -44,7 +44,7 @@ func CountStartingSpaces(line string) int CountStartingSpaces counts the number of spaces at the beginning of a string. -## func [EncodeBasicYaml]() +## func [EncodeBasicYaml]() ```go func EncodeBasicYaml(data any) ([]byte, error) @@ -53,7 +53,7 @@ func EncodeBasicYaml(data any) ([]byte, error) EncodeBasicYaml encodes a basic yaml from an interface. -## func [FixedResourceName]() +## func [FixedResourceName]() ```go func FixedResourceName(name string) string @@ -62,7 +62,7 @@ func FixedResourceName(name string) string FixedResourceName returns a resource name without underscores to respect the kubernetes naming convention. -## func [GetContainerByName]() +## func [GetContainerByName]() ```go func GetContainerByName(name string, containers []corev1.Container) (*corev1.Container, int) @@ -71,7 +71,7 @@ func GetContainerByName(name string, containers []corev1.Container) (*corev1.Con GetContainerByName returns a container by name and its index in the array. It returns nil, \-1 if not found. -## func [GetKind]() +## func [GetKind]() ```go func GetKind(path string) (kind string) @@ -80,7 +80,7 @@ func GetKind(path string) (kind string) GetKind returns the kind of the resource from the file path. -## func [GetServiceNameByPort]() +## func [GetServiceNameByPort]() ```go func GetServiceNameByPort(port int) string @@ -89,7 +89,7 @@ func GetServiceNameByPort(port int) string GetServiceNameByPort returns the service name for a port. It the service name is not found, it returns an empty string. -## func [GetValuesFromLabel]() +## func [GetValuesFromLabel]() ```go func GetValuesFromLabel(service types.ServiceConfig, LabelValues string) map[string]*EnvConfig @@ -107,7 +107,7 @@ func HashComposefiles(files []string) (string, error) HashComposefiles returns a hash of the compose files. -## func [Int32Ptr]() +## func [Int32Ptr]() ```go func Int32Ptr(i int32) *int32 @@ -116,7 +116,7 @@ func Int32Ptr(i int32) *int32 Int32Ptr returns a pointer to an int32. -## func [PathToName]() +## func [PathToName]() ```go func PathToName(path string) string @@ -125,7 +125,7 @@ func PathToName(path string) string PathToName converts a path to a kubernetes complient name. -## func [StrPtr]() +## func [StrPtr]() ```go func StrPtr(s string) *string @@ -134,7 +134,7 @@ func StrPtr(s string) *string StrPtr returns a pointer to a string. -## func [TplName]() +## func [TplName]() ```go func TplName(serviceName, appname string, suffix ...string) string @@ -143,7 +143,7 @@ func TplName(serviceName, appname string, suffix ...string) string TplName returns the name of the kubernetes resource as a template string. It is used in the templates and defined in \_helper.tpl file. -## func [TplValue]() +## func [TplValue]() ```go func TplValue(serviceName, variable string, pipes ...string) string @@ -151,17 +151,8 @@ func TplValue(serviceName, variable string, pipes ...string) string TplValue returns a string that can be used in a template to access a value from the values file. - -## func [Warn]() - -```go -func Warn(msg ...any) -``` - -Warn prints a warning message - -## func [WordWrap]() +## func [WordWrap]() ```go func WordWrap(text string, lineWidth int) string @@ -170,7 +161,7 @@ func WordWrap(text string, lineWidth int) string WordWrap wraps a string to a given line width. Warning: it may break the string. You need to check the result. -## func [Wrap]() +## func [Wrap]() ```go func Wrap(src, above, below string) string @@ -179,7 +170,7 @@ func Wrap(src, above, below string) string Wrap wraps a string with a string above and below. It will respect the indentation of the src string. -## type [EnvConfig]() +## type [EnvConfig]() EnvConfig is a struct to hold the description of an environment variable. @@ -190,32 +181,4 @@ type EnvConfig struct { } ``` - -## type [Icon]() - -Icon is a unicode icon - -```go -type Icon string -``` - -Icons used in katenary. - -```go -const ( - IconSuccess Icon = "✅" - IconFailure Icon = "❌" - IconWarning Icon = "❕" - IconNote Icon = "📝" - IconWorld Icon = "🌐" - IconPlug Icon = "🔌" - IconPackage Icon = "📦" - IconCabinet Icon = "🗄️" - IconInfo Icon = "🔵" - IconSecret Icon = "🔒" - IconConfig Icon = "🔧" - IconDependency Icon = "🔗" -) -``` - Generated by [gomarkdoc]() diff --git a/internal/logger/logger.go b/internal/logger/logger.go index 0cc0993..45c9f91 100644 --- a/internal/logger/logger.go +++ b/internal/logger/logger.go @@ -22,26 +22,30 @@ const ( const reset = "\033[0m" +// Info prints an informational message. func Info(msg ...any) { message("", IconInfo, msg...) } -// Warn prints a warning message +// Warn prints a warning message. func Warn(msg ...any) { orange := "\033[38;5;214m" message(orange, IconWarning, msg...) } +// Success prints a success message. func Success(msg ...any) { green := "\033[38;5;34m" message(green, IconSuccess, msg...) } +// Failure prints a failure message. func Failure(msg ...any) { red := "\033[38;5;196m" message(red, IconFailure, msg...) } +// Log prints a message with a custom icon. func Log(icon Icon, msg ...any) { message("", icon, msg...) } From a4647aa69a4e9685119cd8e22f3a3420c6efc1d3 Mon Sep 17 00:00:00 2001 From: Patrice Ferlet Date: Tue, 16 Sep 2025 08:58:51 +0200 Subject: [PATCH 07/15] chore(code): Unecessary type checking Changed how to use the type checking for label content. --- internal/utils/utils.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/internal/utils/utils.go b/internal/utils/utils.go index 4e6030b..4231075 100644 --- a/internal/utils/utils.go +++ b/internal/utils/utils.go @@ -136,16 +136,17 @@ func GetValuesFromLabel(service types.ServiceConfig, LabelValues string) map[str log.Printf("Error parsing label %s: %s", v, err) log.Fatal(err) } + for _, value := range labelContent { - switch val := value.(type) { + switch value := value.(type) { case string: - descriptions[val] = nil + descriptions[value] = nil case map[string]any: - for k, v := range value.(map[string]any) { + for k, v := range value { descriptions[k] = &EnvConfig{Service: service, Description: v.(string)} } case map[any]any: - for k, v := range value.(map[any]any) { + for k, v := range value { descriptions[k.(string)] = &EnvConfig{Service: service, Description: v.(string)} } default: From 8c443ba4020959584f3fcaf20d8ef0a2f2acc7c4 Mon Sep 17 00:00:00 2001 From: Patrice Ferlet Date: Tue, 16 Sep 2025 08:59:27 +0200 Subject: [PATCH 08/15] chore(doc): regenerate the doc --- doc/docs/faq.md | 4 +++- doc/docs/packages/internal/utils.md | 10 +++++----- doc/share/man/man1/katenary.1 | 31 +++++++++++++++++++---------- 3 files changed, 29 insertions(+), 16 deletions(-) diff --git a/doc/docs/faq.md b/doc/docs/faq.md index a1c68c6..c1c5758 100644 --- a/doc/docs/faq.md +++ b/doc/docs/faq.md @@ -78,7 +78,7 @@ tested some concepts. 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/Katenary/katenary). + if you have some issues, if you have some ideas, please open an issue on [our repository](https://repo.katenary.io/Katenary/katenary). - 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. @@ -88,6 +88,8 @@ You can help us in many ways. 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. +Please, contact us by email at [contact at katenary dot io](mailto:contact@katenary.io). + ### If you're an individual All main contributors[^3] will be listed on the website and in the documentation. diff --git a/doc/docs/packages/internal/utils.md b/doc/docs/packages/internal/utils.md index a2f27bd..88fb19d 100644 --- a/doc/docs/packages/internal/utils.md +++ b/doc/docs/packages/internal/utils.md @@ -17,7 +17,7 @@ const DirectoryPermission = 0o755 ``` -## func [AsResourceName]() +## func [AsResourceName]() ```go func AsResourceName(name string) string @@ -26,7 +26,7 @@ func AsResourceName(name string) string AsResourceName returns a resource name with underscores to respect the kubernetes naming convention. It's the opposite of FixedResourceName. -## func [Confirm]() +## func [Confirm]() ```go func Confirm(question string, icon ...logger.Icon) bool @@ -44,7 +44,7 @@ func CountStartingSpaces(line string) int CountStartingSpaces counts the number of spaces at the beginning of a string. -## func [EncodeBasicYaml]() +## func [EncodeBasicYaml]() ```go func EncodeBasicYaml(data any) ([]byte, error) @@ -53,7 +53,7 @@ func EncodeBasicYaml(data any) ([]byte, error) EncodeBasicYaml encodes a basic yaml from an interface. -## func [FixedResourceName]() +## func [FixedResourceName]() ```go func FixedResourceName(name string) string @@ -152,7 +152,7 @@ func TplValue(serviceName, variable string, pipes ...string) string TplValue returns a string that can be used in a template to access a value from the values file. -## func [WordWrap]() +## func [WordWrap]() ```go func WordWrap(text string, lineWidth int) string diff --git a/doc/share/man/man1/katenary.1 b/doc/share/man/man1/katenary.1 index 5f87b77..922b672 100644 --- a/doc/share/man/man1/katenary.1 +++ b/doc/share/man/man1/katenary.1 @@ -1,7 +1,7 @@ '\" t .\" Automatically generated by Pandoc 3.1.11.1 .\" -.TH "Katenary" "1" "2025-08-29" "mkdocs-manpage v2.0.1" "Katenary helm chart generator" +.TH "Katenary" "1" "2025-09-15" "mkdocs-manpage v2.0.1" "Katenary helm chart generator" .SH Basic Usage Basically, you can use \f[CR]katenary\f[R] to transpose a docker\-compose file (or any compose file compatible with \f[CR]podman\-compose\f[R] and \f[CR]docker\-compose\f[R]) to a configurable Helm Chart. This resulting helm chart can be installed with \f[CR]helm\f[R] command to your Kubernetes cluster. @@ -414,11 +414,11 @@ The file or directory is relative to the service directory. .PP If it is a directory, all files inside it are added to the ConfigMap. .PP -If the directory as subdirectories, so one configmap per subpath are created. +If the directory as subdirectories, so one ConfigMap per sub\-path are created. .PP Warning .PP -It is not intended to be used to store an entire project in configmaps. +It is not intended to be used to store an entire project in ConfigMaps. It is intended to be used to store configuration files that are not managed by the application, like nginx configuration files. Keep in mind that your project sources should be stored in an application image or in a storage. .PP @@ -438,8 +438,13 @@ Create a cronjob from the service. .PP This adds a cronjob to the chart. .PP -The label value is a YAML object with the following attributes: \- command: the command to be executed \- schedule: the cron schedule (cron format or \[at]every where \[dq]every\[dq] is a duration like 1h30m, daily, hourly...) -\- rbac: false (optionnal), if true, it will create a role, a rolebinding and a serviceaccount to make your cronjob able to connect the Kubernetes API +The label value is a YAML object with the following attributes: +.IP \[bu] 2 +command: the command to be executed +.IP \[bu] 2 +schedule: the cron schedule (cron format or \[at]every where \[dq]every\[dq] is a duration like 1h30m, daily, hourly...) +.IP \[bu] 2 +rbac: false (optionnal), if true, it will create a role, a rolebinding and a serviceaccount to make your cronjob able to connect the Kubernetes API .PP \f[B]Example:\f[R] .IP @@ -532,7 +537,7 @@ service1: service2: image: php:7.4\-fpm labels: - # get the congigMap from service1 where FOO is + # get the congigMap from service1 where FOO is # defined inside this service too katenary.v3/env\-from: |\- \- myservice1 @@ -555,7 +560,13 @@ a \f[CR]voumeMount\f[R] in the pod for \f[B]each container\f[R] .IP \[bu] 2 a \f[CR]initContainer\f[R] for each definition .PP -Fields: \- name: the name of the volume (manadatory) \- mountPath: the path where the volume is mounted in the pod (optional, default is \f[CR]/opt\f[R]) \- init: a command to run to initialize the volume with data (optional) +Fields: +.IP \[bu] 2 +name: the name of the volume (manadatory) +.IP \[bu] 2 +mountPath: the path where the volume is mounted in the pod (optional, default is \f[CR]/opt\f[R]) +.IP \[bu] 2 +init: a command to run to initialize the volume with data (optional) .PP Warning .PP @@ -645,7 +656,7 @@ ghost: image: ghost:1.25.5 labels: # The chart is now named ghost, and the appVersion is 1.25.5. - # In Deployment, the image attribute is set to ghost:1.25.5 if + # In Deployment, the image attribute is set to ghost:1.25.5 if # you don\[aq]t change the \[dq]tag\[dq] attribute in values.yaml katenary.v3/main\-app: true .EE @@ -734,7 +745,7 @@ Environment variables to be added to the values.yaml .PP \f[B]Type\f[R]: \f[CR][]string or map[string]string\f[R] .PP -By default, all environment variables in the \[dq]env\[dq] and environment files are added to configmaps with the static values set. +By default, all environment variables in the \[dq]env\[dq] and environment files are added to ConfigMaps with the static values set. This label allows adding environment variables to the values.yaml file. .PP Note that the value inside the configmap is \f[CR]{{ tpl vaname . }}\f[R], so you can set the value to a template that will be rendered with the values.yaml file. @@ -756,7 +767,7 @@ labels: \- TO_CONFIGURE # complex values, set as a template in values.yaml with a documentation \- A_COMPLEX_VALUE: |\- - This is the documentation for the variable to + This is the documentation for the variable to configure in values.yaml. It can be, of course, a multiline text. .EE From a17d35df0392c3459d61be978f8256fd4c48c02d Mon Sep 17 00:00:00 2001 From: Patrice Ferlet Date: Tue, 16 Sep 2025 13:49:11 +0200 Subject: [PATCH 09/15] chore(oci): Enhance OCI build There were too many `${IMAGE_NAME,,}` to always do a lower case operation. I now export the variable in the first step. --- .gitea/workflows/build-oci.yaml | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/.gitea/workflows/build-oci.yaml b/.gitea/workflows/build-oci.yaml index a003b54..504ca29 100644 --- a/.gitea/workflows/build-oci.yaml +++ b/.gitea/workflows/build-oci.yaml @@ -20,10 +20,19 @@ jobs: steps: - name: Extract version run: | + # remove "releases/" VERSION="${VERSION#releases/}" + # set image name to lower case + IMAGE_NAME="${IMAGE_NAME,,}" + echo "Exporting variable VERSION=$VERSION" + echo "Exporting variable IMAGE_NAME=$IMAGE_NAME" + echo "VERSION=$VERSION" >> $GITEA_OUTPUT + echo "IMAGE_NAME=$IMAGE_NAME" >> $GITEA_OUTPUT + echo "VERSION=$VERSION" >> $GITEA_ENV + echo "IMAGE_NAME=$IMAGE_NAME" >> $GITEA_ENV - name: Install Buildah run: |- @@ -44,12 +53,12 @@ jobs: - name: Build and tag run: |- - echo "Building image $REGISTRY/${IMAGE_NAME,,}:$VERSION / latest" - buildah build --isolation=chroot --build-arg VERSION=$VERSION -t katenary -f ./oci/katenary/Containerfile . - buildah tag katenary $REGISTRY/${IMAGE_NAME,,}:$VERSION - buildah tag katenary $REGISTRY/${IMAGE_NAME,,}:latest + echo "Building image ${REGISTRY}/${IMAGE_NAME}:${VERSION} / latest" + buildah build --isolation=chroot --build-arg VERSION=${VERSION} -t katenary -f ./oci/katenary/Containerfile . + buildah tag katenary ${REGISTRY}/${IMAGE_NAME}:${VERSION} + buildah tag katenary ${REGISTRY}/${IMAGE_NAME}:latest - name: Push image run: |- - buildah push $REGISTRY/${IMAGE_NAME,,}:$VERSION - buildah push $REGISTRY/${IMAGE_NAME,,}:latest + buildah push ${REGISTRY}/${IMAGE_NAME}:${VERSION} + buildah push ${REGISTRY}/${IMAGE_NAME}:latest From bd24e833cb3a97d79694b6e0cbb618556c2980d4 Mon Sep 17 00:00:00 2001 From: Patrice Ferlet Date: Tue, 16 Sep 2025 13:49:38 +0200 Subject: [PATCH 10/15] chore(oci): rename the step --- .gitea/workflows/build-oci.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitea/workflows/build-oci.yaml b/.gitea/workflows/build-oci.yaml index 504ca29..d54d72f 100644 --- a/.gitea/workflows/build-oci.yaml +++ b/.gitea/workflows/build-oci.yaml @@ -18,7 +18,7 @@ jobs: contents: read packages: write steps: - - name: Extract version + - name: Extract version and image name run: | # remove "releases/" VERSION="${VERSION#releases/}" From b8333eacf2ce98f83c21b9958d5c2f3171e4233c Mon Sep 17 00:00:00 2001 From: Patrice Ferlet Date: Mon, 22 Sep 2025 13:52:10 +0200 Subject: [PATCH 11/15] chore(go): At this time, stay with 1.24 for development Even if it works on CI, Go 1.24 is actually easier to manage in different Linux distributions. Maybe we will change the requiments: - if I decide that Fedora 43 (next release) is the "official distribution to use for development) - if I decide to ask developpers to use Homebrew to install Go - others reasons As I decided, at this time, to use RPM version of golang, the 1.24 version is probably the best choice for the moment. --- go.mod | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 74bf7b1..70472cf 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,8 @@ module katenary.io -go 1.25 +go 1.24.0 + +toolchain go1.24.7 require ( github.com/compose-spec/compose-go v1.20.2 From f0436ebce1892e828cc7795d401ea187560822e6 Mon Sep 17 00:00:00 2001 From: Patrice Ferlet Date: Tue, 23 Sep 2025 12:28:58 +0200 Subject: [PATCH 12/15] fix(err): When Katenary fails, help message was displayed This is because Cobra thought the command was not correct. --- cmd/katenary/main.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/cmd/katenary/main.go b/cmd/katenary/main.go index 79d6861..9b04921 100644 --- a/cmd/katenary/main.go +++ b/cmd/katenary/main.go @@ -146,11 +146,11 @@ func generateConvertCommand() *cobra.Command { convertCmd := &cobra.Command{ Use: "convert", 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 { appVersion = &givenAppVersion } - return generator.Convert(generator.ConvertOptions{ + if err := generator.Convert(generator.ConvertOptions{ Force: force, OutputDir: outputDir, Profiles: profiles, @@ -159,7 +159,9 @@ func generateConvertCommand() *cobra.Command { ChartVersion: chartVersion, Icon: icon, EnvFiles: envFiles, - }, dockerComposeFile...) + }, dockerComposeFile...); err != nil { + os.Exit(1) + } }, } From 614a1df5ba543cc930154bf8ff38c310713605e1 Mon Sep 17 00:00:00 2001 From: Patrice Ferlet Date: Tue, 23 Sep 2025 12:30:43 +0200 Subject: [PATCH 13/15] fix(dependson): Fixes how depends-on are managed - depends-on were not renamed - static files were not well managed - droping depends-on deployment to fast fixes #174 and #173 --- internal/generator/converter.go | 2 +- internal/generator/deployment.go | 14 ++++---------- internal/generator/generator.go | 27 ++++++++++++++++++++++----- 3 files changed, 27 insertions(+), 16 deletions(-) diff --git a/internal/generator/converter.go b/internal/generator/converter.go index 6526b0f..1bc9d3f 100644 --- a/internal/generator/converter.go +++ b/internal/generator/converter.go @@ -130,7 +130,7 @@ func Convert(config ConvertOptions, dockerComposeFile ...string) error { // parse the compose files project, err := parser.Parse(config.Profiles, config.EnvFiles, dockerComposeFile...) if err != nil { - fmt.Println(err) + logger.Failure("Cannot parse compose files", err.Error()) return err } diff --git a/internal/generator/deployment.go b/internal/generator/deployment.go index a1fc677..3d079bd 100644 --- a/internal/generator/deployment.go +++ b/internal/generator/deployment.go @@ -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 { - 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 { // 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 + logger.Info("Adding dependency from ", d.service.Name, " to ", to.service.Name) for _, container := range to.Spec.Template.Spec.Containers { commands := []string{} 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) defer func(d *Deployment, container *corev1.Container, index int) { d.Spec.Template.Spec.Containers[index] = *container }(d, container, index) - if _, found := tobind[volume.Source]; !isSamePod && volume.Type == "bind" && !found { + if _, found := tobind[volume.Source]; volume.Type == "bind" && !found { logger.Warn( "Bind volumes are not supported yet, " + "excepting for those declared as " + diff --git a/internal/generator/generator.go b/internal/generator/generator.go index 7548e03..80c1c48 100644 --- a/internal/generator/generator.go +++ b/internal/generator/generator.go @@ -9,6 +9,7 @@ import ( "katenary.io/internal/generator/labels" "katenary.io/internal/generator/labels/labelstructs" + "katenary.io/internal/logger" "katenary.io/internal/utils" "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 // in the target deployment + drops := []string{} for _, service := range podToMerge { if samepod, ok := service.Labels[labels.LabelSamePod]; ok && samepod != "" { // move this deployment volumes to the target deployment @@ -109,9 +111,11 @@ func Generate(project *types.Project) (*HelmChart, error) { // 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) + drops = append(drops, service.Name) } 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 { err := deployments[s.Name].DependsOn(dep, d) 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 { - 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! for _, s := range project.Services { chart.setEnvironmentValuesFrom(s, deployments) @@ -226,6 +235,7 @@ func fixResourceNames(project *types.Project) error { s.Labels[labels.LabelSamePod] = fixed project.Services[j] = s } + // also, the value-from label should be updated if valuefrom, ok := s.Labels[labels.LabelValuesFrom]; ok { vf, err := labelstructs.GetValueFrom(valuefrom) @@ -244,8 +254,15 @@ func fixResourceNames(project *types.Project) error { } } 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 } From 9bd1ebb59af3cdc4916674763747a85820dffabe Mon Sep 17 00:00:00 2001 From: Patrice Ferlet Date: Tue, 23 Sep 2025 12:34:05 +0200 Subject: [PATCH 14/15] chore(doc) Regenerate doc code --- doc/docs/packages/internal/generator.md | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/doc/docs/packages/internal/generator.md b/doc/docs/packages/internal/generator.md index 0fe06c1..f22befb 100644 --- a/doc/docs/packages/internal/generator.md +++ b/doc/docs/packages/internal/generator.md @@ -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. -### func \(\*Deployment\) [AddLegacyVolume]() +### func \(\*Deployment\) [AddLegacyVolume]() ```go 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. -### func \(\*Deployment\) [BindFrom]() +### func \(\*Deployment\) [BindFrom]() ```go func (d *Deployment) BindFrom(service types.ServiceConfig, binded *Deployment) @@ -376,7 +376,7 @@ func (d *Deployment) BindFrom(service types.ServiceConfig, binded *Deployment) -### func \(\*Deployment\) [BindMapFilesToContainer]() +### func \(\*Deployment\) [BindMapFilesToContainer]() ```go 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 -### func \(\*Deployment\) [DependsOn]() +### func \(\*Deployment\) [DependsOn]() ```go 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. -### func \(\*Deployment\) [Filename]() +### func \(\*Deployment\) [Filename]() ```go func (d *Deployment) Filename() string @@ -403,7 +403,7 @@ func (d *Deployment) Filename() string Filename returns the filename of the deployment. -### func \(\*Deployment\) [MountExchangeVolumes]() +### func \(\*Deployment\) [MountExchangeVolumes]() ```go func (d *Deployment) MountExchangeVolumes() @@ -412,7 +412,7 @@ func (d *Deployment) MountExchangeVolumes() -### func \(\*Deployment\) [SetEnvFrom]() +### func \(\*Deployment\) [SetEnvFrom]() ```go 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. -### func \(\*Deployment\) [Yaml]() +### func \(\*Deployment\) [Yaml]() ```go func (d *Deployment) Yaml() ([]byte, error) @@ -471,7 +471,7 @@ type HelmChart struct { ``` -### func [Generate]() +### func [Generate]() ```go func Generate(project *types.Project) (*HelmChart, error) From 569ca195dfcc201f29de802be8e46789c8d6a5c2 Mon Sep 17 00:00:00 2001 From: Patrice Ferlet Date: Sat, 18 Oct 2025 14:43:16 +0200 Subject: [PATCH 15/15] chore(packages) Use compose-go v2 This prepares the next release. We need to support the compose v2 syntax as soon as possible to avoid accumulating technical debt. --- cmd/katenary/main.go | 2 +- go.mod | 40 ++++----- go.sum | 91 +++++++++----------- internal/generator/chart.go | 2 +- internal/generator/configMap.go | 2 +- internal/generator/configMap_test.go | 2 +- internal/generator/converter.go | 2 +- internal/generator/cronJob.go | 2 +- internal/generator/deployment.go | 2 +- internal/generator/generator.go | 6 +- internal/generator/ingress.go | 2 +- internal/generator/katenaryfile/main.go | 51 ++++++----- internal/generator/katenaryfile/main_test.go | 15 ++-- internal/generator/rbac.go | 2 +- internal/generator/secret.go | 2 +- internal/generator/service.go | 2 +- internal/generator/utils.go | 2 +- internal/generator/utils_test.go | 23 +++-- internal/generator/values.go | 2 +- internal/generator/volume.go | 2 +- internal/parser/main.go | 8 +- internal/utils/utils.go | 2 +- 22 files changed, 133 insertions(+), 131 deletions(-) diff --git a/cmd/katenary/main.go b/cmd/katenary/main.go index 9b04921..1051f35 100644 --- a/cmd/katenary/main.go +++ b/cmd/katenary/main.go @@ -15,7 +15,7 @@ import ( "katenary.io/internal/generator/labels" "katenary.io/internal/utils" - "github.com/compose-spec/compose-go/cli" + "github.com/compose-spec/compose-go/v2/cli" "github.com/spf13/cobra" ) diff --git a/go.mod b/go.mod index 70472cf..ef72875 100644 --- a/go.mod +++ b/go.mod @@ -5,14 +5,14 @@ go 1.24.0 toolchain go1.24.7 require ( - github.com/compose-spec/compose-go v1.20.2 + github.com/compose-spec/compose-go/v2 v2.9.0 github.com/invopop/jsonschema v0.13.0 github.com/mitchellh/go-wordwrap v1.0.1 - github.com/spf13/cobra v1.9.1 + github.com/spf13/cobra v1.10.1 github.com/thediveo/netdb v1.1.2 gopkg.in/yaml.v3 v3.0.1 - k8s.io/api v0.33.4 - k8s.io/apimachinery v0.33.4 + k8s.io/api v0.34.1 + k8s.io/apimachinery v0.34.1 sigs.k8s.io/yaml v1.6.0 ) @@ -25,35 +25,33 @@ require ( github.com/fxamacker/cbor/v2 v2.9.0 // indirect github.com/go-logr/logr v1.4.3 // indirect github.com/go-task/slim-sprig/v3 v3.0.0 // indirect + github.com/go-viper/mapstructure/v2 v2.4.0 // indirect github.com/gogo/protobuf v1.3.2 // indirect - github.com/imdario/mergo v0.3.16 // indirect github.com/inconshreveable/mousetrap v1.1.0 // indirect github.com/json-iterator/go v1.1.12 // indirect github.com/kr/text v0.2.0 // indirect - github.com/mailru/easyjson v0.9.0 // indirect + github.com/mailru/easyjson v0.9.1 // indirect github.com/mattn/go-shellwords v1.0.12 // indirect - github.com/mitchellh/mapstructure v1.5.0 // indirect github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect - github.com/modern-go/reflect2 v1.0.2 // indirect + github.com/modern-go/reflect2 v1.0.3-0.20250322232337-35a7c28c31ee // indirect github.com/opencontainers/go-digest v1.0.0 // indirect - github.com/pkg/errors v0.9.1 // indirect + github.com/santhosh-tekuri/jsonschema/v6 v6.0.1 // indirect github.com/sirupsen/logrus v1.9.3 // indirect - github.com/spf13/pflag v1.0.7 // indirect + github.com/spf13/pflag v1.0.10 // indirect github.com/wk8/go-ordered-map/v2 v2.1.8 // indirect github.com/x448/float16 v0.8.4 // indirect - github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb // indirect - github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect - github.com/xeipuuv/gojsonschema v1.2.0 // indirect - go.yaml.in/yaml/v2 v2.4.2 // indirect - golang.org/x/exp v0.0.0-20250813145105-42675adae3e6 // indirect - golang.org/x/net v0.43.0 // indirect - golang.org/x/sync v0.16.0 // indirect - golang.org/x/sys v0.35.0 // indirect - golang.org/x/text v0.28.0 // indirect + github.com/xhit/go-str2duration/v2 v2.1.0 // indirect + go.yaml.in/yaml/v2 v2.4.3 // indirect + go.yaml.in/yaml/v3 v3.0.4 // indirect + golang.org/x/net v0.46.0 // indirect + golang.org/x/sync v0.17.0 // indirect + golang.org/x/sys v0.37.0 // indirect + golang.org/x/text v0.30.0 // indirect + golang.org/x/tools v0.38.0 // indirect gopkg.in/inf.v0 v0.9.1 // indirect k8s.io/klog/v2 v2.130.1 // indirect - k8s.io/utils v0.0.0-20250604170112-4c0f3b243397 // indirect + k8s.io/utils v0.0.0-20251002143259-bc988d571ff4 // indirect sigs.k8s.io/json v0.0.0-20250730193827-2d320260d730 // indirect sigs.k8s.io/randfill v1.0.0 // indirect - sigs.k8s.io/structured-merge-diff/v4 v4.7.0 // indirect + sigs.k8s.io/structured-merge-diff/v6 v6.3.0 // indirect ) diff --git a/go.sum b/go.sum index b8e29a8..8c35a3c 100644 --- a/go.sum +++ b/go.sum @@ -2,8 +2,8 @@ github.com/bahlo/generic-list-go v0.2.0 h1:5sz/EEAK+ls5wF+NeqDpk5+iNdMDXrh3z3nPn github.com/bahlo/generic-list-go v0.2.0/go.mod h1:2KvAjgMlE5NNynlg/5iLrrCCZ2+5xWbdbCW3pNTGyYg= github.com/buger/jsonparser v1.1.1 h1:2PnMjfWD7wBILjqQbt530v576A/cAbQvEW9gGIpYMUs= github.com/buger/jsonparser v1.1.1/go.mod h1:6RYKKt7H4d4+iWqouImQ9R2FZql3VbhNgx27UK13J/0= -github.com/compose-spec/compose-go v1.20.2 h1:u/yfZHn4EaHGdidrZycWpxXgFffjYULlTbRfJ51ykjQ= -github.com/compose-spec/compose-go v1.20.2/go.mod h1:+MdqXV4RA7wdFsahh/Kb8U0pAJqkg7mr4PM9tFKU8RM= +github.com/compose-spec/compose-go/v2 v2.9.0 h1:UHSv/QHlo6QJtrT4igF1rdORgIUhDo1gWuyJUoiNNIM= +github.com/compose-spec/compose-go/v2 v2.9.0/go.mod h1:Oky9AZGTRB4E+0VbTPZTUu4Kp+oEMMuwZXZtPPVT1iE= github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -11,6 +11,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/distribution/reference v0.6.0 h1:0IXCQ5g4/QMHHkarYzh5l+u8T3t73zM5QvfrDyIgxBk= github.com/distribution/reference v0.6.0/go.mod h1:BbU0aIcezP1/5jX/8MP0YiH4SdvB5Y4f/wlDRiLyi3E= +github.com/dlclark/regexp2 v1.11.0 h1:G/nrcoOa7ZXlpoa/91N3X7mM3r8eIlMBBJZvsz/mxKI= +github.com/dlclark/regexp2 v1.11.0/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8= github.com/docker/go-connections v0.6.0 h1:LlMG9azAe1TqfR7sO+NJttz1gy6KO7VJBh+pMmjSD94= github.com/docker/go-connections v0.6.0/go.mod h1:AahvXYshr6JgfUJGdDCs2b5EZG/vmaMAntpSFH5BFKE= github.com/docker/go-units v0.5.0 h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4= @@ -21,16 +23,15 @@ github.com/go-logr/logr v1.4.3 h1:CjnDlHq8ikf6E492q6eKboGOC0T8CDaOvkHCIg8idEI= github.com/go-logr/logr v1.4.3/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= github.com/go-task/slim-sprig/v3 v3.0.0 h1:sUs3vkvUymDpBKi3qH1YSqBQk9+9D/8M2mN1vB6EwHI= github.com/go-task/slim-sprig/v3 v3.0.0/go.mod h1:W848ghGpv3Qj3dhTPRyJypKRiqCdHZiAzKg9hl15HA8= +github.com/go-viper/mapstructure/v2 v2.4.0 h1:EBsztssimR/CONLSZZ04E8qAkxNYq4Qp9LvH92wZUgs= +github.com/go-viper/mapstructure/v2 v2.4.0/go.mod h1:oJDH3BJKyqBA2TXFhDsKDGDTlndYOZ6rGS0BRZIxGhM= github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= -github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8= github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38 h1:yAJXTCF9TqKcTiHJAE8dj7HMvPfh66eeA2JYW7eFpSE= github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= -github.com/imdario/mergo v0.3.16 h1:wwQJbIsHYGMUyLSPrEq1CT16AhnhNJQ51+4fdHUnCl4= -github.com/imdario/mergo v0.3.16/go.mod h1:WBLT9ZmE3lPoWsEzCh9LPo3TiwVN+ZKEjmz+hD27ysY= github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= github.com/invopop/jsonschema v0.13.0 h1:KvpoAJWEjR3uD9Kbm2HWJmqsEaHt8lBUpd0qHcIi21E= @@ -43,39 +44,38 @@ github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= -github.com/mailru/easyjson v0.9.0 h1:PrnmzHw7262yW8sTBwxi1PdJA3Iw/EKBa8psRf7d9a4= -github.com/mailru/easyjson v0.9.0/go.mod h1:1+xMtQp2MRNVL/V1bOzuP3aP8VNwRW55fQUto+XFtTU= +github.com/mailru/easyjson v0.9.1 h1:LbtsOm5WAswyWbvTEOqhypdPeZzHavpZx96/n553mR8= +github.com/mailru/easyjson v0.9.1/go.mod h1:1+xMtQp2MRNVL/V1bOzuP3aP8VNwRW55fQUto+XFtTU= github.com/mattn/go-shellwords v1.0.12 h1:M2zGm7EW6UQJvDeQxo4T51eKPurbeFbe8WtebGE2xrk= github.com/mattn/go-shellwords v1.0.12/go.mod h1:EZzvwXDESEeg03EKmM+RmDnNOPKG4lLtQsUlTZDWQ8Y= github.com/mitchellh/go-wordwrap v1.0.1 h1:TLuKupo69TCn6TQSyGxwI1EblZZEsQ0vMlAFQflz0v0= github.com/mitchellh/go-wordwrap v1.0.1/go.mod h1:R62XHJLzvMFRBbcrT7m7WgmE1eOyTSsCt+hzestvNj0= -github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY= -github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg= github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= -github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M= github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= +github.com/modern-go/reflect2 v1.0.3-0.20250322232337-35a7c28c31ee h1:W5t00kpgFdJifH4BDsTlE89Zl93FEloxaWZfGcifgq8= +github.com/modern-go/reflect2 v1.0.3-0.20250322232337-35a7c28c31ee/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= github.com/onsi/ginkgo/v2 v2.21.0 h1:7rg/4f3rB88pb5obDgNZrNHrQ4e6WpjonchcpuBRnZM= github.com/onsi/ginkgo/v2 v2.21.0/go.mod h1:7Du3c42kxCUegi0IImZ1wUQzMBVecgIHjR1C+NkhLQo= github.com/onsi/gomega v1.35.1 h1:Cwbd75ZBPxFSuZ6T+rN/WCb/gOc6YgFBXLlZLhC7Ds4= github.com/onsi/gomega v1.35.1/go.mod h1:PvZbdDc8J6XJEpDK4HCuRBm8a6Fzp9/DmhC9C7yFlog= github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U= github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM= -github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= -github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/rogpeppe/go-internal v1.13.1 h1:KvO1DLK/DRN07sQ1LQKScxyZJuNnedQ5/wKSR38lUII= github.com/rogpeppe/go-internal v1.13.1/go.mod h1:uMEvuHeurkdAXX61udpOXGD/AzZDWNMNyH2VO9fmH0o= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= +github.com/santhosh-tekuri/jsonschema/v6 v6.0.1 h1:PKK9DyHxif4LZo+uQSgXNqs0jj5+xZwwfKHgph2lxBw= +github.com/santhosh-tekuri/jsonschema/v6 v6.0.1/go.mod h1:JXeL+ps8p7/KNMjDQk3TCwPpBy0wYklyWTfbkIzdIFU= github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ= github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= -github.com/spf13/cobra v1.9.1 h1:CXSaggrXdbHK9CF+8ywj8Amf7PBRmPCOJugH954Nnlo= -github.com/spf13/cobra v1.9.1/go.mod h1:nDyEzZ8ogv936Cinf6g1RU9MRY64Ir93oCnqb9wxYW0= -github.com/spf13/pflag v1.0.6/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= -github.com/spf13/pflag v1.0.7 h1:vN6T9TfwStFPFM5XzjsvmzZkLuaLX+HS+0SeFLRgU6M= -github.com/spf13/pflag v1.0.7/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= +github.com/spf13/cobra v1.10.1 h1:lJeBwCfmrnXthfAupyUTzJ/J4Nc1RsHC/mSRU2dll/s= +github.com/spf13/cobra v1.10.1/go.mod h1:7SmJGaTHFVBY0jW4NXGluQoLvhqFQM+6XSKD+P4XaB0= +github.com/spf13/pflag v1.0.9/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= +github.com/spf13/pflag v1.0.10 h1:4EBh2KAYBwaONj6b2Ye1GiHfwjqyROoF4RwYO+vPwFk= +github.com/spf13/pflag v1.0.10/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= @@ -87,53 +87,46 @@ github.com/wk8/go-ordered-map/v2 v2.1.8 h1:5h/BUHu93oj4gIdvHHHGsScSTMijfx5PeYkE/ github.com/wk8/go-ordered-map/v2 v2.1.8/go.mod h1:5nJHM5DyteebpVlHnWMV0rPz6Zp7+xBAnxjb1X5vnTw= github.com/x448/float16 v0.8.4 h1:qLwI1I70+NjRFUR3zs1JPUCgaCXSh3SW62uAKT1mSBM= github.com/x448/float16 v0.8.4/go.mod h1:14CWIYCyZA/cWjXOioeEpHeN/83MdbZDRQHoFcYsOfg= -github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU= -github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb h1:zGWFAtiMcyryUHoUjUJX0/lt1H2+i2Ka2n+D3DImSNo= -github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU= -github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 h1:EzJWgHovont7NscjpAxXsDA8S8BMYve8Y5+7cuRE7R0= -github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415/go.mod h1:GwrjFmJcFw6At/Gs6z4yjiIwzuJ1/+UwLxMQDVQXShQ= -github.com/xeipuuv/gojsonschema v1.2.0 h1:LhYJRs+L4fBtjZUfuSZIKGeVu0QRy8e5Xi7D17UxZ74= -github.com/xeipuuv/gojsonschema v1.2.0/go.mod h1:anYRn/JVcOK2ZgGU+IjEV4nwlhoK5sQluxsYJ78Id3Y= +github.com/xhit/go-str2duration/v2 v2.1.0 h1:lxklc02Drh6ynqX+DdPyp5pCKLUQpRT8bp8Ydu2Bstc= +github.com/xhit/go-str2duration/v2 v2.1.0/go.mod h1:ohY8p+0f07DiV6Em5LKB0s2YpLtXVyJfNt1+BlmyAsU= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= -go.yaml.in/yaml/v2 v2.4.2 h1:DzmwEr2rDGHl7lsFgAHxmNz/1NlQ7xLIrlN2h5d1eGI= -go.yaml.in/yaml/v2 v2.4.2/go.mod h1:081UH+NErpNdqlCXm3TtEran0rJZGxAYx9hb/ELlsPU= -go.yaml.in/yaml/v3 v3.0.3 h1:bXOww4E/J3f66rav3pX3m8w6jDE4knZjGOw8b5Y6iNE= -go.yaml.in/yaml/v3 v3.0.3/go.mod h1:tBHosrYAkRZjRAOREWbDnBXUf08JOwYq++0QNwQiWzI= +go.yaml.in/yaml/v2 v2.4.3 h1:6gvOSjQoTB3vt1l+CU+tSyi/HOjfOjRLJ4YwYZGwRO0= +go.yaml.in/yaml/v2 v2.4.3/go.mod h1:zSxWcmIDjOzPXpjlTTbAsKokqkDNAVtZO0WOMiT90s8= +go.yaml.in/yaml/v3 v3.0.4 h1:tfq32ie2Jv2UxXFdLJdh3jXuOzWiL1fo0bu/FbuKpbc= +go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -golang.org/x/exp v0.0.0-20250813145105-42675adae3e6 h1:SbTAbRFnd5kjQXbczszQ0hdk3ctwYf3qBNH9jIsGclE= -golang.org/x/exp v0.0.0-20250813145105-42675adae3e6/go.mod h1:4QTo5u+SEIbbKW1RacMZq1YEfOBqeXa19JeshGi+zc4= golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= -golang.org/x/net v0.43.0 h1:lat02VYK2j4aLzMzecihNvTlJNQUq316m2Mr9rnM6YE= -golang.org/x/net v0.43.0/go.mod h1:vhO1fvI4dGsIjh73sWfUVjj3N7CA9WkKJNQm2svM6Jg= +golang.org/x/net v0.46.0 h1:giFlY12I07fugqwPuWJi68oOnpfqFnJIJzaIIm2JVV4= +golang.org/x/net v0.46.0/go.mod h1:Q9BGdFy1y4nkUwiLvT5qtyhAnEHgnQ/zd8PfU6nc210= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.16.0 h1:ycBJEhp9p4vXvUZNszeOq0kGTPghopOL8q0fq3vstxw= -golang.org/x/sync v0.16.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA= +golang.org/x/sync v0.17.0 h1:l60nONMj9l5drqw6jlhIELNv9I0A4OFgRsG9k2oT9Ug= +golang.org/x/sync v0.17.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.35.0 h1:vz1N37gP5bs89s7He8XuIYXpyY0+QlsKmzipCbUtyxI= -golang.org/x/sys v0.35.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k= +golang.org/x/sys v0.37.0 h1:fdNQudmxPjkdUTPnLn5mdQv7Zwvbvpaxqs831goi9kQ= +golang.org/x/sys v0.37.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.28.0 h1:rhazDwis8INMIwQ4tpjLDzUhx6RlXqZNPEM0huQojng= -golang.org/x/text v0.28.0/go.mod h1:U8nCwOR8jO/marOQ0QbDiOngZVEBB7MAiitBuMjXiNU= +golang.org/x/text v0.30.0 h1:yznKA/E9zq54KzlzBEAWn1NXSQ8DIp/NYMy88xJjl4k= +golang.org/x/text v0.30.0/go.mod h1:yDdHFIX9t+tORqspjENWgzaCVXgk0yYnYuSZ8UzzBVM= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= -golang.org/x/tools v0.36.0 h1:kWS0uv/zsvHEle1LbV5LE8QujrxB3wfQyxHfhOk0Qkg= -golang.org/x/tools v0.36.0/go.mod h1:WBDiHKJK8YgLHlcQPYQzNCkUxUypCaa5ZegCVutKm+s= +golang.org/x/tools v0.38.0 h1:Hx2Xv8hISq8Lm16jvBZ2VQf+RLmbd7wVUsALibYI/IQ= +golang.org/x/tools v0.38.0/go.mod h1:yEsQ/d/YK8cjh0L6rZlY8tgtlKiBNTL14pGDJPJpYQs= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= @@ -148,21 +141,19 @@ gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gotest.tools/v3 v3.4.0 h1:ZazjZUfuVeZGLAmlKKuyv3IKP5orXcwtOwDQH6YVr6o= gotest.tools/v3 v3.4.0/go.mod h1:CtbdzLSsqVhDgMtKsx03ird5YTGB3ar27v0u/yKBW5g= -k8s.io/api v0.33.4 h1:oTzrFVNPXBjMu0IlpA2eDDIU49jsuEorGHB4cvKupkk= -k8s.io/api v0.33.4/go.mod h1:VHQZ4cuxQ9sCUMESJV5+Fe8bGnqAARZ08tSTdHWfeAc= -k8s.io/apimachinery v0.33.4 h1:SOf/JW33TP0eppJMkIgQ+L6atlDiP/090oaX0y9pd9s= -k8s.io/apimachinery v0.33.4/go.mod h1:BHW0YOu7n22fFv/JkYOEfkUYNRN0fj0BlvMFWA7b+SM= +k8s.io/api v0.34.1 h1:jC+153630BMdlFukegoEL8E/yT7aLyQkIVuwhmwDgJM= +k8s.io/api v0.34.1/go.mod h1:SB80FxFtXn5/gwzCoN6QCtPD7Vbu5w2n1S0J5gFfTYk= +k8s.io/apimachinery v0.34.1 h1:dTlxFls/eikpJxmAC7MVE8oOeP1zryV7iRyIjB0gky4= +k8s.io/apimachinery v0.34.1/go.mod h1:/GwIlEcWuTX9zKIg2mbw0LRFIsXwrfoVxn+ef0X13lw= k8s.io/klog/v2 v2.130.1 h1:n9Xl7H1Xvksem4KFG4PYbdQCQxqc/tTUyrgXaOhHSzk= k8s.io/klog/v2 v2.130.1/go.mod h1:3Jpz1GvMt720eyJH1ckRHK1EDfpxISzJ7I9OYgaDtPE= -k8s.io/utils v0.0.0-20250604170112-4c0f3b243397 h1:hwvWFiBzdWw1FhfY1FooPn3kzWuJ8tmbZBHi4zVsl1Y= -k8s.io/utils v0.0.0-20250604170112-4c0f3b243397/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0= +k8s.io/utils v0.0.0-20251002143259-bc988d571ff4 h1:SjGebBtkBqHFOli+05xYbK8YF1Dzkbzn+gDM4X9T4Ck= +k8s.io/utils v0.0.0-20251002143259-bc988d571ff4/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0= sigs.k8s.io/json v0.0.0-20250730193827-2d320260d730 h1:IpInykpT6ceI+QxKBbEflcR5EXP7sU1kvOlxwZh5txg= sigs.k8s.io/json v0.0.0-20250730193827-2d320260d730/go.mod h1:mdzfpAEoE6DHQEN0uh9ZbOCuHbLK5wOm7dK4ctXE9Tg= -sigs.k8s.io/randfill v0.0.0-20250304075658-069ef1bbf016/go.mod h1:XeLlZ/jmk4i1HRopwe7/aU3H5n1zNUcX6TM94b3QxOY= sigs.k8s.io/randfill v1.0.0 h1:JfjMILfT8A6RbawdsK2JXGBR5AQVfd+9TbzrlneTyrU= sigs.k8s.io/randfill v1.0.0/go.mod h1:XeLlZ/jmk4i1HRopwe7/aU3H5n1zNUcX6TM94b3QxOY= -sigs.k8s.io/structured-merge-diff/v4 v4.7.0 h1:qPeWmscJcXP0snki5IYF79Z8xrl8ETFxgMd7wez1XkI= -sigs.k8s.io/structured-merge-diff/v4 v4.7.0/go.mod h1:dDy58f92j70zLsuZVuUX5Wp9vtxXpaZnkPGWeqDfCps= -sigs.k8s.io/yaml v1.4.0/go.mod h1:Ejl7/uTz7PSA4eKMyQCUTnhZYNmLIl+5c2lQPGR2BPY= +sigs.k8s.io/structured-merge-diff/v6 v6.3.0 h1:jTijUJbW353oVOd9oTlifJqOGEkUw2jB/fXCbTiQEco= +sigs.k8s.io/structured-merge-diff/v6 v6.3.0/go.mod h1:M3W8sfWvn2HhQDIbGWj3S099YozAsymCo/wrT5ohRUE= sigs.k8s.io/yaml v1.6.0 h1:G8fkbMSAFqgEFgh4b1wmtzDnioxFCUgTZhlbj5P9QYs= sigs.k8s.io/yaml v1.6.0/go.mod h1:796bPqUfzR/0jLAl6XjHl3Ck7MiyVv8dbTdyT3/pMf4= diff --git a/internal/generator/chart.go b/internal/generator/chart.go index 50dfc9a..39289c9 100644 --- a/internal/generator/chart.go +++ b/internal/generator/chart.go @@ -14,7 +14,7 @@ import ( "katenary.io/internal/logger" "katenary.io/internal/utils" - "github.com/compose-spec/compose-go/types" + "github.com/compose-spec/compose-go/v2/types" corev1 "k8s.io/api/core/v1" ) diff --git a/internal/generator/configMap.go b/internal/generator/configMap.go index b8a497f..2279df0 100644 --- a/internal/generator/configMap.go +++ b/internal/generator/configMap.go @@ -14,7 +14,7 @@ import ( "katenary.io/internal/logger" "katenary.io/internal/utils" - "github.com/compose-spec/compose-go/types" + "github.com/compose-spec/compose-go/v2/types" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) diff --git a/internal/generator/configMap_test.go b/internal/generator/configMap_test.go index 0e83ef8..0b63c60 100644 --- a/internal/generator/configMap_test.go +++ b/internal/generator/configMap_test.go @@ -9,7 +9,7 @@ import ( "katenary.io/internal/generator/labels" - "github.com/compose-spec/compose-go/types" + "github.com/compose-spec/compose-go/v2/types" appv1 "k8s.io/api/apps/v1" v1 "k8s.io/api/core/v1" "sigs.k8s.io/yaml" diff --git a/internal/generator/converter.go b/internal/generator/converter.go index 1bc9d3f..2f043ba 100644 --- a/internal/generator/converter.go +++ b/internal/generator/converter.go @@ -20,7 +20,7 @@ import ( "katenary.io/internal/parser" "katenary.io/internal/utils" - "github.com/compose-spec/compose-go/types" + "github.com/compose-spec/compose-go/v2/types" ) const ingressClassHelp = `# Default value for ingress.class annotation diff --git a/internal/generator/cronJob.go b/internal/generator/cronJob.go index 5ff4dfd..72d554a 100644 --- a/internal/generator/cronJob.go +++ b/internal/generator/cronJob.go @@ -8,7 +8,7 @@ import ( "katenary.io/internal/generator/labels/labelstructs" "katenary.io/internal/utils" - "github.com/compose-spec/compose-go/types" + "github.com/compose-spec/compose-go/v2/types" batchv1 "k8s.io/api/batch/v1" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" diff --git a/internal/generator/deployment.go b/internal/generator/deployment.go index 3d079bd..69b185b 100644 --- a/internal/generator/deployment.go +++ b/internal/generator/deployment.go @@ -14,7 +14,7 @@ import ( "katenary.io/internal/logger" "katenary.io/internal/utils" - "github.com/compose-spec/compose-go/types" + "github.com/compose-spec/compose-go/v2/types" appsv1 "k8s.io/api/apps/v1" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" diff --git a/internal/generator/generator.go b/internal/generator/generator.go index 80c1c48..4e5d60c 100644 --- a/internal/generator/generator.go +++ b/internal/generator/generator.go @@ -12,7 +12,7 @@ import ( "katenary.io/internal/logger" "katenary.io/internal/utils" - "github.com/compose-spec/compose-go/types" + "github.com/compose-spec/compose-go/v2/types" corev1 "k8s.io/api/core/v1" "sigs.k8s.io/yaml" ) @@ -216,9 +216,9 @@ func Generate(project *types.Project) (*HelmChart, error) { // dropIngoredServices removes all services with the "ignore" label set to true (or yes). func dropIngoredServices(project *types.Project) { - for i, service := range project.Services { + for name, service := range project.Services { if isIgnored(service) { - project.Services = append(project.Services[:i], project.Services[i+1:]...) + delete(project.Services, name) } } } diff --git a/internal/generator/ingress.go b/internal/generator/ingress.go index 2ae2c54..9f1c78f 100644 --- a/internal/generator/ingress.go +++ b/internal/generator/ingress.go @@ -8,7 +8,7 @@ import ( "katenary.io/internal/generator/labels/labelstructs" "katenary.io/internal/utils" - "github.com/compose-spec/compose-go/types" + "github.com/compose-spec/compose-go/v2/types" networkv1 "k8s.io/api/networking/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) diff --git a/internal/generator/katenaryfile/main.go b/internal/generator/katenaryfile/main.go index ed72216..f8a37d7 100644 --- a/internal/generator/katenaryfile/main.go +++ b/internal/generator/katenaryfile/main.go @@ -12,7 +12,7 @@ import ( "katenary.io/internal/generator/labels/labelstructs" "katenary.io/internal/logger" - "github.com/compose-spec/compose-go/types" + "github.com/compose-spec/compose-go/v2/types" "github.com/invopop/jsonschema" "gopkg.in/yaml.v3" ) @@ -70,35 +70,37 @@ func OverrideWithConfig(project *types.Project) { log.Fatal(err) return } - for i, p := range project.Services { + for _, p := range project.Services { name := p.Name - if project.Services[i].Labels == nil { - project.Services[i].Labels = make(map[string]string) - } - mustGetLabelContent := func(o any, s *types.ServiceConfig, labelName string) { - err := getLabelContent(o, s, labelName) + mustGetLabelContent := func(o any, labelName string) { + s, ok := project.Services[name] + if !ok { + return + } + err := getLabelContent(o, &s, labelName) if err != nil { log.Fatal(err) } + project.Services[name] = s } if s, ok := services[name]; ok { - mustGetLabelContent(s.MainApp, &project.Services[i], labels.LabelMainApp) - mustGetLabelContent(s.Values, &project.Services[i], labels.LabelValues) - mustGetLabelContent(s.Secrets, &project.Services[i], labels.LabelSecrets) - mustGetLabelContent(s.Ports, &project.Services[i], labels.LabelPorts) - mustGetLabelContent(s.Ingress, &project.Services[i], labels.LabelIngress) - mustGetLabelContent(s.HealthCheck, &project.Services[i], labels.LabelHealthCheck) - mustGetLabelContent(s.SamePod, &project.Services[i], labels.LabelSamePod) - mustGetLabelContent(s.Description, &project.Services[i], labels.LabelDescription) - mustGetLabelContent(s.Ignore, &project.Services[i], labels.LabelIgnore) - mustGetLabelContent(s.Dependencies, &project.Services[i], labels.LabelDependencies) - mustGetLabelContent(s.ConfigMapFiles, &project.Services[i], labels.LabelConfigMapFiles) - mustGetLabelContent(s.MapEnv, &project.Services[i], labels.LabelMapEnv) - mustGetLabelContent(s.CronJob, &project.Services[i], labels.LabelCronJob) - mustGetLabelContent(s.EnvFrom, &project.Services[i], labels.LabelEnvFrom) - mustGetLabelContent(s.ExchangeVolumes, &project.Services[i], labels.LabelExchangeVolume) - mustGetLabelContent(s.ValuesFrom, &project.Services[i], labels.LabelValuesFrom) + mustGetLabelContent(s.MainApp, labels.LabelMainApp) + mustGetLabelContent(s.Values, labels.LabelValues) + mustGetLabelContent(s.Secrets, labels.LabelSecrets) + mustGetLabelContent(s.Ports, labels.LabelPorts) + mustGetLabelContent(s.Ingress, labels.LabelIngress) + mustGetLabelContent(s.HealthCheck, labels.LabelHealthCheck) + mustGetLabelContent(s.SamePod, labels.LabelSamePod) + mustGetLabelContent(s.Description, labels.LabelDescription) + mustGetLabelContent(s.Ignore, labels.LabelIgnore) + mustGetLabelContent(s.Dependencies, labels.LabelDependencies) + mustGetLabelContent(s.ConfigMapFiles, labels.LabelConfigMapFiles) + mustGetLabelContent(s.MapEnv, labels.LabelMapEnv) + mustGetLabelContent(s.CronJob, labels.LabelCronJob) + mustGetLabelContent(s.EnvFrom, labels.LabelEnvFrom) + mustGetLabelContent(s.ExchangeVolumes, labels.LabelExchangeVolume) + mustGetLabelContent(s.ValuesFrom, labels.LabelValuesFrom) } } logger.Info("Katenary file loaded successfully, the services are now configured.") @@ -129,6 +131,9 @@ func getLabelContent(o any, service *types.ServiceConfig, labelName string) erro val = strings.TrimSpace(string(c)) } + if service.Labels == nil { + service.Labels = types.Labels{} + } service.Labels[labelName] = val return nil } diff --git a/internal/generator/katenaryfile/main_test.go b/internal/generator/katenaryfile/main_test.go index bef7da4..50003b0 100644 --- a/internal/generator/katenaryfile/main_test.go +++ b/internal/generator/katenaryfile/main_test.go @@ -1,13 +1,14 @@ package katenaryfile import ( + "context" "os" "path/filepath" "testing" "katenary.io/internal/generator/labels" - "github.com/compose-spec/compose-go/cli" + "github.com/compose-spec/compose-go/v2/cli" ) func TestBuildSchema(t *testing.T) { @@ -53,13 +54,13 @@ webapp: cli.WithWorkingDirectory(tmpDir), cli.WithDefaultConfigPath, ) - project, err := cli.ProjectFromOptions(options) + project, err := cli.ProjectFromOptions(context.TODO(), options) if err != nil { t.Fatalf("Failed to create project from options: %s", err.Error()) } OverrideWithConfig(project) - w := project.Services[0].Labels + w := project.Services["webapp"].Labels if v, ok := w[labels.LabelPorts]; !ok { t.Fatal("Expected ports to be defined", v) } @@ -103,13 +104,13 @@ webapp: cli.WithWorkingDirectory(tmpDir), cli.WithDefaultConfigPath, ) - project, err := cli.ProjectFromOptions(options) + project, err := cli.ProjectFromOptions(context.TODO(), options) if err != nil { t.Fatalf("Failed to create project from options: %s", err.Error()) } OverrideWithConfig(project) - w := project.Services[0].Labels + w := project.Services["webapp"].Labels if v, ok := w[labels.LabelPorts]; !ok { t.Fatal("Expected ports to be defined", v) } @@ -158,13 +159,13 @@ webapp: cli.WithWorkingDirectory(tmpDir), cli.WithDefaultConfigPath, ) - project, err := cli.ProjectFromOptions(options) + project, err := cli.ProjectFromOptions(context.TODO(), options) if err != nil { t.Fatalf("Failed to create project from options: %s", err.Error()) } OverrideWithConfig(project) - w := project.Services[0].Labels + w := project.Services["webapp"].Labels if v, ok := w[labels.LabelConfigMapFiles]; !ok { t.Fatal("Expected configmap-files to be defined", v) } diff --git a/internal/generator/rbac.go b/internal/generator/rbac.go index 5f02a34..b888ec0 100644 --- a/internal/generator/rbac.go +++ b/internal/generator/rbac.go @@ -3,7 +3,7 @@ package generator import ( "katenary.io/internal/utils" - "github.com/compose-spec/compose-go/types" + "github.com/compose-spec/compose-go/v2/types" corev1 "k8s.io/api/core/v1" rbacv1 "k8s.io/api/rbac/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" diff --git a/internal/generator/secret.go b/internal/generator/secret.go index dda895e..242a511 100644 --- a/internal/generator/secret.go +++ b/internal/generator/secret.go @@ -7,7 +7,7 @@ import ( "katenary.io/internal/generator/labels" "katenary.io/internal/utils" - "github.com/compose-spec/compose-go/types" + "github.com/compose-spec/compose-go/v2/types" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) diff --git a/internal/generator/service.go b/internal/generator/service.go index a9dc13e..5a667b2 100644 --- a/internal/generator/service.go +++ b/internal/generator/service.go @@ -7,7 +7,7 @@ import ( "katenary.io/internal/utils" - "github.com/compose-spec/compose-go/types" + "github.com/compose-spec/compose-go/v2/types" v1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/intstr" diff --git a/internal/generator/utils.go b/internal/generator/utils.go index 940bf7c..6150d55 100644 --- a/internal/generator/utils.go +++ b/internal/generator/utils.go @@ -9,7 +9,7 @@ import ( "katenary.io/internal/generator/labels/labelstructs" "katenary.io/internal/utils" - "github.com/compose-spec/compose-go/types" + "github.com/compose-spec/compose-go/v2/types" corev1 "k8s.io/api/core/v1" "sigs.k8s.io/yaml" ) diff --git a/internal/generator/utils_test.go b/internal/generator/utils_test.go index 98d59d4..ed0f517 100644 --- a/internal/generator/utils_test.go +++ b/internal/generator/utils_test.go @@ -1,6 +1,7 @@ package generator import ( + "context" "fmt" "os" "path/filepath" @@ -9,7 +10,7 @@ import ( "katenary.io/internal/generator/labels" "katenary.io/internal/utils" - "github.com/compose-spec/compose-go/cli" + "github.com/compose-spec/compose-go/v2/cli" ) func TestSplitPorts(t *testing.T) { @@ -28,7 +29,7 @@ services: composeFile := filepath.Join(tmpDir, "compose.yaml") os.MkdirAll(tmpDir, utils.DirectoryPermission) - if err := os.WriteFile(composeFile, []byte(composeFileContent), 0644); err != nil { + if err := os.WriteFile(composeFile, []byte(composeFileContent), 0o644); err != nil { t.Log(err) } defer os.RemoveAll(tmpDir) @@ -39,15 +40,17 @@ services: cli.WithWorkingDirectory(tmpDir), cli.WithDefaultConfigPath, ) - project, err := cli.ProjectFromOptions(options) + project, err := cli.ProjectFromOptions(context.TODO(), options) if err != nil { t.Fatal(err) } - if err := fixPorts(&project.Services[0]); err != nil { + s := project.Services["foo"] + if err := fixPorts(&s); err != nil { t.Errorf("Expected no error, got %s", err) } + project.Services["foo"] = s found := 0 - for _, p := range project.Services[0].Ports { + for _, p := range project.Services["foo"].Ports { switch p.Target { case 80, 443: found++ @@ -76,7 +79,7 @@ services: composeFile := filepath.Join(tmpDir, "compose.yaml") os.MkdirAll(tmpDir, utils.DirectoryPermission) - if err := os.WriteFile(composeFile, []byte(composeFileContent), 0644); err != nil { + if err := os.WriteFile(composeFile, []byte(composeFileContent), 0o644); err != nil { t.Log(err) } defer os.RemoveAll(tmpDir) @@ -87,15 +90,17 @@ services: cli.WithWorkingDirectory(tmpDir), cli.WithDefaultConfigPath, ) - project, err := cli.ProjectFromOptions(options) + project, err := cli.ProjectFromOptions(context.TODO(), options) if err != nil { t.Fatal(err) } - if err := fixPorts(&project.Services[0]); err != nil { + s := project.Services["foo"] + if err := fixPorts(&s); err != nil { t.Errorf("Expected no error, got %s", err) } + project.Services["foo"] = s found := 0 - for _, p := range project.Services[0].Ports { + for _, p := range project.Services["foo"].Ports { switch p.Target { case 80, 443, 8080: found++ diff --git a/internal/generator/values.go b/internal/generator/values.go index a52304d..f129e9a 100644 --- a/internal/generator/values.go +++ b/internal/generator/values.go @@ -3,7 +3,7 @@ package generator import ( "strings" - "github.com/compose-spec/compose-go/types" + "github.com/compose-spec/compose-go/v2/types" ) // RepositoryValue is a docker repository image and tag that will be saved in values.yaml. diff --git a/internal/generator/volume.go b/internal/generator/volume.go index fd06db1..4e7b64b 100644 --- a/internal/generator/volume.go +++ b/internal/generator/volume.go @@ -5,7 +5,7 @@ import ( "katenary.io/internal/utils" - "github.com/compose-spec/compose-go/types" + "github.com/compose-spec/compose-go/v2/types" v1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/resource" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" diff --git a/internal/parser/main.go b/internal/parser/main.go index c5445b6..ce6a1b3 100644 --- a/internal/parser/main.go +++ b/internal/parser/main.go @@ -2,11 +2,12 @@ package parser import ( + "context" "log" "path/filepath" - "github.com/compose-spec/compose-go/cli" - "github.com/compose-spec/compose-go/types" + "github.com/compose-spec/compose-go/v2/cli" + "github.com/compose-spec/compose-go/v2/types" ) func init() { @@ -53,5 +54,6 @@ func Parse(profiles []string, envFiles []string, dockerComposeFile ...string) (* if err != nil { return nil, err } - return cli.ProjectFromOptions(options) + ctx := context.TODO() + return cli.ProjectFromOptions(ctx, options) } diff --git a/internal/utils/utils.go b/internal/utils/utils.go index 4231075..6c0c22e 100644 --- a/internal/utils/utils.go +++ b/internal/utils/utils.go @@ -7,7 +7,7 @@ import ( "path/filepath" "strings" - "github.com/compose-spec/compose-go/types" + "github.com/compose-spec/compose-go/v2/types" "github.com/mitchellh/go-wordwrap" "github.com/thediveo/netdb" "gopkg.in/yaml.v3"