Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add dependencies documentation #17

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 68 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,78 @@
## Purpose

This repository defines an interface to mounting filesystems to be consumed by
various Kubernetes and out-of-tree CSI components.
This repository defines an interface to mounting filesystems to be consumed by
various Kubernetes and out-of-tree CSI components.

Consumers of this repository can make use of functions like 'Mount' to mount
Consumers of this repository can make use of functions like 'Mount' to mount
source to target as fstype with given options, 'Unmount' to unmount a target.
Other useful functions include 'List' all mounted file systems and find all
mount references to a path using 'GetMountRefs'

## Dependencies

This repository depends on the following cli tools

Linux platform:
* systemd-run (optional)
* mount
* umount
* fsck
* mkfs.ext*
* mkfs.xfs
* blkid
* resize2fs
* xfs_growfs
* btrfs
* blockdev
* dumpe2fs
* xfs_io

Windows platform:
* cmd
* mklink
* rmdir
* powershell

You can install these dependencies using the following commands in dockerfile:

```shell
# Install dependencies

FROM --platform=${TARGETARCH} debian:12.5 AS tools

RUN apt-get update && apt-get install -y --no-install-recommends \
bash \
mount \
udev \
btrfs-progs \
e2fsprogs \
xfsprogs \
util-linux \
rsync

COPY csi-deps.sh /csi-deps.sh
RUN /csi-deps.sh

# Build the final image

FROM --platform=${TARGETARCH} scratch AS final

COPY --from=gcr.io/distroless/base-debian12 . .
COPY --from=tools /dest /
## You csi driver binary
## COPY --from=csi-build /bin /bin

# Check if the dependencies are installed correctly

FROM --platform=${TARGETARCH} final AS check-tools

COPY --from=tools /bin/sh /bin/sh
COPY csi-deps-check.sh /csi-deps-check.sh

SHELL ["/bin/sh"]
RUN /csi-deps-check.sh
```

## Community, discussion, contribution, and support

Learn how to engage with the Kubernetes community on the [community
Expand All @@ -28,4 +93,3 @@ Code of Conduct](code-of-conduct.md).
### Contibution Guidelines

See [CONTRIBUTING.md](CONTRIBUTING.md) for more information.

36 changes: 36 additions & 0 deletions csi-deps-check.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/sh

# Copyright 2022 The Kubernetes Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

set -o errexit

# We will check all necessary utils in the image.
# They all have to launch without errors.

# This utils are using by
# go mod k8s.io/mount-utils
/bin/mount -V
/bin/umount -V
/sbin/blkid -V
/sbin/blockdev -V
/sbin/dumpe2fs -V
/sbin/fsck --version
/sbin/mke2fs -V
/sbin/mkfs.ext4 -V
/sbin/mkfs.xfs -V
/usr/sbin/xfs_io -V
/sbin/xfs_repair -V
/usr/sbin/xfs_growfs -V
/bin/btrfs --version
88 changes: 88 additions & 0 deletions csi-deps.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
#!/bin/sh -x

# Copyright 2022 The Kubernetes Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

set -o errexit
set -o nounset

#
# We will copy all dependencies for CSI Node driver to /dest directory
# all utils are using by csi-plugin
# to format/mount/unmount/resize the volumes.
#
# It is very important to have slim image,
# because it runs as root (privileged mode) on the nodes
#

DEST=/dest

copy_deps() {
PROG="$1"

mkdir -p "${DEST}$(dirname $PROG)"

if [ -d "${PROG}" ]; then
rsync -av "${PROG}/" "${DEST}${PROG}/"
else
cp -Lv "$PROG" "${DEST}${PROG}"
fi

if [ -x ${PROG} -o $(/usr/bin/ldd "$PROG" >/dev/null) ]; then
DEPS="$(/usr/bin/ldd "$PROG" | /bin/grep '=>' | /usr/bin/awk '{ print $3 }')"

for d in $DEPS; do
mkdir -p "${DEST}$(dirname $d)"
cp -Lv "$d" "${DEST}${d}"
done
fi
}

# Common lib /lib64/ld-linux-*.so.2
# needs for all utils
ARCH=$(uname -m)
if [ $ARCH = "aarch64" ] || [ $ARCH = "armv7l" ]; then
mkdir -p ${DEST}/lib && cp -Lv /lib/ld-linux-*.so.* ${DEST}/lib/
elif [ $ARCH = "s390x" ]; then
mkdir -p ${DEST}/lib && cp -Lv /lib/ld64.so.* ${DEST}/lib/
elif [ $ARCH = "ppc64le" ]; then
mkdir -p ${DEST}/lib64 && cp -Lv /lib64/ld64.so.* ${DEST}/lib64/
else
mkdir -p ${DEST}/lib64 && cp -Lv /lib64/ld-linux-*.so.* ${DEST}/lib64/
fi

# This utils are using by
# go mod k8s.io/mount-utils
copy_deps /etc/mke2fs.conf
copy_deps /bin/mount
copy_deps /bin/umount
copy_deps /sbin/blkid
copy_deps /sbin/blockdev
copy_deps /sbin/dumpe2fs
copy_deps /sbin/fsck
copy_deps /sbin/fsck.xfs
cp /sbin/fsck* ${DEST}/sbin/
copy_deps /sbin/e2fsck
# from pkg e2fsprogs - e2image, e2label, e2scrub and etc.
cp /sbin/e2* ${DEST}/sbin/
copy_deps /sbin/mke2fs
copy_deps /sbin/resize2fs
cp /sbin/mkfs* ${DEST}/sbin/
copy_deps /sbin/mkfs.xfs
copy_deps /sbin/xfs_repair
copy_deps /usr/sbin/xfs_growfs
copy_deps /usr/sbin/xfs_io
cp /usr/sbin/xfs* ${DEST}/usr/sbin/
copy_deps /bin/btrfs
cp /bin/btrfs* ${DEST}/bin/