-
Notifications
You must be signed in to change notification settings - Fork 583
/
templates.go
39 lines (33 loc) · 943 Bytes
/
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
package templates
import (
"bytes"
"text/template"
"github.com/rancher/rke/util"
)
var VersionedTemplate = map[string]map[string]string{
"calico": map[string]string{
"v1.14": CalicoTemplateV113,
"v1.13": CalicoTemplateV113,
"default": CalicoTemplateV112,
},
"canal": map[string]string{
"v1.14": CanalTemplateV113,
"v1.13": CanalTemplateV113,
"default": CanalTemplateV112,
},
}
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"]
}