/
apiext.go
75 lines (65 loc) · 1.94 KB
/
apiext.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package main
import (
_ "embed"
"fmt"
"io"
"sort"
"text/template"
)
//go:embed apiext.yaml
var apiextTmplStr string
const (
namespace = "emissary-system"
apiextSvcName = "emissary-apiext"
)
var globalLabels = map[string]string{
// https://kubernetes.io/docs/concepts/overview/working-with-objects/common-labels/
"app.kubernetes.io/name": "emissary-apiext",
"app.kubernetes.io/instance": "emissary-apiext",
"app.kubernetes.io/part-of": "emissary-apiext",
"app.kubernetes.io/managed-by": "kubectl_apply_-f_emissary-apiext.yaml",
}
func writeAPIExt(output io.Writer, args Args, crdNames []string) error {
if args.Target == TargetInternalValidator {
return nil
}
sort.Strings(crdNames)
labelSelectors := map[string]string{
"app.kubernetes.io/name": "emissary-apiext",
"app.kubernetes.io/instance": "emissary-apiext",
"app.kubernetes.io/part-of": "emissary-apiext",
}
var image string
switch args.Target {
case TargetAPIServerKAT:
image = "{images[emissary]}"
case TargetAPIServerKubectl:
image = "$imageRepo$:$version$"
default:
return fmt.Errorf("unsure which image to use for args.Target=%q", args.Target)
}
data := map[string]interface{}{
// Constants that are easier to edit here than in YAML.
"Labels": globalLabels,
"LabelSelectors": labelSelectors,
"Names": map[string]string{
// These are *just* the names that appear in multiple places, and therefore
// need to be consistent. Names that are on-offs can just go straight in
// the YAML.
"Namespace": namespace,
"Service": apiextSvcName,
"ServiceAccount": "emissary-apiext",
"ClusterRole": "emissary-apiext",
"Role": "emissary-apiext",
},
// CLI Args
"Target": args.Target,
"Image": image,
// Input files
"CRDNames": crdNames,
}
apiextTmpl := template.Must(template.New("apiext.yaml").
Option("missingkey=error").
Parse(apiextTmplStr))
return apiextTmpl.Execute(output, data)
}