Skip to content

Commit 74dec8d

Browse files
authored
add new parameter node_extra_taints (puppetlabs#586)
1 parent 6e259d1 commit 74dec8d

File tree

8 files changed

+108
-3
lines changed

8 files changed

+108
-3
lines changed

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -821,6 +821,19 @@ An override to the label of a node.
821821

822822
Defaults to `hostname`.
823823

824+
#### `node_extra_taints`
825+
826+
Additional taints for node.
827+
Defaults to `undef`.
828+
829+
For example,
830+
831+
```puppet
832+
[{'key' => 'dedicated','value' => 'NewNode','effect' => 'NoSchedule', 'operator', => 'Equal'}]
833+
```
834+
835+
About kubernetes taints `https://kubernetes.io/docs/concepts/scheduling-eviction/taint-and-toleration/`
836+
824837
#### `runc_source`
825838

826839
The download URL for `runc`.

manifests/config/worker.pp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
Optional[String] $feature_gates = undef,
1515
Optional[String] $cloud_provider = $kubernetes::cloud_provider,
1616
Optional[String] $cloud_config = $kubernetes::cloud_config,
17+
Optional[Array[Hash]] $node_extra_taints = $kubernetes::node_extra_taints,
1718
Optional[Array] $kubelet_extra_arguments = $kubernetes::kubelet_extra_arguments,
1819
Optional[Hash] $kubelet_extra_config = $kubernetes::kubelet_extra_config,
1920
Optional[Array] $ignore_preflight_errors = undef,

manifests/init.pp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,12 @@
326326
# Defaults to hostname.
327327
# NOTE: Ignored when cloud_provider is AWS, until this lands fixed https://github.com/kubernetes/kubernetes/pull/61878
328328
#
329+
# [*node_extra_taints*]
330+
# Additional taints for node.
331+
# Example:
332+
# [{'key' => 'dedicated','value' => 'NewNode','effect' => 'NoSchedule', 'operator' => 'Equal'}]
333+
# Defaults to undef
334+
#
329335
# [*token*]
330336
# A string to use when joining nodes to the cluster. Must be in the form of '[a-z0-9]{6}.[a-z0-9]{16}'
331337
# Defaults to undef
@@ -643,7 +649,8 @@
643649
Array $controllermanager_extra_arguments = [],
644650
Array $scheduler_extra_arguments = [],
645651
String $service_cidr = '10.96.0.0/12',
646-
Optional[Stdlib::Fqdn] $node_label = undef,
652+
Optional[String] $node_label = undef,
653+
Optional[Array[Hash]] $node_extra_taints = undef,
647654
Optional[String] $controller_address = undef,
648655
Optional[String] $cloud_provider = undef,
649656
Optional[String] $cloud_config = undef,

spec/classes/config/worker_spec.rb

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,38 @@
7272
expect(config_yaml['nodeRegistration']['kubeletExtraArgs']).to include('cloud-provider' => 'aws')
7373
end
7474
end
75+
76+
context 'with version => 1.20.0 and node_extra_taints => [{key => key1, value => NewNode, effect => NoSchedule, operator => Equal}' do
77+
let(:params) do
78+
{
79+
'kubernetes_version' => '1.20.0',
80+
'node_extra_taints' => [
81+
{
82+
'key' => 'key1',
83+
'value' => 'NewNode',
84+
'effect' => 'NoSchedule',
85+
'operator' => 'Equal',
86+
},
87+
{
88+
'key' => 'key2',
89+
'value' => 'NewNode',
90+
'effect' => 'NoSchedule',
91+
'operator' => 'Equal',
92+
},
93+
],
94+
}
95+
end
96+
97+
let(:config_yaml) { YAML.safe_load(catalogue.resource('file', '/etc/kubernetes/config.yaml').send(:parameters)[:content]) }
98+
99+
it 'has arg key1 in first YAML document (taints) NodeRegistration' do
100+
expect(config_yaml['nodeRegistration']['taints'][0]['key']).to include('key1')
101+
end
102+
it 'has arg key2 in first YAML document (taints) NodeRegistration' do
103+
expect(config_yaml['nodeRegistration']['taints'][1]['key']).to include('key2')
104+
end
105+
it 'has arg effect in first YAML document (taints) NodeRegistration' do
106+
expect(config_yaml['nodeRegistration']['taints'][0]['effect']).to include('NoSchedule')
107+
end
108+
end
75109
end

templates/v1alpha3/config_worker.yaml.erb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,19 @@ tlsBootstrapToken: <%= @tls_bootstrap_token %>
2222
token: <%= @token %>
2323
nodeRegistration:
2424
name: <%= @node_name %>
25+
<%- if @node_extra_taints -%>
26+
taints:
27+
<%- @node_extra_taints.each do |item| -%>
28+
- key: <%= item['key'] %>
29+
<%- if item['value'] -%>
30+
value: <%= item['value'] %>
31+
<%- end -%>
32+
<%- if item['operator'] -%>
33+
operator: <%= item['operator'] %>
34+
<%- end -%>
35+
effect: <%= item['effect'] %>
36+
<%- end -%>
37+
<%- end -%>
2538
<%- if @container_runtime == "cri_containerd" -%>
2639
criSocket: unix:///run/containerd/containerd.sock
2740
<%- end -%>

templates/v1beta1/config_worker.yaml.erb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,19 @@ discovery:
1212
- 'sha256:<%= @discovery_token_hash %>'
1313
nodeRegistration:
1414
name: <%= @node_name %>
15+
<%- if @node_extra_taints -%>
16+
taints:
17+
<%- @node_extra_taints.each do |item| -%>
18+
- key: <%= item['key'] %>
19+
<%- if item['value'] -%>
20+
value: <%= item['value'] %>
21+
<%- end -%>
22+
<%- if item['operator'] -%>
23+
operator: <%= item['operator'] %>
24+
<%- end -%>
25+
effect: <%= item['effect'] %>
26+
<%- end -%>
27+
<%- end -%>
1528
<%- if @container_runtime == "cri_containerd" -%>
1629
criSocket: unix:///run/containerd/containerd.sock
1730
<%- end -%>

templates/v1beta2/config_worker.yaml.erb

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,21 @@ discovery:
1515
- 'sha256:<%= @discovery_token_hash %>'
1616
nodeRegistration:
1717
name: <%= @node_name %>
18+
<%- if @node_extra_taints -%>
19+
taints:
20+
<%- @node_extra_taints.each do |item| -%>
21+
- key: <%= item['key'] %>
22+
<%- if item['value'] -%>
23+
value: <%= item['value'] %>
24+
<%- end -%>
25+
<%- if item['operator'] -%>
26+
operator: <%= item['operator'] %>
27+
<%- end -%>
28+
effect: <%= item['effect'] %>
29+
<%- end -%>
30+
<%- end -%>
1831
<%- if @container_runtime == "cri_containerd" -%>
1932
criSocket: unix:///run/containerd/containerd.sock
20-
taints: null
2133
<%- end -%>
2234
kubeletExtraArgs:
2335
<%- if @cloud_provider -%>

templates/v1beta3/config_worker.yaml.erb

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,21 @@ discovery:
1414
- 'sha256:<%= @discovery_token_hash %>'
1515
nodeRegistration:
1616
name: <%= @node_name %>
17+
<%- if @node_extra_taints -%>
18+
taints:
19+
<%- @node_extra_taints.each do |item| -%>
20+
- key: <%= item['key'] %>
21+
<%- if item['value'] -%>
22+
value: <%= item['value'] %>
23+
<%- end -%>
24+
<%- if item['operator'] -%>
25+
operator: <%= item['operator'] %>
26+
<%- end -%>
27+
effect: <%= item['effect'] %>
28+
<%- end -%>
29+
<%- end -%>
1730
<%- if @container_runtime == "cri_containerd" -%>
1831
criSocket: unix:///run/containerd/containerd.sock
19-
taints: null
2032
<%- end -%>
2133
kubeletExtraArgs:
2234
<%- if @cloud_provider -%>

0 commit comments

Comments
 (0)