Skip to content

Commit

Permalink
Merge pull request #69 from peng9808/main
Browse files Browse the repository at this point in the history
Adjust code structure
  • Loading branch information
peng9808 authored Apr 1, 2024
2 parents 914242e + 2a277ee commit 7905d4e
Show file tree
Hide file tree
Showing 11 changed files with 140 additions and 6 deletions.
3 changes: 2 additions & 1 deletion docker-drbd9/Dockerfile.bionic
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 2 additions & 1 deletion docker-drbd9/Dockerfile.flatcar
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ FROM gentoo/stage3
MAINTAINER Roland Kammerer <[email protected]>

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
Expand Down
2 changes: 2 additions & 0 deletions docker-drbd9/Dockerfile.focal
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions docker-drbd9/Dockerfile.jammy
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion docker-drbd9/Dockerfile.kylin10
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 2 additions & 0 deletions docker-drbd9/Dockerfile.rhel7
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions docker-drbd9/Dockerfile.rhel8
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions docker-drbd9/Dockerfile.rhel9
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
121 changes: 121 additions & 0 deletions docker-drbd9/entrypoint.adapter.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
#!/bin/bash -x
## Maintainer Alex Zheng <[email protected]>
## 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
4 changes: 2 additions & 2 deletions helm/drbd-adapter/templates/daemonset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion helm/drbd-adapter/templates/job.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7905d4e

Please sign in to comment.