refactor(longhorn): update disk tasks for namespace support and improve retry parameters
- Add longhorn_namespace to kubectl and k8s_json_patch operations - Change patch format from plural 'patches' to singular 'patch' - Adjust retry logic: reduce retries from 40 to 24, delay from 15 to 5 - Include KUBECONFIG and PATH environment variables for k8s operations - Comment out python kubernetes library installation block with explanation
This commit is contained in:
parent
7327676b13
commit
5b728bf3e0
1 changed files with 42 additions and 8 deletions
|
|
@ -7,12 +7,12 @@
|
||||||
|
|
||||||
- name: Disks | Wait for worker nodes to appear in Longhorn
|
- name: Disks | Wait for worker nodes to appear in Longhorn
|
||||||
ansible.builtin.command:
|
ansible.builtin.command:
|
||||||
argv: [kubectl, get, node.longhorn.io, "{{ item }}"]
|
argv: [kubectl, get, node.longhorn.io, "{{ item }}", -n, "{{ longhorn_namespace }}"]
|
||||||
loop: "{{ groups['workers'] }}"
|
loop: "{{ groups['workers'] }}"
|
||||||
register: _lh_node_wait
|
register: _lh_node_wait
|
||||||
until: _lh_node_wait.rc == 0
|
until: _lh_node_wait.rc == 0
|
||||||
retries: 40
|
retries: 24
|
||||||
delay: 15
|
delay: 5
|
||||||
changed_when: false
|
changed_when: false
|
||||||
failed_when: _lh_node_wait.rc != 0 and _lh_node_wait.attempts | default(0) >= 24
|
failed_when: _lh_node_wait.rc != 0 and _lh_node_wait.attempts | default(0) >= 24
|
||||||
environment:
|
environment:
|
||||||
|
|
@ -21,6 +21,18 @@
|
||||||
|
|
||||||
# ── Step 2: register dedicated disks via k8s_json_patch ──
|
# ── Step 2: register dedicated disks via k8s_json_patch ──
|
||||||
|
|
||||||
|
# - name: Disks | Install python kubernetes library for kubernetes.core modules
|
||||||
|
# ansible.builtin.pip:
|
||||||
|
# name:
|
||||||
|
# - kubernetes
|
||||||
|
# # Rocky Linux's rpm-packaged python3-oauthlib (3.1.1) strips SIGNATURE_RSA
|
||||||
|
# # (crypto hardening), which breaks requests-oauthlib's import used by the
|
||||||
|
# # kubernetes library. A bare "oauthlib" pip requirement is satisfied by
|
||||||
|
# # that already-installed 3.1.1 and no-ops, so the version floor is
|
||||||
|
# # required to force pip to actually install a newer, unpatched build.
|
||||||
|
# - "oauthlib>=3.2.0"
|
||||||
|
# executable: pip3
|
||||||
|
|
||||||
- name: Disks | Build flat worker-disk list
|
- name: Disks | Build flat worker-disk list
|
||||||
ansible.builtin.set_fact:
|
ansible.builtin.set_fact:
|
||||||
_lh_worker_disks: "{{ _lh_worker_disks | default([]) + [hostvars[item].longhorn_disks | default([]) | map('combine', {'node': item}) | list] | flatten }}"
|
_lh_worker_disks: "{{ _lh_worker_disks | default([]) + [hostvars[item].longhorn_disks | default([]) | map('combine', {'node': item}) | list] | flatten }}"
|
||||||
|
|
@ -30,8 +42,9 @@
|
||||||
kubernetes.core.k8s_json_patch:
|
kubernetes.core.k8s_json_patch:
|
||||||
api_version: longhorn.io/v1beta1
|
api_version: longhorn.io/v1beta1
|
||||||
kind: Node
|
kind: Node
|
||||||
|
namespace: "{{ longhorn_namespace }}"
|
||||||
name: "{{ item.node }}"
|
name: "{{ item.node }}"
|
||||||
patches:
|
patch:
|
||||||
- op: add
|
- op: add
|
||||||
path: "/spec/disks/{{ item.mountpoint | basename | replace('/', '~1') }}"
|
path: "/spec/disks/{{ item.mountpoint | basename | replace('/', '~1') }}"
|
||||||
value:
|
value:
|
||||||
|
|
@ -44,6 +57,9 @@
|
||||||
label: "{{ item.node }}/{{ item.mountpoint | basename }}"
|
label: "{{ item.node }}/{{ item.mountpoint | basename }}"
|
||||||
register: _disk_patch
|
register: _disk_patch
|
||||||
changed_when: false
|
changed_when: false
|
||||||
|
environment:
|
||||||
|
KUBECONFIG: "{{ longhorn_kubeconfig }}"
|
||||||
|
PATH: /usr/local/bin:/usr/bin:/bin
|
||||||
|
|
||||||
# ── Step 3: remove auto-created default disk at /var/lib/longhorn ─────────────
|
# ── Step 3: remove auto-created default disk at /var/lib/longhorn ─────────────
|
||||||
|
|
||||||
|
|
@ -51,6 +67,7 @@
|
||||||
kubernetes.core.k8s_info:
|
kubernetes.core.k8s_info:
|
||||||
api_version: longhorn.io/v1beta1
|
api_version: longhorn.io/v1beta1
|
||||||
kind: Node
|
kind: Node
|
||||||
|
namespace: "{{ longhorn_namespace }}"
|
||||||
name: "{{ item }}"
|
name: "{{ item }}"
|
||||||
loop: "{{ groups['workers'] }}"
|
loop: "{{ groups['workers'] }}"
|
||||||
register: _lh_node_info
|
register: _lh_node_info
|
||||||
|
|
@ -63,8 +80,9 @@
|
||||||
kubernetes.core.k8s_json_patch:
|
kubernetes.core.k8s_json_patch:
|
||||||
api_version: longhorn.io/v1beta1
|
api_version: longhorn.io/v1beta1
|
||||||
kind: Node
|
kind: Node
|
||||||
|
namespace: "{{ longhorn_namespace }}"
|
||||||
name: "{{ item.item }}"
|
name: "{{ item.item }}"
|
||||||
patches:
|
patch:
|
||||||
- op: add
|
- op: add
|
||||||
path: "/spec/disks/{{ item.resources[0].spec.disks | dict2items | selectattr('key', 'match', 'default-disk-.*') | first | default({key: ''}) | key | replace('/', '~1') }}"
|
path: "/spec/disks/{{ item.resources[0].spec.disks | dict2items | selectattr('key', 'match', 'default-disk-.*') | first | default({key: ''}) | key | replace('/', '~1') }}"
|
||||||
value:
|
value:
|
||||||
|
|
@ -77,13 +95,17 @@
|
||||||
- item.resources[0].spec.disks | default({}) | dict2items | selectattr('key', 'match', 'default-disk-.*') | selectattr('value.allowScheduling', 'equalto', true) | list | length > 0
|
- item.resources[0].spec.disks | default({}) | dict2items | selectattr('key', 'match', 'default-disk-.*') | selectattr('value.allowScheduling', 'equalto', true) | list | length > 0
|
||||||
register: _disable_default
|
register: _disable_default
|
||||||
changed_when: false
|
changed_when: false
|
||||||
|
environment:
|
||||||
|
KUBECONFIG: "{{ longhorn_kubeconfig }}"
|
||||||
|
PATH: /usr/local/bin:/usr/bin:/bin
|
||||||
|
|
||||||
- name: Disks | Remove auto-created default disk
|
- name: Disks | Remove auto-created default disk
|
||||||
kubernetes.core.k8s_json_patch:
|
kubernetes.core.k8s_json_patch:
|
||||||
api_version: longhorn.io/v1beta1
|
api_version: longhorn.io/v1beta1
|
||||||
kind: Node
|
kind: Node
|
||||||
|
namespace: "{{ longhorn_namespace }}"
|
||||||
name: "{{ item.item }}"
|
name: "{{ item.item }}"
|
||||||
patches:
|
patch:
|
||||||
- op: remove
|
- op: remove
|
||||||
path: "/spec/disks/{{ item.resources[0].spec.disks | dict2items | selectattr('key', 'match', 'default-disk-.*') | map(attribute='key') | first | default('') | replace('/', '~1') }}"
|
path: "/spec/disks/{{ item.resources[0].spec.disks | dict2items | selectattr('key', 'match', 'default-disk-.*') | map(attribute='key') | first | default('') | replace('/', '~1') }}"
|
||||||
loop: "{{ _lh_node_info.results }}"
|
loop: "{{ _lh_node_info.results }}"
|
||||||
|
|
@ -92,6 +114,9 @@
|
||||||
- item.resources[0].spec.disks | default({}) | dict2items | selectattr('key', 'match', 'default-disk-.*') | list | length > 0
|
- item.resources[0].spec.disks | default({}) | dict2items | selectattr('key', 'match', 'default-disk-.*') | list | length > 0
|
||||||
register: _remove_default
|
register: _remove_default
|
||||||
changed_when: false
|
changed_when: false
|
||||||
|
environment:
|
||||||
|
KUBECONFIG: "{{ longhorn_kubeconfig }}"
|
||||||
|
PATH: /usr/local/bin:/usr/bin:/bin
|
||||||
|
|
||||||
# ── Step 4: remove auto-created default disk from control_plane nodes ─────────
|
# ── Step 4: remove auto-created default disk from control_plane nodes ─────────
|
||||||
# Control plane nodes have no dedicated storage disks; Longhorn must not
|
# Control plane nodes have no dedicated storage disks; Longhorn must not
|
||||||
|
|
@ -101,6 +126,7 @@
|
||||||
kubernetes.core.k8s_info:
|
kubernetes.core.k8s_info:
|
||||||
api_version: longhorn.io/v1beta1
|
api_version: longhorn.io/v1beta1
|
||||||
kind: Node
|
kind: Node
|
||||||
|
namespace: "{{ longhorn_namespace }}"
|
||||||
name: "{{ item }}"
|
name: "{{ item }}"
|
||||||
loop: "{{ groups['control_plane'] }}"
|
loop: "{{ groups['control_plane'] }}"
|
||||||
register: _lh_cp_node_info
|
register: _lh_cp_node_info
|
||||||
|
|
@ -114,8 +140,9 @@
|
||||||
kubernetes.core.k8s_json_patch:
|
kubernetes.core.k8s_json_patch:
|
||||||
api_version: longhorn.io/v1beta1
|
api_version: longhorn.io/v1beta1
|
||||||
kind: Node
|
kind: Node
|
||||||
|
namespace: "{{ longhorn_namespace }}"
|
||||||
name: "{{ item.item }}"
|
name: "{{ item.item }}"
|
||||||
patches:
|
patch:
|
||||||
- op: add
|
- op: add
|
||||||
path: "/spec/disks/{{ item.resources[0].spec.disks | dict2items | selectattr('key', 'match', 'default-disk-.*') | first | default({key: ''}) | key | replace('/', '~1') }}"
|
path: "/spec/disks/{{ item.resources[0].spec.disks | dict2items | selectattr('key', 'match', 'default-disk-.*') | first | default({key: ''}) | key | replace('/', '~1') }}"
|
||||||
value:
|
value:
|
||||||
|
|
@ -128,13 +155,17 @@
|
||||||
- item.resources[0].spec.disks | default({}) | dict2items | selectattr('key', 'match', 'default-disk-.*') | selectattr('value.allowScheduling', 'equalto', true) | list | length > 0
|
- item.resources[0].spec.disks | default({}) | dict2items | selectattr('key', 'match', 'default-disk-.*') | selectattr('value.allowScheduling', 'equalto', true) | list | length > 0
|
||||||
register: _disable_cp_default
|
register: _disable_cp_default
|
||||||
changed_when: false
|
changed_when: false
|
||||||
|
environment:
|
||||||
|
KUBECONFIG: "{{ longhorn_kubeconfig }}"
|
||||||
|
PATH: /usr/local/bin:/usr/bin:/bin
|
||||||
|
|
||||||
- name: Disks | Remove auto-created default disk from control_plane nodes
|
- name: Disks | Remove auto-created default disk from control_plane nodes
|
||||||
kubernetes.core.k8s_json_patch:
|
kubernetes.core.k8s_json_patch:
|
||||||
api_version: longhorn.io/v1beta1
|
api_version: longhorn.io/v1beta1
|
||||||
kind: Node
|
kind: Node
|
||||||
|
namespace: "{{ longhorn_namespace }}"
|
||||||
name: "{{ item.item }}"
|
name: "{{ item.item }}"
|
||||||
patches:
|
patch:
|
||||||
- op: remove
|
- op: remove
|
||||||
path: "/spec/disks/{{ item.resources[0].spec.disks | dict2items | selectattr('key', 'match', 'default-disk-.*') | map(attribute='key') | first | default('') | replace('/', '~1') }}"
|
path: "/spec/disks/{{ item.resources[0].spec.disks | dict2items | selectattr('key', 'match', 'default-disk-.*') | map(attribute='key') | first | default('') | replace('/', '~1') }}"
|
||||||
loop: "{{ _lh_cp_node_info.results }}"
|
loop: "{{ _lh_cp_node_info.results }}"
|
||||||
|
|
@ -143,3 +174,6 @@
|
||||||
- item.resources[0].spec.disks | default({}) | dict2items | selectattr('key', 'match', 'default-disk-.*') | list | length > 0
|
- item.resources[0].spec.disks | default({}) | dict2items | selectattr('key', 'match', 'default-disk-.*') | list | length > 0
|
||||||
register: _remove_cp_default
|
register: _remove_cp_default
|
||||||
changed_when: false
|
changed_when: false
|
||||||
|
environment:
|
||||||
|
KUBECONFIG: "{{ longhorn_kubeconfig }}"
|
||||||
|
PATH: /usr/local/bin:/usr/bin:/bin
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue