Fix path label

This commit is contained in:
2022-06-01 16:51:45 +02:00
parent 75500c0830
commit 403e7fb7e5
5 changed files with 14 additions and 12 deletions

View File

@@ -6,6 +6,7 @@ import (
"katenary/compose" "katenary/compose"
"katenary/helm" "katenary/helm"
"katenary/logger" "katenary/logger"
"katenary/tools"
"log" "log"
"net/url" "net/url"
"os" "os"
@@ -272,7 +273,7 @@ func buildConfigMapFromPath(name, path string) *helm.ConfigMap {
files[filename] = string(c) files[filename] = string(c)
} }
cm := helm.NewConfigMap(name, GetRelPath(path)) cm := helm.NewConfigMap(name, tools.GetRelPath(path))
cm.Data = files cm.Data = files
return cm return cm
} }
@@ -337,7 +338,7 @@ func prepareVolumes(deployment, name string, s *types.ServiceConfig, container *
isConfigMap := false isConfigMap := false
for _, cmVol := range configMapsVolumes { for _, cmVol := range configMapsVolumes {
if GetRelPath(volname) == cmVol { if tools.GetRelPath(volname) == cmVol {
isConfigMap = true isConfigMap = true
break break
} }
@@ -366,10 +367,10 @@ func prepareVolumes(deployment, name string, s *types.ServiceConfig, container *
// the volume is a path and it's explicitally asked to be a configmap in labels // the volume is a path and it's explicitally asked to be a configmap in labels
cm := buildConfigMapFromPath(name, volname) cm := buildConfigMapFromPath(name, volname)
cm.K8sBase.Metadata.Name = helm.ReleaseNameTpl + "-" + name + "-" + PathToName(volname) cm.K8sBase.Metadata.Name = helm.ReleaseNameTpl + "-" + name + "-" + tools.PathToName(volname)
// build a configmapRef for this volume // build a configmapRef for this volume
volname := PathToName(volname) volname := tools.PathToName(volname)
volumes = append(volumes, map[string]interface{}{ volumes = append(volumes, map[string]interface{}{
"name": volname, "name": volname,
"configMap": map[string]string{ "configMap": map[string]string{
@@ -586,7 +587,7 @@ func prepareEnvFromFiles(name string, s *types.ServiceConfig, container *helm.Co
// manage environment files (env_file in compose) // manage environment files (env_file in compose)
for _, envfile := range s.EnvFile { for _, envfile := range s.EnvFile {
f := PathToName(envfile) f := tools.PathToName(envfile)
f = strings.ReplaceAll(f, ".env", "") f = strings.ReplaceAll(f, ".env", "")
isSecret := false isSecret := false
for _, s := range secretsFiles { for _, s := range secretsFiles {
@@ -876,7 +877,7 @@ func addVolumeFrom(deployment *helm.Deployment, container *helm.Container, s *ty
for name, volumes := range volumesFrom { for name, volumes := range volumesFrom {
for volumeName := range volumes { for volumeName := range volumes {
initianame := volumeName initianame := volumeName
volumeName = PathToName(volumeName) volumeName = tools.PathToName(volumeName)
// get the volume from the deployment container "name" // get the volume from the deployment container "name"
var ctn *helm.Container var ctn *helm.Container
for _, c := range deployment.Spec.Template.Spec.Containers { for _, c := range deployment.Spec.Template.Spec.Containers {

View File

@@ -4,6 +4,7 @@ import (
"katenary/compose" "katenary/compose"
"katenary/generator/writers" "katenary/generator/writers"
"katenary/helm" "katenary/helm"
"katenary/tools"
"log" "log"
"os" "os"
"path/filepath" "path/filepath"
@@ -175,7 +176,7 @@ func Generate(p *compose.Parser, katernayVersion, appName, appVersion, chartVers
// there could be several files, so let's force the filename // there could be several files, so let's force the filename
name := c.(helm.Named).Name() + "-" + c.GetType() name := c.(helm.Named).Name() + "-" + c.GetType()
suffix := c.GetPathRessource() suffix := c.GetPathRessource()
suffix = PathToName(suffix) suffix = tools.PathToName(suffix)
name += suffix name += suffix
name = PrefixRE.ReplaceAllString(name, "") name = PrefixRE.ReplaceAllString(name, "")
writers.BuildConfigMap(c, kind, n, name, templatesDir) writers.BuildConfigMap(c, kind, n, name, templatesDir)

View File

@@ -4,6 +4,7 @@ import (
"errors" "errors"
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"katenary/tools"
"strings" "strings"
) )
@@ -31,8 +32,7 @@ func NewConfigMap(name, path string) *ConfigMap {
base.Metadata.Name = ReleaseNameTpl + "-" + name base.Metadata.Name = ReleaseNameTpl + "-" + name
base.Metadata.Labels[K+"/component"] = name base.Metadata.Labels[K+"/component"] = name
if path != "" { if path != "" {
//base.Metadata.Labels[K+"/path"] = path base.Metadata.Labels[K+"/path"] = tools.PathToName(path)
base.Metadata.Labels[K+"/path"] = `{{ "` + path + `" | quote }}`
} }
return &ConfigMap{ return &ConfigMap{
K8sBase: base, K8sBase: base,
@@ -97,7 +97,7 @@ func NewSecret(name, path string) *Secret {
base.Metadata.Name = ReleaseNameTpl + "-" + name base.Metadata.Name = ReleaseNameTpl + "-" + name
base.Metadata.Labels[K+"/component"] = name base.Metadata.Labels[K+"/component"] = name
if path != "" { if path != "" {
base.Metadata.Labels[K+"/path"] = `{{ "` + path + `" | quote }}` base.Metadata.Labels[K+"/path"] = tools.PathToName(path)
} }
return &Secret{ return &Secret{
K8sBase: base, K8sBase: base,

View File

@@ -1,4 +1,4 @@
package generator package tools
import ( import (
"katenary/compose" "katenary/compose"

View File

@@ -1,4 +1,4 @@
package generator package tools
import ( import (
"katenary/compose" "katenary/compose"