From 419269955eccb5464f8b5e2a8e9fe5fe9a8c35ef Mon Sep 17 00:00:00 2001 From: Petr Horacek Date: Thu, 29 Aug 2019 00:40:58 +0200 Subject: [PATCH 1/2] configure host networking policy with default bridge Configure linux bridge as the default network interface. Signed-off-by: Petr Horacek --- CNV/Makefile | 1 + CNV/cnv-2.1.0.sh | 3 ++ CNV/configure-network.sh | 53 +++++++++++++++++++ OpenShift/99_post_install.sh | 25 --------- .../99-brext-master.yaml.template | 22 -------- .../assets/post-install/ifcfg-bridge.template | 8 --- .../post-install/ifcfg-interface.template | 5 -- 7 files changed, 57 insertions(+), 60 deletions(-) create mode 100755 CNV/configure-network.sh delete mode 100644 OpenShift/assets/post-install/99-brext-master.yaml.template delete mode 100644 OpenShift/assets/post-install/ifcfg-bridge.template delete mode 100644 OpenShift/assets/post-install/ifcfg-interface.template diff --git a/CNV/Makefile b/CNV/Makefile index c17958e..4ab34f8 100644 --- a/CNV/Makefile +++ b/CNV/Makefile @@ -6,6 +6,7 @@ all: deploy deploy: ./cnv-2.1.0.sh + ./configure-network.sh upgrade: ./cnv-upgrade.sh diff --git a/CNV/cnv-2.1.0.sh b/CNV/cnv-2.1.0.sh index 3432fae..617f2fe 100755 --- a/CNV/cnv-2.1.0.sh +++ b/CNV/cnv-2.1.0.sh @@ -162,3 +162,6 @@ metadata: spec: BareMetalPlatform: true EOF + +echo "Waiting for HCO to get fully deployed" +oc wait -n ${TARGET_NAMESPACE} hyperconverged hyperconverged-cluster --for condition=Available --timeout=10m diff --git a/CNV/configure-network.sh b/CNV/configure-network.sh new file mode 100755 index 0000000..2181475 --- /dev/null +++ b/CNV/configure-network.sh @@ -0,0 +1,53 @@ +#!/bin/bash + +set -ex + +MACHINE_CIDR=$(grep 'machineCIDR' ../OpenShift/install-config.yaml | sed 's/\(.*\): *\(.*\)/\2/') +BRIDGE_NAME=brext + +export KUBECONFIG=${KUBECONFIG:-../OpenShift/ocp/auth/kubeconfig} + +echo "Configuring networks on nodes" + +echo "Detecting the default interface" +while ! default_iface=$(oc get nodenetworkstate ${node} -o jsonpath="{.items[0].status.currentState.routes.running[?(@.destination==\"${MACHINE_CIDR}\")].next-hop-interface}" | cut -d " " -f 1); do + sleep 10 +done + +if [ "${default_iface}" == "${BRIDGE_NAME}" ]; then + echo "Bridge ${BRIDGE_NAME} seems to be already configured as the default interface, skipping the rest of network setup" + exit 0 +fi + +echo "Applying node network configuration policy" +cat < ${BREXT_FILE} - echo "Done creating bridge definition" - else - echo "Bridge already there!" - fi -} - apply_mc(){ # Disable auto reboot hosts in order to apply several mcos at the same time for node_type in master worker; do @@ -229,6 +205,5 @@ function add-machine-ips() { } add-machine-ips -create_bridge create_ntp_config apply_mc diff --git a/OpenShift/assets/post-install/99-brext-master.yaml.template b/OpenShift/assets/post-install/99-brext-master.yaml.template deleted file mode 100644 index d0e6225..0000000 --- a/OpenShift/assets/post-install/99-brext-master.yaml.template +++ /dev/null @@ -1,22 +0,0 @@ -apiVersion: machineconfiguration.openshift.io/v1 -kind: MachineConfig -metadata: - labels: - machineconfiguration.openshift.io/role: master - name: 99-brext-master -spec: - config: - ignition: - version: 2.2.0 - storage: - files: - - contents: - source: data:text/plain;charset=utf-8;base64,${interface_content} - filesystem: root - mode: 0644 - path: /etc/sysconfig/network-scripts/ifcfg-${interface} - - contents: - source: data:text/plain;charset=utf-8;base64,${bridge_content} - filesystem: root - mode: 0644 - path: /etc/sysconfig/network-scripts/ifcfg-${bridge} diff --git a/OpenShift/assets/post-install/ifcfg-bridge.template b/OpenShift/assets/post-install/ifcfg-bridge.template deleted file mode 100644 index ac4de35..0000000 --- a/OpenShift/assets/post-install/ifcfg-bridge.template +++ /dev/null @@ -1,8 +0,0 @@ -DEVICE=${bridge} -NAME=${bridge} -TYPE=Bridge -ONBOOT=yes -NM_CONTROLLED=yes -BOOTPROTO=dhcp -BRIDGING_OPTS=vlan_filtering=1 -BRIDGE_VLANS="1 pvid untagged,20,300-400 untagged" diff --git a/OpenShift/assets/post-install/ifcfg-interface.template b/OpenShift/assets/post-install/ifcfg-interface.template deleted file mode 100644 index c010bc6..0000000 --- a/OpenShift/assets/post-install/ifcfg-interface.template +++ /dev/null @@ -1,5 +0,0 @@ -DEVICE=${interface} -BRIDGE=${bridge} -ONBOOT=yes -NM_CONTROLLED=yes -BOOTPROTO=none From a54fe41419406b22d8f276d2e3a08732101d48a9 Mon Sep 17 00:00:00 2001 From: Petr Horacek Date: Fri, 20 Sep 2019 12:45:12 +0200 Subject: [PATCH 2/2] configure networking explicitly on each node Due to a bug in kubernetes-nmstate/nmstate/NM, we get a random MAC address on our bridge after reboot. Because of that we get a different IP address and lose the host. With this patch, we explicitly request MAC of the NIC on the bridge. Signed-off-by: Petr Horacek --- CNV/configure-network.sh | 34 +++++++++++++++++++++------------- README.md | 10 ++++++---- 2 files changed, 27 insertions(+), 17 deletions(-) diff --git a/CNV/configure-network.sh b/CNV/configure-network.sh index 2181475..ce84150 100755 --- a/CNV/configure-network.sh +++ b/CNV/configure-network.sh @@ -7,30 +7,38 @@ BRIDGE_NAME=brext export KUBECONFIG=${KUBECONFIG:-../OpenShift/ocp/auth/kubeconfig} +nodes=$(oc get nodes -o jsonpath='{range .items[*]}{.metadata.name} {end}') + echo "Configuring networks on nodes" +for node in $nodes; do + echo "Detecting the default interface" + while ! default_iface=$(oc get nodenetworkstate ${node} -o jsonpath="{.status.currentState.routes.running[?(@.destination==\"${MACHINE_CIDR}\")].next-hop-interface}" | cut -d " " -f 1); do + sleep 10 + done -echo "Detecting the default interface" -while ! default_iface=$(oc get nodenetworkstate ${node} -o jsonpath="{.items[0].status.currentState.routes.running[?(@.destination==\"${MACHINE_CIDR}\")].next-hop-interface}" | cut -d " " -f 1); do - sleep 10 -done + if [ "${default_iface}" == "${BRIDGE_NAME}" ]; then + echo "Bridge ${BRIDGE_NAME} seems to be already configured as the default interface on node ${node}, skipping the rest of network setup" + continue + fi -if [ "${default_iface}" == "${BRIDGE_NAME}" ]; then - echo "Bridge ${BRIDGE_NAME} seems to be already configured as the default interface, skipping the rest of network setup" - exit 0 -fi + echo "Detecting MAC address of the default interface" + default_iface_mac=$(oc get nodenetworkstate ${node} -o jsonpath="{.status.currentState.interfaces[?(@.name==\"${default_iface}\")].mac-address}") -echo "Applying node network configuration policy" -cat <