From 403e7fb7e5402d57014c286ee0d9166331c7004f Mon Sep 17 00:00:00 2001 From: Patrice Ferlet Date: Wed, 1 Jun 2022 16:51:45 +0200 Subject: [PATCH] Fix path label --- generator/main.go | 13 +++++++------ generator/writer.go | 3 ++- helm/configAndSecretMap.go | 6 +++--- generator/utils.go => tools/path.go | 2 +- generator/utils_test.go => tools/path_test.go | 2 +- 5 files changed, 14 insertions(+), 12 deletions(-) rename generator/utils.go => tools/path.go (96%) rename generator/utils_test.go => tools/path_test.go (93%) diff --git a/generator/main.go b/generator/main.go index 1110542..e3471d7 100644 --- a/generator/main.go +++ b/generator/main.go @@ -6,6 +6,7 @@ import ( "katenary/compose" "katenary/helm" "katenary/logger" + "katenary/tools" "log" "net/url" "os" @@ -272,7 +273,7 @@ func buildConfigMapFromPath(name, path string) *helm.ConfigMap { files[filename] = string(c) } - cm := helm.NewConfigMap(name, GetRelPath(path)) + cm := helm.NewConfigMap(name, tools.GetRelPath(path)) cm.Data = files return cm } @@ -337,7 +338,7 @@ func prepareVolumes(deployment, name string, s *types.ServiceConfig, container * isConfigMap := false for _, cmVol := range configMapsVolumes { - if GetRelPath(volname) == cmVol { + if tools.GetRelPath(volname) == cmVol { isConfigMap = true 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 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 - volname := PathToName(volname) + volname := tools.PathToName(volname) volumes = append(volumes, map[string]interface{}{ "name": volname, "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) for _, envfile := range s.EnvFile { - f := PathToName(envfile) + f := tools.PathToName(envfile) f = strings.ReplaceAll(f, ".env", "") isSecret := false for _, s := range secretsFiles { @@ -876,7 +877,7 @@ func addVolumeFrom(deployment *helm.Deployment, container *helm.Container, s *ty for name, volumes := range volumesFrom { for volumeName := range volumes { initianame := volumeName - volumeName = PathToName(volumeName) + volumeName = tools.PathToName(volumeName) // get the volume from the deployment container "name" var ctn *helm.Container for _, c := range deployment.Spec.Template.Spec.Containers { diff --git a/generator/writer.go b/generator/writer.go index 2cd0471..45a1fef 100644 --- a/generator/writer.go +++ b/generator/writer.go @@ -4,6 +4,7 @@ import ( "katenary/compose" "katenary/generator/writers" "katenary/helm" + "katenary/tools" "log" "os" "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 name := c.(helm.Named).Name() + "-" + c.GetType() suffix := c.GetPathRessource() - suffix = PathToName(suffix) + suffix = tools.PathToName(suffix) name += suffix name = PrefixRE.ReplaceAllString(name, "") writers.BuildConfigMap(c, kind, n, name, templatesDir) diff --git a/helm/configAndSecretMap.go b/helm/configAndSecretMap.go index 9b5f6b2..5a3a7c6 100644 --- a/helm/configAndSecretMap.go +++ b/helm/configAndSecretMap.go @@ -4,6 +4,7 @@ import ( "errors" "fmt" "io/ioutil" + "katenary/tools" "strings" ) @@ -31,8 +32,7 @@ func NewConfigMap(name, path string) *ConfigMap { base.Metadata.Name = ReleaseNameTpl + "-" + name base.Metadata.Labels[K+"/component"] = name if path != "" { - //base.Metadata.Labels[K+"/path"] = path - base.Metadata.Labels[K+"/path"] = `{{ "` + path + `" | quote }}` + base.Metadata.Labels[K+"/path"] = tools.PathToName(path) } return &ConfigMap{ K8sBase: base, @@ -97,7 +97,7 @@ func NewSecret(name, path string) *Secret { base.Metadata.Name = ReleaseNameTpl + "-" + name base.Metadata.Labels[K+"/component"] = name if path != "" { - base.Metadata.Labels[K+"/path"] = `{{ "` + path + `" | quote }}` + base.Metadata.Labels[K+"/path"] = tools.PathToName(path) } return &Secret{ K8sBase: base, diff --git a/generator/utils.go b/tools/path.go similarity index 96% rename from generator/utils.go rename to tools/path.go index 5c24c70..016acae 100644 --- a/generator/utils.go +++ b/tools/path.go @@ -1,4 +1,4 @@ -package generator +package tools import ( "katenary/compose" diff --git a/generator/utils_test.go b/tools/path_test.go similarity index 93% rename from generator/utils_test.go rename to tools/path_test.go index f7c64e3..cbda344 100644 --- a/generator/utils_test.go +++ b/tools/path_test.go @@ -1,4 +1,4 @@ -package generator +package tools import ( "katenary/compose"