-
Notifications
You must be signed in to change notification settings - Fork 581
/
templates.go
45 lines (39 loc) · 1.08 KB
/
templates.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
package templates
import (
"bytes"
"text/template"
"github.com/rancher/rke/util"
)
var VersionedTemplate = map[string]map[string]string{
"calico": map[string]string{
"v1.15": CalicoTemplateV115,
"v1.14": CalicoTemplateV113,
"v1.13": CalicoTemplateV113,
"default": CalicoTemplateV112,
},
"canal": map[string]string{
"v1.15": CanalTemplateV115,
"v1.14": CanalTemplateV113,
"v1.13": CanalTemplateV113,
"default": CanalTemplateV112,
},
"flannel": map[string]string{
"v1.15": FlannelTemplateV115,
"default": FlannelTemplate,
},
}
func CompileTemplateFromMap(tmplt string, configMap interface{}) (string, error) {
out := new(bytes.Buffer)
t := template.Must(template.New("compiled_template").Parse(tmplt))
if err := t.Execute(out, configMap); err != nil {
return "", err
}
return out.String(), nil
}
func GetVersionedTemplates(templateName string, k8sVersion string) string {
versionedTemplate := VersionedTemplate[templateName]
if t, ok := versionedTemplate[util.GetTagMajorVersion(k8sVersion)]; ok {
return t
}
return versionedTemplate["default"]
}