Skip to content

Commit bd2b783

Browse files
committed
add systemd services for configuration after start
this adds 4 small systemd services that: - creates crc specific configurations for dnsmasq - sets a new uuid as cluster id - creates the pod for routes-controller - tries to grow the disk and filesystem - checks if the cluster operators are ready
1 parent 914f90f commit bd2b783

12 files changed

+189
-0
lines changed

createdisk-library.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,3 +400,21 @@ function remove_pull_secret_from_disk() {
400400
esac
401401
}
402402

403+
function copy_systemd_units() {
404+
${SSH} core@${VM_IP} -- 'mkdir -p /home/core/systemd-units && mkdir -p /home/core/systemd-scripts'
405+
${SCP} systemd/crc-*.service core@${VM_IP}:/home/core/systemd-units/
406+
${SCP} systemd/crc-*.sh core@${VM_IP}:/home/core/systemd-scripts/
407+
408+
case "${BUNDLE_TYPE}" in
409+
"snc"|"okd")
410+
${SCP} systemd/ocp-*.service core@${VM_IP}:/home/core/systemd-units/
411+
${SCP} systemd/ocp-*.sh core@${VM_IP}:/home/core/systemd-scripts/
412+
;;
413+
esac
414+
415+
${SSH} core@${VM_IP} -- 'sudo cp /home/core/systemd-units/* /etc/systemd/system/ && sudo cp /home/core/systemd-scripts/* /usr/local/bin/'
416+
${SSH} core@${VM_IP} -- 'ls /home/core/systemd-scripts/ | xargs -t -I % sudo chmod +x /usr/local/bin/%'
417+
${SSH} core@${VM_IP} -- 'sudo restorecon -rv /usr/local/bin'
418+
${SSH} core@${VM_IP} -- 'ls /home/core/systemd-units/ | xargs sudo systemctl enable'
419+
${SSH} core@${VM_IP} -- 'rm -rf /home/core/systemd-units /home/core/systemd-scripts'
420+
}

createdisk.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,8 @@ if [ "${ARCH}" == "aarch64" ] && [ ${BUNDLE_TYPE} != "okd" ]; then
130130
${SSH} core@${VM_IP} -- "sudo rpm-ostree install https://kojipkgs.fedoraproject.org//packages/qemu/8.2.6/3.fc40/aarch64/qemu-user-static-x86-8.2.6-3.fc40.aarch64.rpm"
131131
fi
132132

133+
copy_systemd_units
134+
133135
cleanup_vm_image ${VM_NAME} ${VM_IP}
134136

135137
# Delete all the pods and lease from the etcd db so that when this bundle is use for the cluster provision, everything comes up in clean state.

systemd/crc-cluster-status.service

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[Unit]
2+
Description=CRC Unit checking if cluster is ready
3+
After=kubelet.service
4+
Requires=kubelet.service
5+
6+
[Service]
7+
Type=oneshot
8+
ExecStart=/usr/local/bin/crc-cluster-status.sh
9+
StandardOutput=journal
10+
11+
[Install]
12+
WantedBy=multi-user.target

systemd/crc-cluster-status.sh

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/bin/bash
2+
3+
set -x
4+
5+
export KUBECONFIG=/opt/kubeconfig
6+
7+
function check_cluster_unhealthy() {
8+
WAIT="authentication|console|etcd|ingress|openshift-apiserver"
9+
10+
until `oc get co > /dev/null 2>&1`
11+
do
12+
sleep 2
13+
done
14+
15+
for i in $(oc get co | grep -P "$WAIT" | awk '{ print $3 }')
16+
do
17+
if [[ $i == "False" ]]
18+
then
19+
return 0
20+
fi
21+
done
22+
return 1
23+
}
24+
25+
# rm -rf /tmp/.crc-cluster-ready
26+
27+
COUNTER=0
28+
CLUSTER_HEALTH_SLEEP=8
29+
CLUSTER_HEALTH_RETRIES=500
30+
31+
while $(check_cluster_unhealthy)
32+
do
33+
sleep $CLUSTER_HEALTH_SLEEP
34+
if [[ $COUNTER == $CLUSTER_HEALTH_RETRIES ]]
35+
then
36+
return 1
37+
fi
38+
((COUNTER++))
39+
done
40+
41+
# need to set a marker to let `crc` know the cluster is ready
42+
# touch /tmp/.crc-cluster-ready
43+

