diff --git a/docker-drbd9/Dockerfile.bionic b/docker-drbd9/Dockerfile.bionic index fd70e8a..d21b5e7 100644 --- a/docker-drbd9/Dockerfile.bionic +++ b/docker-drbd9/Dockerfile.bionic @@ -11,7 +11,8 @@ RUN apt-get update && apt-get install -y kmod gnupg wget make gcc patch curl && COPY /drbd.tar.gz / COPY /pkgs /pkgs - +COPY /entrypoint.adapter.sh / +RUN chmod +x /entrypoint.adapter.sh COPY /entry.sh / RUN chmod +x /entry.sh diff --git a/docker-drbd9/Dockerfile.flatcar b/docker-drbd9/Dockerfile.flatcar index ec244b7..10e0ca6 100644 --- a/docker-drbd9/Dockerfile.flatcar +++ b/docker-drbd9/Dockerfile.flatcar @@ -2,7 +2,8 @@ FROM gentoo/stage3 MAINTAINER Roland Kammerer COPY /drbd.tar.gz / - +COPY /entrypoint.adapter.sh / +RUN chmod +x /entrypoint.adapter.sh COPY /entry.sh / RUN chmod +x /entry.sh ENTRYPOINT /entry.sh diff --git a/docker-drbd9/Dockerfile.focal b/docker-drbd9/Dockerfile.focal index 91fea7f..858b3f5 100644 --- a/docker-drbd9/Dockerfile.focal +++ b/docker-drbd9/Dockerfile.focal @@ -11,6 +11,8 @@ RUN apt-get update && apt-get install -y kmod gnupg wget make gcc patch curl && COPY /drbd.tar.gz / COPY /pkgs /pkgs +COPY /entrypoint.adapter.sh / +RUN chmod +x /entrypoint.adapter.sh COPY /entry.sh / RUN chmod +x /entry.sh diff --git a/docker-drbd9/Dockerfile.jammy b/docker-drbd9/Dockerfile.jammy index 1899d1d..a04c8d6 100644 --- a/docker-drbd9/Dockerfile.jammy +++ b/docker-drbd9/Dockerfile.jammy @@ -10,6 +10,8 @@ RUN apt-get update && apt-get install -y kmod gnupg wget make gcc patch elfutils COPY /drbd.tar.gz / COPY /pkgs /pkgs +COPY /entrypoint.adapter.sh / +RUN chmod +x /entrypoint.adapter.sh COPY /entry.sh / RUN chmod +x /entry.sh diff --git a/docker-drbd9/Dockerfile.kylin10 b/docker-drbd9/Dockerfile.kylin10 index 5bd02e2..2856e27 100644 --- a/docker-drbd9/Dockerfile.kylin10 +++ b/docker-drbd9/Dockerfile.kylin10 @@ -38,7 +38,8 @@ RUN wget --no-check-certificate https://pkg.linbit.com/downloads/drbd/"$([[ $DRB COPY /pkgs /pkgs COPY /drbdUtils.tar.gz / COPY /install-drbdutils.sh / +COPY /entrypoint.adapter.sh / +RUN chmod +x /entrypoint.adapter.sh COPY /entry.sh / RUN chmod +x /entry.sh - ENTRYPOINT /entry.sh diff --git a/docker-drbd9/Dockerfile.rhel7 b/docker-drbd9/Dockerfile.rhel7 index 3f6e988..f9239d7 100644 --- a/docker-drbd9/Dockerfile.rhel7 +++ b/docker-drbd9/Dockerfile.rhel7 @@ -26,6 +26,8 @@ RUN wget --no-check-certificate https://pkg.linbit.com/downloads/drbd/"$([[ $DRB # =lbbuild COPY /drbd.tar.gz / COPY /pkgs /pkgs +COPY /entrypoint.adapter.sh / +RUN chmod +x /entrypoint.adapter.sh COPY /entry.sh / RUN chmod +x /entry.sh diff --git a/docker-drbd9/Dockerfile.rhel8 b/docker-drbd9/Dockerfile.rhel8 index f84060c..6049458 100644 --- a/docker-drbd9/Dockerfile.rhel8 +++ b/docker-drbd9/Dockerfile.rhel8 @@ -47,6 +47,8 @@ RUN wget --no-check-certificate https://pkg.linbit.com/downloads/drbd/"$([[ $DRB # these are now the kmod pkgs: COPY /pkgs /pkgs +COPY /entrypoint.adapter.sh / +RUN chmod +x /entrypoint.adapter.sh COPY /entry.sh / RUN chmod +x /entry.sh diff --git a/docker-drbd9/Dockerfile.rhel9 b/docker-drbd9/Dockerfile.rhel9 index 3dd96b5..6e44dcc 100644 --- a/docker-drbd9/Dockerfile.rhel9 +++ b/docker-drbd9/Dockerfile.rhel9 @@ -37,6 +37,8 @@ RUN curl -fsSL https://pkg.linbit.com/downloads/drbd/"$([[ $DRBD_VERSION =~ ^9.0 # these are now the kmod pkgs: COPY /pkgs /pkgs +COPY /entrypoint.adapter.sh / +RUN chmod +x /entrypoint.adapter.sh COPY /entry.sh / RUN chmod +x /entry.sh diff --git a/docker-drbd9/entrypoint.adapter.sh b/docker-drbd9/entrypoint.adapter.sh new file mode 100755 index 0000000..de4ba97 --- /dev/null +++ b/docker-drbd9/entrypoint.adapter.sh @@ -0,0 +1,121 @@ +#!/bin/bash -x +## Maintainer Alex Zheng +## This is a wrapper scripts to have drbd9 containers automatically adapt host distros + +## Check if image matches os type +which lbdisttool.py + +image_dist="$(lbdisttool.py -l | awk -F'.' '{print $1}' )" +host_dist="$(lbdisttool.py -l --os-release /etc/host-release | awk -F'.' '{print $1}' )" + +# For Kylin v10 +if [ -z $image_dist ] \ + && grep -i "kylin .* v10" /etc/os-release; then + echo "Image distro is Kylin V10" + image_dist=kylin10 +fi + +if [ -z $host_dist ] \ + && uname -r | grep -i '.ky10.' \ + && grep -i "kylin .* v10" /etc/host-release; then + echo "Host distro is Kylin V10" + host_dist=kylin10 +fi + +# For DaemonSet: Gracefully exit for distro mismatch, so that next initContainer may start +# For Job: Exit failure +if [[ $host_dist != $image_dist ]]; then + echo "Image type does not match OS type, skip !" + [[ $LB_SKIP == 'yes' ]] && exit 0 || exit 1 +fi + +## Unload current drbd modules from kernel if it is lower than the target version +# (only possible if no [drbd_xxx] process is running) +RUNNING_DRBD_VERSION=$( cat /proc/drbd | awk '/^version:/ {print $2}' ) + +if [ -z $RUNNING_DRBD_VERSION ]; then + echo "No DRBD Module is loaded" +elif [[ $RUNNING_DRBD_VERSION == $DRBD_VERSION ]] || \ + [[ $( printf "$RUNNING_DRBD_VERSION\n$DRBD_VERSION" | sort -V | tail -1 ) != $DRBD_VERSION ]] +then + echo "The loaded DRBD module version is already $RUNNING_DRBD_VERSION" +else + echo "The loaded DRBD module version $RUNNING_DRBD_VERSION is lower than $DRBD_VERSION" + if [[ $LB_UPGRADE == 'yes' ]] || [[ $RUNNING_DRBD_VERSION =~ ^8 ]]; then + for i in drbd_transport_tcp drbd; do + if lsmod | grep -w $i; then + rmmod $i || true + fi + done + fi +fi + +## Main Logic +# If no shipped module is found, then compile from source +echo "OS_KERNEL:$1" +export DRBD_EXIST='no' +export DRBD_RMP_INSTALL='no' +export OS_KERNEL=$1 +if [[ $host_dist == 'kylin10' ]]; then + LB_HOW=compile +else + LB_HOW=shipped_modules +fi +if [[ $LB_HOW == 'shipped_modules' ]]; then + source /entry.sh + echo "Successfully loaded shipped module" +elif [[ $LB_HOW == 'compile' ]]; then + source /entry.sh + echo "Successfully loaded compiled module" +fi + +echo "DRBD IS ALREADY EXIST (yes or no):$DRBD_EXIST" +echo "DRBD INSTALL BY PRM (yes or no) :$DRBD_RMP_INSTALL" +#If the installation through rpm is successful, exit directly. +if [[ "$DRBD_RMP_INSTALL" == 'yes' ]];then + echo "Successfully installed rbd using rpm package" + exit 0 +fi + +# Drop modules to the host so it can independently load from OS +if [[ $LB_DROP == yes ]]; then + + # drop modules + if [[ $host_dist =~ rhel|kylin10 ]]; then + KODIR="/lib/modules/$(uname -r)/extra/drbd" + elif [[ $host_dist =~ bionic|focal|jammy ]]; then + KODIR="/lib/modules/$(uname -r)/updates/dkms/drbd" + else + KODIR="/lib/modules/$(uname -r)/drbd" + fi + mkdir -vp "$KODIR" + cp -vf /tmp/ko/*.ko "${KODIR}/" + + # register modules + depmod -a + + # onboot load modules + cp -vf /pkgs/drbd.modules-load.conf /etc/modules-load.d/drbd.conf + cp -vf /pkgs/drbd.modules /etc/sysconfig/modules/ + + # drop drbd utils and set up conf directories + cp -vf /pkgs/utils/* /usr-local-bin + cat /pkgs/drbd.conf > /etc/drbd.conf + cp -vf /pkgs/global_common.conf /etc/drbd.d/ + +fi + +# Check if DRBD is loaded correctly +if [[ $( cat /proc/drbd | awk '/^version/ {print $2}' ) != $DRBD_VERSION ]]; then + echo "ERROR: DRBD is NOT loaded with the right version" + exit 1 +fi + +# Check if hostname is the same as k8s node name +# With `hostNetwork`, container `hostname` cmd result is from host /proc/sys/kernel/hostname and /proc/sys/kernel/domainname +if [[ $LB_CHECK_HOSTNAME == 'yes' ]] && [[ $(hostname) != $NODE_NAME ]]; then + echo "ERROR: Hostname does not match K8s node name!" + exit 1 +fi + +exit 0 diff --git a/helm/drbd-adapter/templates/daemonset.yaml b/helm/drbd-adapter/templates/daemonset.yaml index 307a946..e6e5de8 100644 --- a/helm/drbd-adapter/templates/daemonset.yaml +++ b/helm/drbd-adapter/templates/daemonset.yaml @@ -56,8 +56,8 @@ spec: image: {{ $.Values.registry }}/drbd9-{{ $dist }}:{{ $tag }} imagePullPolicy: {{ $.Values.imagePullPolicy }} command: - - /pkgs/entrypoint.adapter.sh - - {{ $kernelVersion }} + - /entrypoint.adapter.sh + - {{ $kernelVersion }} securityContext: privileged: true env: diff --git a/helm/drbd-adapter/templates/job.yaml b/helm/drbd-adapter/templates/job.yaml index 55724ef..c39f040 100644 --- a/helm/drbd-adapter/templates/job.yaml +++ b/helm/drbd-adapter/templates/job.yaml @@ -58,7 +58,7 @@ spec: image: {{ $.Values.registry }}/drbd9-{{ $distro }}:{{ $tag }} imagePullPolicy: {{ $.Values.imagePullPolicy }} command: - - /pkgs/entrypoint.adapter.sh + - /entrypoint.adapter.sh - {{ $kernelVersion }} securityContext: privileged: true