Skip to content

Commit 1f5383b

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 - adds the pull secret to the cluster - sets kubeadmin and developer user passwords
1 parent 914f90f commit 1f5383b

16 files changed

+272
-0
lines changed

Diff for: createdisk-library.sh

+18
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+
}

Diff for: createdisk.sh

+2
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.

Diff for: systemd/crc-dnsmasq.service

+14
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 && exit 1 || exit 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

Diff for: systemd/crc-dnsmasq.sh

+20
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+

Diff for: systemd/crc-routes-controller.service

+13
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 && exit 1 || exit 0"
9+
ExecStart=/usr/local/bin/crc-routes-controller.sh
10+
StandardOutput=journal
11+
12+
[Install]
13+
WantedBy=multi-user.target

Diff for: systemd/crc-routes-controller.sh

+17
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+

Diff for: systemd/ocp-cluster-status.service

+12
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/ocp-cluster-status.sh
9+
StandardOutput=journal
10+
11+
[Install]
12+
WantedBy=multi-user.target

Diff for: systemd/ocp-cluster-status.sh

+43
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+

Diff for: systemd/ocp-clusterid.service

+12
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

Diff for: systemd/ocp-clusterid.sh

+17
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

Diff for: systemd/ocp-growfs.service

+10
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

Diff for: systemd/ocp-growfs.sh

+11
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::-1}" "${root_partition#/dev/???}"
7+
8+
rootFS="/sysroot"
9+
mount -o remount,rw "${rootFS}"
10+
xfs_growfs "${rootFS}"
11+
#mount -o remount,ro "${rootFS}"

Diff for: systemd/ocp-pullsecret.service

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[Unit]
2+
Description=CRC Unit for adding pull secret to cluster
3+
After=kubelet.service
4+
Requires=kubelet.service
5+
ConditionPathExists=/opt/crc/pull-secret
6+
7+
[Service]
8+
Type=oneshot
9+
ExecStart=/usr/local/bin/ocp-pullsecret.sh
10+
StandardOutput=journal
11+
12+
[Install]
13+
WantedBy=multi-user.target

Diff for: systemd/ocp-pullsecret.sh

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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 secret > /dev/null 2>&1`
10+
do
11+
[ $retry == $max_retry ] && exit 1
12+
sleep 5
13+
((retry++))
14+
done
15+
16+
# check if existing pull-secret is valid if not add the one from /opt/crc/pull-secret
17+
existingPsB64=$(oc get secret pull-secret -n openshift-config -o jsonpath="{['data']['\.dockerconfigjson']}")
18+
existingPs=$(echo "${existingPsB64}" | base64 -d)
19+
20+
echo "${existingPs}" | jq -e '.auths'
21+
22+
if [[ $? != 0 ]]; then
23+
pullSecretB64=$(cat /opt/crc/pull-secret)
24+
oc patch secret pull-secret -n openshift-config --type merge -p "{\"data\":{\".dockerconfigjson\":\"${pullSecretB64}\"}}"
25+
fi
26+
27+
rm -f /opt/crc/pull-secret

Diff for: systemd/ocp-userpasswords.service

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[Unit]
2+
Description=CRC Unit for adding pull secret to cluster
3+
After=kubelet.service
4+
Requires=kubelet.service
5+
ConditionPathExists=/opt/crc/pass_developer
6+
ConditionPathExists=/opt/crc/pass_kubeadmin
7+
8+
[Service]
9+
Type=oneshot
10+
ExecStart=/usr/local/bin/ocp-userpasswords.sh
11+
StandardOutput=journal
12+
13+
[Install]
14+
WantedBy=multi-user.target

Diff for: systemd/ocp-userpasswords.sh

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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 secret > /dev/null 2>&1`
10+
do
11+
[ $retry == $max_retry ] && exit 1
12+
sleep 5
13+
((retry++))
14+
done
15+
16+
PASS_DEVELOPER=$(cat /opt/crc/pass_developer)
17+
PASS_KUBEADMIN=$(cat /opt/crc/pass_kubeadmin)
18+
19+
podman run --rm -ti xmartlabs/htpasswd developer $PASS_DEVELOPER > /tmp/htpasswd.developer
20+
podman run --rm -ti xmartlabs/htpasswd kubeadmin $PASS_KUBEADMIN > /tmp/htpasswd.kubeadmin
21+
22+
cat /tmp/htpasswd.developer > /tmp/htpasswd.txt
23+
cat /tmp/htpasswd.kubeadmin >> /tmp/htpasswd.txt
24+
sed -i '/^\s*$/d' /tmp/htpasswd.txt
25+
26+
oc create secret generic htpass-secret --from-file=htpasswd=/tmp/htpasswd.txt -n openshift-config --dry-run=client -o yaml > /tmp/htpass-secret.yaml
27+
oc replace -f /tmp/htpass-secret.yaml
28+
29+
rm -f /opt/crc/pass_developer /opt/crc/pass_kubeadmin

0 commit comments

Comments
 (0)