Fix remove-node by removing jq usage (#7405)
Signed-off-by: Etienne Champetier <e.champetier@ateme.com>
This commit is contained in:
parent
2d1597bf10
commit
36a3a78952
1 changed files with 5 additions and 15 deletions
|
@ -3,25 +3,13 @@
|
||||||
set_fact:
|
set_fact:
|
||||||
nodes_to_drain: []
|
nodes_to_drain: []
|
||||||
|
|
||||||
- name: remove-node | Identify nodes to drain, ignore non-cluster nodes
|
- name: remove-node | List nodes
|
||||||
shell: |
|
command: kubectl get nodes -o go-template={% raw %}'{{ range .items }}{{ .metadata.name }}{{ "\n" }}{{ end }}'{% endraw %}
|
||||||
set -o pipefail
|
|
||||||
{{ bin_dir }}/kubectl get nodes -o json \
|
|
||||||
| jq .items[].metadata.name \
|
|
||||||
| jq "select(. | test(\"^{{ hostvars[item]['kube_override_hostname']|default(item) }}$\"))"
|
|
||||||
loop: "{{ node.split(',') | default(groups['kube-node']) }}"
|
|
||||||
register: nodes
|
register: nodes
|
||||||
delegate_to: "{{ groups['kube_control_plane']|first }}"
|
delegate_to: "{{ groups['kube_control_plane']|first }}"
|
||||||
changed_when: false
|
changed_when: false
|
||||||
run_once: true
|
run_once: true
|
||||||
|
|
||||||
- name: remove-node | Generate list of nodes to drain
|
|
||||||
set_fact:
|
|
||||||
nodes_to_drain: "{{ nodes_to_drain }} + [ '{{ item.stdout | regex_replace('\"', '') }}' ]"
|
|
||||||
loop: "{{ nodes.results }}"
|
|
||||||
when: item.stdout | length != 0
|
|
||||||
run_once: true
|
|
||||||
|
|
||||||
- name: remove-node | Drain node except daemonsets resource # noqa 301
|
- name: remove-node | Drain node except daemonsets resource # noqa 301
|
||||||
command: >-
|
command: >-
|
||||||
{{ bin_dir }}/kubectl --kubeconfig /etc/kubernetes/admin.conf drain
|
{{ bin_dir }}/kubectl --kubeconfig /etc/kubernetes/admin.conf drain
|
||||||
|
@ -30,7 +18,9 @@
|
||||||
--grace-period {{ drain_grace_period }}
|
--grace-period {{ drain_grace_period }}
|
||||||
--timeout {{ drain_timeout }}
|
--timeout {{ drain_timeout }}
|
||||||
--delete-local-data {{ hostvars[item]['kube_override_hostname']|default(item) }}
|
--delete-local-data {{ hostvars[item]['kube_override_hostname']|default(item) }}
|
||||||
loop: "{{ nodes_to_drain }}"
|
loop: "{{ node.split(',') | default(groups['kube-node']) }}"
|
||||||
|
# ignore servers that are not nodes
|
||||||
|
when: hostvars[item]['kube_override_hostname']|default(item) in nodes.stdout_lines
|
||||||
register: result
|
register: result
|
||||||
failed_when: result.rc != 0 and not allow_ungraceful_removal
|
failed_when: result.rc != 0 and not allow_ungraceful_removal
|
||||||
delegate_to: "{{ groups['kube_control_plane']|first }}"
|
delegate_to: "{{ groups['kube_control_plane']|first }}"
|
||||||
|
|
Loading…
Reference in a new issue