mirror of
https://github.com/kubernetes-sigs/kubespray.git
synced 2025-12-14 05:45:06 +03:00
Use a variable for standardizing kubectl invocation (#8329)
* Add kubectl variable * Replace kubectl usage by kubectl variable in roles * Remove redundant --kubeconfig on kubectl usage * Replace unecessary shell usage with command
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
- needs_cordoning|default(false)
|
||||
- kube_network_plugin == 'cilium'
|
||||
command: >
|
||||
{{ bin_dir }}/kubectl --kubeconfig {{ kube_config_dir }}/admin.conf
|
||||
{{ kubectl }}
|
||||
wait pod -n kube-system -l k8s-app=cilium
|
||||
--field-selector 'spec.nodeName=={{ kube_override_hostname|default(inventory_hostname) }}'
|
||||
--for=condition=Ready
|
||||
@@ -12,7 +12,7 @@
|
||||
delegate_to: "{{ groups['kube_control_plane'][0] }}"
|
||||
|
||||
- name: Uncordon node
|
||||
command: "{{ bin_dir }}/kubectl --kubeconfig {{ kube_config_dir }}/admin.conf uncordon {{ kube_override_hostname|default(inventory_hostname) }}"
|
||||
command: "{{ kubectl }} uncordon {{ kube_override_hostname|default(inventory_hostname) }}"
|
||||
delegate_to: "{{ groups['kube_control_plane'][0] }}"
|
||||
when:
|
||||
- needs_cordoning|default(false)
|
||||
|
||||
@@ -17,9 +17,9 @@
|
||||
# Node Ready: type = ready, status = True
|
||||
# Node NotReady: type = ready, status = Unknown
|
||||
- name: See if node is in ready state
|
||||
shell: >-
|
||||
{{ bin_dir }}/kubectl get node {{ kube_override_hostname|default(inventory_hostname) }}
|
||||
-o jsonpath='{ range .status.conditions[?(@.type == "Ready")].status }{ @ }{ end }'
|
||||
command: >
|
||||
{{ kubectl }} get node {{ kube_override_hostname|default(inventory_hostname) }}
|
||||
-o jsonpath={ range .status.conditions[?(@.type == "Ready")].status }{ @ }{ end }
|
||||
register: kubectl_node_ready
|
||||
delegate_to: "{{ groups['kube_control_plane'][0] }}"
|
||||
failed_when: false
|
||||
@@ -28,9 +28,9 @@
|
||||
# SchedulingDisabled: unschedulable = true
|
||||
# else unschedulable key doesn't exist
|
||||
- name: See if node is schedulable
|
||||
shell: >-
|
||||
{{ bin_dir }}/kubectl get node {{ kube_override_hostname|default(inventory_hostname) }}
|
||||
-o jsonpath='{ .spec.unschedulable }'
|
||||
command: >
|
||||
{{ kubectl }} get node {{ kube_override_hostname|default(inventory_hostname) }}
|
||||
-o jsonpath={ .spec.unschedulable }
|
||||
register: kubectl_node_schedulable
|
||||
delegate_to: "{{ groups['kube_control_plane'][0] }}"
|
||||
failed_when: false
|
||||
@@ -48,11 +48,11 @@
|
||||
- name: Node draining
|
||||
block:
|
||||
- name: Cordon node
|
||||
command: "{{ bin_dir }}/kubectl cordon {{ kube_override_hostname|default(inventory_hostname) }}"
|
||||
command: "{{ kubectl }} cordon {{ kube_override_hostname|default(inventory_hostname) }}"
|
||||
delegate_to: "{{ groups['kube_control_plane'][0] }}"
|
||||
|
||||
- name: Check kubectl version
|
||||
command: "{{ bin_dir }}/kubectl version --client --short"
|
||||
command: "{{ kubectl }} version --client --short"
|
||||
register: kubectl_version
|
||||
delegate_to: "{{ groups['kube_control_plane'][0] }}"
|
||||
run_once: yes
|
||||
@@ -70,7 +70,7 @@
|
||||
|
||||
- name: Drain node
|
||||
command: >-
|
||||
{{ bin_dir }}/kubectl drain
|
||||
{{ kubectl }} drain
|
||||
--force
|
||||
--ignore-daemonsets
|
||||
--grace-period {{ hostvars['localhost']['drain_grace_period_after_failure'] | default(drain_grace_period) }}
|
||||
@@ -98,7 +98,7 @@
|
||||
|
||||
- name: Drain node - fallback with disabled eviction
|
||||
command: >-
|
||||
{{ bin_dir }}/kubectl drain
|
||||
{{ kubectl }} drain
|
||||
--force
|
||||
--ignore-daemonsets
|
||||
--grace-period {{ drain_fallback_grace_period }}
|
||||
@@ -117,7 +117,7 @@
|
||||
|
||||
rescue:
|
||||
- name: Set node back to schedulable
|
||||
command: "{{ bin_dir }}/kubectl --kubeconfig {{ kube_config_dir }}/admin.conf uncordon {{ inventory_hostname }}"
|
||||
command: "{{ kubectl }} uncordon {{ inventory_hostname }}"
|
||||
when: upgrade_node_uncordon_after_drain_failure
|
||||
- name: Fail after rescue
|
||||
fail:
|
||||
|
||||
Reference in New Issue
Block a user