@@ -12,6 +12,24 @@ import (
1212 "github.com/ytsaurus/ytsaurus-k8s-operator/pkg/consts"
1313)
1414
15+ const (
16+ runtimeTypeOCI = "oci"
17+
18+ runtimeNameRunc = "runc"
19+ crioRuntimePathRunc = "/usr/libexec/crio/runc"
20+
21+ runtimeNameCrun = "crun"
22+ crioRuntimePathCrun = "/usr/libexec/crio/crun"
23+
24+ runtimeNameNvidia = "nvidia"
25+ runtimePathNvidia = "/usr/bin/nvidia-container-runtime"
26+
27+ crioMonitorCgroup = "pod"
28+ crioMonitorPath = "/usr/libexec/crio/conmon"
29+
30+ shmSizeAnnotation = "io.kubernetes.cri-o.ShmSize"
31+ )
32+
1533type CRIConfigGenerator struct {
1634 Service ytv1.CRIServiceType
1735 Spec ytv1.CRIJobEnvironmentSpec
@@ -69,29 +87,84 @@ func (cri *CRIConfigGenerator) GetCRIToolsEnv() []corev1.EnvVar {
6987 return env
7088}
7189
72- func (cri * CRIConfigGenerator ) GetCRIOEnv () []corev1.EnvVar {
73- var env []corev1.EnvVar
90+ func (cri * CRIConfigGenerator ) GetCRIOConfig () ([]byte , error ) {
91+ // See https://github.com/cri-o/cri-o/blob/main/docs/crio.conf.5.md
92+
93+ crioAPI := map [string ]any {
94+ "listen" : cri .GetSocketPath (),
95+ }
96+
97+ crioImage := map [string ]any {}
98+
99+ crioMetrics := map [string ]any {}
100+
101+ crioRuntimeRuntimes := map [string ]any {
102+ runtimeNameRunc : map [string ]any {
103+ "runtime_type" : runtimeTypeOCI ,
104+ "runtime_path" : crioRuntimePathRunc ,
105+ "allowed_annotations" : []string {
106+ shmSizeAnnotation ,
107+ },
108+ "monitor_cgroup" : crioMonitorCgroup ,
109+ "monitor_path" : crioMonitorPath ,
110+ },
111+ runtimeNameCrun : map [string ]any {
112+ "runtime_type" : runtimeTypeOCI ,
113+ "runtime_path" : crioRuntimePathCrun ,
114+ "allowed_annotations" : []string {
115+ shmSizeAnnotation ,
116+ },
117+ "monitor_cgroup" : crioMonitorCgroup ,
118+ "monitor_path" : crioMonitorPath ,
119+ },
120+ }
121+
122+ crioRuntime := map [string ]any {
123+ "cgroup_manager" : "cgroupfs" ,
124+ "conmon_cgroup" : crioMonitorCgroup ,
125+ "default_runtime" : runtimeNameCrun ,
126+ "runtimes" : crioRuntimeRuntimes ,
127+ }
128+
129+ crio := map [string ]any {
130+ "api" : crioAPI ,
131+ "image" : crioImage ,
132+ "metrics" : crioMetrics ,
133+ "runtime" : crioRuntime ,
134+ }
135+
136+ config := map [string ]any {
137+ "crio" : crio ,
138+ }
74139
75- // See https://github.com/cri-o/cri-o/blob/main/docs/crio.8.md
76- env = append (env ,
77- corev1.EnvVar {Name : "CONTAINER_LISTEN" , Value : cri .GetSocketPath ()},
78- corev1.EnvVar {Name : "CONTAINER_CGROUP_MANAGER" , Value : "cgroupfs" },
79- corev1.EnvVar {Name : "CONTAINER_CONMON_CGROUP" , Value : "pod" },
80- )
81140 if cri .StoragePath != nil {
82- env = append ( env , corev1. EnvVar { Name : "CONTAINER_ROOT" , Value : * cri .StoragePath })
141+ crio [ "root" ] = * cri .StoragePath
83142 }
143+
84144 if cri .Spec .SandboxImage != nil {
85- env = append ( env , corev1. EnvVar { Name : "CONTAINER_PAUSE_IMAGE" , Value : * cri .Spec .SandboxImage })
145+ crioImage [ "pause_image" ] = * cri .Spec .SandboxImage
86146 }
147+
87148 if cri .MonitoringPort != 0 {
88- env = append (env ,
89- corev1.EnvVar {Name : "CONTAINER_ENABLE_METRICS" , Value : "true" },
90- corev1.EnvVar {Name : "CONTAINER_METRICS_HOST" , Value : "" },
91- corev1.EnvVar {Name : "CONTAINER_METRICS_PORT" , Value : fmt .Sprintf ("%d" , cri .MonitoringPort )},
92- )
149+ crioMetrics ["enable_metrics" ] = true
150+ crioMetrics ["metrics_host" ] = ""
151+ crioMetrics ["metrics_port" ] = cri .MonitoringPort
93152 }
94- return env
153+
154+ if cri .Runtime != nil && cri .Runtime .Nvidia != nil {
155+ crioRuntimeRuntimes [runtimeNameNvidia ] = map [string ]any {
156+ "runtime_type" : runtimeTypeOCI ,
157+ "runtime_path" : runtimePathNvidia ,
158+ "allowed_annotations" : []string {
159+ shmSizeAnnotation ,
160+ },
161+ "monitor_cgroup" : crioMonitorCgroup ,
162+ "monitor_path" : crioMonitorPath ,
163+ }
164+ crioRuntime ["default_runtime" ] = runtimeNameNvidia
165+ }
166+
167+ return marshallYsonConfig (config )
95168}
96169
97170func (cri * CRIConfigGenerator ) GetContainerdConfig () ([]byte , error ) {
@@ -143,25 +216,25 @@ func (cri *CRIConfigGenerator) GetContainerdConfig() ([]byte, error) {
143216
144217func (cri * CRIConfigGenerator ) getContainerdRuntimes () (runtimes map [string ]any , defaultRuntimeName string ) {
145218 runtimes = map [string ]any {
146- "runc" : map [string ]any {
219+ runtimeNameRunc : map [string ]any {
147220 "runtime_type" : "io.containerd.runc.v2" ,
148221 "sandbox_mode" : "podsandbox" ,
149222 "options" : map [string ]any {
150223 "SystemdCgroup" : false ,
151224 },
152225 },
153226 }
154- defaultRuntimeName = "runc"
227+ defaultRuntimeName = runtimeNameRunc
155228
156229 if cri .Runtime != nil && cri .Runtime .Nvidia != nil {
157- runtimes ["nvidia" ] = map [string ]any {
230+ runtimes [runtimeNameNvidia ] = map [string ]any {
158231 "runtime_type" : "io.containerd.runc.v2" ,
159232 "sandbox_mode" : "podsandbox" ,
160233 "options" : map [string ]any {
161- "BinaryName" : "/usr/bin/nvidia-container-runtime" ,
234+ "BinaryName" : runtimePathNvidia ,
162235 },
163236 }
164- defaultRuntimeName = "nvidia"
237+ defaultRuntimeName = runtimeNameNvidia
165238 }
166239
167240 return runtimes , defaultRuntimeName
0 commit comments