Skip to content
This repository was archived by the owner on Jan 9, 2023. It is now read-only.

Commit 68ce8b9

Browse files
authored
Merge pull request #296 from dippynark/294-support-hard-and-soft-eviction
Support hard and soft evictions
2 parents 818e20a + 08197b4 commit 68ce8b9

File tree

3 files changed

+123
-4
lines changed

3 files changed

+123
-4
lines changed

puppet/modules/kubernetes/manifests/kubelet.pp

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,21 @@
1010
String $role = 'worker',
1111
String $container_runtime = 'docker',
1212
String $kubelet_dir = '/var/lib/kubelet',
13-
String $hard_eviction_memory_threshold =
14-
five_percent_of_total_ram(dig44($facts, ['memory', 'system', 'total_bytes'], 1)),
13+
Optional[String] $eviction_hard_memory_available_threshold = '5%',
14+
Optional[String] $eviction_hard_nodefs_available_threshold = '10%',
15+
Optional[String] $eviction_hard_nodefs_inodes_free_threshold = '5%',
16+
Boolean $eviction_soft_enabled = true,
17+
Optional[String] $eviction_soft_memory_available_threshold = '10%',
18+
Optional[String] $eviction_soft_nodefs_available_threshold = '15%',
19+
Optional[String] $eviction_soft_nodefs_inodes_free_threshold = '10%',
20+
Optional[String] $eviction_soft_memory_available_grace_period = '0m',
21+
Optional[String] $eviction_soft_nodefs_available_grace_period = '0m',
22+
Optional[String] $eviction_soft_nodefs_inodes_free_grace_period = '0m',
23+
String $eviction_max_pod_grace_period = '-1',
24+
String $eviction_pressure_transition_period = '2m',
25+
Optional[String] $eviction_minimum_reclaim_memory_available = '100Mi',
26+
Optional[String] $eviction_minimum_reclaim_nodefs_available = '1Gi',
27+
Optional[String] $eviction_minimum_reclaim_nodefs_inodes_free = undef,
1528
Optional[String] $network_plugin = undef,
1629
Integer $network_plugin_mtu = 1460,
1730
Boolean $allow_privileged = true,
@@ -43,6 +56,30 @@
4356
){
4457
require ::kubernetes
4558

59+
if ! $eviction_soft_memory_available_threshold or ! $eviction_soft_memory_available_grace_period {
60+
$_eviction_soft_memory_available_threshold = undef
61+
$_eviction_soft_memory_available_grace_period = undef
62+
} else {
63+
$_eviction_soft_memory_available_threshold = $eviction_soft_memory_available_threshold
64+
$_eviction_soft_memory_available_grace_period = $eviction_soft_memory_available_grace_period
65+
}
66+
67+
if ! $eviction_soft_nodefs_available_threshold or ! $eviction_soft_nodefs_available_grace_period {
68+
$_eviction_soft_nodefs_available_threshold = undef
69+
$_eviction_soft_nodefs_available_grace_period = undef
70+
} else {
71+
$_eviction_soft_nodefs_available_threshold = $eviction_soft_nodefs_available_threshold
72+
$_eviction_soft_nodefs_available_grace_period = $eviction_soft_nodefs_available_grace_period
73+
}
74+
75+
if ! $eviction_soft_nodefs_inodes_free_threshold or ! $eviction_soft_nodefs_inodes_free_grace_period {
76+
$_eviction_soft_nodefs_inodes_free_threshold = undef
77+
$_eviction_soft_nodefs_inodes_free_grace_period = undef
78+
} else {
79+
$_eviction_soft_nodefs_inodes_free_threshold = $eviction_soft_nodefs_inodes_free_threshold
80+
$_eviction_soft_nodefs_inodes_free_grace_period = $eviction_soft_nodefs_inodes_free_grace_period
81+
}
82+
4683
$_systemd_wants = $systemd_wants
4784
if $container_runtime == 'docker' {
4885
$_systemd_after = ['docker.service'] + $systemd_after

puppet/modules/kubernetes/spec/classes/kubelet_spec.rb

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,43 @@
2020
should_not contain_file(service_file).with_content(/--network-plugin/)
2121
should contain_file(service_file).with_content(/--container-runtime=docker/)
2222
should contain_file(service_file).with_content(%r{--kubeconfig=/etc/kubernetes/kubeconfig-kubelet})
23-
should contain_file(service_file).with_content(%r{--eviction-hard=memory.available<191Mi})
23+
should contain_file(service_file).with_content(%r{--eviction-hard=memory.available<5%})
24+
should contain_file(service_file).with_content(%r{--eviction-minimum-reclaim=memory.available=100Mi,nodefs.available=1Gi})
25+
should contain_file(service_file).with_content(%r{--eviction-soft=memory.available<10%,nodefs.available<15%,nodefs.inodesFree<10%})
26+
should contain_file(service_file).with_content(%r{--eviction-soft-grace-period=memory.available=0m,nodefs.available=0m,nodefs.inodesFree=0m})
27+
should contain_file(service_file).with_content(%r{--eviction-max-pod-grace-period=-1})
28+
should contain_file(service_file).with_content(%r{--eviction-pressure-transition-period=2m})
29+
end
30+
end
31+
32+
context 'without soft evictions' do
33+
let(:params) { {
34+
"eviction_soft_enabled" => false
35+
}}
36+
it do
37+
should_not contain_file(service_file).with_content(%r{--eviction-soft})
38+
should_not contain_file(service_file).with_content(%r{--eviction-soft-grace-period})
39+
should_not contain_file(service_file).with_content(%r{--eviction-max-pod-grace-period})
40+
should_not contain_file(service_file).with_content(%r{--eviction-pressure-transition-period})
41+
should contain_file(service_file).with_content(%r{--eviction-hard=memory.available<5%})
42+
should contain_file(service_file).with_content(%r{--eviction-minimum-reclaim=memory.available=100Mi,nodefs.available=1Gi})
43+
end
44+
end
45+
46+
context 'soft evictions with modifications' do
47+
let(:params) { {
48+
"eviction_soft_memory_available_threshold" => '15%',
49+
"eviction_minimum_reclaim_nodefs_available" => '2Gi',
50+
"eviction_soft_nodefs_inodes_free_grace_period" => '1m',
51+
"eviction_max_pod_grace_period" => '300',
52+
"eviction_pressure_transition_period" => '5m'
53+
}}
54+
it do
55+
should contain_file(service_file).with_content(%r{--eviction-soft=memory.available<15%,nodefs.available<15%,nodefs.inodesFree<10%})
56+
should contain_file(service_file).with_content(%r{--eviction-minimum-reclaim=memory.available=100Mi,nodefs.available=2Gi})
57+
should contain_file(service_file).with_content(%r{--eviction-soft-grace-period=memory.available=0m,nodefs.available=0m,nodefs.inodesFree=1m})
58+
should contain_file(service_file).with_content(%r{--eviction-max-pod-grace-period=300})
59+
should contain_file(service_file).with_content(%r{--eviction-pressure-transition-period=5m})
2460
end
2561
end
2662

puppet/modules/kubernetes/templates/kubelet.service.erb

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,53 @@ ExecStart=<%= scope['kubernetes::_dest_dir'] %>/kubelet \
103103
"--tls-cert-file=<%= @cert_file %>" \
104104
"--tls-private-key-file=<%= @key_file %>" \
105105
<% end -%>
106-
"--eviction-hard=memory.available<<%= @hard_eviction_memory_threshold %>" \
106+
<%
107+
# build eviction hard command line
108+
@eviction_hard = []
109+
@eviction_hard << "memory.available<#{@eviction_hard_memory_available_threshold}" unless @eviction_hard_memory_available_threshold.nil? or @eviction_hard_memory_available_threshold == 'nil'
110+
@eviction_hard << "nodefs.available<#{@eviction_hard_nodefs_available_threshold}" unless @eviction_hard_nodefs_available_threshold.nil? or @eviction_hard_nodefs_available_threshold == 'nil'
111+
@eviction_hard << "nodefs.inodesFree<#{@eviction_hard_nodefs_inodes_free_threshold}" unless @eviction_hard_nodefs_inodes_free_threshold.nil? or @eviction_hard_nodefs_inodes_free_threshold == 'nil'
112+
-%>
113+
<% if @eviction_hard.length > 0 -%>
114+
"--eviction-hard=<%= @eviction_hard.join(',') %>" \
115+
<% end -%>
116+
<% if @eviction_soft_enabled -%>
117+
<%
118+
# build eviction soft command line
119+
@eviction_soft = []
120+
121+
@eviction_soft << "memory.available<#{@_eviction_soft_memory_available_threshold}" unless @_eviction_soft_memory_available_threshold.nil? or @_eviction_soft_memory_available_threshold == 'nil'
122+
@eviction_soft << "nodefs.available<#{@_eviction_soft_nodefs_available_threshold}" unless @_eviction_soft_nodefs_available_threshold.nil? or @_eviction_soft_nodefs_available_threshold == 'nil'
123+
@eviction_soft << "nodefs.inodesFree<#{@_eviction_soft_nodefs_inodes_free_threshold}" unless @_eviction_soft_nodefs_inodes_free_threshold.nil? or @_eviction_soft_nodefs_inodes_free_threshold == 'nil'
124+
-%>
125+
<% if @eviction_soft.length > 0 -%>
126+
<%
127+
# build eviction soft grace period command line
128+
@eviction_soft_grace_period = []
129+
130+
@eviction_soft_grace_period << "memory.available=#{@_eviction_soft_memory_available_grace_period}" unless @_eviction_soft_memory_available_grace_period.nil? or @_eviction_soft_memory_available_grace_period == 'nil'
131+
@eviction_soft_grace_period << "nodefs.available=#{@_eviction_soft_nodefs_available_grace_period}" unless @_eviction_soft_nodefs_available_grace_period.nil? or @_eviction_soft_nodefs_available_grace_period == 'nil'
132+
@eviction_soft_grace_period << "nodefs.inodesFree=#{@_eviction_soft_nodefs_inodes_free_grace_period}" unless @_eviction_soft_nodefs_inodes_free_grace_period.nil? or @_eviction_soft_nodefs_inodes_free_grace_period == 'nil'
133+
-%>
134+
<% if @eviction_soft_grace_period.length > 0 -%>
135+
--eviction-soft=<%= @eviction_soft.join(',') %> \
136+
--eviction-soft-grace-period=<%= @eviction_soft_grace_period.join(',') %> \
137+
--eviction-max-pod-grace-period=<%= @eviction_max_pod_grace_period %> \
138+
--eviction-pressure-transition-period=<%= @eviction_pressure_transition_period %> \
139+
<% end -%>
140+
<% end -%>
141+
<% end -%>
142+
<%
143+
# build minumum reclaim command line
144+
@eviction_minimum_reclaim = []
145+
146+
@eviction_minimum_reclaim << "memory.available=#{@eviction_minimum_reclaim_memory_available}" unless @eviction_minimum_reclaim_memory_available.nil? or @eviction_minimum_reclaim_memory_available == 'nil'
147+
@eviction_minimum_reclaim << "nodefs.available=#{@eviction_minimum_reclaim_nodefs_available}" unless @eviction_minimum_reclaim_nodefs_available.nil? or @eviction_minimum_reclaim_nodefs_available == 'nil'
148+
@eviction_minimum_reclaim << "nodefs.inodesFree=#{@eviction_minimum_reclaim_nodefs_inodes_free}" unless @eviction_minimum_reclaim_nodefs_inodes_free.nil? or @eviction_minimum_reclaim_nodefs_inodes_free == 'nil'
149+
-%>
150+
<% if @eviction_minimum_reclaim.length > 0 -%>
151+
"--eviction-minimum-reclaim=<%= @eviction_minimum_reclaim.join(',') %>" \
152+
<% end -%>
107153
<% if @_feature_gates != [] -%>
108154
--feature-gates=<%= @_feature_gates.join(',') %> \
109155
<% end -%>

0 commit comments

Comments
 (0)