-
Notifications
You must be signed in to change notification settings - Fork 583
/
templates.go
44 lines (37 loc) · 1.26 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
package templates
import (
"bytes"
"encoding/json"
"text/template"
"github.com/rancher/norman/types/convert"
"github.com/rancher/rke/metadata"
"github.com/rancher/rke/util"
)
func CompileTemplateFromMap(tmplt string, configMap interface{}) (string, error) {
out := new(bytes.Buffer)
t := template.Must(template.New("compiled_template").Funcs(template.FuncMap{"GetKubednsStubDomains": GetKubednsStubDomains}).Parse(tmplt))
if err := t.Execute(out, configMap); err != nil {
return "", err
}
return out.String(), nil
}
func GetVersionedTemplates(templateName string, data map[string]interface{}, k8sVersion string) string {
if template, ok := data[templateName]; ok {
return convert.ToString(template)
}
versionedTemplate := metadata.K8sVersionToTemplates[templateName]
if t, ok := versionedTemplate[util.GetTagMajorVersion(k8sVersion)]; ok {
return t
}
return versionedTemplate["default"]
}
func GetKubednsStubDomains(stubDomains map[string][]string) string {
json, _ := json.Marshal(stubDomains)
return string(json)
}
func GetDefaultVersionedTemplate(templateName string, data map[string]interface{}) string {
if template, ok := data[templateName]; ok {
return convert.ToString(template)
}
return metadata.K8sVersionToTemplates[templateName]["default"]
}