diff --git a/99_post_install.sh b/99_post_install.sh new file mode 100644 index 0000000..a37b2c8 --- /dev/null +++ b/99_post_install.sh @@ -0,0 +1,55 @@ +#!/usr/bin/env bash +set -xe + +source logging.sh +source common.sh + +KUBECONFIG=${KUBECONFIG:-ocp/auth/kubeconfig} +IFCFG_INTERFACE="assets/post-install/ifcfg-interface.template" +IFCFG_BRIDGE="assets/post-install/ifcfg-bridge.template" + +export bridge="${bridge:-brext}" + +create_bridge(){ + echo "Deploying Bridge ${bridge}..." + + FIRST_MASTER=$(oc get node -o custom-columns=IP:.status.addresses[0].address --no-headers | head -1) + export interface=$(ssh -q -o StrictHostKeyChecking=no core@$FIRST_MASTER "ip r | grep default | grep -Po '(?<=dev )(\S+)'") + if [ "$interface" == "" ] ; then + echo "Issue detecting interface to use! Leaving..." + exit 1 + if [ "$interface" != "$bridge" ] ; then + echo "Using interface $interface" + export interface_content=$(envsubst < ${IFCFG_INTERFACE} | base64) + export bridge_content=$(envsubst < ${IFCFG_BRIDGE} | base64) + envsubst < assets/post-install/99-brext-master.yaml.template > assets/post-install/99-brext-master.yaml + echo "Done creating bridge definition" + else + echo "Bridge already there!" + fi +} + +apply_mc(){ + for node_type in master node; do + # Disable auto reboot hosts in order to apply several mcos at the same time + oc patch --type=merge --patch='{"spec":{"paused":true}}' machineconfigpool/${node_type} + + # Apply machine configs + echo "Applying machine configs..." + oc create -f assets/post-install/*-${node_type}.yaml + + # Enable auto reboot + oc patch --type=merge --patch='{"spec":{"paused":false}}' machineconfigpool/${node_type} + + echo "Rebooting nodes..." + # This sleep is required because the machine-config changes are not immediate + sleep 30 + + # The 'while' is required because in the process of rebooting the masters, the + # oc wait connection is lost a few times, which is normal + while ! oc wait mcp/${node_type} --for condition=updated --timeout 600s ; do sleep 1 ; done + done +} + +create_bridge +apply_mc diff --git a/assets/post-install/99-brext-master.yaml.template b/assets/post-install/99-brext-master.yaml.template new file mode 100644 index 0000000..d0e6225 --- /dev/null +++ b/assets/post-install/99-brext-master.yaml.template @@ -0,0 +1,22 @@ +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/assets/post-install/README.md b/assets/post-install/README.md new file mode 100644 index 0000000..ae7e81b --- /dev/null +++ b/assets/post-install/README.md @@ -0,0 +1,2 @@ +This directory hosts machine-config objects that will be applied in an +alphabetically sorted list after a successful installation. diff --git a/assets/post-install/ifcfg-bridge.template b/assets/post-install/ifcfg-bridge.template new file mode 100644 index 0000000..ac4de35 --- /dev/null +++ b/assets/post-install/ifcfg-bridge.template @@ -0,0 +1,8 @@ +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/assets/post-install/ifcfg-interface.template b/assets/post-install/ifcfg-interface.template new file mode 100644 index 0000000..c010bc6 --- /dev/null +++ b/assets/post-install/ifcfg-interface.template @@ -0,0 +1,5 @@ +DEVICE=${interface} +BRIDGE=${bridge} +ONBOOT=yes +NM_CONTROLLED=yes +BOOTPROTO=none