Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow arbitrary extra kubeadm config.yaml snippets #141

Merged
merged 1 commit into from
Aug 1, 2018
Merged
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
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,12 @@ The name of the cloud provider configured in `/etc/kubernetes/cloud-config`.

Defaults to `undef`.

#### `kubeadm_extra_config`

A hash containing extra configuration data to be serialised with `to_yaml` and appended to the config.yaml file used by kubeadm.

Defaults to `{}`.

#### `kubernetes_apt_location`
The APT repo URL for the Kubernetes packages.

Expand Down
5 changes: 4 additions & 1 deletion manifests/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
String $service_cidr = $kubernetes::service_cidr,
String $node_label = $kubernetes::node_label,
Optional[String] $cloud_provider = $kubernetes::cloud_provider,

Hash $kubeadm_extra_config = $kubernetes::kubeadm_extra_config,
) {

$kube_dirs = ['/etc/kubernetes','/etc/kubernetes/manifests','/etc/kubernetes/pki','/etc/kubernetes/pki/etcd']
Expand Down Expand Up @@ -63,6 +63,9 @@
content => template('kubernetes/etcd/etcd.service.erb'),
}

# to_yaml emits a complete YAML document, so we must remove the leading '---'
$kubeadm_extra_config_yaml = regsubst(to_yaml($kubeadm_extra_config), '^---\n', '')

file { '/etc/kubernetes/config.yaml':
ensure => present,
content => template('kubernetes/config.yaml.erb'),
Expand Down
5 changes: 5 additions & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,10 @@
# Note: this file is not managed within this module and must be present before bootstrapping the kubernetes controller
# Defaults to undef
#
# [*kubeadm_extra_config*]
# A hash containing extra configuration data to be serialised with `to_yaml` and appended to the config.yaml file used by kubeadm.
# Defaults to {}
#
# [*kubernetes_apt_location*]
# The APT repo URL for the Kubernetes packages.
# Defaults to https://apt.kubernetes.io
Expand Down Expand Up @@ -305,6 +309,7 @@
String $node_label = $kubernetes::params::node_label,
Optional[String] $controller_address = $kubernetes::params::controller_address,
Optional[String] $cloud_provider = $kubernetes::params::cloud_provider,
Hash $kubeadm_extra_config = $kubernetes::params::kubeadm_extra_config,
Optional[String] $runc_source = $kubernetes::params::runc_source,
Optional[String] $containerd_archive = $kubernetes::params::containerd_archive,
Optional[String] $containerd_source = $kubernetes::params::containerd_source,
Expand Down
1 change: 1 addition & 0 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
$service_cidr = '10.96.0.0/12'
$controller_address = undef
$cloud_provider = undef
$kubeadm_extra_config = {}
$kubernetes_apt_location = 'http://apt.kubernetes.io'
$kubernetes_apt_release = "kubernetes-${::lsbdistcodename}"
$kubernetes_apt_repos = 'main'
Expand Down
2 changes: 2 additions & 0 deletions spec/classes/config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
'service_cidr' => '10.96.0.0/12',
'node_label' => 'foo',
'cloud_provider' => 'undef',
'kubeadm_extra_config' => {'foo' => ['bar', 'baz']},
}
end

Expand All @@ -53,5 +54,6 @@

it { should contain_file('/etc/systemd/system/etcd.service') }
it { should contain_file('/etc/kubernetes/config.yaml') }
it { should contain_file('/etc/kubernetes/config.yaml').with_content(/foo:\n- bar\n- baz/) }
end
end
10 changes: 6 additions & 4 deletions spec/classes/service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@
apiserver_extra_arguments => ["foo"],
service_cidr => "10.96.0.0/12",
node_label => "foo",
cloud_provider => ":undef",}
' }
cloud_provider => ":undef",
kubeadm_extra_config => {"foo" => ["bar", "baz"]},
}' }
let(:params) do
{
'container_runtime' => 'cri_containerd',
Expand Down Expand Up @@ -89,8 +90,9 @@
apiserver_extra_arguments => ["foo"],
service_cidr => "10.96.0.0/12",
node_label => "foo",
cloud_provider => ":undef",}
' }
cloud_provider => ":undef",
kubeadm_extra_config => {"foo" => ["bar", "baz"]},
}' }
let(:params) do
{
'container_runtime' => 'docker',
Expand Down
1 change: 1 addition & 0 deletions templates/config.yaml.erb
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,4 @@ apiServerCertSANs:
<%- if @cloud_provider -%>
cloudProvider: <%= @cloud_provider %>
<%- end -%>
<%= @kubeadm_extra_config_yaml %>