Skip to content

Commit

Permalink
Remove relocation script (#59)
Browse files Browse the repository at this point in the history
* Remove relocation script

* Update NMStateConfig

* fix var

* add dns

* fix linter

* update doc

* remove dns config

* fix MNO
  • Loading branch information
loganmc10 authored Mar 13, 2024
1 parent dc5b75b commit 403e78a
Show file tree
Hide file tree
Showing 13 changed files with 91 additions and 164 deletions.
4 changes: 1 addition & 3 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ jobs:
- name: Check code
run: |
ansible-lint -s -x yaml[line-length],var-naming[no-role-prefix] --exclude .github
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}}"
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}}"
shellcheck -o all relocatable_ip.sh relocatable_ip_sno.sh edge/roles/edge_csr_approver/files/csr_approver.sh
shellcheck -o all edge/roles/edge_csr_approver/files/csr_approver.sh
test-container:
runs-on: ubuntu-latest
Expand Down
1 change: 1 addition & 0 deletions common/roles/install_deps/tasks/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
name:
- kubernetes
- netaddr
- jmespath
4 changes: 2 additions & 2 deletions edge/docs/RELOCATABLE.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Relocatable Edge Cluster
This feature requires OpenShift 4.12 or higher.
This feature requires OpenShift 4.14 or higher. It also requires MCE 2.5+ (ACM 2.10+).

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.

## How it works
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.
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.

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.

Expand Down
28 changes: 0 additions & 28 deletions edge/roles/edge_install/tasks/get_relocatable_ip.yaml

This file was deleted.

63 changes: 53 additions & 10 deletions edge/roles/edge_install/tasks/setup_host_networking.yaml
Original file line number Diff line number Diff line change
@@ -1,17 +1,60 @@
- name: Calculate relocatable IP
when: edgeCluster.relocatable is defined
block:
- name: Increment relocatable IP address
ansible.builtin.set_fact:
interface_number: "{{ (interface_number | int) + 1 }}"

- name: Filter the relocatable interface
ansible.builtin.set_fact:
filtered_interface: "{{ nmstate_host.networkConfig.interfaces | json_query('[?name == `' + edgeCluster.relocatable.interface + '`]') | first }}"

- name: Create entry for IPv4 address list
when: cluster_ipv4
block:
- name: Get IPv4 addresses
ansible.builtin.set_fact:
ipv4_addresses: "{{ filtered_interface.ipv4.address | default([]) }}"

- name: Append IPv4 relocatable address
ansible.builtin.set_fact:
ipv4_addresses: "{{ ipv4_addresses + [{'ip': relocatable_ipv4_subnet | ansible.utils.nthhost(interface_number | int), 'prefix-length': relocatable_ipv4_subnet | ansible.utils.ipaddr('prefix')}] }}"

- name: Update IPv4 addresses
ansible.builtin.set_fact:
filtered_interface: "{{ filtered_interface | combine({'ipv4': {'address': ipv4_addresses}}, recursive=true) }}"

- name: Create entry for IPv6 address list
when: cluster_ipv6
block:
- name: Get IPv6 addresses
ansible.builtin.set_fact:
ipv6_addresses: "{{ filtered_interface.ipv6.address | default([]) }}"

- name: Append IPv6 relocatable address
ansible.builtin.set_fact:
ipv6_addresses: "{{ ipv6_addresses + [{'ip': relocatable_ipv6_subnet | ansible.utils.nthhost(interface_number | int), 'prefix-length': relocatable_ipv6_subnet | ansible.utils.ipaddr('prefix')}] }}"

- name: Update IPv6 addresses
ansible.builtin.set_fact:
filtered_interface: "{{ filtered_interface | combine({'ipv6': {'address': ipv6_addresses}}, recursive=true) }}"

- name: Get all non-reloctable interfaces
ansible.builtin.set_fact:
interfaces_list: "{{ nmstate_host.networkConfig.interfaces | json_query('[?name != `' + edgeCluster.relocatable.interface + '`]') }}"

- name: Add reloctable interface
ansible.builtin.set_fact:
interfaces_list: "{{ interfaces_list + [filtered_interface] }}"

- name: Create new networkConfig
ansible.builtin.set_fact:
relocatable_network_config: "{{ nmstate_host.networkConfig | combine({'interfaces': interfaces_list}, recursive=true) }}"

- name: Create NMStateConfig
kubernetes.core.k8s:
template: NMStateConfig.yaml.j2
apply: true
state: present
register: k8s_result
until: k8s_result is not failed

