Skip to content
This repository has been archived by the owner on Mar 23, 2020. It is now read-only.

Commit

Permalink
Added post-install script to apply mcos
Browse files Browse the repository at this point in the history
Also added the bridge creation as a function instead a different script.
  • Loading branch information
e-minguez committed Aug 28, 2019
1 parent 9ad830f commit f3610fd
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 0 deletions.
55 changes: 55 additions & 0 deletions 99_post_install.sh
Original file line number Diff line number Diff line change
@@ -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
22 changes: 22 additions & 0 deletions assets/post-install/99-brext-master.yaml.template
Original file line number Diff line number Diff line change
@@ -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}
2 changes: 2 additions & 0 deletions assets/post-install/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
This directory hosts machine-config objects that will be applied in an
alphabetically sorted list after a successful installation.
8 changes: 8 additions & 0 deletions assets/post-install/ifcfg-bridge.template
Original file line number Diff line number Diff line change
@@ -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"
5 changes: 5 additions & 0 deletions assets/post-install/ifcfg-interface.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
DEVICE=${interface}
BRIDGE=${bridge}
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=none

0 comments on commit f3610fd

Please sign in to comment.