systemd/crc-dnsmasq.service

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[Unit]
2+
Description=CRC Unit for configuring dnsmasq
3+
Requires=ovs-configuration.service
4+
After=ovs-configuration.service
5+
6+
[Service]
7+
Type=oneshot
8+
ExecCondition=/usr/bin/bash -c "/usr/bin/ping -c1 gateway && echo 1 || echo 0"
9+
ExecStart=/usr/local/bin/crc-dnsmasq.sh
10+
ExecStartPost=/usr/bin/systemctl start dnsmasq.service
11+
StandardOutput=journal
12+
13+
[Install]
14+
WantedBy=multi-user.target

systemd/crc-dnsmasq.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/bin/bash
2+
3+
set -x
4+
5+
hostName=$(hostname)
6+
ip=$(ip -4 addr show br-ex | grep -oP '(?<=inet\s)192+(\.\d+){3}')
7+
iip=$(hostname -i)
8+
9+
cat << EOF > /etc/dnsmasq.d/crc-dnsmasq.conf
10+
listen-address=$ip
11+
expand-hosts
12+
log-queries
13+
local=/crc.testing/
14+
domain=crc.testing
15+
address=/apps-crc.testing/$ip
16+
address=/api.crc.testing/$ip
17+
address=/api-int.crc.testing/$ip
18+
address=/$hostName.crc.testing/$iip
19+
EOF
20+

systemd/crc-routes-controller.service

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[Unit]
2+
Description=CRC Unit starting routes controller
3+
After=kubelet.service
4+
Requires=kubelet.service
5+
6+
[Service]
7+
Type=oneshot
8+
ExecCondition=/usr/bin/bash -c "/usr/bin/ping -c1 gateway && echo 1 || echo 0"
9+
ExecStart=/usr/local/bin/crc-routes-controller.sh
10+
StandardOutput=journal
11+
12+
[Install]
13+
WantedBy=multi-user.target

systemd/crc-routes-controller.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/bash
2+
3+
set -x
4+
5+
export KUBECONFIG=/opt/kubeconfig
6+
7+
retry=0
8+
max_retry=20
9+
until `oc get pods > /dev/null 2>&1`
10+
do
11+
[ $retry == $max_retry ] && exit 1
12+
sleep 5
13+
((retry++))
14+
done
15+
16+
oc apply -f /opt/crc/routes-controller.yaml
17+

systemd/ocp-clusterid.service

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[Unit]
2+
Description=CRC Unit setting random cluster ID
3+
After=kubelet.service
4+
Requires=kubelet.service
5+
6+
[Service]
7+
Type=oneshot
8+
ExecStart=/usr/local/bin/ocp-clusterid.sh
9+
StandardOutput=journal
10+
11+
[Install]
12+
WantedBy=multi-user.target

systemd/ocp-clusterid.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/bash
2+
3+
set -x
4+
5+
export KUBECONFIG="/opt/kubeconfig"
6+
uuid=$(uuidgen)
7+
8+
retry=0
9+
max_retry=20
10+
until `oc get clusterversion > /dev/null 2>&1`
11+
do
12+
[ $retry == $max_retry ] && exit 1
13+
sleep 5
14+
((retry++))
15+
done
16+
17+
oc patch clusterversion version -p "{\"spec\":{\"clusterID\":\"${uuid}\"}}" --type merge

systemd/ocp-growfs.service

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[Unit]
2+
Description=CRC Unit to grow the root filesystem
3+
4+
[Service]
5+
Type=oneshot
6+
ExecStart=/usr/local/bin/ocp-growfs.sh
7+
StandardOutput=journal
8+
9+
[Install]
10+
WantedBy=multi-user.target

systemd/ocp-growfs.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/bash
2+
3+
set -x
4+
5+
root_partition=$(/usr/sbin/blkid -t TYPE=xfs -o device)
6+
/usr/bin/growpart "${root_partition#?}" "${root_partition#/dev/???}"
7+
8+
rootFS="/sysroot"
9+
mount -o remount,rw "${rootFS}"
10+
xfs_growfs "${rootFS}"
11+
#mount -o remount,ro "${rootFS}"

0 commit comments

Comments
 (0)