2019-04-19 21:08:05 +00:00
|
|
|
package templates
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"text/template"
|
|
|
|
|
|
|
|
"github.com/rancher/k3s/pkg/daemons/config"
|
|
|
|
)
|
|
|
|
|
|
|
|
type ContainerdConfig struct {
|
2019-10-07 23:04:58 +00:00
|
|
|
NodeConfig *config.Node
|
|
|
|
IsRunningInUserNS bool
|
|
|
|
PrivateRegistryConfig *Registry
|
2019-04-19 21:08:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const ContainerdConfigTemplate = `
|
|
|
|
[plugins.opt]
|
2019-10-18 19:31:06 +00:00
|
|
|
path = "{{ .NodeConfig.Containerd.Opt }}"
|
2019-04-19 21:08:05 +00:00
|
|
|
|
|
|
|
[plugins.cri]
|
2019-10-18 19:31:06 +00:00
|
|
|
stream_server_address = "127.0.0.1"
|
|
|
|
stream_server_port = "10010"
|
2020-08-11 23:17:32 +00:00
|
|
|
enable_selinux = {{ .NodeConfig.SELinux }}
|
2019-05-03 17:36:12 +00:00
|
|
|
|
|
|
|
{{- if .IsRunningInUserNS }}
|
2019-10-18 19:31:06 +00:00
|
|
|
disable_cgroup = true
|
|
|
|
disable_apparmor = true
|
|
|
|
restrict_oom_score_adj = true
|
2019-10-23 15:02:07 +00:00
|
|
|
{{end}}
|
2019-05-03 17:36:12 +00:00
|
|
|
|
|
|
|
{{- if .NodeConfig.AgentConfig.PauseImage }}
|
2019-10-18 19:31:06 +00:00
|
|
|
sandbox_image = "{{ .NodeConfig.AgentConfig.PauseImage }}"
|
2019-10-23 15:02:07 +00:00
|
|
|
{{end}}
|
2019-04-19 21:08:05 +00:00
|
|
|
|
2020-07-17 23:16:23 +00:00
|
|
|
{{- if .NodeConfig.AgentConfig.Snapshotter }}
|
|
|
|
[plugins.cri.containerd]
|
2020-11-03 17:09:52 +00:00
|
|
|
disable_snapshot_annotations = true
|
2020-07-17 23:16:23 +00:00
|
|
|
snapshotter = "{{ .NodeConfig.AgentConfig.Snapshotter }}"
|
|
|
|
{{end}}
|
|
|
|
|
2019-05-03 17:36:12 +00:00
|
|
|
{{- if not .NodeConfig.NoFlannel }}
|
2019-10-18 19:31:06 +00:00
|
|
|
[plugins.cri.cni]
|
|
|
|
bin_dir = "{{ .NodeConfig.AgentConfig.CNIBinDir }}"
|
|
|
|
conf_dir = "{{ .NodeConfig.AgentConfig.CNIConfDir }}"
|
2019-10-23 15:02:07 +00:00
|
|
|
{{end}}
|
2019-10-07 23:04:58 +00:00
|
|
|
|
2019-10-18 19:29:41 +00:00
|
|
|
[plugins.cri.containerd.runtimes.runc]
|
|
|
|
runtime_type = "io.containerd.runc.v2"
|
|
|
|
|
2019-10-07 23:04:58 +00:00
|
|
|
{{ if .PrivateRegistryConfig }}
|
|
|
|
{{ if .PrivateRegistryConfig.Mirrors }}
|
|
|
|
[plugins.cri.registry.mirrors]{{end}}
|
|
|
|
{{range $k, $v := .PrivateRegistryConfig.Mirrors }}
|
|
|
|
[plugins.cri.registry.mirrors."{{$k}}"]
|
2019-10-18 19:31:06 +00:00
|
|
|
endpoint = [{{range $i, $j := $v.Endpoints}}{{if $i}}, {{end}}{{printf "%q" .}}{{end}}]
|
2019-10-07 23:04:58 +00:00
|
|
|
{{end}}
|
|
|
|
|
|
|
|
{{range $k, $v := .PrivateRegistryConfig.Configs }}
|
|
|
|
{{ if $v.Auth }}
|
|
|
|
[plugins.cri.registry.configs."{{$k}}".auth]
|
2020-04-03 00:40:55 +00:00
|
|
|
{{ if $v.Auth.Username }}username = {{ printf "%q" $v.Auth.Username }}{{end}}
|
|
|
|
{{ if $v.Auth.Password }}password = {{ printf "%q" $v.Auth.Password }}{{end}}
|
|
|
|
{{ if $v.Auth.Auth }}auth = {{ printf "%q" $v.Auth.Auth }}{{end}}
|
|
|
|
{{ if $v.Auth.IdentityToken }}identitytoken = {{ printf "%q" $v.Auth.IdentityToken }}{{end}}
|
2019-10-07 23:04:58 +00:00
|
|
|
{{end}}
|
|
|
|
{{ if $v.TLS }}
|
|
|
|
[plugins.cri.registry.configs."{{$k}}".tls]
|
2019-10-18 19:31:06 +00:00
|
|
|
{{ if $v.TLS.CAFile }}ca_file = "{{ $v.TLS.CAFile }}"{{end}}
|
|
|
|
{{ if $v.TLS.CertFile }}cert_file = "{{ $v.TLS.CertFile }}"{{end}}
|
|
|
|
{{ if $v.TLS.KeyFile }}key_file = "{{ $v.TLS.KeyFile }}"{{end}}
|
2020-08-05 10:44:56 +00:00
|
|
|
{{ if $v.TLS.InsecureSkipVerify }}insecure_skip_verify = true{{end}}
|
2019-10-07 23:04:58 +00:00
|
|
|
{{end}}
|
|
|
|
{{end}}
|
|
|
|
{{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
|
|
|
|
}
|