-
Notifications
You must be signed in to change notification settings - Fork 0
/
kube_defs_tool.cue
65 lines (52 loc) · 1.42 KB
/
kube_defs_tool.cue
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
60
61
62
63
64
65
package kube
import (
"strings"
"regexp"
"tool/file"
"tool/exec"
)
// runs `go get` and `cue get go` for all packages imported in kube_defs.go
command: "update-gomod-defs": {
readDefsGo: file.Read & {
filename: "kube_defs.go"
contents: string
}
let matches = regexp.FindAllSubmatch(#"\s*_\s*"(.+)"(\s*//\s*(.*))?\n"#, readDefsGo.contents, -1)
let commands = [
for match in matches {
let package = match[1]
let args = match[3]
strings.Join([
"echo -n \(package)..",
"go get \(package)",
"echo -n .",
"cue get go \(package) \(args)",
"echo done."],
" && ")
},
]
run: exec.Run & {
cmd: ["sh", "-c", strings.Join(commands, "\n")]
}
}
// Extracts jsonnet config and generates cue definitions.
command: "update-jsonnet-defs": "kube-prometheus": exec.Run & {
dir: "cue.mod/pkg/github.com/prometheus-operator/kube-prometheus"
cmd: ["sh", "-c", """
echo $PWD
#go install github.com/google/go-jsonnet/cmd/jsonnet@latest
#go install github.com/jsonnet-bundler/jsonnet-bundler/cmd/jb@latest
set -e
git clean -fd
git restore .
git checkout main
git pull
jb install
jsonnet -J vendor -m manifests -c ../export.jsonnet
cue import -p manifests -f ./manifests/*.json
mkdir -p ../../../../gen/github.com/prometheus-operator/kube-prometheus/manifests
mv manifests/*.cue ../../../../gen/github.com/prometheus-operator/kube-prometheus/manifests
git clean -fd
git restore .
"""]
}