Added the mergeDefaultEvictionSettings Kubelet Config

This commit is contained in:
vaibhav2107 2024-09-24 01:54:07 +05:30 committed by Vaibhav Goel
parent 165da9ad0f
commit a97c6a7045
12 changed files with 58 additions and 0 deletions

View File

@ -443,6 +443,12 @@ func loadConfigFile(name string) (*kubeletconfiginternal.KubeletConfiguration, e
// See: https://github.com/kubernetes/kubernetes/pull/110263 // See: https://github.com/kubernetes/kubernetes/pull/110263
if kc.EvictionHard == nil { if kc.EvictionHard == nil {
kc.EvictionHard = eviction.DefaultEvictionHard kc.EvictionHard = eviction.DefaultEvictionHard
} else if kc.MergeDefaultEvictionSettings {
for k, v := range eviction.DefaultEvictionHard {
if _, exists := kc.EvictionHard[k]; !exists {
kc.EvictionHard[k] = v
}
}
} }
return kc, err return kc, err
} }

View File

@ -64353,6 +64353,13 @@ func schema_k8sio_kubelet_config_v1beta1_KubeletConfiguration(ref common.Referen
}, },
}, },
}, },
"mergeDefaultEvictionSettings": {
SchemaProps: spec.SchemaProps{
Description: "mergeDefaultEvictionSettings indicates that defaults for the evictionHard, evictionSoft, evictionSoftGracePeriod, and evictionMinimumReclaim fields should be merged into values specified for those fields in this configuration. Signals specified in this configuration take precedence. Signals not specified in this configuration inherit their defaults. If false, and if any signal is specified in this configuration then other signals that are not specified in this configuration will be set to 0. It applies to merging the fields for which the default exists, and currently only evictionHard has default values. Default: false",
Type: []string{"boolean"},
Format: "",
},
},
"podsPerCore": { "podsPerCore": {
SchemaProps: spec.SchemaProps{ SchemaProps: spec.SchemaProps{
Description: "podsPerCore is the maximum number of pods per core. Cannot exceed maxPods. The value must be a non-negative integer. If 0, there is no limit on the number of Pods. Default: 0", Description: "podsPerCore is the maximum number of pods per core. Cannot exceed maxPods. The value must be a non-negative integer. If 0, there is no limit on the number of Pods. Default: 0",

View File

@ -98,6 +98,7 @@ func Funcs(codecs runtimeserializer.CodecFactory) []interface{} {
obj.HairpinMode = v1beta1.PromiscuousBridge obj.HairpinMode = v1beta1.PromiscuousBridge
obj.EvictionHard = eviction.DefaultEvictionHard obj.EvictionHard = eviction.DefaultEvictionHard
obj.EvictionPressureTransitionPeriod = metav1.Duration{Duration: 5 * time.Minute} obj.EvictionPressureTransitionPeriod = metav1.Duration{Duration: 5 * time.Minute}
obj.MergeDefaultEvictionSettings = false
obj.MakeIPTablesUtilChains = true obj.MakeIPTablesUtilChains = true
obj.IPTablesMasqueradeBit = kubeletconfigv1beta1.DefaultIPTablesMasqueradeBit obj.IPTablesMasqueradeBit = kubeletconfigv1beta1.DefaultIPTablesMasqueradeBit
obj.IPTablesDropBit = kubeletconfigv1beta1.DefaultIPTablesDropBit obj.IPTablesDropBit = kubeletconfigv1beta1.DefaultIPTablesDropBit

View File

@ -258,6 +258,7 @@ var (
"MaxPods", "MaxPods",
"MemoryManagerPolicy", "MemoryManagerPolicy",
"MemorySwap.SwapBehavior", "MemorySwap.SwapBehavior",
"MergeDefaultEvictionSettings",
"NodeLeaseDurationSeconds", "NodeLeaseDurationSeconds",
"NodeStatusMaxImages", "NodeStatusMaxImages",
"NodeStatusUpdateFrequency.Duration", "NodeStatusUpdateFrequency.Duration",

View File

@ -70,6 +70,7 @@ maxPods: 110
memoryManagerPolicy: None memoryManagerPolicy: None
memorySwap: {} memorySwap: {}
memoryThrottlingFactor: 0.9 memoryThrottlingFactor: 0.9
mergeDefaultEvictionSettings: false
nodeLeaseDurationSeconds: 40 nodeLeaseDurationSeconds: 40
nodeStatusMaxImages: 50 nodeStatusMaxImages: 50
nodeStatusReportFrequency: 5m0s nodeStatusReportFrequency: 5m0s

View File

@ -70,6 +70,7 @@ maxPods: 110
memoryManagerPolicy: None memoryManagerPolicy: None
memorySwap: {} memorySwap: {}
memoryThrottlingFactor: 0.9 memoryThrottlingFactor: 0.9
mergeDefaultEvictionSettings: false
nodeLeaseDurationSeconds: 40 nodeLeaseDurationSeconds: 40
nodeStatusMaxImages: 50 nodeStatusMaxImages: 50
nodeStatusReportFrequency: 5m0s nodeStatusReportFrequency: 5m0s

View File

@ -322,6 +322,14 @@ type KubeletConfiguration struct {
// amount of a given resource the kubelet will reclaim when performing a pod eviction while // amount of a given resource the kubelet will reclaim when performing a pod eviction while
// that resource is under pressure. For example: {"imagefs.available": "2Gi"} // that resource is under pressure. For example: {"imagefs.available": "2Gi"}
EvictionMinimumReclaim map[string]string EvictionMinimumReclaim map[string]string
// mergeDefaultEvictionSettings indicates that defaults for the evictionHard, evictionSoft, evictionSoftGracePeriod, and evictionMinimumReclaim
// fields should be merged into values specified for those fields in this configuration.
// Signals specified in this configuration take precedence.
// Signals not specified in this configuration inherit their defaults.
// If false, and if any signal is specified in this configuration then other signals that
// are not specified in this configuration will be set to 0.
// It applies to merging the fields for which the default exists, and currently only evictionHard has default values.
MergeDefaultEvictionSettings bool
// podsPerCore is the maximum number of pods per core. Cannot exceed MaxPods. // podsPerCore is the maximum number of pods per core. Cannot exceed MaxPods.
// If 0, this field is ignored. // If 0, this field is ignored.
PodsPerCore int32 PodsPerCore int32

View File

@ -236,6 +236,9 @@ func SetDefaults_KubeletConfiguration(obj *kubeletconfigv1beta1.KubeletConfigura
if obj.EvictionPressureTransitionPeriod == zeroDuration { if obj.EvictionPressureTransitionPeriod == zeroDuration {
obj.EvictionPressureTransitionPeriod = metav1.Duration{Duration: 5 * time.Minute} obj.EvictionPressureTransitionPeriod = metav1.Duration{Duration: 5 * time.Minute}
} }
if obj.MergeDefaultEvictionSettings == nil {
obj.MergeDefaultEvictionSettings = ptr.To(false)
}
if obj.EnableControllerAttachDetach == nil { if obj.EnableControllerAttachDetach == nil {
obj.EnableControllerAttachDetach = ptr.To(true) obj.EnableControllerAttachDetach = ptr.To(true)
} }

View File

@ -104,6 +104,7 @@ func TestSetDefaultsKubeletConfiguration(t *testing.T) {
MaxParallelImagePulls: nil, MaxParallelImagePulls: nil,
EvictionHard: nil, EvictionHard: nil,
EvictionPressureTransitionPeriod: metav1.Duration{Duration: 5 * time.Minute}, EvictionPressureTransitionPeriod: metav1.Duration{Duration: 5 * time.Minute},
MergeDefaultEvictionSettings: ptr.To(false),
EnableControllerAttachDetach: ptr.To(true), EnableControllerAttachDetach: ptr.To(true),
MakeIPTablesUtilChains: ptr.To(true), MakeIPTablesUtilChains: ptr.To(true),
IPTablesMasqueradeBit: ptr.To[int32](DefaultIPTablesMasqueradeBit), IPTablesMasqueradeBit: ptr.To[int32](DefaultIPTablesMasqueradeBit),
@ -221,6 +222,7 @@ func TestSetDefaultsKubeletConfiguration(t *testing.T) {
EvictionPressureTransitionPeriod: zeroDuration, EvictionPressureTransitionPeriod: zeroDuration,
EvictionMaxPodGracePeriod: 0, EvictionMaxPodGracePeriod: 0,
EvictionMinimumReclaim: map[string]string{}, EvictionMinimumReclaim: map[string]string{},
MergeDefaultEvictionSettings: ptr.To(false),
PodsPerCore: 0, PodsPerCore: 0,
EnableControllerAttachDetach: ptr.To(false), EnableControllerAttachDetach: ptr.To(false),
ProtectKernelDefaults: false, ProtectKernelDefaults: false,
@ -334,6 +336,7 @@ func TestSetDefaultsKubeletConfiguration(t *testing.T) {
EvictionSoftGracePeriod: map[string]string{}, EvictionSoftGracePeriod: map[string]string{},
EvictionPressureTransitionPeriod: metav1.Duration{Duration: 5 * time.Minute}, EvictionPressureTransitionPeriod: metav1.Duration{Duration: 5 * time.Minute},
EvictionMinimumReclaim: map[string]string{}, EvictionMinimumReclaim: map[string]string{},
MergeDefaultEvictionSettings: ptr.To(false),
EnableControllerAttachDetach: ptr.To(false), EnableControllerAttachDetach: ptr.To(false),
MakeIPTablesUtilChains: ptr.To(false), MakeIPTablesUtilChains: ptr.To(false),
IPTablesMasqueradeBit: ptr.To[int32](0), IPTablesMasqueradeBit: ptr.To[int32](0),
@ -472,6 +475,7 @@ func TestSetDefaultsKubeletConfiguration(t *testing.T) {
EvictionMinimumReclaim: map[string]string{ EvictionMinimumReclaim: map[string]string{
"imagefs.available": "1Gi", "imagefs.available": "1Gi",
}, },
MergeDefaultEvictionSettings: ptr.To(true),
PodsPerCore: 1, PodsPerCore: 1,
EnableControllerAttachDetach: ptr.To(true), EnableControllerAttachDetach: ptr.To(true),
ProtectKernelDefaults: true, ProtectKernelDefaults: true,
@ -630,6 +634,7 @@ func TestSetDefaultsKubeletConfiguration(t *testing.T) {
PodsPerCore: 1, PodsPerCore: 1,
EnableControllerAttachDetach: ptr.To(true), EnableControllerAttachDetach: ptr.To(true),
ProtectKernelDefaults: true, ProtectKernelDefaults: true,
MergeDefaultEvictionSettings: ptr.To(true),
MakeIPTablesUtilChains: ptr.To(true), MakeIPTablesUtilChains: ptr.To(true),
IPTablesMasqueradeBit: ptr.To[int32](1), IPTablesMasqueradeBit: ptr.To[int32](1),
IPTablesDropBit: ptr.To[int32](1), IPTablesDropBit: ptr.To[int32](1),
@ -748,6 +753,7 @@ func TestSetDefaultsKubeletConfiguration(t *testing.T) {
MaxParallelImagePulls: nil, MaxParallelImagePulls: nil,
EvictionHard: nil, EvictionHard: nil,
EvictionPressureTransitionPeriod: metav1.Duration{Duration: 5 * time.Minute}, EvictionPressureTransitionPeriod: metav1.Duration{Duration: 5 * time.Minute},
MergeDefaultEvictionSettings: ptr.To(false),
EnableControllerAttachDetach: ptr.To(true), EnableControllerAttachDetach: ptr.To(true),
MakeIPTablesUtilChains: ptr.To(true), MakeIPTablesUtilChains: ptr.To(true),
IPTablesMasqueradeBit: ptr.To[int32](DefaultIPTablesMasqueradeBit), IPTablesMasqueradeBit: ptr.To[int32](DefaultIPTablesMasqueradeBit),
@ -843,6 +849,7 @@ func TestSetDefaultsKubeletConfiguration(t *testing.T) {
MaxParallelImagePulls: ptr.To[int32](5), MaxParallelImagePulls: ptr.To[int32](5),
EvictionHard: nil, EvictionHard: nil,
EvictionPressureTransitionPeriod: metav1.Duration{Duration: 5 * time.Minute}, EvictionPressureTransitionPeriod: metav1.Duration{Duration: 5 * time.Minute},
MergeDefaultEvictionSettings: ptr.To(false),
EnableControllerAttachDetach: ptr.To(true), EnableControllerAttachDetach: ptr.To(true),
MakeIPTablesUtilChains: ptr.To(true), MakeIPTablesUtilChains: ptr.To(true),
IPTablesMasqueradeBit: ptr.To[int32](DefaultIPTablesMasqueradeBit), IPTablesMasqueradeBit: ptr.To[int32](DefaultIPTablesMasqueradeBit),
@ -938,6 +945,7 @@ func TestSetDefaultsKubeletConfiguration(t *testing.T) {
MaxParallelImagePulls: ptr.To[int32](1), MaxParallelImagePulls: ptr.To[int32](1),
EvictionHard: nil, EvictionHard: nil,
EvictionPressureTransitionPeriod: metav1.Duration{Duration: 5 * time.Minute}, EvictionPressureTransitionPeriod: metav1.Duration{Duration: 5 * time.Minute},
MergeDefaultEvictionSettings: ptr.To(false),
EnableControllerAttachDetach: ptr.To(true), EnableControllerAttachDetach: ptr.To(true),
MakeIPTablesUtilChains: ptr.To(true), MakeIPTablesUtilChains: ptr.To(true),
IPTablesMasqueradeBit: ptr.To[int32](DefaultIPTablesMasqueradeBit), IPTablesMasqueradeBit: ptr.To[int32](DefaultIPTablesMasqueradeBit),
@ -1033,6 +1041,7 @@ func TestSetDefaultsKubeletConfiguration(t *testing.T) {
MaxParallelImagePulls: nil, MaxParallelImagePulls: nil,
EvictionHard: nil, EvictionHard: nil,
EvictionPressureTransitionPeriod: metav1.Duration{Duration: 5 * time.Minute}, EvictionPressureTransitionPeriod: metav1.Duration{Duration: 5 * time.Minute},
MergeDefaultEvictionSettings: ptr.To(false),
EnableControllerAttachDetach: ptr.To(true), EnableControllerAttachDetach: ptr.To(true),
MakeIPTablesUtilChains: ptr.To(true), MakeIPTablesUtilChains: ptr.To(true),
IPTablesMasqueradeBit: ptr.To[int32](DefaultIPTablesMasqueradeBit), IPTablesMasqueradeBit: ptr.To[int32](DefaultIPTablesMasqueradeBit),

View File

@ -483,6 +483,9 @@ func autoConvert_v1beta1_KubeletConfiguration_To_config_KubeletConfiguration(in
out.EvictionPressureTransitionPeriod = in.EvictionPressureTransitionPeriod out.EvictionPressureTransitionPeriod = in.EvictionPressureTransitionPeriod
out.EvictionMaxPodGracePeriod = in.EvictionMaxPodGracePeriod out.EvictionMaxPodGracePeriod = in.EvictionMaxPodGracePeriod
out.EvictionMinimumReclaim = *(*map[string]string)(unsafe.Pointer(&in.EvictionMinimumReclaim)) out.EvictionMinimumReclaim = *(*map[string]string)(unsafe.Pointer(&in.EvictionMinimumReclaim))
if err := v1.Convert_Pointer_bool_To_bool(&in.MergeDefaultEvictionSettings, &out.MergeDefaultEvictionSettings, s); err != nil {
return err
}
out.PodsPerCore = in.PodsPerCore out.PodsPerCore = in.PodsPerCore
if err := v1.Convert_Pointer_bool_To_bool(&in.EnableControllerAttachDetach, &out.EnableControllerAttachDetach, s); err != nil { if err := v1.Convert_Pointer_bool_To_bool(&in.EnableControllerAttachDetach, &out.EnableControllerAttachDetach, s); err != nil {
return err return err
@ -685,6 +688,9 @@ func autoConvert_config_KubeletConfiguration_To_v1beta1_KubeletConfiguration(in
out.EvictionPressureTransitionPeriod = in.EvictionPressureTransitionPeriod out.EvictionPressureTransitionPeriod = in.EvictionPressureTransitionPeriod
out.EvictionMaxPodGracePeriod = in.EvictionMaxPodGracePeriod out.EvictionMaxPodGracePeriod = in.EvictionMaxPodGracePeriod
out.EvictionMinimumReclaim = *(*map[string]string)(unsafe.Pointer(&in.EvictionMinimumReclaim)) out.EvictionMinimumReclaim = *(*map[string]string)(unsafe.Pointer(&in.EvictionMinimumReclaim))
if err := v1.Convert_bool_To_Pointer_bool(&in.MergeDefaultEvictionSettings, &out.MergeDefaultEvictionSettings, s); err != nil {
return err
}
out.PodsPerCore = in.PodsPerCore out.PodsPerCore = in.PodsPerCore
if err := v1.Convert_bool_To_Pointer_bool(&in.EnableControllerAttachDetach, &out.EnableControllerAttachDetach, s); err != nil { if err := v1.Convert_bool_To_Pointer_bool(&in.EnableControllerAttachDetach, &out.EnableControllerAttachDetach, s); err != nil {
return err return err

View File

@ -546,6 +546,16 @@ type KubeletConfiguration struct {
// Default: nil // Default: nil
// +optional // +optional
EvictionMinimumReclaim map[string]string `json:"evictionMinimumReclaim,omitempty"` EvictionMinimumReclaim map[string]string `json:"evictionMinimumReclaim,omitempty"`
// mergeDefaultEvictionSettings indicates that defaults for the evictionHard, evictionSoft, evictionSoftGracePeriod, and evictionMinimumReclaim
// fields should be merged into values specified for those fields in this configuration.
// Signals specified in this configuration take precedence.
// Signals not specified in this configuration inherit their defaults.
// If false, and if any signal is specified in this configuration then other signals that
// are not specified in this configuration will be set to 0.
// It applies to merging the fields for which the default exists, and currently only evictionHard has default values.
// Default: false
// +optional
MergeDefaultEvictionSettings *bool `json:"mergeDefaultEvictionSettings,omitempty"`
// podsPerCore is the maximum number of pods per core. Cannot exceed maxPods. // podsPerCore is the maximum number of pods per core. Cannot exceed maxPods.
// The value must be a non-negative integer. // The value must be a non-negative integer.
// If 0, there is no limit on the number of Pods. // If 0, there is no limit on the number of Pods.

View File

@ -372,6 +372,11 @@ func (in *KubeletConfiguration) DeepCopyInto(out *KubeletConfiguration) {
(*out)[key] = val (*out)[key] = val
} }
} }
if in.MergeDefaultEvictionSettings != nil {
in, out := &in.MergeDefaultEvictionSettings, &out.MergeDefaultEvictionSettings
*out = new(bool)
**out = **in
}
if in.EnableControllerAttachDetach != nil { if in.EnableControllerAttachDetach != nil {
in, out := &in.EnableControllerAttachDetach, &out.EnableControllerAttachDetach in, out := &in.EnableControllerAttachDetach, &out.EnableControllerAttachDetach
*out = new(bool) *out = new(bool)