2019-04-19 21:08:05 +00:00
|
|
|
package templates
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"text/template"
|
|
|
|
|
|
|
|
"github.com/rancher/k3s/pkg/daemons/config"
|
|
|
|
)
|
|
|
|
|
|
|
|
type ContainerdConfig struct {
|
|
|
|
NodeConfig *config.Node
|
|
|
|
IsRunningInUserNS bool
|
|
|
|
}
|
|
|
|
|
|
|
|
const ContainerdConfigTemplate = `
|
|
|
|
[plugins.opt]
|
|
|
|
path = "{{ .NodeConfig.Containerd.Opt }}"
|
|
|
|
|
|
|
|
[plugins.cri]
|
|
|
|
stream_server_address = "{{ .NodeConfig.AgentConfig.NodeName }}"
|
|
|
|
stream_server_port = "10010"
|
2019-05-03 17:36:12 +00:00
|
|
|
|
|
|
|
{{- if .IsRunningInUserNS }}
|
2019-04-19 21:08:05 +00:00
|
|
|
disable_cgroup = true
|
|
|
|
disable_apparmor = true
|
|
|
|
restrict_oom_score_adj = true
|
2019-05-03 17:36:12 +00:00
|
|
|
{{ end -}}
|
|
|
|
|
|
|
|
{{- if .NodeConfig.AgentConfig.PauseImage }}
|
|
|
|
sandbox_image = "{{ .NodeConfig.AgentConfig.PauseImage }}"
|
|
|
|
{{ end -}}
|
2019-04-19 21:08:05 +00:00
|
|
|
|
2019-05-03 17:36:12 +00:00
|
|
|
{{- if not .NodeConfig.NoFlannel }}
|
2019-04-19 21:08:05 +00:00
|
|
|
[plugins.cri.cni]
|
|
|
|
bin_dir = "{{ .NodeConfig.AgentConfig.CNIBinDir }}"
|
|
|
|
conf_dir = "{{ .NodeConfig.AgentConfig.CNIConfDir }}"
|
2019-05-03 17:36:12 +00:00
|
|
|
{{ end -}}
|
2019-04-19 21:08:05 +00:00
|
|
|
`
|
|
|
|
|
|
|
|
func ParseTemplateFromConfig(templateBuffer string, config interface{}) (string, error) {
|
|
|
|
out := new(bytes.Buffer)
|
|
|
|
t := template.Must(template.New("compiled_template").Parse(templateBuffer))
|
|
|
|
if err := t.Execute(out, config); err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
return out.String(), nil
|
|
|
|
}
|