mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-07-17 20:00:07 +00:00
Add negative validation for imageMinimumGCAge
This commit is contained in:
2
pkg/generated/openapi/zz_generated.openapi.go
generated
2
pkg/generated/openapi/zz_generated.openapi.go
generated
@@ -70225,7 +70225,7 @@ func schema_k8sio_kubelet_config_v1beta1_KubeletConfiguration(ref common.Referen
|
||||
},
|
||||
"imageMinimumGCAge": {
|
||||
SchemaProps: spec.SchemaProps{
|
||||
Description: "imageMinimumGCAge is the minimum age for an unused image before it is garbage collected. Default: \"2m\"",
|
||||
Description: "imageMinimumGCAge is the minimum age for an unused image before it is garbage collected. The field value must be greater than 0. If unset or 0, defaults to 2m. Default: \"2m\"",
|
||||
Ref: ref(metav1.Duration{}.OpenAPIModelName()),
|
||||
},
|
||||
},
|
||||
|
||||
@@ -219,6 +219,8 @@ type KubeletConfiguration struct {
|
||||
NodeLeaseDurationSeconds int32
|
||||
// ImageMinimumGCAge is the minimum age for an unused image before it is
|
||||
// garbage collected.
|
||||
// The field value must be greater than 0.
|
||||
// If unset or 0, defaults to 2m.
|
||||
ImageMinimumGCAge metav1.Duration
|
||||
// ImageMaximumGCAge is the maximum age an image can be unused before it is garbage collected.
|
||||
// The default of this field is "0s", which disables this field--meaning images won't be garbage
|
||||
|
||||
@@ -96,6 +96,9 @@ func ValidateKubeletConfiguration(kc *kubeletconfig.KubeletConfiguration, featur
|
||||
if kc.ImageMaximumGCAge.Duration != 0 && !localFeatureGate.Enabled(features.ImageMaximumGCAge) {
|
||||
allErrors = append(allErrors, fmt.Errorf("invalid configuration: ImageMaximumGCAge feature gate is required for Kubelet configuration option imageMaximumGCAge"))
|
||||
}
|
||||
if kc.ImageMinimumGCAge.Duration < 0 {
|
||||
allErrors = append(allErrors, fmt.Errorf("invalid configuration: imageMinimumGCAge %v must not be negative", kc.ImageMinimumGCAge.Duration))
|
||||
}
|
||||
if kc.ImageMaximumGCAge.Duration < 0 {
|
||||
allErrors = append(allErrors, fmt.Errorf("invalid configuration: imageMaximumGCAge %v must not be negative", kc.ImageMaximumGCAge.Duration))
|
||||
}
|
||||
|
||||
@@ -48,6 +48,7 @@ var (
|
||||
HealthzPort: 10248,
|
||||
ImageGCHighThresholdPercent: 85,
|
||||
ImageGCLowThresholdPercent: 80,
|
||||
ImageMinimumGCAge: metav1.Duration{Duration: 2 * time.Minute},
|
||||
ImagePullCredentialsVerificationPolicy: "NeverVerifyPreloadedImages",
|
||||
IPTablesDropBit: 15,
|
||||
IPTablesMasqueradeBit: 14,
|
||||
@@ -751,6 +752,20 @@ func TestValidateKubeletConfiguration(t *testing.T) {
|
||||
return conf
|
||||
},
|
||||
errMsg: "unrecognized feature gate: invalid",
|
||||
}, {
|
||||
name: "invalid configuration: invalid ImageMinimumGCAge",
|
||||
configure: func(conf *kubeletconfig.KubeletConfiguration) *kubeletconfig.KubeletConfiguration {
|
||||
conf.ImageMinimumGCAge = metav1.Duration{Duration: -1}
|
||||
return conf
|
||||
},
|
||||
errMsg: "invalid configuration: imageMinimumGCAge -1ns must not be negative",
|
||||
}, {
|
||||
name: "valid ImageMinimumGCAge set to default 1ns",
|
||||
configure: func(conf *kubeletconfig.KubeletConfiguration) *kubeletconfig.KubeletConfiguration {
|
||||
// Verify that values other than the default are accepted.
|
||||
conf.ImageMinimumGCAge = metav1.Duration{Duration: 1 * time.Nanosecond}
|
||||
return conf
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@@ -335,6 +335,8 @@ type KubeletConfiguration struct {
|
||||
NodeLeaseDurationSeconds int32 `json:"nodeLeaseDurationSeconds,omitempty"`
|
||||
// imageMinimumGCAge is the minimum age for an unused image before it is
|
||||
// garbage collected.
|
||||
// The field value must be greater than 0.
|
||||
// If unset or 0, defaults to 2m.
|
||||
// Default: "2m"
|
||||
// +optional
|
||||
ImageMinimumGCAge metav1.Duration `json:"imageMinimumGCAge,omitempty"`
|
||||
|
||||
Reference in New Issue
Block a user