Skip to content

Commit d90d53d

Browse files
committed
Update createdisk script to create microshift bundle
1 parent 9e300d9 commit d90d53d

File tree

2 files changed

+64
-18
lines changed

2 files changed

+64
-18
lines changed

createdisk-library.sh

+15
Original file line numberDiff line numberDiff line change
@@ -383,3 +383,18 @@ function download_podman() {
383383
mv podman-remote/windows/podman-${version}/usr/bin/podman.exe podman-remote/windows
384384
fi
385385
}
386+
387+
# As of now sparsify helper is very specific to OCP/OKD kind of bundle where we get the
388+
# partition for the root label and then mount it with guestfish to cleanup /boot. With
389+
# microshift vm we are using lvm and guestfish error out during mount
390+
# mount /dev/sda3 /
391+
# libguestfs: error: mount: mount exited with status 32: mount: /sysroot: unknown filesystem type 'LVM2_member'
392+
# There might be other way for guestfish to mount lvm but as of now using a seperate helper is easy.
393+
function sparsify_lvm() {
394+
local destDir=$1
395+
sudo cp /var/lib/libvirt/images/${SNC_PRODUCT_NAME}.qcow2 ${destDir}
396+
sudo chown $USER:$USER -R ${destDir}
397+
export LIBGUESTFS_BACKEND=direct
398+
virt-sparsify --in-place ${destDir}/${SNC_PRODUCT_NAME}.qcow2
399+
chmod 0644 ${destDir}/${SNC_PRODUCT_NAME}.qcow2
400+
}

createdisk.sh

+49-18
Original file line numberDiff line numberDiff line change
@@ -15,36 +15,61 @@ INSTALL_DIR=${1:-crc-tmp-install-data}
1515

1616
# If the user set OKD_VERSION in the environment, then use it to set BASE_OS
1717
OKD_VERSION=${OKD_VERSION:-none}
18-
destDirPrefix="crc"
1918
if [[ ${OKD_VERSION} != "none" ]]
2019
then
2120
BASE_OS=fedora-coreos
2221
destDirPrefix="crc_okd"
2322
fi
2423
BASE_OS=${BASE_OS:-rhcos}
2524
OPENSHIFT_VERSION=$(${JQ} -r .clusterInfo.openshiftVersion $INSTALL_DIR/crc-bundle-info.json)
25+
BUNDLE_TYPE=$(${JQ} -r .type $INSTALL_DIR/crc-bundle-info.json)
26+
destDirPrefix="crc"
27+
if [ ${BUNDLE_TYPE} == "microshift" ]; then
28+
destDirPrefix="crc_${BUNDLE_TYPE}"
29+
BASE_OS=rhel
30+
fi
2631

2732
# SNC_PRODUCT_NAME: If user want to use other than default product name (crc)
2833
# VM_PREFIX: short VM name (set by SNC_PRODUCT_NAME) + random string generated by openshift-installer
2934
SNC_PRODUCT_NAME=${SNC_PRODUCT_NAME:-crc}
30-
VM_PREFIX=$(get_vm_prefix ${SNC_PRODUCT_NAME})
31-
VM_NAME="${VM_PREFIX}-master-0"
35+
if [ ${BUNDLE_TYPE} == "microshift" ]; then
36+
VM_NAME=${SNC_PRODUCT_NAME}
37+
else
38+
VM_PREFIX=$(get_vm_prefix ${SNC_PRODUCT_NAME})
39+
VM_NAME="${VM_PREFIX}-master-0"
40+
fi
3241

33-
# Get the IP of the VM
3442
VM_IP=$(sudo virsh domifaddr ${VM_NAME} | tail -2 | head -1 | awk '{print $4}' | cut -d/ -f1)
3543

36-
# Remove unused images from container storage
37-
${SSH} core@${VM_IP} -- 'sudo crictl rmi --prune'
38-
39-
# Disable kubelet service
40-
${SSH} core@${VM_IP} -- sudo systemctl disable kubelet
41-
42-
# Stop the kubelet service so it will not reprovision the pods
43-
${SSH} core@${VM_IP} -- sudo systemctl stop kubelet
44+
if [ ${BUNDLE_TYPE} != "microshift" ]; then
45+
# Remove unused images from container storage
46+
${SSH} core@${VM_IP} -- 'sudo crictl rmi --prune'
47+
48+
# Disable kubelet service
49+
${SSH} core@${VM_IP} -- sudo systemctl disable kubelet
50+
51+
# Stop the kubelet service so it will not reprovision the pods
52+
${SSH} core@${VM_IP} -- sudo systemctl stop kubelet
53+
fi
4454

4555
# Enable the podman.socket service for API V2
4656
${SSH} core@${VM_IP} -- sudo systemctl enable podman.socket
4757

58+
if [ ${BUNDLE_TYPE} == "microshift" ]; then
59+
# Pull openshift release images because as part of microshift bundle creation we
60+
# don't run microshift service which fetch these image but instead service is run
61+
# as part of crc so user have a fresh cluster instead something already provisioned
62+
# but images we cache it as part of bundle.
63+
${SSH} core@${VM_IP} 'sudo bash -x -s' <<EOF
64+
jq --raw-output '.images | to_entries | map(.value) | join("\n")' /usr/share/microshift/release/release-$(uname -i).json | xargs -n1 podman pull --authfile /etc/crio/openshift-pull-secret
65+
EOF
66+
# Disable firewalld otherwise generated bundle have it running and each podman container
67+
# which try to expose a port need to added to firewalld rule manually
68+
# also in case of microshift the ports like 2222, 443, 80 ..etc need to be manually added
69+
# and OCP/OKD/podman bundles have it disabled by default.
70+
${SSH} core@${VM_IP} -- sudo systemctl disable firewalld
71+
fi
72+
4873
# Remove audit logs
4974
${SSH} core@${VM_IP} -- 'sudo find /var/log/ -iname "*.log" -exec rm -f {} \;'
5075

@@ -76,7 +101,7 @@ cat crio-wipe.service | ${SSH} core@${VM_IP} "sudo tee -a /etc/systemd/system/cr
76101
# Preload routes controller
77102
${SSH} core@${VM_IP} -- "sudo podman pull quay.io/crcont/routes-controller:${image_tag}"
78103

79-
if [ "${ARCH}" == "aarch64" ]; then
104+
if [ "${ARCH}" == "aarch64" ] && [ ${BUNDLE_TYPE} != "okd" ]; then
80105
# aarch64 support is mainly used on Apple M1 machines which can't run a rhel8 kernel
81106
# https://access.redhat.com/solutions/6545411
82107
install_rhel9_kernel ${VM_IP}
@@ -107,12 +132,14 @@ if [ -n "${SNC_GENERATE_MACOS_BUNDLE}" ]; then
107132
${SSH} core@${VM_IP} -- "sudo rm -fr /tmp/kernel"
108133
fi
109134

110-
# Add internalIP as node IP for kubelet systemd unit file
111-
# More details at https://bugzilla.redhat.com/show_bug.cgi?id=1872632
112-
${SSH} core@${VM_IP} 'sudo bash -x -s' <<EOF
135+
if [ ${BUNDLE_TYPE} == "snc" ]; then
136+
# Add internalIP as node IP for kubelet systemd unit file
137+
# More details at https://bugzilla.redhat.com/show_bug.cgi?id=1872632
138+
${SSH} core@${VM_IP} 'sudo bash -x -s' <<EOF
113139
echo '[Service]' > /etc/systemd/system/kubelet.service.d/80-nodeip.conf
114140
echo 'Environment=KUBELET_NODE_IP="${VM_IP}"' >> /etc/systemd/system/kubelet.service.d/80-nodeip.conf
115141
EOF
142+
fi
116143

117144
podman_version=$(${SSH} core@${VM_IP} -- 'rpm -q --qf %{version} podman')
118145

@@ -136,8 +163,12 @@ libvirtDestDir="${destDirPrefix}_libvirt_${destDirSuffix}"
136163
rm -fr ${libvirtDestDir} ${libvirtDestDir}.crcbundle
137164
mkdir "$libvirtDestDir"
138165

139-
create_qemu_image "$libvirtDestDir" "${VM_PREFIX}-base" "${VM_NAME}"
140-
mv "${libvirtDestDir}/${VM_NAME}" "${libvirtDestDir}/${SNC_PRODUCT_NAME}.qcow2"
166+
if [ $BUNDLE_TYPE != "microshift" ]; then
167+
create_qemu_image "$libvirtDestDir" "${VM_PREFIX}-base" "${VM_NAME}"
168+
mv "${libvirtDestDir}/${VM_NAME}" "${libvirtDestDir}/${SNC_PRODUCT_NAME}.qcow2"
169+
else
170+
sparsify_lvm "${libvirtDestDir}"
171+
fi
141172
copy_additional_files "$INSTALL_DIR" "$libvirtDestDir" "${VM_NAME}"
142173
create_tarball "$libvirtDestDir"
143174

0 commit comments

Comments
 (0)