Skip to content

Commit

Permalink
Merge pull request #211 from hoo29/custom-node-names
Browse files Browse the repository at this point in the history
Add rke2_node_name
  • Loading branch information
MonolithProjects committed Apr 22, 2024
2 parents 232adc3 + a8ae730 commit 457b145
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 12 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,9 @@ rke2_debug: false
# (Optional) Customize default kube-proxy arguments
# rke2_kube_proxy_arg:
# - "proxy-mode=ipvs"

# The value for the node-name configuration item
rke2_node_name: "{{ inventory_hostname }}"
```

## Inventory file example
Expand Down
3 changes: 3 additions & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -281,3 +281,6 @@ rke2_debug: false
# (Optional) Customize default kube-proxy arguments
# rke2_kube_proxy_arg:
# - "proxy-mode=ipvs"

# The value for the node-name configuration item
rke2_node_name: "{{ inventory_hostname }}"
2 changes: 1 addition & 1 deletion tasks/change_config.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
- name: Restart RKE2 service on {{ inventory_hostname }}
- name: Restart RKE2 service on {{ rke2_node_name }}
ansible.builtin.service:
name: "{{ rke2_service_name }}"
state: restarted
Expand Down
4 changes: 2 additions & 2 deletions tasks/first_server.yml
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@

- name: Wait for the first server be ready - no CNI
ansible.builtin.shell: |
{{ rke2_data_path }}/bin/kubectl --kubeconfig /etc/rancher/rke2/rke2.yaml get node "{{ inventory_hostname }}" -o jsonpath='{range .status.conditions[*]}{.message}{"\n"}{end}'
{{ rke2_data_path }}/bin/kubectl --kubeconfig /etc/rancher/rke2/rke2.yaml get node "{{ rke2_node_name }}" -o jsonpath='{range .status.conditions[*]}{.message}{"\n"}{end}'
args:
executable: /bin/bash
changed_when: false
Expand All @@ -121,7 +121,7 @@
- name: Wait for the first server be ready - with CNI
ansible.builtin.shell: |
set -o pipefail
{{ rke2_data_path }}/bin/kubectl --kubeconfig /etc/rancher/rke2/rke2.yaml get nodes | grep "{{ inventory_hostname }}"
{{ rke2_data_path }}/bin/kubectl --kubeconfig /etc/rancher/rke2/rke2.yaml get nodes | grep "{{ rke2_node_name }}"
args:
executable: /bin/bash
changed_when: false
Expand Down
12 changes: 6 additions & 6 deletions tasks/rolling_restart.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
---

- name: Cordon and Drain the node {{ inventory_hostname }}
- name: Cordon and Drain the node {{ rke2_node_name }}
ansible.builtin.shell: |
set -o pipefail
{{ rke2_data_path }}/bin/kubectl --kubeconfig /etc/rancher/rke2/rke2.yaml \
cordon "{{ inventory_hostname }}" && \
cordon "{{ rke2_node_name }}" && \
{{ rke2_data_path }}/bin/kubectl --kubeconfig /etc/rancher/rke2/rke2.yaml \
drain "{{ inventory_hostname }}" --ignore-daemonsets --delete-emptydir-data
drain "{{ rke2_node_name }}" --ignore-daemonsets --delete-emptydir-data
args:
executable: /bin/bash
register: drain
Expand All @@ -19,7 +19,7 @@
run_once: true
when: rke2_drain_node_during_upgrade

- name: Restart RKE2 service on {{ inventory_hostname }}
- name: Restart RKE2 service on {{ rke2_node_name }}
ansible.builtin.service:
name: "{{ rke2_service_name }}"
state: restarted
Expand All @@ -40,11 +40,11 @@
delegate_to: "{{ active_server | default(groups[rke2_servers_group_name].0) }}"
run_once: true

- name: Uncordon the node {{ inventory_hostname }}
- name: Uncordon the node {{ rke2_node_name }}
ansible.builtin.shell: |
set -o pipefail
{{ rke2_data_path }}/bin/kubectl --kubeconfig /etc/rancher/rke2/rke2.yaml \
uncordon "{{ inventory_hostname }}"
uncordon "{{ rke2_node_name }}"
args:
executable: /bin/bash
changed_when: false
Expand Down
4 changes: 2 additions & 2 deletions tasks/standalone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@

- name: Wait for the first server be ready - no CNI
ansible.builtin.shell: |
{{ rke2_data_path }}/bin/kubectl --kubeconfig /etc/rancher/rke2/rke2.yaml get node "{{ inventory_hostname }}" -o jsonpath='{range .status.conditions[*]}{.message}{"\n"}{end}'
{{ rke2_data_path }}/bin/kubectl --kubeconfig /etc/rancher/rke2/rke2.yaml get node "{{ rke2_node_name }}" -o jsonpath='{range .status.conditions[*]}{.message}{"\n"}{end}'
args:
executable: /bin/bash
changed_when: false
Expand All @@ -55,7 +55,7 @@
- name: Wait for the first server be ready - with CNI
ansible.builtin.shell: |
set -o pipefail
{{ rke2_data_path }}/bin/kubectl --kubeconfig /etc/rancher/rke2/rke2.yaml get nodes | grep "{{ inventory_hostname }}"
{{ rke2_data_path }}/bin/kubectl --kubeconfig /etc/rancher/rke2/rke2.yaml get nodes | grep "{{ rke2_node_name }}"
args:
executable: /bin/bash
changed_when: false
Expand Down
2 changes: 1 addition & 1 deletion templates/config.yaml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ node-label:
{% endfor %}
{% endif %}
snapshotter: {{ rke2_snapshooter }}
node-name: {{ inventory_hostname }}
node-name: {{ rke2_node_name }}
{% if ( disable_kube_proxy | bool ) %}
disable-kube-proxy: true
{% endif %}
Expand Down

0 comments on commit 457b145

Please sign in to comment.