Code cleaning
Using gofumpt. Add documentation. Some fixes on type checking and const icon type declaration.
This commit is contained in:
@@ -4,9 +4,6 @@ import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
"katenary/generator/extrafiles"
|
||||
"katenary/parser"
|
||||
"katenary/utils"
|
||||
"log"
|
||||
"os"
|
||||
"os/exec"
|
||||
@@ -15,6 +12,10 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"katenary/generator/extrafiles"
|
||||
"katenary/parser"
|
||||
"katenary/utils"
|
||||
|
||||
"github.com/compose-spec/compose-go/types"
|
||||
goyaml "gopkg.in/yaml.v3"
|
||||
)
|
||||
@@ -34,7 +35,6 @@ const headerHelp = `# This file is autogenerated by katenary
|
||||
// Convert a compose (docker, podman...) project to a helm chart.
|
||||
// It calls Generate() to generate the chart and then write it to the disk.
|
||||
func Convert(config ConvertOptions, dockerComposeFile ...string) {
|
||||
|
||||
var (
|
||||
templateDir = filepath.Join(config.OutputDir, "templates")
|
||||
helpersPath = filepath.Join(config.OutputDir, "templates", "_helpers.tpl")
|
||||
@@ -103,7 +103,7 @@ func Convert(config ConvertOptions, dockerComposeFile ...string) {
|
||||
os.RemoveAll(config.OutputDir)
|
||||
|
||||
// create the chart directory
|
||||
if err := os.MkdirAll(templateDir, 0755); err != nil {
|
||||
if err := os.MkdirAll(templateDir, 0o755); err != nil {
|
||||
fmt.Println(utils.IconFailure, err)
|
||||
os.Exit(1)
|
||||
}
|
||||
@@ -134,7 +134,7 @@ func Convert(config ConvertOptions, dockerComposeFile ...string) {
|
||||
}
|
||||
|
||||
servicename := template.Servicename
|
||||
if err := os.MkdirAll(filepath.Join(templateDir, servicename), 0755); err != nil {
|
||||
if err := os.MkdirAll(filepath.Join(templateDir, servicename), 0o755); err != nil {
|
||||
fmt.Println(utils.IconFailure, err)
|
||||
os.Exit(1)
|
||||
}
|
||||
@@ -142,7 +142,7 @@ func Convert(config ConvertOptions, dockerComposeFile ...string) {
|
||||
// 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), 0755)
|
||||
err := os.MkdirAll(filepath.Dir(name), 0o755)
|
||||
if err != nil {
|
||||
fmt.Println(utils.IconFailure, err)
|
||||
os.Exit(1)
|
||||
@@ -163,7 +163,6 @@ func Convert(config ConvertOptions, dockerComposeFile ...string) {
|
||||
}
|
||||
|
||||
// calculate the sha1 hash of the services
|
||||
|
||||
buf := bytes.NewBuffer(nil)
|
||||
encoder := goyaml.NewEncoder(buf)
|
||||
encoder.SetIndent(2)
|
||||
@@ -437,7 +436,6 @@ func addChartDoc(values []byte, project *types.Project) []byte {
|
||||
}
|
||||
}
|
||||
return []byte(chartDoc + strings.Join(lines, "\n"))
|
||||
|
||||
}
|
||||
|
||||
const imagePullPolicyHelp = `# imagePullPolicy allows you to specify a policy to cache or always pull an image.
|
||||
@@ -466,7 +464,6 @@ func addImagePullPolicyHelp(values []byte) []byte {
|
||||
}
|
||||
|
||||
func addVariablesDoc(values []byte, project *types.Project) []byte {
|
||||
|
||||
lines := strings.Split(string(values), "\n")
|
||||
|
||||
currentService := ""
|
||||
@@ -550,7 +547,6 @@ func removeNewlinesInsideBrackets(values []byte) []byte {
|
||||
replacement = regexp.MustCompile(`\s+`).ReplaceAll(replacement, []byte(" "))
|
||||
// remove newlines inside brackets
|
||||
return bytes.ReplaceAll(b, matches[1], replacement)
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
@@ -607,8 +603,8 @@ func checkOldLabels(project *types.Project) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// 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...")
|
||||
helm, err := exec.LookPath("helm")
|
||||
@@ -623,8 +619,8 @@ func helmUpdate(config ConvertOptions) error {
|
||||
return cmd.Run()
|
||||
}
|
||||
|
||||
// helmLint runs "helm lint" on the output directory.
|
||||
func helmLint(config ConvertOptions) error {
|
||||
|
||||
fmt.Println(utils.IconInfo, "Linting...")
|
||||
helm, err := exec.LookPath("helm")
|
||||
if err != nil {
|
||||
@@ -635,5 +631,4 @@ func helmLint(config ConvertOptions) error {
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
return cmd.Run()
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user