From 4aff1d9fdbf0f0e04b1157182d5ecc0e8b024a5d Mon Sep 17 00:00:00 2001 From: Vladimir Zhukov Date: Mon, 7 Nov 2022 12:26:34 +0300 Subject: [PATCH] add new parameter node_extra_taints --- README.md | 13 +++++++++ manifests/config/worker.pp | 1 + manifests/init.pp | 7 +++++ spec/classes/config/worker_spec.rb | 34 +++++++++++++++++++++++ templates/v1alpha3/config_worker.yaml.erb | 13 +++++++++ templates/v1beta1/config_worker.yaml.erb | 13 +++++++++ templates/v1beta2/config_worker.yaml.erb | 14 +++++++++- templates/v1beta3/config_worker.yaml.erb | 14 +++++++++- 8 files changed, 107 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index bd820da3..7cb9cdaa 100644 --- a/README.md +++ b/README.md @@ -809,6 +809,19 @@ An override to the label of a node. Defaults to `hostname`. +#### `node_extra_taints` + +Additional taints for node. +Defaults to `undef`. + +For example, + +```puppet + [{'key' => 'dedicated','value' => 'NewNode','effect' => 'NoSchedule', 'operator', => 'Equal'}] +``` + +About kubernetes taints `https://kubernetes.io/docs/concepts/scheduling-eviction/taint-and-toleration/` + #### `runc_source` The download URL for `runc`. diff --git a/manifests/config/worker.pp b/manifests/config/worker.pp index 7ef26718..f2742a98 100644 --- a/manifests/config/worker.pp +++ b/manifests/config/worker.pp @@ -14,6 +14,7 @@ Optional[String] $feature_gates = undef, Optional[String] $cloud_provider = $kubernetes::cloud_provider, Optional[String] $cloud_config = $kubernetes::cloud_config, + Optional[Array[Hash]] $node_extra_taints = $kubernetes::node_extra_taints, Optional[Array] $kubelet_extra_arguments = $kubernetes::kubelet_extra_arguments, Optional[Hash] $kubelet_extra_config = $kubernetes::kubelet_extra_config, Optional[Array] $ignore_preflight_errors = undef, diff --git a/manifests/init.pp b/manifests/init.pp index 761fc152..8d5ee0d7 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -318,6 +318,12 @@ # Defaults to hostname. # NOTE: Ignored when cloud_provider is AWS, until this lands fixed https://github.com/kubernetes/kubernetes/pull/61878 # +# [*node_extra_taints*] +# Additional taints for node. +# Example: +# [{'key' => 'dedicated','value' => 'NewNode','effect' => 'NoSchedule', 'operator' => 'Equal'}] +# Defaults to undef +# # [*token*] # A string to use when joining nodes to the cluster. Must be in the form of '[a-z0-9]{6}.[a-z0-9]{16}' # Defaults to undef @@ -636,6 +642,7 @@ Array $scheduler_extra_arguments = [], String $service_cidr = '10.96.0.0/12', Optional[String] $node_label = undef, + Optional[Array[Hash]] $node_extra_taints = undef, Optional[String] $controller_address = undef, Optional[String] $cloud_provider = undef, Optional[String] $cloud_config = undef, diff --git a/spec/classes/config/worker_spec.rb b/spec/classes/config/worker_spec.rb index 6d7590a6..b46f8ffa 100644 --- a/spec/classes/config/worker_spec.rb +++ b/spec/classes/config/worker_spec.rb @@ -72,4 +72,38 @@ expect(config_yaml['nodeRegistration']['kubeletExtraArgs']).to include('cloud-provider' => 'aws') end end + + context 'with version => 1.20.0 and node_extra_taints => [{key => key1, value => NewNode, effect => NoSchedule, operator => Equal}' do + let(:params) do + { + 'kubernetes_version' => '1.20.0', + 'node_extra_taints' => [ + { + 'key' => 'key1', + 'value' => 'NewNode', + 'effect' => 'NoSchedule', + 'operator' => 'Equal', + }, + { + 'key' => 'key2', + 'value' => 'NewNode', + 'effect' => 'NoSchedule', + 'operator' => 'Equal', + }, + ], + } + end + + let(:config_yaml) { YAML.safe_load(catalogue.resource('file', '/etc/kubernetes/config.yaml').send(:parameters)[:content]) } + + it 'has arg key1 in first YAML document (taints) NodeRegistration' do + expect(config_yaml['nodeRegistration']['taints'][0]['key']).to include('key1') + end + it 'has arg key2 in first YAML document (taints) NodeRegistration' do + expect(config_yaml['nodeRegistration']['taints'][1]['key']).to include('key2') + end + it 'has arg effect in first YAML document (taints) NodeRegistration' do + expect(config_yaml['nodeRegistration']['taints'][0]['effect']).to include('NoSchedule') + end + end end diff --git a/templates/v1alpha3/config_worker.yaml.erb b/templates/v1alpha3/config_worker.yaml.erb index bc35045b..79c4fee9 100644 --- a/templates/v1alpha3/config_worker.yaml.erb +++ b/templates/v1alpha3/config_worker.yaml.erb @@ -22,6 +22,19 @@ tlsBootstrapToken: <%= @tls_bootstrap_token %> token: <%= @token %> nodeRegistration: name: <%= @node_name %> +<%- if @node_extra_taints -%> + taints: + <%- @node_extra_taints.each do |item| -%> + - key: <%= item['key'] %> + <%- if item['value'] -%> + value: <%= item['value'] %> + <%- end -%> + <%- if item['operator'] -%> + operator: <%= item['operator'] %> + <%- end -%> + effect: <%= item['effect'] %> + <%- end -%> +<%- end -%> <%- if @container_runtime == "cri_containerd" -%> criSocket: unix:///run/containerd/containerd.sock <%- end -%> diff --git a/templates/v1beta1/config_worker.yaml.erb b/templates/v1beta1/config_worker.yaml.erb index 5afd48ef..9943b5b3 100644 --- a/templates/v1beta1/config_worker.yaml.erb +++ b/templates/v1beta1/config_worker.yaml.erb @@ -12,6 +12,19 @@ discovery: - 'sha256:<%= @discovery_token_hash %>' nodeRegistration: name: <%= @node_name %> +<%- if @node_extra_taints -%> + taints: + <%- @node_extra_taints.each do |item| -%> + - key: <%= item['key'] %> + <%- if item['value'] -%> + value: <%= item['value'] %> + <%- end -%> + <%- if item['operator'] -%> + operator: <%= item['operator'] %> + <%- end -%> + effect: <%= item['effect'] %> + <%- end -%> +<%- end -%> <%- if @container_runtime == "cri_containerd" -%> criSocket: unix:///run/containerd/containerd.sock <%- end -%> diff --git a/templates/v1beta2/config_worker.yaml.erb b/templates/v1beta2/config_worker.yaml.erb index 14e967c5..65113616 100644 --- a/templates/v1beta2/config_worker.yaml.erb +++ b/templates/v1beta2/config_worker.yaml.erb @@ -15,9 +15,21 @@ discovery: - 'sha256:<%= @discovery_token_hash %>' nodeRegistration: name: <%= @node_name %> +<%- if @node_extra_taints -%> + taints: + <%- @node_extra_taints.each do |item| -%> + - key: <%= item['key'] %> + <%- if item['value'] -%> + value: <%= item['value'] %> + <%- end -%> + <%- if item['operator'] -%> + operator: <%= item['operator'] %> + <%- end -%> + effect: <%= item['effect'] %> + <%- end -%> +<%- end -%> <%- if @container_runtime == "cri_containerd" -%> criSocket: unix:///run/containerd/containerd.sock - taints: null <%- end -%> kubeletExtraArgs: <%- if @cloud_provider -%> diff --git a/templates/v1beta3/config_worker.yaml.erb b/templates/v1beta3/config_worker.yaml.erb index 88e65124..06a37e97 100644 --- a/templates/v1beta3/config_worker.yaml.erb +++ b/templates/v1beta3/config_worker.yaml.erb @@ -14,9 +14,21 @@ discovery: - 'sha256:<%= @discovery_token_hash %>' nodeRegistration: name: <%= @node_name %> +<%- if @node_extra_taints -%> + taints: + <%- @node_extra_taints.each do |item| -%> + - key: <%= item['key'] %> + <%- if item['value'] -%> + value: <%= item['value'] %> + <%- end -%> + <%- if item['operator'] -%> + operator: <%= item['operator'] %> + <%- end -%> + effect: <%= item['effect'] %> + <%- end -%> +<%- end -%> <%- if @container_runtime == "cri_containerd" -%> criSocket: unix:///run/containerd/containerd.sock - taints: null <%- end -%> kubeletExtraArgs: <%- if @cloud_provider -%>