Skip to content

Commit 1c0fbad

Browse files
committed
Allow mounting extra volumes to apiserver pod
In some environments, additional volumes are rqeuired for the apiserver to function as expected. For example, on CentOS 7 controller nodes, the host CA certificate bundles mounted at /etc/ssl/certs are broken since this directory contains symlinks pointing to an unmounted path. In other environments this may be used to provision a specific directory which is referred to by other apiserver arugments, e.g. "--oidc-ca-file".
1 parent 970891b commit 1c0fbad

File tree

9 files changed

+38
-4
lines changed

9 files changed

+38
-4
lines changed

manifests/config.pp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
Optional[String] $apiserver_crt = $kubernetes::apiserver_crt,
4545
Optional[String] $apiserver_key = $kubernetes::apiserver_key,
4646
Array $apiserver_extra_arguments = $kubernetes::apiserver_extra_arguments,
47+
Array $apiserver_extra_volumes = $kubernetes::apiserver_extra_volumes,
4748
Optional[String] $ca_crt = $kubernetes::ca_crt,
4849
Optional[String] $ca_key = $kubernetes::ca_key,
4950
Optional[String] $front_proxy_ca_crt = $kubernetes::front_proxy_ca_crt,

manifests/init.pp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,6 @@
5959
# An example with hiera would be kubernetes::kube_api_advertise_address: "%{::ipaddress_enp0s8}"
6060
# defaults to undef
6161
#
62-
# [*$apiserver_extra_arguments*]
63-
# This is an array to pass extra configuration to the Kubernetes api.
64-
# Defaults to []
65-
#
6662
# [*etcd_version*]
6763
# The version of etcd that you would like to use.
6864
# Defaults to 3.0.17
@@ -169,6 +165,11 @@
169165
# A string array of extra arguments to be passed to the api server.
170166
# Defaults to []
171167
#
168+
# [*apiserver_extra_volumes*]
169+
# An array of objects describing additional volumes and volumeMounts to be configured in the api server pod. Each
170+
# value should be a hash with `name`, `hostPath`, `mountPath`, and `readOnly` properties.
171+
# Defaults to []
172+
#
172173
# [*ca_crt*]
173174
# The clusters ca certificate. Must be passed as cert not a file.
174175
# Defaults to undef
@@ -281,6 +282,7 @@
281282
Optional[String] $apiserver_crt = $kubernetes::params::apiserver_crt,
282283
Optional[String] $apiserver_key = $kubernetes::params::apiserver_key,
283284
Array $apiserver_extra_arguments = $kubernetes::params::apiserver_extra_arguments,
285+
Array $apiserver_extra_volumes = $kubernetes::params::apiserver_extra_volumes,
284286
Optional[String] $ca_crt = $kubernetes::params::ca_crt,
285287
Optional[String] $ca_key = $kubernetes::params::ca_key,
286288
Optional[String] $front_proxy_ca_crt = $kubernetes::params::front_proxy_ca_crt,

manifests/params.pp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
$apiserver_crt = undef
5353
$apiserver_key = undef
5454
$apiserver_extra_arguments = []
55+
$apiserver_extra_volumes = []
5556
$ca_crt = undef
5657
$ca_key = undef
5758
$front_proxy_ca_crt = undef

spec/classes/cluster_roles_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
apiserver_crt => "foo",
4343
apiserver_key => "foo",
4444
apiserver_extra_arguments => ["--some-extra-arg=foo"],
45+
apiserver_extra_volumes => [],
4546
kubernetes_fqdn => "kube.foo.dev",
4647
ca_crt => "foo",
4748
ca_key => "foo",

spec/classes/config_spec.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,12 @@
5757
'apiserver_crt' => 'foo',
5858
'apiserver_key' => 'foo',
5959
'apiserver_extra_arguments' => ['--some-extra-arg=foo'],
60+
'apiserver_extra_volumes' => [{
61+
'name' => 'customvolume',
62+
'hostPath' => '/path/on/host',
63+
'mountPath' => '/path/in/container',
64+
'readOnly' => true,
65+
}],
6066
'kubernetes_fqdn' => 'kube.foo.dev',
6167
'ca_crt' => 'foo',
6268
'ca_key' => 'foo',
@@ -109,6 +115,8 @@
109115
should contain_file('/etc/kubernetes/manifests/kube-apiserver.yaml')
110116
.with_content(/^\s*- --experimental-bootstrap-token-auth=true$/) # with kubernetes_version = 1.7.x
111117
.with_content(/^\s*- --some-extra-arg=foo$/)
118+
.with_content(/^\s*- mountPath: \/path\/in\/container\n\s*name: customvolume\n\s*readOnly: true$/)
119+
.with_content(/^\s*- hostPath:\n\s*path: \/path\/on\/host\n\s*name: customvolume$/)
112120
}
113121
end
114122

@@ -156,6 +164,12 @@
156164
'apiserver_crt' => 'foo',
157165
'apiserver_key' => 'foo',
158166
'apiserver_extra_arguments' => ['--some-extra-arg=foo'],
167+
'apiserver_extra_volumes' => [{
168+
'name' => 'customvolume',
169+
'hostPath' => '/path/on/host',
170+
'mountPath' => '/path/in/container',
171+
'readOnly' => true,
172+
}],
159173
'kubernetes_fqdn' => 'kube.foo.dev',
160174
'ca_crt' => 'foo',
161175
'ca_key' => 'foo',

spec/classes/kube_addons_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
apiserver_crt => "foo",
5555
apiserver_key => "foo",
5656
apiserver_extra_arguments => ["--some-extra-arg=foo"],
57+
apiserver_extra_volumes => [],
5758
kubernetes_fqdn => "kube.foo.dev",
5859
ca_crt => "foo",
5960
ca_key => "foo",

spec/classes/packages_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
apiserver_crt => "foo",
4545
apiserver_key => "foo",
4646
apiserver_extra_arguments => ["--some-extra-arg=foo"],
47+
apiserver_extra_volumes => [],
4748
kubernetes_fqdn => "kube.foo.dev",
4849
ca_crt => "foo",
4950
ca_key => "foo",

spec/classes/service_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
apiserver_crt => "foo",
5555
apiserver_key => "foo",
5656
apiserver_extra_arguments => ["--some-extra-arg=foo"],
57+
apiserver_extra_volumes => [],
5758
kubernetes_fqdn => "kube.foo.dev",
5859
ca_crt => "foo",
5960
ca_key => "foo",

templates/kube-apiserver.yaml.erb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,13 @@ spec:
6868
readOnly: true
6969
- mountPath: /etc/ssl/certs
7070
name: certs
71+
<% @apiserver_extra_volumes.each do |vol| -%>
72+
- mountPath: <%= vol['mountPath'] %>
73+
name: <%= vol['name'] %>
74+
<%- if vol['readOnly'] -%>
75+
readOnly: true
76+
<%- end -%>
77+
<% end -%>
7178
hostNetwork: true
7279
volumes:
7380
- hostPath:
@@ -76,4 +83,9 @@ spec:
7683
- hostPath:
7784
path: /etc/ssl/certs
7885
name: certs
86+
<% @apiserver_extra_volumes.each do |vol| -%>
87+
- hostPath:
88+
path: <%= vol['hostPath'] %>
89+
name: <%= vol['name'] %>
90+
<% end -%>
7991
status: {}

0 commit comments

Comments
 (0)