fix(configmap): File from the root of project ends by a dash
fixes #150 If we mount a file from the root of project, the names ends by a dash. That makes helm failing to install the package.
This commit is contained in:
@@ -2,8 +2,10 @@ package generator
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
"katenary/generator/labels"
|
"katenary/generator/labels"
|
||||||
"os"
|
"os"
|
||||||
|
"regexp"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/compose-spec/compose-go/types"
|
"github.com/compose-spec/compose-go/types"
|
||||||
@@ -90,3 +92,41 @@ func TestAppendBadDir(t *testing.T) {
|
|||||||
t.Errorf("Expected error, got nil")
|
t.Errorf("Expected error, got nil")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestRootConfigmapfile(t *testing.T) {
|
||||||
|
composeFile := `
|
||||||
|
services:
|
||||||
|
web:
|
||||||
|
image: nginx
|
||||||
|
volumes:
|
||||||
|
- ./foo.txt:/etc/foo.txt
|
||||||
|
labels:
|
||||||
|
%[1]s/configmap-files: |-
|
||||||
|
- ./foo.txt
|
||||||
|
`
|
||||||
|
composeFile = fmt.Sprintf(composeFile, labels.KatenaryLabelPrefix)
|
||||||
|
tmpDir := setup(composeFile)
|
||||||
|
defer teardown(tmpDir)
|
||||||
|
|
||||||
|
currentDir, _ := os.Getwd()
|
||||||
|
os.Chdir(tmpDir)
|
||||||
|
defer os.Chdir(currentDir)
|
||||||
|
fooTxt := "foo content"
|
||||||
|
fooFp, _ := os.Create("foo.txt")
|
||||||
|
io.WriteString(fooFp, fooTxt)
|
||||||
|
fooFp.Close()
|
||||||
|
|
||||||
|
output := internalCompileTest(t, "-s", "templates/web/statics/configmap.yaml")
|
||||||
|
configMap := v1.ConfigMap{}
|
||||||
|
if err := yaml.Unmarshal([]byte(output), &configMap); err != nil {
|
||||||
|
t.Errorf(unmarshalError, err)
|
||||||
|
}
|
||||||
|
if configMap.Data == nil {
|
||||||
|
t.Error("Expected configmap data to not be nil")
|
||||||
|
}
|
||||||
|
// if the configmap.Name ends by anything that is not alphanumeric, there is a problem
|
||||||
|
valid := regexp.MustCompile(`.*[a-zA-Z0-9]+$`)
|
||||||
|
if !valid.MatchString(configMap.Name) {
|
||||||
|
t.Errorf("ConfigMap name %s is not valid", configMap.Name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@@ -635,12 +635,16 @@ func (d *Deployment) appendFileToConfigMap(service types.ServiceConfig, appName
|
|||||||
// in generate.go
|
// in generate.go
|
||||||
dirname := filepath.Dir(volume.Source)
|
dirname := filepath.Dir(volume.Source)
|
||||||
pathname := utils.PathToName(dirname)
|
pathname := utils.PathToName(dirname)
|
||||||
|
pathname = strings.TrimSpace(pathname)
|
||||||
|
if len(pathname) != 0 {
|
||||||
|
pathname += "-" + pathname
|
||||||
|
}
|
||||||
var cm *ConfigMap
|
var cm *ConfigMap
|
||||||
if v, ok := d.configMaps[pathname]; !ok {
|
if v, ok := d.configMaps[pathname]; !ok {
|
||||||
cm = NewConfigMap(*d.service, appName, true)
|
cm = NewConfigMap(*d.service, appName, true)
|
||||||
cm.usage = FileMapUsageFiles
|
cm.usage = FileMapUsageFiles
|
||||||
cm.path = dirname
|
cm.path = dirname
|
||||||
cm.Name = utils.TplName(service.Name, appName) + "-" + pathname
|
cm.Name = utils.TplName(service.Name, appName) + pathname
|
||||||
d.configMaps[pathname] = &ConfigMapMount{
|
d.configMaps[pathname] = &ConfigMapMount{
|
||||||
configMap: cm,
|
configMap: cm,
|
||||||
mountPath: []mountPathConfig{{
|
mountPath: []mountPathConfig{{
|
||||||
|
Reference in New Issue
Block a user