Skip to content

Commit 9297039

Browse files
committed
Merge branch 'main' of github.com:logicmonitor/helm-charts-qa
2 parents 010676d + ccfac1c commit 9297039

File tree

13 files changed

+421
-19
lines changed

13 files changed

+421
-19
lines changed

charts/argus/Chart.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ maintainers:
66
77
name: LogicMonitor
88
name: argus
9-
version: 2.2.0-rc10
9+
version: 2.2.0-rt01
1010
home: https://logicmonitor.github.io/helm-charts-qa
1111
appVersion: v8.2.0-rc2

charts/collectorset-controller/Chart.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ maintainers:
66
77
name: LogicMonitor
88
name: collectorset-controller
9-
version: 1.1.0-rc08
9+
version: 1.1.0-rt01
1010
home: https://logicmonitor.github.io/helm-charts-qa
1111
appVersion: v4.1.0-rc4

charts/lm-container/Chart.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ apiVersion: v2
22
name: lm-container
33
description: A Helm chart for Logicmonitor's Kubernetes monitoring solutions
44
type: application
5-
version: 1.1.0-rc14
5+
version: 1.1.0-rt01
66
maintainers:
77
- name: LogicMonitor
88
@@ -11,7 +11,7 @@ kubeVersion: ">= 1.16.0-0"
1111
dependencies:
1212
- name: argus
1313
# need to explicitly quote to make it string, else json schema fails
14-
version: "2.2.0-rc10"
14+
version: "2.2.0-rt01"
1515
repository: https://logicmonitor.github.io/helm-charts-qa
1616
# uncomment to test umbrella chart in while developing
1717
# repository: file://../argus
@@ -22,7 +22,7 @@ dependencies:
2222
- monitoring
2323
- name: collectorset-controller
2424
# need to explicitly quote to make it string, else json schema fails
25-
version: "1.1.0-rc08"
25+
version: "1.1.0-rt01"
2626
repository: https://logicmonitor.github.io/helm-charts-qa
2727
# uncomment to test umbrella chart in while developing
2828
# repository: file://../collectorset-controller

scripts/lmtf/go.mod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module github.com/logicmonitor/helm-charts-qa/scripts/lmtf
2+
3+
go 1.18

scripts/lmtf/lmtf

2.36 MB
Binary file not shown.

scripts/lmtf/lmtf-mac

2.33 MB
Binary file not shown.

scripts/lmtf/main.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"github.com/logicmonitor/helm-charts-qa/scripts/lmtf/pkg/load"
6+
"github.com/logicmonitor/helm-charts-qa/scripts/lmtf/pkg/tmpl"
7+
"github.com/logicmonitor/helm-charts-qa/scripts/lmtf/pkg/vardef"
8+
"os"
9+
)
10+
11+
func main() {
12+
if len(os.Args) < 4 {
13+
fmt.Println("Insufficient params: <path> <tmpl file> <var file>")
14+
return
15+
}
16+
m, err := load.WalkSchema(os.Args[1])
17+
if err != nil {
18+
fmt.Println("chart directory doesn't exist")
19+
}
20+
out := tmpl.ProcessTemplates(m, "lmc", "")
21+
outGlobal := tmpl.ProcessTemplatesGlobal(m, "lmc", "")
22+
23+
tmplStr := fmt.Sprintf("%s\n%s", out, outGlobal)
24+
25+
err = os.WriteFile(os.Args[2], []byte(tmplStr), os.ModePerm)
26+
varDef := vardef.ProcessVarDef(m, "")
27+
defs := vardef.Dump(varDef)
28+
29+
err = os.WriteFile(os.Args[3], []byte(defs), os.ModePerm)
30+
31+
}

scripts/lmtf/pkg/load/load.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package load
2+
3+
import (
4+
"encoding/json"
5+
"io/ioutil"
6+
)
7+
8+
func WalkSchema(path string) (map[string]any, error) {
9+
argusSchemaFile := path + "/values.schema.json"
10+
bytes, err := ioutil.ReadFile(argusSchemaFile)
11+
m := map[string]any{}
12+
if err == nil {
13+
err = json.Unmarshal(bytes, &m)
14+
if err != nil {
15+
return nil, err
16+
}
17+
}
18+
files, err := ioutil.ReadDir(path + "/charts")
19+
if err != nil {
20+
return m, nil
21+
}
22+
23+
for _, f := range files {
24+
if f.IsDir() {
25+
schema, err := WalkSchema(path + "/charts/" + f.Name())
26+
if err != nil {
27+
}
28+
mv := m["properties"].(map[string]any)
29+
30+
mv[f.Name()] = schema
31+
}
32+
}
33+
34+
return m, nil
35+
}

