Fix problems with local volumes to configmap

- make it possible to mount only one file as configmap
- remove "dots" from path to convert it to volume name
- see #11 that can be resolved
This commit is contained in:
2022-05-23 11:13:42 +02:00
parent 1e8fd44857
commit 63afc3066b
3 changed files with 22 additions and 3 deletions

View File

@@ -264,6 +264,10 @@ func buildConfigMapFromPath(name, path string) *helm.ConfigMap {
c, _ := ioutil.ReadFile(f) c, _ := ioutil.ReadFile(f)
files[filename] = string(c) files[filename] = string(c)
} }
} else {
c, _ := ioutil.ReadFile(path)
_, filename := filepath.Split(path)
files[filename] = string(c)
} }
cm := helm.NewConfigMap(name, GetRelPath(path)) cm := helm.NewConfigMap(name, GetRelPath(path))
@@ -356,7 +360,6 @@ func prepareVolumes(deployment, name string, s *types.ServiceConfig, container *
pointToFile := "" pointToFile := ""
if !stat.IsDir() { if !stat.IsDir() {
pointToFile = filepath.Base(volname) pointToFile = filepath.Base(volname)
volname = filepath.Dir(volname)
} }
// 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
@@ -364,6 +367,7 @@ func prepareVolumes(deployment, name string, s *types.ServiceConfig, container *
cm.K8sBase.Metadata.Name = helm.ReleaseNameTpl + "-" + name + "-" + PathToName(volname) cm.K8sBase.Metadata.Name = helm.ReleaseNameTpl + "-" + name + "-" + PathToName(volname)
// build a configmapRef for this volume // build a configmapRef for this volume
volname := 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{
@@ -386,7 +390,8 @@ func prepareVolumes(deployment, name string, s *types.ServiceConfig, container *
fileGeneratorChan <- cm fileGeneratorChan <- cm
} }
} else { } else {
// rmove minus sign from volume name // It's a Volume. Mount this from PVC to declare.
volname = strings.ReplaceAll(volname, "-", "") volname = strings.ReplaceAll(volname, "-", "")
isEmptyDir := false isEmptyDir := false

View File

@@ -7,7 +7,7 @@ import (
) )
// replaceChars replaces some chars in a string. // 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. // GetRelPath return the relative path from the root of the project.
func GetRelPath(path string) string { func GetRelPath(path string) string {

14
generator/utils_test.go Normal file
View File

@@ -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)
}
}