Skip to content

Commit f77aea1

Browse files
authoredJun 14, 2025··
Cleanup: kubeadm-config v1beta4 extra args defined conditions (#12307)
* Cleanup: kubeadm-config v1beta4 extra args defined conditions Some variables have already been defined, so there is no need to useconditional statements to check whether they have been defined. Signed-off-by: ChengHao Yang <[email protected]> * Cleanup: cloud-provider extra args Signed-off-by: ChengHao Yang <[email protected]> --------- Signed-off-by: ChengHao Yang <[email protected]>
1 parent f810e80 commit f77aea1

File tree

2 files changed

+9
-45
lines changed

2 files changed

+9
-45
lines changed
 

‎roles/kubernetes/control-plane/templates/kubeadm-config.v1beta3.yaml.j2

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -106,18 +106,10 @@ certificatesDir: {{ kube_cert_dir }}
106106
imageRepository: {{ kube_image_repo }}
107107
apiServer:
108108
extraArgs:
109-
{% if kube_apiserver_etcd_compaction_interval is defined %}
110109
etcd-compaction-interval: "{{ kube_apiserver_etcd_compaction_interval }}"
111-
{% endif %}
112-
{% if kube_apiserver_pod_eviction_not_ready_timeout_seconds is defined %}
113110
default-not-ready-toleration-seconds: "{{ kube_apiserver_pod_eviction_not_ready_timeout_seconds }}"
114-
{% endif %}
115-
{% if kube_apiserver_pod_eviction_unreachable_timeout_seconds is defined %}
116111
default-unreachable-toleration-seconds: "{{ kube_apiserver_pod_eviction_unreachable_timeout_seconds }}"
117-
{% endif %}
118-
{% if kube_api_anonymous_auth is defined %}
119112
anonymous-auth: "{{ kube_api_anonymous_auth }}"
120-
{% endif %}
121113
{% if kube_apiserver_use_authorization_config_file %}
122114
authorization-config: "{{ kube_config_dir }}/apiserver-authorization-config-{{ kube_apiserver_authorization_config_api_version }}.yaml"
123115
{% else %}
@@ -150,7 +142,7 @@ apiServer:
150142
{% if kube_apiserver_service_account_lookup %}
151143
service-account-lookup: "{{ kube_apiserver_service_account_lookup }}"
152144
{% endif %}
153-
{% if kube_oidc_auth | default(false) and kube_oidc_url is defined and kube_oidc_client_id is defined %}
145+
{% if kube_oidc_auth and kube_oidc_url is defined and kube_oidc_client_id is defined %}
154146
oidc-issuer-url: "{{ kube_oidc_url }}"
155147
oidc-client-id: "{{ kube_oidc_client_id }}"
156148
{% if kube_oidc_ca_file is defined %}
@@ -169,7 +161,7 @@ apiServer:
169161
oidc-groups-prefix: "{{ kube_oidc_groups_prefix }}"
170162
{% endif %}
171163
{% endif %}
172-
{% if kube_webhook_token_auth | default(false) %}
164+
{% if kube_webhook_token_auth %}
173165
authentication-token-webhook-config-file: {{ kube_config_dir }}/webhook-token-auth-config.yaml
174166
{% endif %}
175167
{% if kube_webhook_authorization and not kube_apiserver_use_authorization_config_file %}
@@ -213,9 +205,7 @@ apiServer:
213205
tls-cipher-suites: {% for tls in tls_cipher_suites %}{{ tls }}{{ "," if not loop.last else "" }}{% endfor %}
214206

215207
{% endif %}
216-
{% if event_ttl_duration is defined %}
217208
event-ttl: {{ event_ttl_duration }}
218-
{% endif %}
219209
{% if kubelet_rotate_server_certificates %}
220210
kubelet-certificate-authority: {{ kube_cert_dir }}/ca.crt
221211
{% endif %}
@@ -229,12 +219,12 @@ apiServer:
229219
hostPath: {{ kube_token_dir }}
230220
mountPath: {{ kube_token_dir }}
231221
{% endif %}
232-
{% if kube_webhook_token_auth | default(false) %}
222+
{% if kube_webhook_token_auth %}
233223
- name: webhook-token-auth-config
234224
hostPath: {{ kube_config_dir }}/webhook-token-auth-config.yaml
235225
mountPath: {{ kube_config_dir }}/webhook-token-auth-config.yaml
236226
{% endif %}
237-
{% if kube_webhook_authorization | default(false) %}
227+
{% if kube_webhook_authorization %}
238228
- name: webhook-authorization-config
239229
hostPath: {{ kube_config_dir }}/webhook-authorization-config.yaml
240230
mountPath: {{ kube_config_dir }}/webhook-authorization-config.yaml

‎roles/kubernetes/control-plane/templates/kubeadm-config.v1beta4.yaml.j2

Lines changed: 5 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -125,22 +125,14 @@ certificatesDir: {{ kube_cert_dir }}
125125
imageRepository: {{ kube_image_repo }}
126126
apiServer:
127127
extraArgs:
128-
{% if kube_apiserver_etcd_compaction_interval is defined %}
129128
- name: etcd-compaction-interval
130129
value: "{{ kube_apiserver_etcd_compaction_interval }}"
131-
{% endif %}
132-
{% if kube_apiserver_pod_eviction_not_ready_timeout_seconds is defined %}
133130
- name: default-not-ready-toleration-seconds
134131
value: "{{ kube_apiserver_pod_eviction_not_ready_timeout_seconds }}"
135-
{% endif %}
136-
{% if kube_apiserver_pod_eviction_unreachable_timeout_seconds is defined %}
137132
- name: default-unreachable-toleration-seconds
138133
value: "{{ kube_apiserver_pod_eviction_unreachable_timeout_seconds }}"
139-
{% endif %}
140-
{% if kube_api_anonymous_auth is defined %}
141134
- name: anonymous-auth
142135
value: "{{ kube_api_anonymous_auth }}"
143-
{% endif %}
144136
{% if kube_apiserver_use_authorization_config_file %}
145137
- name: authorization-config
146138
value: "{{ kube_config_dir }}/apiserver-authorization-config-{{ kube_apiserver_authorization_config_api_version }}.yaml"
@@ -186,7 +178,7 @@ apiServer:
186178
- name: service-account-lookup
187179
value: "{{ kube_apiserver_service_account_lookup }}"
188180
{% endif %}
189-
{% if kube_oidc_auth | default(false) and kube_oidc_url is defined and kube_oidc_client_id is defined %}
181+
{% if kube_oidc_auth and kube_oidc_url is defined and kube_oidc_client_id is defined %}
190182
- name: oidc-issuer-url
191183
value: "{{ kube_oidc_url }}"
192184
- name: oidc-client-id
@@ -212,7 +204,7 @@ apiServer:
212204
value: "{{ kube_oidc_groups_prefix }}"
213205
{% endif %}
214206
{% endif %}
215-
{% if kube_webhook_token_auth | default(false) %}
207+
{% if kube_webhook_token_auth %}
216208
- name: authentication-token-webhook-config-file
217209
value: "{{ kube_config_dir }}/webhook-token-auth-config.yaml"
218210
{% endif %}
@@ -274,10 +266,8 @@ apiServer:
274266
- name: tls-cipher-suites
275267
value: "{% for tls in tls_cipher_suites %}{{ tls }}{{ ',' if not loop.last else '' }}{% endfor %}"
276268
{% endif %}
277-
{% if event_ttl_duration is defined %}
278269
- name: event-ttl
279270
value: "{{ event_ttl_duration }}"
280-
{% endif %}
281271
{% if kubelet_rotate_server_certificates %}
282272
- name: kubelet-certificate-authority
283273
value: "{{ kube_cert_dir }}/ca.crt"
@@ -293,12 +283,12 @@ apiServer:
293283
hostPath: {{ kube_token_dir }}
294284
mountPath: {{ kube_token_dir }}
295285
{% endif %}
296-
{% if kube_webhook_token_auth | default(false) %}
286+
{% if kube_webhook_token_auth %}
297287
- name: webhook-token-auth-config
298288
hostPath: {{ kube_config_dir }}/webhook-token-auth-config.yaml
299289
mountPath: {{ kube_config_dir }}/webhook-token-auth-config.yaml
300290
{% endif %}
301-
{% if kube_webhook_authorization | default(false) %}
291+
{% if kube_webhook_authorization %}
302292
- name: webhook-authorization-config
303293
hostPath: {{ kube_config_dir }}/webhook-authorization-config.yaml
304294
mountPath: {{ kube_config_dir }}/webhook-authorization-config.yaml
@@ -395,12 +385,6 @@ controllerManager:
395385
- name: "{{ key }}"
396386
value: "{{ kube_kubeadm_controller_extra_args[key] }}"
397387
{% endfor %}
398-
{% if cloud_provider is defined and cloud_provider in ["openstack", "azure", "vsphere", "aws", "gce"] %}
399-
- name: cloud-provider
400-
value: "{{ cloud_provider }}"
401-
- name: cloud-config
402-
value: "{{ kube_config_dir }}/cloud_config"
403-
{% endif %}
404388
{% if kube_network_plugin is defined and kube_network_plugin not in ["cloud"] %}
405389
- name: configure-cloud-routes
406390
value: "false"
@@ -417,18 +401,8 @@ controllerManager:
417401
- name: tls-cipher-suites
418402
value: "{% for tls in tls_cipher_suites %}{{ tls }}{{ ',' if not loop.last else '' }}{% endfor %}"
419403
{% endif %}
420-
{% if cloud_provider is defined and cloud_provider in ["openstack", "azure", "vsphere", "aws", "gce"] or controller_manager_extra_volumes %}
404+
{% if controller_manager_extra_volumes %}
421405
extraVolumes:
422-
{% if cloud_provider is defined and cloud_provider in ["openstack"] and openstack_cacert is defined %}
423-
- name: openstackcacert
424-
hostPath: "{{ kube_config_dir }}/openstack-cacert.pem"
425-
mountPath: "{{ kube_config_dir }}/openstack-cacert.pem"
426-
{% endif %}
427-
{% if cloud_provider is defined and cloud_provider in ["openstack", "azure", "vsphere", "aws", "gce"] %}
428-
- name: cloud-config
429-
hostPath: {{ kube_config_dir }}/cloud_config
430-
mountPath: {{ kube_config_dir }}/cloud_config
431-
{% endif %}
432406
{% for volume in controller_manager_extra_volumes %}
433407
- name: {{ volume.name }}
434408
hostPath: {{ volume.hostPath }}

0 commit comments

Comments
 (0)
Please sign in to comment.