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:
@@ -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
|
||||
|
@@ -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 {
|
||||
|
14
generator/utils_test.go
Normal file
14
generator/utils_test.go
Normal 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)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user