2022-04-08 17:44:40 +00:00
|
|
|
//go:build linux
|
2021-06-10 19:27:00 +00:00
|
|
|
|
|
|
|
package templates
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"text/template"
|
|
|
|
)
|
|
|
|
|
|
|
|
const ContainerdConfigTemplate = `
|
2023-03-13 20:42:17 +00:00
|
|
|
# File generated by {{ .Program }}. DO NOT EDIT. Use config.toml.tmpl instead.
|
2022-10-13 16:03:02 +00:00
|
|
|
version = 2
|
2021-06-10 19:27:00 +00:00
|
|
|
|
2022-10-13 16:03:02 +00:00
|
|
|
[plugins."io.containerd.internal.v1.opt"]
|
|
|
|
path = "{{ .NodeConfig.Containerd.Opt }}"
|
|
|
|
[plugins."io.containerd.grpc.v1.cri"]
|
2021-06-10 19:27:00 +00:00
|
|
|
stream_server_address = "127.0.0.1"
|
|
|
|
stream_server_port = "10010"
|
|
|
|
enable_selinux = {{ .NodeConfig.SELinux }}
|
2022-07-28 08:53:56 +00:00
|
|
|
enable_unprivileged_ports = {{ .EnableUnprivileged }}
|
|
|
|
enable_unprivileged_icmp = {{ .EnableUnprivileged }}
|
2021-06-10 19:27:00 +00:00
|
|
|
|
|
|
|
{{- if .DisableCgroup}}
|
|
|
|
disable_cgroup = true
|
|
|
|
{{end}}
|
|
|
|
{{- if .IsRunningInUserNS }}
|
|
|
|
disable_apparmor = true
|
|
|
|
restrict_oom_score_adj = true
|
|
|
|
{{end}}
|
|
|
|
|
|
|
|
{{- if .NodeConfig.AgentConfig.PauseImage }}
|
|
|
|
sandbox_image = "{{ .NodeConfig.AgentConfig.PauseImage }}"
|
|
|
|
{{end}}
|
|
|
|
|
|
|
|
{{- if .NodeConfig.AgentConfig.Snapshotter }}
|
2022-10-13 16:03:02 +00:00
|
|
|
[plugins."io.containerd.grpc.v1.cri".containerd]
|
2021-06-10 19:27:00 +00:00
|
|
|
snapshotter = "{{ .NodeConfig.AgentConfig.Snapshotter }}"
|
2021-09-01 23:27:42 +00:00
|
|
|
disable_snapshot_annotations = {{ if eq .NodeConfig.AgentConfig.Snapshotter "stargz" }}false{{else}}true{{end}}
|
|
|
|
{{ if eq .NodeConfig.AgentConfig.Snapshotter "stargz" }}
|
|
|
|
{{ if .NodeConfig.AgentConfig.ImageServiceSocket }}
|
2022-10-13 16:03:02 +00:00
|
|
|
[plugins."io.containerd.snapshotter.v1.stargz"]
|
2021-09-01 23:27:42 +00:00
|
|
|
cri_keychain_image_service_path = "{{ .NodeConfig.AgentConfig.ImageServiceSocket }}"
|
2022-10-13 16:03:02 +00:00
|
|
|
[plugins."io.containerd.snapshotter.v1.stargz".cri_keychain]
|
2021-09-01 23:27:42 +00:00
|
|
|
enable_keychain = true
|
|
|
|
{{end}}
|
|
|
|
{{ if .PrivateRegistryConfig }}
|
|
|
|
{{ if .PrivateRegistryConfig.Mirrors }}
|
2022-10-13 16:03:02 +00:00
|
|
|
[plugins."io.containerd.snapshotter.v1.stargz".registry.mirrors]{{end}}
|
2021-09-01 23:27:42 +00:00
|
|
|
{{range $k, $v := .PrivateRegistryConfig.Mirrors }}
|
2022-10-13 16:03:02 +00:00
|
|
|
[plugins."io.containerd.snapshotter.v1.stargz".registry.mirrors."{{$k}}"]
|
2021-09-01 23:27:42 +00:00
|
|
|
endpoint = [{{range $i, $j := $v.Endpoints}}{{if $i}}, {{end}}{{printf "%q" .}}{{end}}]
|
|
|
|
{{if $v.Rewrites}}
|
2022-10-13 16:03:02 +00:00
|
|
|
[plugins."io.containerd.snapshotter.v1.stargz".registry.mirrors."{{$k}}".rewrite]
|
2021-09-01 23:27:42 +00:00
|
|
|
{{range $pattern, $replace := $v.Rewrites}}
|
|
|
|
"{{$pattern}}" = "{{$replace}}"
|
|
|
|
{{end}}
|
|
|
|
{{end}}
|
|
|
|
{{end}}
|
|
|
|
{{range $k, $v := .PrivateRegistryConfig.Configs }}
|
|
|
|
{{ if $v.Auth }}
|
2022-10-13 16:03:02 +00:00
|
|
|
[plugins."io.containerd.snapshotter.v1.stargz".registry.configs."{{$k}}".auth]
|
2021-09-01 23:27:42 +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}}
|
|
|
|
{{end}}
|
|
|
|
{{ if $v.TLS }}
|
2022-10-13 16:03:02 +00:00
|
|
|
[plugins."io.containerd.snapshotter.v1.stargz".registry.configs."{{$k}}".tls]
|
2021-09-01 23:27:42 +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}}
|
|
|
|
{{ if $v.TLS.InsecureSkipVerify }}insecure_skip_verify = true{{end}}
|
|
|
|
{{end}}
|
|
|
|
{{end}}
|
|
|
|
{{end}}
|
|
|
|
{{end}}
|
2021-06-10 19:27:00 +00:00
|
|
|
{{end}}
|
|
|
|
|
|
|
|
{{- if not .NodeConfig.NoFlannel }}
|
2022-10-13 16:03:02 +00:00
|
|
|
[plugins."io.containerd.grpc.v1.cri".cni]
|
2021-06-10 19:27:00 +00:00
|
|
|
bin_dir = "{{ .NodeConfig.AgentConfig.CNIBinDir }}"
|
|
|
|
conf_dir = "{{ .NodeConfig.AgentConfig.CNIConfDir }}"
|
|
|
|
{{end}}
|
|
|
|
|
2022-10-13 16:03:02 +00:00
|
|
|
[plugins."io.containerd.grpc.v1.cri".containerd.runtimes.runc]
|
2021-06-10 19:27:00 +00:00
|
|
|
runtime_type = "io.containerd.runc.v2"
|
|
|
|
|
2022-10-13 16:03:02 +00:00
|
|
|
[plugins."io.containerd.grpc.v1.cri".containerd.runtimes.runc.options]
|
|
|
|
SystemdCgroup = {{ .SystemdCgroup }}
|
2022-04-18 23:06:50 +00:00
|
|
|
|
2021-06-10 19:27:00 +00:00
|
|
|
{{ if .PrivateRegistryConfig }}
|
|
|
|
{{ if .PrivateRegistryConfig.Mirrors }}
|
2022-10-13 16:03:02 +00:00
|
|
|
[plugins."io.containerd.grpc.v1.cri".registry.mirrors]{{end}}
|
2021-06-10 19:27:00 +00:00
|
|
|
{{range $k, $v := .PrivateRegistryConfig.Mirrors }}
|
2022-10-13 16:03:02 +00:00
|
|
|
[plugins."io.containerd.grpc.v1.cri".registry.mirrors."{{$k}}"]
|
2021-06-10 19:27:00 +00:00
|
|
|
endpoint = [{{range $i, $j := $v.Endpoints}}{{if $i}}, {{end}}{{printf "%q" .}}{{end}}]
|
|
|
|
{{if $v.Rewrites}}
|
2022-10-13 16:03:02 +00:00
|
|
|
[plugins."io.containerd.grpc.v1.cri".registry.mirrors."{{$k}}".rewrite]
|
2021-06-10 19:27:00 +00:00
|
|
|
{{range $pattern, $replace := $v.Rewrites}}
|
|
|
|
"{{$pattern}}" = "{{$replace}}"
|
|
|
|
{{end}}
|
|
|
|
{{end}}
|
|
|
|
{{end}}
|
|
|
|
|
|
|
|
{{range $k, $v := .PrivateRegistryConfig.Configs }}
|
|
|
|
{{ if $v.Auth }}
|
2022-10-13 16:03:02 +00:00
|
|
|
[plugins."io.containerd.grpc.v1.cri".registry.configs."{{$k}}".auth]
|
2021-06-10 19:27:00 +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}}
|
|
|
|
{{end}}
|
|
|
|
{{ if $v.TLS }}
|
2022-10-13 16:03:02 +00:00
|
|
|
[plugins."io.containerd.grpc.v1.cri".registry.configs."{{$k}}".tls]
|
2021-06-10 19:27:00 +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}}
|
|
|
|
{{ if $v.TLS.InsecureSkipVerify }}insecure_skip_verify = true{{end}}
|
|
|
|
{{end}}
|
|
|
|
{{end}}
|
|
|
|
{{end}}
|
2021-09-15 21:31:11 +00:00
|
|
|
|
|
|
|
{{range $k, $v := .ExtraRuntimes}}
|
2022-10-13 16:03:02 +00:00
|
|
|
[plugins."io.containerd.grpc.v1.cri".containerd.runtimes."{{$k}}"]
|
2021-09-15 21:31:11 +00:00
|
|
|
runtime_type = "{{$v.RuntimeType}}"
|
2022-10-13 16:03:02 +00:00
|
|
|
[plugins."io.containerd.grpc.v1.cri".containerd.runtimes."{{$k}}".options]
|
2021-09-15 21:31:11 +00:00
|
|
|
BinaryName = "{{$v.BinaryName}}"
|
|
|
|
{{end}}
|
2021-06-10 19:27:00 +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
|
|
|
|
}
|