2017-12-16 03:37:45 +00:00
|
|
|
package templates
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"text/template"
|
2019-02-26 23:14:01 +00:00
|
|
|
|
|
|
|
"github.com/rancher/rke/util"
|
2017-12-16 03:37:45 +00:00
|
|
|
)
|
|
|
|
|
2019-01-08 20:04:42 +00:00
|
|
|
var VersionedTemplate = map[string]map[string]string{
|
|
|
|
"calico": map[string]string{
|
2019-02-26 23:14:01 +00:00
|
|
|
"v1.13": CalicoTemplateV113,
|
|
|
|
"default": CalicoTemplateV112,
|
2019-01-08 20:04:42 +00:00
|
|
|
},
|
|
|
|
"canal": map[string]string{
|
2019-02-26 23:14:01 +00:00
|
|
|
"v1.13": CanalTemplateV113,
|
|
|
|
"default": CanalTemplateV112,
|
2019-01-08 20:04:42 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
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 {
|
2019-02-26 23:14:01 +00:00
|
|
|
|
2019-01-08 20:04:42 +00:00
|
|
|
versionedTemplate := VersionedTemplate[templateName]
|
2019-02-26 23:14:01 +00:00
|
|
|
if t, ok := versionedTemplate[util.GetTagMajorVersion(k8sVersion)]; ok {
|
|
|
|
return t
|
2019-01-08 20:04:42 +00:00
|
|
|
}
|
|
|
|
return versionedTemplate["default"]
|
|
|
|
}
|