Fix names + color activation
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
@@ -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...)
|
||||
|
@@ -29,6 +29,10 @@ type Signable interface {
|
||||
BuildSHA(filename string)
|
||||
}
|
||||
|
||||
type Named interface {
|
||||
Name() string
|
||||
}
|
||||
|
||||
type Metadata struct {
|
||||
Name string `yaml:"name,omitempty"`
|
||||
Labels map[string]string `yaml:"labels"`
|
||||
@@ -66,10 +70,14 @@ func (k *K8sBase) BuildSHA(filename string) {
|
||||
k.Metadata.Annotations[K+"/docker-compose-sha256"] = fmt.Sprintf("%x", string(sum[:]))
|
||||
}
|
||||
|
||||
func (k K8sBase) Get() string {
|
||||
func (k *K8sBase) Get() string {
|
||||
return k.Kind
|
||||
}
|
||||
|
||||
func (k *K8sBase) Name() string {
|
||||
return k.Metadata.Name
|
||||
}
|
||||
|
||||
func GetProjectName() string {
|
||||
if len(Appname) > 0 {
|
||||
return Appname
|
||||
|
14
main.go
14
main.go
@@ -9,6 +9,7 @@ import (
|
||||
"katenary/helm"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"gopkg.in/yaml.v3"
|
||||
@@ -20,6 +21,8 @@ var AppVersion = "0.0.1"
|
||||
var Version = "master"
|
||||
var ChartsDir = "chart"
|
||||
|
||||
var PrefixRE = regexp.MustCompile(`\{\{.*\}\}-?`)
|
||||
|
||||
func main() {
|
||||
flag.StringVar(&ChartsDir, "chart-dir", ChartsDir, "set the chart directory")
|
||||
flag.StringVar(&ComposeFile, "compose", ComposeFile, "set the compose file to parse")
|
||||
@@ -163,6 +166,17 @@ func main() {
|
||||
}
|
||||
fp.Close()
|
||||
|
||||
case *helm.ConfigMap, *helm.Secret:
|
||||
// there could be several files, so let's force the filename
|
||||
name := c.(helm.Named).Name()
|
||||
name = PrefixRE.ReplaceAllString(name, "")
|
||||
fname := filepath.Join(templatesDir, n+"."+name+"."+kind+".yaml")
|
||||
fp, _ := os.Create(fname)
|
||||
enc := yaml.NewEncoder(fp)
|
||||
enc.SetIndent(2)
|
||||
enc.Encode(c)
|
||||
fp.Close()
|
||||
|
||||
default:
|
||||
fname := filepath.Join(templatesDir, n+"."+kind+".yaml")
|
||||
fp, _ := os.Create(fname)
|
||||
|
Reference in New Issue
Block a user