Skip to content
This repository was archived by the owner on Jan 30, 2019. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions lib/puppet/functions/five_percent_of_total_ram.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Puppet::Functions.create_function(:five_percent_of_total_ram) do
dispatch :five_percent_of_total_ram do
param 'Integer', :total_bytes
end

def five_percent_of_total_ram(total_bytes)
five_percent = (total_bytes * 0.05 / 1024**2).round
default = 100

if five_percent < default
'100Mi'
else
five_percent.to_s + 'Mi'
end
end
end
2 changes: 2 additions & 0 deletions manifests/kubelet.pp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
String $role = 'worker',
String $container_runtime = 'docker',
String $kubelet_dir = '/var/lib/kubelet',
String $hard_eviction_memory_threshold =
five_percent_of_total_ram(dig44($facts, ['memory', 'system', 'total_bytes'], 1)),
Optional[String] $network_plugin = undef,
Integer $network_plugin_mtu = 1460,
Boolean $allow_privileged = true,
Expand Down
1 change: 1 addition & 0 deletions spec/classes/kubelet_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
should_not contain_file(service_file).with_content(/--network-plugin/)
should contain_file(service_file).with_content(/--container-runtime=docker/)
should contain_file(service_file).with_content(%r{--kubeconfig=/etc/kubernetes/kubeconfig-kubelet})
should contain_file(service_file).with_content(%r{--eviction-hard="memory.available<191Mi"})
end
end

Expand Down
5 changes: 5 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,10 @@
:path => '/bin:/sbin:/usr/bin:/usr/sbin:/opt/bin',
:osfamily => 'RedHat',
:kernelversion => '3.11.1',
:memory => {
:system => {
:total_bytes => 4_000_000_000,
}
}
}
end
1 change: 1 addition & 0 deletions templates/kubelet.service.erb
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ ExecStart=<%= scope['kubernetes::_dest_dir'] %>/kubelet \
"--tls-cert-file=<%= @cert_file %>" \
"--tls-private-key-file=<%= @key_file %>" \
<% end -%>
--eviction-hard="memory.available<<%= @hard_eviction_memory_threshold %>" \
--logtostderr=true

Restart=on-failure
Expand Down