-
Notifications
You must be signed in to change notification settings - Fork 0
/
spec.go
59 lines (50 loc) · 952 Bytes
/
spec.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 main
import (
"gopkg.in/yaml.v2"
"log"
)
type Spec struct {
Name string
Namespace string
Template string
Values yaml.MapSlice
}
func (s Spec) toYtt() string {
s.validate()
out, err := yaml.Marshal(s)
if err != nil {
log.Fatal(err)
}
res := "#@data/values\n#@overlay/match-child-defaults missing_ok=True\n---\n" + string(out)
return res
}
func (s Spec) toHelm() string {
s.validate()
out, err := yaml.Marshal(s.Values)
if err != nil {
log.Fatal(err)
}
return string(out)
}
func (s Spec) validate() {
if s.Namespace == "" {
log.Fatal("Namespace must not empty: ", s)
}
if s.Name == "" {
log.Fatal("Name must not be empty: ", s)
}
}
func parseSpec(data string) Spec {
var spec Spec
err := yaml.UnmarshalStrict([]byte(data), &spec)
if err != nil {
log.Fatal(err)
}
return spec
}
func (s Spec) patch(patch Patch) Spec {
if patch.Namespace != "" {
s.Namespace = patch.Namespace
}
return s
}