scripts/lmtf/pkg/tmpl/tmpl.go

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
package tmpl
2+
3+
import (
4+
"fmt"
5+
"strings"
6+
)
7+
8+
const indent = " "
9+
10+
func ProcessTemplatesGlobal(m map[string]any, parent string, currKey string) string {
11+
props := GetGlobalProps(m)
12+
m2 := map[string]any{
13+
"properties": props,
14+
}
15+
out := ProcessTemplates(m2, "lmc.global", "")
16+
out = strings.ReplaceAll(out, "\n", "\n"+indent)
17+
out = "%{ if lmc.global != null }\nglobal:" + indent + out + "\n%{ endif }"
18+
19+
return out
20+
}
21+
22+
func GetGlobalProps(m map[string]any) map[string]any {
23+
res := make(map[string]any, 0)
24+
if props, ok := m["properties"]; ok {
25+
for k, v := range props.(map[string]any) {
26+
pm := v.(map[string]any)
27+
if k == "global" {
28+
29+
if pmv, ok := pm["properties"]; ok {
30+
for k2, v2 := range pmv.(map[string]any) {
31+
res[k2] = v2
32+
}
33+
}
34+
} else {
35+
cm := GetGlobalProps(pm)
36+
for k, v := range cm {
37+
res[k] = v
38+
}
39+
}
40+
}
41+
}
42+
return res
43+
}
44+
func ProcessTemplates(m map[string]any, parent string, currKey string) string {
45+
if currKey == "global" {
46+
return ""
47+
}
48+
yamlEncode := false
49+
optional := false
50+
tfCommentExists := false
51+
if comment, ok := m["$comment"]; ok {
52+
val := comment.(string)
53+
for _, item := range strings.Split(val, " ") {
54+
if strings.HasPrefix(item, "tf:") && !strings.HasSuffix(item, "-ignore") {
55+
tfCommentExists = true
56+
varNm := strings.TrimPrefix(item, "tf:")
57+
arr := strings.Split(varNm, ",")
58+
for _, sa := range arr {
59+
if sa == "yamlencode" {
60+
yamlEncode = true
61+
}
62+
if sa == "optional" {
63+
optional = true
64+
}
65+
}
66+
}
67+
}
68+
}
69+
out := ""
70+
outOrig := ""
71+
if props, ok := m["properties"]; ok {
72+
propsMap := props.(map[string]any)
73+
for k, v := range propsMap {
74+
pk := ""
75+
if currKey != "" {
76+
pk = parent + "." + currKey
77+
} else {
78+
pk = parent
79+
}
80+
res := ProcessTemplates(v.(map[string]any), pk, k)
81+
82+
if res != "" {
83+
outOrig = fmt.Sprintf("%s\n%s", outOrig, res)
84+
}
85+
}
86+
}
87+
88+
if outOrig != "" {
89+
out = strings.ReplaceAll(outOrig, "\n", "\n"+indent)
90+
out = indent + out
91+
}
92+
93+
res := ""
94+
absCurrKey := parent + "." + currKey
95+
if tfCommentExists {
96+
if optional {
97+
if out != "" {
98+
res = fmt.Sprintf("%s{ if %s != null }\n%s:%s\n%s{ endif }", "%", absCurrKey, currKey, out, "%")
99+
//res = fmt.Sprintf("%s{ if contains(keys(%s), \"%s\" ) && %s != null }\n%s:%s\n%s{ endif }", "%", parent, currKey, absCurrKey, currKey, out, "%")
100+
} else {
101+
if yamlEncode {
102+
res = fmt.Sprintf("%s{ if %s != null }\n%s:\n%s${yamlencode(%s)}\n%s{ endif }", "%", absCurrKey, currKey, indent, absCurrKey, "%")
103+
//res = fmt.Sprintf("%s{ if contains(keys(%s), \"%s\" ) && %s != null }\n%s:\n%s${yamlencode(%s)}\n%s{ endif }", "%", parent, currKey, absCurrKey, currKey, indent, absCurrKey, "%")
104+
} else {
105+
res = fmt.Sprintf("%s{ if %s != null }\n%s: ${%s}\n%s{ endif }", "%", absCurrKey, currKey, absCurrKey, "%")
106+
//res = fmt.Sprintf("%s{ if contains(keys(%s), \"%s\" ) && %s != null }\n%s: ${%s}\n%s{ endif }", "%", parent, currKey, absCurrKey, currKey, absCurrKey, "%")
107+
}
108+
}
109+
} else {
110+
if out != "" {
111+
res = fmt.Sprintf("%s:\n%s%s", currKey, indent, out)
112+
} else {
113+
if yamlEncode {
114+
res = fmt.Sprintf("%s:\n%s${yamlencode(%s)}", currKey, indent, absCurrKey)
115+
} else {
116+
res = fmt.Sprintf("%s: %s${%s}", currKey, indent, absCurrKey)
117+
}
118+
}
119+
}
120+
} else {
121+
if out != "" {
122+
if currKey != "" {
123+
res = fmt.Sprintf("%s:%s", currKey, out)
124+
} else {
125+
res = outOrig
126+
}
127+
}
128+
}
129+
return res
130+
}

0 commit comments

Comments
 (0)