diff --git a/generator/main.go b/generator/main.go index 4d2a252..88580b8 100644 --- a/generator/main.go +++ b/generator/main.go @@ -264,6 +264,10 @@ func buildConfigMapFromPath(name, path string) *helm.ConfigMap { c, _ := ioutil.ReadFile(f) files[filename] = string(c) } + } else { + c, _ := ioutil.ReadFile(path) + _, filename := filepath.Split(path) + files[filename] = string(c) } cm := helm.NewConfigMap(name, GetRelPath(path)) @@ -356,7 +360,6 @@ func prepareVolumes(deployment, name string, s *types.ServiceConfig, container * pointToFile := "" if !stat.IsDir() { pointToFile = filepath.Base(volname) - volname = filepath.Dir(volname) } // the volume is a path and it's explicitally asked to be a configmap in labels @@ -364,6 +367,7 @@ func prepareVolumes(deployment, name string, s *types.ServiceConfig, container * cm.K8sBase.Metadata.Name = helm.ReleaseNameTpl + "-" + name + "-" + PathToName(volname) // build a configmapRef for this volume + volname := PathToName(volname) volumes = append(volumes, map[string]interface{}{ "name": volname, "configMap": map[string]string{ @@ -386,7 +390,8 @@ func prepareVolumes(deployment, name string, s *types.ServiceConfig, container * fileGeneratorChan <- cm } } else { - // rmove minus sign from volume name + // It's a Volume. Mount this from PVC to declare. + volname = strings.ReplaceAll(volname, "-", "") isEmptyDir := false diff --git a/generator/utils.go b/generator/utils.go index a862035..5c24c70 100644 --- a/generator/utils.go +++ b/generator/utils.go @@ -7,7 +7,7 @@ import ( ) // replaceChars replaces some chars in a string. -const replaceChars = `[^a-zA-Z0-9._]` +const replaceChars = `[^a-zA-Z0-9_]+` // GetRelPath return the relative path from the root of the project. func GetRelPath(path string) string { diff --git a/generator/utils_test.go b/generator/utils_test.go new file mode 100644 index 0000000..f7c64e3 --- /dev/null +++ b/generator/utils_test.go @@ -0,0 +1,14 @@ +package generator + +import ( + "katenary/compose" + "testing" +) + +func Test_PathToName(t *testing.T) { + path := compose.GetCurrentDir() + "/envéfoo.file" + name := PathToName(path) + if name != "env-foo-file" { + t.Error("Expected env-foo-file, got ", name) + } +}