|
| 1 | +#!/bin/sh |
| 2 | + |
| 3 | +# Copyright 2022 The Kubernetes Authors. |
| 4 | +# |
| 5 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | +# you may not use this file except in compliance with the License. |
| 7 | +# You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, software |
| 12 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | +# See the License for the specific language governing permissions and |
| 15 | +# limitations under the License. |
| 16 | + |
| 17 | +set -o errexit |
| 18 | +set -o nounset |
| 19 | + |
| 20 | +# |
| 21 | +# We will copy all dependencies for CSI Node driver to /dest directory |
| 22 | +# all utils are using by cinder-csi-plugin |
| 23 | +# to format/mount/unmount/resize the volumes. |
| 24 | +# |
| 25 | +# It is very important to have slim image, |
| 26 | +# because it runs as root (privileged mode) on the nodes |
| 27 | +# |
| 28 | + |
| 29 | +DEST=/dest |
| 30 | + |
| 31 | +copy_deps() { |
| 32 | + PROG="$1" |
| 33 | + |
| 34 | + mkdir -p "${DEST}$(dirname $PROG)" |
| 35 | + |
| 36 | + if [ -d "${PROG}" ]; then |
| 37 | + rsync -av "${PROG}/" "${DEST}${PROG}/" |
| 38 | + else |
| 39 | + cp -Lv "$PROG" "${DEST}${PROG}" |
| 40 | + fi |
| 41 | + |
| 42 | + if [ -x ${PROG} -o $(/usr/bin/ldd "$PROG" >/dev/null) ]; then |
| 43 | + DEPS="$(/usr/bin/ldd "$PROG" | /bin/grep '=>' | /usr/bin/awk '{ print $3 }')" |
| 44 | + |
| 45 | + for d in $DEPS; do |
| 46 | + mkdir -p "${DEST}$(dirname $d)" |
| 47 | + cp -Lv "$d" "${DEST}${d}" |
| 48 | + done |
| 49 | + fi |
| 50 | +} |
| 51 | + |
| 52 | +# Commmon lib /lib64/ld-linux-*.so.2 |
| 53 | +# needs for all utils |
| 54 | +mkdir -p ${DEST}/lib64 && cp -Lv /lib64/ld-linux-*.so.2 ${DEST}/lib64/ |
| 55 | + |
| 56 | +# This utils are using by |
| 57 | +# go mod k8s.io/mount-utils |
| 58 | +copy_deps /etc/mke2fs.conf |
| 59 | +copy_deps /bin/mount |
| 60 | +copy_deps /bin/umount |
| 61 | +copy_deps /sbin/blkid |
| 62 | +copy_deps /sbin/blockdev |
| 63 | +copy_deps /sbin/dumpe2fs |
| 64 | +copy_deps /sbin/fsck |
| 65 | +copy_deps /sbin/fsck.xfs |
| 66 | +cp /sbin/fsck* ${DEST}/sbin/ |
| 67 | +copy_deps /sbin/e2fsck |
| 68 | +# from pkg e2fsprogs - e2image, e2label, e2scrub and etc. |
| 69 | +cp /sbin/e2* ${DEST}/sbin/ |
| 70 | +copy_deps /sbin/mke2fs |
| 71 | +copy_deps /sbin/resize2fs |
| 72 | +cp /sbin/mkfs* ${DEST}/sbin/ |
| 73 | +copy_deps /sbin/mkfs.xfs |
| 74 | +copy_deps /sbin/xfs_repair |
| 75 | +copy_deps /usr/sbin/xfs_growfs |
| 76 | +copy_deps /usr/sbin/xfs_io |
| 77 | +cp /usr/sbin/xfs* ${DEST}/usr/sbin/ |
| 78 | +copy_deps /bin/btrfs |
| 79 | +cp /bin/btrfs* ${DEST}/bin/ |
| 80 | + |
| 81 | +# This utils are using by |
| 82 | +# go mod k8s.io/cloud-provider-openstack/pkg/util/mount |
| 83 | +copy_deps /bin/udevadm |
| 84 | +copy_deps /lib/udev/rules.d |
| 85 | +copy_deps /bin/findmnt |
0 commit comments