Better path to name + more comments

This commit is contained in:
2022-05-07 17:39:52 +02:00
parent 2b1dc68303
commit e7e4746774
2 changed files with 13 additions and 8 deletions

View File

@@ -10,6 +10,7 @@ import (
"net/url"
"os"
"path/filepath"
"regexp"
"runtime"
"strconv"
"strings"
@@ -889,9 +890,12 @@ func addVolumeFrom(deployment *helm.Deployment, container *helm.Container, s *ty
}
}
// replaceChars replaces some chars in a string.
const replaceChars = `[^a-zA-Z0-9._-]`
// PathToName transform a path to a yaml name.
func PathToName(path string) string {
path = strings.TrimPrefix(path, "./")
path = strings.ReplaceAll(path, ".", "-")
path = strings.ReplaceAll(path, "/", "-")
path = regexp.MustCompile(replaceChars).ReplaceAllString(path, "-")
return path
}