Fix names + color activation

This commit is contained in:
2021-12-02 16:07:15 +01:00
parent b894de6232
commit a292170a63
4 changed files with 42 additions and 3 deletions

View File

@@ -103,7 +103,9 @@ func parseService(name string, s compose.Service, ret chan interface{}) {
store = helm.NewSecret(cf)
}
if err := store.AddEnvFile(envfile); err != nil {
ActivateColors = true
Red(err.Error())
ActivateColors = false
os.Exit(2)
}
container.EnvFrom = append(container.EnvFrom, map[string]map[string]string{
@@ -177,14 +179,17 @@ func parseService(name string, s compose.Service, ret chan interface{}) {
if !isCM && (strings.HasPrefix(volname, ".") || strings.HasPrefix(volname, "/")) {
// local volume cannt be mounted
ActivateColors = true
Redf("You cannot, at this time, have local volume in %s deployment\n", name)
ActivateColors = false
continue
}
if isCM {
// the volume is a path and it's explicitally asked to be a configmap in labels
cm := buildCMFromPath(volname)
volname = strings.Replace(volname, "./", "", 1)
volname = strings.ReplaceAll(volname, ".", "-")
cm.K8sBase.Metadata.Name = "{{ .Release.Name }}-" + volname
cm.K8sBase.Metadata.Name = "{{ .Release.Name }}-" + volname + "-" + name
// build a configmap from the volume path
volumes = append(volumes, map[string]interface{}{
"name": volname,
@@ -449,8 +454,10 @@ func buildCMFromPath(path string) *helm.ConfigMap {
if err != nil {
fmt.Fprintf(os.Stderr, "An error occured reading volume path %s\n", err.Error())
} else {
fmt.Printf("Warning, %s is a directory, at this time we only "+
ActivateColors = true
Yellowf("Warning, %s is a directory, at this time we only "+
"can create configmap for first level file list\n", f)
ActivateColors = false
}
continue
}

View File

@@ -8,6 +8,8 @@ import (
type Color int
var ActivateColors = false
const (
GREY Color = 30 + iota
RED
@@ -21,6 +23,10 @@ const (
var waiter = sync.Mutex{}
func color(c Color, args ...interface{}) {
if !ActivateColors {
fmt.Println(args...)
return
}
waiter.Lock()
fmt.Fprintf(os.Stdout, "\x1b[%dm", c)
fmt.Fprint(os.Stdout, args...)
@@ -29,6 +35,10 @@ func color(c Color, args ...interface{}) {
}
func colorf(c Color, format string, args ...interface{}) {
if !ActivateColors {
fmt.Printf(format, args...)
return
}
waiter.Lock()
fmt.Fprintf(os.Stdout, "\x1b[%dm", c)
fmt.Fprintf(os.Stdout, format, args...)