-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathconfig.go
59 lines (49 loc) · 1.32 KB
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package configurator
import (
"github.com/ghodss/yaml"
"k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
// Config represents a default ConfigMap
// and any applicable overrides
type Config struct {
Name string `yaml:"name"`
Namespace string `yaml:"namespace"`
Default map[string]string `yaml:"default"`
Overrides map[string]map[string]string `yaml:"overrides"`
Annotations map[string]string `yaml:"annotations,omitempty"`
}
// NewConfigFromYaml reads yaml from a byte slice
// and returns a populated config.
func NewConfigFromYaml(in []byte) Config {
var cfg Config
yaml.Unmarshal(in, &cfg)
return cfg
}
// OutputAll returns a Default ConfigMap and
// any merged overrides
func (c Config) OutputAll() map[string]v1.ConfigMap {
results := make(map[string]v1.ConfigMap)
base := v1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Name: c.Name,
Namespace: c.Namespace,
Annotations: c.Annotations,
},
TypeMeta: metav1.TypeMeta{
Kind: "ConfigMap",
APIVersion: "v1",
},
Data: c.Default,
}
results["default"] = base
for override, merge := range c.Overrides {
o := v1.ConfigMap{}
base.DeepCopyInto(&o)
for k, v := range merge {
o.Data[k] = v
}
results[override] = o
}
return results
}