2017-12-16 03:37:45 +00:00
|
|
|
package templates
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"text/template"
|
|
|
|
)
|
|
|
|
|
2019-01-08 20:04:42 +00:00
|
|
|
var VersionedTemplate = map[string]map[string]string{
|
|
|
|
"calico": map[string]string{
|
|
|
|
"v1.13.1-rancher1-1": CalicoTemplateV113,
|
|
|
|
"default": CalicoTemplateV112,
|
|
|
|
},
|
|
|
|
"canal": map[string]string{
|
|
|
|
"v1.13.1-rancher1-1": CanalTemplateV113,
|
|
|
|
"default": CanalTemplateV112,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2018-02-01 21:28:31 +00:00
|
|
|
func CompileTemplateFromMap(tmplt string, configMap interface{}) (string, error) {
|
2017-12-16 03:37:45 +00:00
|
|
|
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
|
|
|
|
}
|
2019-01-08 20:04:42 +00:00
|
|
|
|
|
|
|
func GetVersionedTemplates(templateName string, k8sVersion string) string {
|
|
|
|
versionedTemplate := VersionedTemplate[templateName]
|
|
|
|
if _, ok := versionedTemplate[k8sVersion]; ok {
|
|
|
|
return versionedTemplate[k8sVersion]
|
|
|
|
}
|
|
|
|
return versionedTemplate["default"]
|
|
|
|
}
|