Skip to content

Commit 403e78a

Browse files
authored
Remove relocation script (#59)
* Remove relocation script * Update NMStateConfig * fix var * add dns * fix linter * update doc * remove dns config * fix MNO
1 parent dc5b75b commit 403e78a

File tree

13 files changed

+91
-164
lines changed

13 files changed

+91
-164
lines changed

.github/workflows/build.yaml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@ jobs:
2222
- name: Check code
2323
run: |
2424
ansible-lint -s -x yaml[line-length],var-naming[no-role-prefix] --exclude .github
25-
ansible localhost -m ansible.builtin.template -a "src=edge/roles/edge_install/templates/relocatable_ip.sh.j2 dest=relocatable_ip.sh" -e "{'relocatable_ipv4_subnet': '192.168.7.0/24', 'relocatable_ipv6_subnet': 'fd04::/64', 'edgeCluster':{'relocatable': {'interface': 'eno1'}},'relocatable_interface_macs':'addresses_ipv4[\"11:22:33:44:55:66\"]=\"192.168.7.4/24\";addresses_ipv6[\"11:22:33:44:55:66\"]=\"fd04::4/64\"','cluster_ipv4':true,'cluster_ipv6':true,'controlPlane':{'replicas':3}}"
26-
ansible localhost -m ansible.builtin.template -a "src=edge/roles/edge_install/templates/relocatable_ip.sh.j2 dest=relocatable_ip_sno.sh" -e "{'relocatable_ipv4_subnet': '192.168.7.0/24', 'relocatable_ipv6_subnet': 'fd04::/64', 'edgeCluster':{'relocatable': {'interface': 'eno1'}},'relocatable_interface_macs':'addresses_ipv4[\"11:22:33:44:55:66\"]=\"192.168.7.4/24\";addresses_ipv6[\"11:22:33:44:55:66\"]=\"fd04::4/64\"','cluster_ipv4':true,'cluster_ipv6':true,'controlPlane':{'replicas':1}}"
27-
shellcheck -o all relocatable_ip.sh relocatable_ip_sno.sh edge/roles/edge_csr_approver/files/csr_approver.sh
25+
shellcheck -o all edge/roles/edge_csr_approver/files/csr_approver.sh
2826
2927
test-container:
3028
runs-on: ubuntu-latest

common/roles/install_deps/tasks/main.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
name:
44
- kubernetes
55
- netaddr
6+
- jmespath

edge/docs/RELOCATABLE.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# Relocatable Edge Cluster
2-
This feature requires OpenShift 4.12 or higher.
2+
This feature requires OpenShift 4.14 or higher. It also requires MCE 2.5+ (ACM 2.10+).
33

44
When the ```relocatable``` option is enabled, the cluster is configured in such a way that its primary interface IP addresses can be changed without impacting the operation of the cluster.
55

66
## How it works
7-
You set the value of ```relocatable.interface``` to the name of the external facing interface. A secondary static IP address is assigned to this interface. The machineNetwork CIDR is also set to a static internal subnet. Finally, a MachineConfig is created that modifies /etc/default/nodeip-configuration to tell the cluster to use the static IP as the node IP. 'routingViaHost' is also enabled for OCP 4.12.
7+
You set the value of ```relocatable.interface``` to the name of the external facing interface. A secondary static IP address is assigned to this interface. The machineNetwork CIDR is also set to a static internal subnet. Finally, a MachineConfig is created that modifies /etc/default/nodeip-configuration to tell the cluster to use the static IP as the node IP.
88

99
All of these actions together cause the server to use the static IP for everything related to OpenShift, while still allowing access to the cluster from outside via the primary interface IP address. This means that the external IP can be changed, and the cluster will continue to use the static IP internally for its operation.
1010

edge/roles/edge_install/tasks/get_relocatable_ip.yaml

Lines changed: 0 additions & 28 deletions
This file was deleted.

edge/roles/edge_install/tasks/setup_host_networking.yaml

Lines changed: 53 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,60 @@
1+
- name: Calculate relocatable IP
2+
when: edgeCluster.relocatable is defined
3+
block:
4+
- name: Increment relocatable IP address
5+
ansible.builtin.set_fact:
6+
interface_number: "{{ (interface_number | int) + 1 }}"
7+
8+
- name: Filter the relocatable interface
9+
ansible.builtin.set_fact:
10+
filtered_interface: "{{ nmstate_host.networkConfig.interfaces | json_query('[?name == `' + edgeCluster.relocatable.interface + '`]') | first }}"
11+
12+
- name: Create entry for IPv4 address list
13+
when: cluster_ipv4
14+
block:
15+
- name: Get IPv4 addresses
16+
ansible.builtin.set_fact:
17+
ipv4_addresses: "{{ filtered_interface.ipv4.address | default([]) }}"
18+
19+
- name: Append IPv4 relocatable address
20+
ansible.builtin.set_fact:
21+
ipv4_addresses: "{{ ipv4_addresses + [{'ip': relocatable_ipv4_subnet | ansible.utils.nthhost(interface_number | int), 'prefix-length': relocatable_ipv4_subnet | ansible.utils.ipaddr('prefix')}] }}"
22+
23+
- name: Update IPv4 addresses
24+
ansible.builtin.set_fact:
25+
filtered_interface: "{{ filtered_interface | combine({'ipv4': {'address': ipv4_addresses}}, recursive=true) }}"
26+
27+
- name: Create entry for IPv6 address list
28+
when: cluster_ipv6
29+
block:
30+
- name: Get IPv6 addresses
31+
ansible.builtin.set_fact:
32+
ipv6_addresses: "{{ filtered_interface.ipv6.address | default([]) }}"
33+
34+
- name: Append IPv6 relocatable address
35+
ansible.builtin.set_fact:
36+
ipv6_addresses: "{{ ipv6_addresses + [{'ip': relocatable_ipv6_subnet | ansible.utils.nthhost(interface_number | int), 'prefix-length': relocatable_ipv6_subnet | ansible.utils.ipaddr('prefix')}] }}"
37+
38+
- name: Update IPv6 addresses
39+
ansible.builtin.set_fact:
40+
filtered_interface: "{{ filtered_interface | combine({'ipv6': {'address': ipv6_addresses}}, recursive=true) }}"
41+
42+
- name: Get all non-reloctable interfaces
43+
ansible.builtin.set_fact:
44+
interfaces_list: "{{ nmstate_host.networkConfig.interfaces | json_query('[?name != `' + edgeCluster.relocatable.interface + '`]') }}"
45+
46+
- name: Add reloctable interface
47+
ansible.builtin.set_fact:
48+
interfaces_list: "{{ interfaces_list + [filtered_interface] }}"
49+
50+
- name: Create new networkConfig
51+
ansible.builtin.set_fact:
52+
relocatable_network_config: "{{ nmstate_host.networkConfig | combine({'interfaces': interfaces_list}, recursive=true) }}"
53+
154
- name: Create NMStateConfig
255
kubernetes.core.k8s:
356
template: NMStateConfig.yaml.j2
457
apply: true
558
state: present
659
register: k8s_result
760
until: k8s_result is not failed
8-
9-
- name: Calculate relocatable IP
10-
when: edgeCluster.relocatable is defined
11-
block:
12-
- name: Get relocatable interface index
13-
loop: "{{ nmstate_host.networkConfig.interfaces }}"
14-
loop_control:
15-
label: "{{ item.name }}"
16-
when: item.name == edgeCluster.relocatable.interface
17-
ansible.builtin.include_tasks: get_relocatable_ip.yaml

edge/roles/edge_install/templates/InfraEnv.yaml.j2

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,3 @@ spec:
2121
proxy:
2222
{{ proxy | to_nice_yaml(indent=2) | trim | indent(4) }}
2323
{% endif %}
24-
{% if edgeCluster.relocatable is defined %}
25-
ignitionConfigOverride: '{{ (lookup('ansible.builtin.template', 'RelocatableConfig.yaml.j2') | from_yaml | to_json) }}'
26-
{% endif %}

edge/roles/edge_install/templates/NMStateConfig.yaml.j2

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@ metadata:
77
nmstate-cluster: "{{ metadata.name }}"
88
spec:
99
config:
10+
{% if edgeCluster.relocatable is defined %}
11+
{{ relocatable_network_config | to_nice_yaml(indent=2) | trim | indent(4) }}
12+
{% else %}
1013
{{ nmstate_host.networkConfig | to_nice_yaml(indent=2) | trim | indent(4) }}
14+
{% endif %}
1115
interfaces:
1216
{% for interface in nmstate_host.networkConfig.interfaces %}
1317
{% if interface.type == "ethernet" %}

edge/roles/edge_install/templates/RelocatableConfig.yaml.j2

Lines changed: 0 additions & 28 deletions
This file was deleted.

edge/roles/edge_install/templates/RelocatableConfigMap.yaml.j2

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,4 @@ data:
2626
path: /etc/default/nodeip-configuration
2727
user:
2828
name: root
29-
relocatable_ip_{{ node_type }}.yaml: |
30-
apiVersion: machineconfiguration.openshift.io/v1
31-
kind: MachineConfig
32-
metadata:
33-
labels:
34-
machineconfiguration.openshift.io/role: {{ node_type }}
35-
name: 99-{{ node_type }}-relocatable-ip
36-
spec:
37-
config:
38-
{{ lookup('ansible.builtin.template', 'RelocatableConfig.yaml.j2') | indent(8) }}
3929
{% endfor %}

edge/roles/edge_install/templates/RoutingViaHost.yaml.j2

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ metadata:
44
name: "routing-via-host"
55
namespace: "{{ metadata.name }}"
66
data:
7-
{% if edgeCluster.routingViaHost | default(false) or
8-
(edgeCluster.relocatable is defined and cluster_deployment.resources[0].status.installVersion is ansible.builtin.version("4.13.0", "lt")) %}
7+
{% if edgeCluster.routingViaHost | default(false) %}
98
routing_via_host.yaml: |
109
apiVersion: operator.openshift.io/v1
1110
kind: Network

edge/roles/edge_install/templates/relocatable_ip.sh.j2

Lines changed: 0 additions & 56 deletions
This file was deleted.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
access_control_node: false
2+
node_ipv4_addresses: []
3+
node_ipv6_addresses: []

edge/roles/edge_post_install/tasks/main.yaml

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -39,44 +39,49 @@
3939
ansible.builtin.set_fact:
4040
access_control_node: true
4141

42-
- name: Get BareMetalHosts
42+
- name: Get Agents
4343
kubernetes.core.k8s_info:
44-
api_version: metal3.io/v1alpha1
45-
kind: BareMetalHost
44+
api_version: agent-install.openshift.io/v1beta1
45+
kind: Agent
4646
namespace: "{{ metadata.name }}"
47-
register: bmh_list
48-
until: bmh_list is not failed
47+
register: agent_list
48+
until: agent_list is not failed
4949

5050
- name: Find control plane node
51-
loop: "{{ bmh_list.resources }}"
51+
loop: "{{ agent_list.resources }}"
5252
loop_control:
5353
label: "{{ item.metadata.name }}"
54-
when: item.metadata.annotations['bmac.agent-install.openshift.io/role'] == "master"
54+
when: item.spec.role == "master"
5555
ansible.builtin.set_fact:
5656
control_plane_node: "{{ item }}"
5757

58-
- name: Find IPv4 for first control plane node
59-
loop: "{{ control_plane_node.status.hardware.nics }}"
58+
- name: Get list of IPv4 addresses for first control plane node
59+
loop: "{{ control_plane_node.status.inventory.interfaces }}"
6060
loop_control:
61-
label: "{{ item.ip | default(item.name) }}"
61+
label: "{{ item.name }}"
62+
ansible.builtin.set_fact:
63+
node_ipv4_addresses: "{{ node_ipv4_addresses + item.ipV4Addresses }}"
64+
65+
- name: Find suitable IPv4 address for first control plane node
66+
loop: "{{ node_ipv4_addresses }}"
6267
when:
63-
- item.ip is defined
64-
- item.ip | ansible.utils.ipv4
65-
- not (relocatable_ipv4_subnet | ansible.utils.network_in_usable(item.ip))
68+
- not (relocatable_ipv4_subnet | ansible.utils.network_in_usable(item | ansible.utils.ipaddr('address')))
6669
ansible.builtin.set_fact:
67-
node_ip: "{{ item.ip }}"
70+
node_ip: "{{ item | ansible.utils.ipaddr('address') }}"
6871

69-
- name: Find IPv6 for first control plane node
70-
loop: "{{ control_plane_node.status.hardware.nics }}"
72+
- name: Get list of IPv6 addresses for first control plane node
73+
loop: "{{ control_plane_node.status.inventory.interfaces }}"
7174
loop_control:
72-
label: "{{ item.ip | default(item.name) }}"
75+
label: "{{ item.name }}"
76+
ansible.builtin.set_fact:
77+
node_ipv6_addresses: "{{ node_ipv6_addresses + item.ipV6Addresses }}"
78+
79+
- name: Find suitable IPv6 address for first control plane node
80+
loop: "{{ node_ipv6_addresses }}"
7381
when:
74-
- node_ip is not defined
75-
- item.ip is defined
76-
- item.ip | ansible.utils.ipv6
77-
- not (relocatable_ipv6_subnet | ansible.utils.network_in_usable(item.ip))
82+
- not (relocatable_ipv6_subnet | ansible.utils.network_in_usable(item | ansible.utils.ipaddr('address')))
7883
ansible.builtin.set_fact:
79-
node_ip: "{{ item.ip }}"
84+
node_ip: "{{ item | ansible.utils.ipaddr('address') }}"
8085

8186
- name: Add required environment vars
8287
ansible.builtin.set_fact:

0 commit comments

Comments
 (0)