mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-20 09:33:52 +00:00
Use LoggingConfig within LogOptions
Co-authored-by: mengjiao.liu <mengjiao.liu@daocloud.io> Co-authored-by: Jordan Liggitt <jordan@liggitt.net> Co-authored-by: Heisenberg <yuzhiquanlong@gmail.com>
This commit is contained in:
committed by
Marek Siarkowicz
parent
36896f9cab
commit
f9343f837d
@@ -23,6 +23,7 @@ import (
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
utilerrors "k8s.io/apimachinery/pkg/util/errors"
|
||||
utilvalidation "k8s.io/apimachinery/pkg/util/validation"
|
||||
"k8s.io/apimachinery/pkg/util/validation/field"
|
||||
utilfeature "k8s.io/apiserver/pkg/util/feature"
|
||||
"k8s.io/component-base/logs"
|
||||
"k8s.io/component-base/metrics"
|
||||
@@ -200,11 +201,8 @@ func ValidateKubeletConfiguration(kc *kubeletconfig.KubeletConfiguration) error
|
||||
}
|
||||
allErrors = append(allErrors, metrics.ValidateShowHiddenMetricsVersion(kc.ShowHiddenMetricsForVersion)...)
|
||||
|
||||
logOption := logs.NewOptions()
|
||||
if kc.Logging.Format != "" {
|
||||
logOption.LogFormat = kc.Logging.Format
|
||||
if errs := logs.ValidateLoggingConfiguration(&kc.Logging, field.NewPath("logging")); len(errs) > 0 {
|
||||
allErrors = append(allErrors, errs.ToAggregate().Errors()...)
|
||||
}
|
||||
allErrors = append(allErrors, logOption.Validate()...)
|
||||
|
||||
return utilerrors.NewAggregate(allErrors)
|
||||
}
|
||||
|
@@ -62,6 +62,9 @@ func TestValidateKubeletConfiguration(t *testing.T) {
|
||||
"CustomCPUCFSQuotaPeriod": true,
|
||||
"GracefulNodeShutdown": true,
|
||||
},
|
||||
Logging: componentbaseconfig.LoggingConfiguration{
|
||||
Format: "text",
|
||||
},
|
||||
}
|
||||
if allErrors := ValidateKubeletConfiguration(successCase1); allErrors != nil {
|
||||
t.Errorf("expect no errors, got %v", allErrors)
|
||||
@@ -102,6 +105,9 @@ func TestValidateKubeletConfiguration(t *testing.T) {
|
||||
FeatureGates: map[string]bool{
|
||||
"CustomCPUCFSQuotaPeriod": true,
|
||||
},
|
||||
Logging: componentbaseconfig.LoggingConfiguration{
|
||||
Format: "text",
|
||||
},
|
||||
}
|
||||
if allErrors := ValidateKubeletConfiguration(successCase2); allErrors != nil {
|
||||
t.Errorf("expect no errors, got %v", allErrors)
|
||||
@@ -178,8 +184,11 @@ func TestValidateKubeletConfiguration(t *testing.T) {
|
||||
CPUCFSQuotaPeriod: metav1.Duration{Duration: 100 * time.Millisecond},
|
||||
ShutdownGracePeriod: metav1.Duration{Duration: 30 * time.Second},
|
||||
ShutdownGracePeriodCriticalPods: metav1.Duration{Duration: 60 * time.Second},
|
||||
Logging: componentbaseconfig.LoggingConfiguration{
|
||||
Format: "",
|
||||
},
|
||||
}
|
||||
const numErrsErrorCase1 = 28
|
||||
const numErrsErrorCase1 = 29
|
||||
if allErrors := ValidateKubeletConfiguration(errorCase1); len(allErrors.(utilerrors.Aggregate).Errors()) != numErrsErrorCase1 {
|
||||
t.Errorf("expect %d errors, got %v", numErrsErrorCase1, len(allErrors.(utilerrors.Aggregate).Errors()))
|
||||
}
|
||||
@@ -220,6 +229,9 @@ func TestValidateKubeletConfiguration(t *testing.T) {
|
||||
"CustomCPUCFSQuotaPeriod": true,
|
||||
"GracefulNodeShutdown": true,
|
||||
},
|
||||
Logging: componentbaseconfig.LoggingConfiguration{
|
||||
Format: "text",
|
||||
},
|
||||
}
|
||||
const numErrsErrorCase2 = 3
|
||||
if allErrors := ValidateKubeletConfiguration(errorCase2); len(allErrors.(utilerrors.Aggregate).Errors()) != numErrsErrorCase2 {
|
||||
|
Reference in New Issue
Block a user