- name: Calculate relocatable IP
when: edgeCluster.relocatable is defined
block:
- name: Get relocatable interface index
loop: "{{ nmstate_host.networkConfig.interfaces }}"
loop_control:
label: "{{ item.name }}"
when: item.name == edgeCluster.relocatable.interface
ansible.builtin.include_tasks: get_relocatable_ip.yaml
3 changes: 0 additions & 3 deletions edge/roles/edge_install/templates/InfraEnv.yaml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,3 @@ spec:
proxy:
{{ proxy | to_nice_yaml(indent=2) | trim | indent(4) }}
{% endif %}
{% if edgeCluster.relocatable is defined %}
ignitionConfigOverride: '{{ (lookup('ansible.builtin.template', 'RelocatableConfig.yaml.j2') | from_yaml | to_json) }}'
{% endif %}
4 changes: 4 additions & 0 deletions edge/roles/edge_install/templates/NMStateConfig.yaml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ metadata:
nmstate-cluster: "{{ metadata.name }}"
spec:
config:
{% if edgeCluster.relocatable is defined %}
{{ relocatable_network_config | to_nice_yaml(indent=2) | trim | indent(4) }}
{% else %}
{{ nmstate_host.networkConfig | to_nice_yaml(indent=2) | trim | indent(4) }}
{% endif %}
interfaces:
{% for interface in nmstate_host.networkConfig.interfaces %}
{% if interface.type == "ethernet" %}
Expand Down
28 changes: 0 additions & 28 deletions edge/roles/edge_install/templates/RelocatableConfig.yaml.j2

This file was deleted.

10 changes: 0 additions & 10 deletions edge/roles/edge_install/templates/RelocatableConfigMap.yaml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,4 @@ data:
path: /etc/default/nodeip-configuration
user:
name: root
relocatable_ip_{{ node_type }}.yaml: |
apiVersion: machineconfiguration.openshift.io/v1
kind: MachineConfig
metadata:
labels:
machineconfiguration.openshift.io/role: {{ node_type }}
name: 99-{{ node_type }}-relocatable-ip
spec:
config:
{{ lookup('ansible.builtin.template', 'RelocatableConfig.yaml.j2') | indent(8) }}
{% endfor %}
3 changes: 1 addition & 2 deletions edge/roles/edge_install/templates/RoutingViaHost.yaml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ metadata:
name: "routing-via-host"
namespace: "{{ metadata.name }}"
data:
{% if edgeCluster.routingViaHost | default(false) or
(edgeCluster.relocatable is defined and cluster_deployment.resources[0].status.installVersion is ansible.builtin.version("4.13.0", "lt")) %}
{% if edgeCluster.routingViaHost | default(false) %}
routing_via_host.yaml: |
apiVersion: operator.openshift.io/v1
kind: Network
Expand Down
56 changes: 0 additions & 56 deletions edge/roles/edge_install/templates/relocatable_ip.sh.j2

This file was deleted.

2 changes: 2 additions & 0 deletions edge/roles/edge_post_install/defaults/main.yaml
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
access_control_node: false
node_ipv4_addresses: []
node_ipv6_addresses: []
49 changes: 27 additions & 22 deletions edge/roles/edge_post_install/tasks/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,44 +39,49 @@
ansible.builtin.set_fact:
access_control_node: true

- name: Get BareMetalHosts
- name: Get Agents
kubernetes.core.k8s_info:
api_version: metal3.io/v1alpha1
kind: BareMetalHost
api_version: agent-install.openshift.io/v1beta1
kind: Agent
namespace: "{{ metadata.name }}"
register: bmh_list
until: bmh_list is not failed
register: agent_list
until: agent_list is not failed

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

- name: Find IPv4 for first control plane node
loop: "{{ control_plane_node.status.hardware.nics }}"
- name: Get list of IPv4 addresses for first control plane node
loop: "{{ control_plane_node.status.inventory.interfaces }}"
loop_control:
label: "{{ item.ip | default(item.name) }}"
label: "{{ item.name }}"
ansible.builtin.set_fact:
node_ipv4_addresses: "{{ node_ipv4_addresses + item.ipV4Addresses }}"

- name: Find suitable IPv4 address for first control plane node
loop: "{{ node_ipv4_addresses }}"
when:
- item.ip is defined
- item.ip | ansible.utils.ipv4
- not (relocatable_ipv4_subnet | ansible.utils.network_in_usable(item.ip))
- not (relocatable_ipv4_subnet | ansible.utils.network_in_usable(item | ansible.utils.ipaddr('address')))
ansible.builtin.set_fact:
node_ip: "{{ item.ip }}"
node_ip: "{{ item | ansible.utils.ipaddr('address') }}"

- name: Find IPv6 for first control plane node
loop: "{{ control_plane_node.status.hardware.nics }}"
- name: Get list of IPv6 addresses for first control plane node
loop: "{{ control_plane_node.status.inventory.interfaces }}"
loop_control:
label: "{{ item.ip | default(item.name) }}"
label: "{{ item.name }}"
ansible.builtin.set_fact:
node_ipv6_addresses: "{{ node_ipv6_addresses + item.ipV6Addresses }}"

- name: Find suitable IPv6 address for first control plane node
loop: "{{ node_ipv6_addresses }}"
when:
- node_ip is not defined
- item.ip is defined
- item.ip | ansible.utils.ipv6
- not (relocatable_ipv6_subnet | ansible.utils.network_in_usable(item.ip))
- not (relocatable_ipv6_subnet | ansible.utils.network_in_usable(item | ansible.utils.ipaddr('address')))
ansible.builtin.set_fact:
node_ip: "{{ item.ip }}"
node_ip: "{{ item | ansible.utils.ipaddr('address') }}"

- name: Add required environment vars
ansible.builtin.set_fact:
Expand Down

0 comments on commit 403e78a

Please sign in to comment.