diff --git a/pkg/kubelet/apis/config/validation/validation.go b/pkg/kubelet/apis/config/validation/validation.go index 6633b4e634188..a4195a56a68d8 100644 --- a/pkg/kubelet/apis/config/validation/validation.go +++ b/pkg/kubelet/apis/config/validation/validation.go @@ -342,6 +342,10 @@ func ValidateKubeletConfiguration(kc *kubeletconfig.KubeletConfiguration, featur allErrors = append(allErrors, fmt.Errorf("invalid configuration: containerLogMonitorInterval must be a positive time duration greater than or equal to 3s")) } + if kc.ContainerLogMaxFiles <= 1 { + allErrors = append(allErrors, fmt.Errorf("invalid configuration: containerLogMaxFiles must be greater than 1")) + } + if kc.PodLogsDir == "" { allErrors = append(allErrors, fmt.Errorf("invalid configuration: podLogsDir was not specified")) } diff --git a/pkg/kubelet/apis/config/validation/validation_test.go b/pkg/kubelet/apis/config/validation/validation_test.go index 802c5506d37ce..c4dd686d37aeb 100644 --- a/pkg/kubelet/apis/config/validation/validation_test.go +++ b/pkg/kubelet/apis/config/validation/validation_test.go @@ -79,6 +79,7 @@ var ( }, ContainerRuntimeEndpoint: "unix:///run/containerd/containerd.sock", ContainerLogMaxWorkers: 1, + ContainerLogMaxFiles: 5, ContainerLogMonitorInterval: metav1.Duration{Duration: 10 * time.Second}, SingleProcessOOMKill: ptr.To(!kubeletutil.IsCgroup2UnifiedMode()), CrashLoopBackOff: kubeletconfig.CrashLoopBackOffConfig{ @@ -700,6 +701,13 @@ func TestValidateKubeletConfiguration(t *testing.T) { return config }, errMsg: `invalid configuration: pod logs path "/🧪" mut contains ASCII characters only`, + }, { + name: "invalid containerLogMaxFiles", + configure: func(conf *kubeletconfig.KubeletConfiguration) *kubeletconfig.KubeletConfiguration { + conf.ContainerLogMaxFiles = 1 + return conf + }, + errMsg: "invalid configuration: containerLogMaxFiles must be greater than 1", }, { name: "invalid ContainerRuntimeEndpoint", configure: func(conf *kubeletconfig.KubeletConfiguration) *kubeletconfig.KubeletConfiguration {