Skip to content

Set k3s node IP from access network IP #556

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions ansible/roles/k3s/files/start_k3s.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
k3s_token: "{{ os_metadata.meta.k3s_token }}"
k3s_server_name: "{{ os_metadata.meta.control_address }}"
service_name: "{{ 'k3s-agent' if k3s_server_name is defined else 'k3s' }}"
access_ip: "{{ os_metadata.meta.access_ip }}"
tasks:
- name: Ensure password directory exists
ansible.builtin.file:
Expand All @@ -22,6 +23,13 @@
path: "/etc/systemd/system/{{ service_name }}.service.env"
line: "K3S_TOKEN={{ k3s_token }}"

- name: Add the node IP to the environment
# NB this isn't natively setable via envvars, have to modify
# INSTALL_K3S_EXEC to support it
ansible.builtin.lineinfile:
path: "/etc/systemd/system/{{ service_name }}.service.env"
line: "K3S_NODE_IP={{ access_ip }}"

- name: Add server url to agents
ansible.builtin.lineinfile:
path: "/etc/systemd/system/{{ service_name }}.service.env"
Expand Down
2 changes: 1 addition & 1 deletion ansible/roles/k3s/tasks/install.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
cmd: /usr/bin/k3s-install.sh
environment:
INSTALL_K3S_VERSION: "{{ k3s_version }}"
INSTALL_K3S_EXEC: "{{ item }}"
INSTALL_K3S_EXEC: "{{ item }} --node-ip=${K3S_NODE_IP}"
INSTALL_K3S_SKIP_START: "true"
INSTALL_K3S_SKIP_ENABLE: "true"
INSTALL_K3S_BIN_DIR: "/usr/bin"
Expand Down
4 changes: 2 additions & 2 deletions environments/.stackhpc/tofu/cluster_image.auto.tfvars.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"cluster_image": {
"RL8": "openhpc-RL8-250122-1150-a0899ef8",
"RL9": "openhpc-RL9-250122-1150-a0899ef8"
"RL8": "openhpc-RL8-250130-1126-8f2a7703",
"RL9": "openhpc-RL9-250130-1127-8f2a7703"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ resource "openstack_compute_instance_v2" "control" {
metadata = {
environment_root = var.environment_root
k3s_token = local.k3s_token
# TODO: set k3s_subnet from access_network
access_ip = openstack_networking_port_v2.control[var.cluster_networks[0].network].all_fixed_ips[0]
}

user_data = <<-EOF
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ resource "openstack_compute_instance_v2" "compute_fixed_image" {
environment_root = var.environment_root
k3s_token = var.k3s_token
control_address = var.control_address
access_ip = openstack_networking_port_v2.compute["${each.key}-${var.networks[0].network}"].all_fixed_ips[0]
},
{for e in var.compute_init_enable: e => true}
)
Expand Down Expand Up @@ -138,7 +139,7 @@ resource "openstack_compute_instance_v2" "compute" {
environment_root = var.environment_root
k3s_token = var.k3s_token
control_address = var.control_address
# TODO: set k3s_subnet from access_network
access_ip = openstack_networking_port_v2.compute["${each.key}-${var.networks[0].network}"].all_fixed_ips[0]
},
{for e in var.compute_init_enable: e => true}
)
Expand Down