@@ -28,11 +28,29 @@ spec:
2828 echo "=== content read by the container ==="
2929 cat /host-etc/containerd/config.toml
3030
31- # 2. Attempt to extract 'sandbox' from the config to be compatible with latest containerd config.
31+ # 2. Check containerd config version and look for appropriate sandbox field
3232 # In containerd config version = 2 expect to find pattern `sandbox_image = "registry.k8s.io/pause:3.10.1"`
33- # In containerd config version = 3 expect to find pattern `sandbox = ' registry.k8s.io/pause:3.10.1' `
33+ # In containerd config version = 3 expect to find pattern `sandbox = " registry.k8s.io/pause:3.10.1" `
3434 # For more details: https://github.com/containerd/containerd/blob/main/docs/cri/config.md
35- sandbox_line=$(grep -E '(sandbox)\s*=' /host-etc/containerd/config.toml || true)
35+ version_line=$(grep -E '^version\s*=' /host-etc/containerd/config.toml || true)
36+ if [ -z "$version_line" ]; then
37+ echo "FAIL: no version line found in containerd config"
38+ exit 1
39+ fi
40+
41+ version=$(echo "$version_line" | cut -d'=' -f2 | tr -d ' ')
42+ echo "INFO: containerd config version = $version"
43+ if [ "$version" = "2" ]; then
44+ sandbox_line=$(grep -E 'sandbox_image\s*=' /host-etc/containerd/config.toml || true)
45+ field_name="sandbox_image"
46+ elif [ "$version" = "3" ]; then
47+ sandbox_line=$(grep -E 'sandbox\s*=' /host-etc/containerd/config.toml || true)
48+ field_name="sandbox"
49+ else
50+ echo "FAIL: unsupported containerd config version: $version"
51+ exit 1
52+ fi
53+
3654 # 3. If no sandbox configuration is found, fail explicitly
3755 if [ -z "$sandbox_line" ]; then
3856 echo "FAIL: no sandbox_image or sandbox line found"
0 commit comments