Skip to content

Commit

Permalink
fix kylin10 can not install problem
Browse files Browse the repository at this point in the history
Signed-off-by: peng9808 <[email protected]>
  • Loading branch information
peng9808 committed Apr 1, 2024
1 parent 0aab549 commit dd44727
Show file tree
Hide file tree
Showing 15 changed files with 177 additions and 15 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
6 changes: 4 additions & 2 deletions docker-drbd9/Dockerfile.kylin10
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@ RUN wget --no-check-certificate https://pkg.linbit.com/downloads/drbd/"$([[ $DRB

# these are now the kmod pkgs:
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
Binary file added docker-drbd9/drbdUtils.tar.gz
Binary file not shown.
16 changes: 10 additions & 6 deletions docker-drbd9/entry.sh
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,11 @@ kos::fromsrc() {
# cd $(ls -1 | head -1) || die "Could not cd"
cd drbd-* || die "Could not cd to drbd src dir"
make $LB_MAKEOPTS

cp /drbdUtils.tar.gz /pkgs_root/drbd-utils.tar.gz
cp /install-drbdutils.sh /pkgs_root/install-drbdutils.sh
nsenter --target 1 --mount --uts --ipc --net --pid chmod +x /root/install-drbdutils.sh
nsenter --target 1 --mount --uts --ipc --net --pid /root/install-drbdutils.sh
}

kos::rpm::extract() {
Expand Down Expand Up @@ -242,17 +247,15 @@ if [ -z "$OS_KERNEL" ]; then
debug "The system parameters are obtained successfully (OS_KERNEL)"
exit 1
fi
result=$(lbdisttool.py --os-release $HOSTRELEASE -l || echo "")
substr="${result:0:3}"

drbd_rpm=$(find "$RPMDIR" -type f -name "*$OS_KERNEL*" -print -quit)
var1="$OS_KERNEL"
matchvar="${var1}.rpm"
drbd_rpm=$(find "$RPMDIR" -type f -name "*${matchvar}" -print -quit)
if [ -n "$drbd_rpm" ]; then
utils_rpm=$(find "$RPMDIR" -type f -name "drbd-utils*" -print -quit)
if [[ -n "$drbd_rpm" && -n "$utils_rpm" ]]; then
cp $drbd_rpm /pkgs_root/drbd.rpm
cp $utils_rpm /pkgs_root/drbd_utils.rpm
nsenter --version
nsenter --target 1 --mount --uts --ipc --net --pid ls /root/
nsenter --target 1 --mount --uts --ipc --net --pid rpm -ivh /root/drbd_utils.rpm
nsenter --target 1 --mount --uts --ipc --net --pid rpm -ivh /root/drbd.rpm
exit_code=$?
Expand All @@ -274,7 +277,8 @@ if [ -n "$drbd_rpm" ]; then
else debug "There is no corresponding kernel version rpm package or drbd-utils rpm package"
fi
else
drbd_deb=$(find "$DEBDIR" -type f -name "*$OS_KERNEL*" -print -quit)
matchvar="${var1}.deb"
drbd_deb=$(find "$DEBDIR" -type f -name "*${matchvar}" -print -quit)
utils_deb=$(find "$DEBDIR" -type f -name "drbd-utils*" -print -quit)
if [[ -n "$drbd_deb" && -n "$utils_deb" ]]; then
cp $drbd_deb /pkgs_root/drbd.deb
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
16 changes: 16 additions & 0 deletions docker-drbd9/install-drbdutils.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash -x

# 安装所需软件包
yum install -y build-essential wget flex automake

tar xf /root/drbd-utils.tar.gz

cd /root/drbd-utils/

./autogen.sh

./configure --prefix=/usr --localstatedir=/var --sysconfdir=/etc

make tools

find ./user -type f -executable -name 'drbd[a-z]*' -exec mv -v {} /usr/local/bin/ \;
11 changes: 9 additions & 2 deletions docker-shipper/entrypoint.adapter.sh
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,16 @@ echo "OS_KERNEL:$1"
export DRBD_EXIST='no'
export DRBD_RMP_INSTALL='no'
export OS_KERNEL=$1
if LB_HOW=shipped_modules source /entry.sh ; then
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 source /entry.sh ; then
elif [[ $LB_HOW == 'compile' ]]; then
source /entry.sh
echo "Successfully loaded compiled module"
fi

Expand Down
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 dd44727

Please sign in to comment.