Add possibility to use env file

This commit is contained in:
2021-12-01 11:53:10 +01:00
parent 6aa187af09
commit 236c783188
6 changed files with 76 additions and 10 deletions

47
helm/configMap.go Normal file
View File

@@ -0,0 +1,47 @@
package helm
import (
"errors"
"io/ioutil"
"log"
"strings"
)
type ConfigMap struct {
*K8sBase `yaml:",inline"`
Data map[string]string `yaml:"data"`
}
func NewConfigMap(name string) *ConfigMap {
base := NewBase()
base.Kind = "ConfigMap"
base.Metadata.Name = "{{ .Release.Name }}-" + name
return &ConfigMap{
K8sBase: base,
Data: make(map[string]string),
}
}
func (c *ConfigMap) AddEnvFile(file string) error {
content, err := ioutil.ReadFile(file)
if err != nil {
return err
}
lines := strings.Split(string(content), "\n")
for _, l := range lines {
l = strings.TrimSpace(l)
if len(l) == 0 {
continue
}
parts := strings.SplitN(l, "=", 2)
log.Printf("%d %v\n", len(parts), parts)
if len(parts) < 2 {
return errors.New("The environment file " + file + " is not valid")
}
c.Data[parts[0]] = parts[1]
}
return nil
}

View File

@@ -38,19 +38,21 @@ type ContainerPort struct {
}
type Container struct {
Name string `yaml:"name,omitempty"`
Image string `yaml:"image"`
Ports []*ContainerPort `yaml:"ports,omitempty"`
Env []Value `yaml:"env,omitempty"`
Command []string `yaml:"command,omitempty"`
VolumeMounts []interface{} `yaml:"volumeMounts,omitempty"`
Name string `yaml:"name,omitempty"`
Image string `yaml:"image"`
Ports []*ContainerPort `yaml:"ports,omitempty"`
Env []Value `yaml:"env,omitempty"`
EnvFrom []map[string]map[string]string `yaml:"envFrom,omitempty"`
Command []string `yaml:"command,omitempty"`
VolumeMounts []interface{} `yaml:"volumeMounts,omitempty"`
}
func NewContainer(name, image string, environment, labels map[string]string) *Container {
container := &Container{
Image: image,
Name: name,
Env: make([]Value, len(environment)),
Image: image,
Name: name,
Env: make([]Value, len(environment)),
EnvFrom: make([]map[string]map[string]string, 0),
}
toServices := make([]string, 0)

View File

@@ -7,7 +7,7 @@ import (
const K = "katenary.io"
var Version = "1.0"
var Version = "1.0" // should be set from main.Version
type Kinded interface {
Get() string