Skip to content

Commit ef17a74

Browse files
authored
symlink /var/lib/calico (#4149)
1 parent 7c47656 commit ef17a74

3 files changed

Lines changed: 33 additions & 12 deletions

File tree

snap/hooks/configure

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,19 @@ need_kubelet_restart=false
3535
need_controller_restart=false
3636
need_scheduler_restart=false
3737

38+
# Try to symlink /var/lib/kubelet so that most kubelet device plugins work out of the box.
39+
if ! [ -e /var/lib/kubelet ] && ln -s $SNAP_COMMON/var/lib/kubelet /var/lib/kubelet; then
40+
echo "/var/lib/kubelet linked to $SNAP_COMMON"
41+
fi
42+
43+
# Try to symlink /var/lib/calico so that the Calico CNI plugin picks up the mtu configuration.
44+
if ! [ -e /var/lib/calico ]; then
45+
SNAP_DATA_CURRENT=`echo "${SNAP_DATA}" | sed -e "s,${SNAP_REVISION},current,"`
46+
if ln -s $SNAP_DATA_CURRENT/var/lib/calico /var/lib/calico; then
47+
echo "/var/lib/calico linked to $SNAP_DATA_CURRENT/var/lib/calico"
48+
fi
49+
fi
50+
3851
# If the configurations directory is missing from SNAP_COMMON, we are upgrading from an older MicroK8s version.
3952
if [ ! -d "${SNAP_COMMON}/etc/launcher" ]
4053
then

snap/hooks/install

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,21 @@ fi
3030
cp -r --preserve=mode ${SNAP}/default-args ${SNAP_DATA}/args
3131
mv ${SNAP_DATA}/args/certs.d/localhost__32000 ${SNAP_DATA}/args/certs.d/localhost:32000
3232

33-
# Sym link the host's /var/lib/kubelet to the Snap's. This will be fixed with layouts when
34-
# this Snap is strictly confined. Warn if there's already a directory.
35-
if ! [ -e /var/lib/kubelet ] &&
36-
ln -s $SNAP_COMMON/var/lib/kubelet /var/lib/kubelet
37-
then
38-
echo "\`/var/lib/kubelet\` linked to $SNAP_COMMON"
39-
else
40-
echo "\`/var/lib/kubelet\` already exists. Will not be linking to $SNAP_COMMON"
33+
34+
# Try to symlink /var/lib/kubelet so that most kubelet device plugins work out of the box.
35+
if ! [ -e /var/lib/kubelet ] && ln -s $SNAP_COMMON/var/lib/kubelet /var/lib/kubelet; then
36+
echo "/var/lib/kubelet linked to $SNAP_COMMON"
37+
fi
38+
39+
# Try to symlink /var/lib/calico so that the Calico CNI plugin picks up the mtu configuration.
40+
if ! [ -e /var/lib/calico ]; then
41+
SNAP_DATA_CURRENT=`echo "${SNAP_DATA}" | sed -e "s,${SNAP_REVISION},current,"`
42+
if ln -s $SNAP_DATA_CURRENT/var/lib/calico /var/lib/calico; then
43+
echo "/var/lib/calico linked to $SNAP_DATA_CURRENT/var/lib/calico"
44+
fi
4145
fi
4246

47+
4348
# Create the credentials directory
4449
mkdir -p ${SNAP_DATA}/credentials
4550

snap/hooks/remove

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,16 @@ export PATH="$SNAP/usr/sbin:$SNAP/usr/bin:$SNAP/sbin:$SNAP/bin:$PATH:/usr/bin:/u
77

88
snapctl stop ${SNAP_NAME}.daemon-kubelite 2>&1 || true
99

10-
# Sym link the host's /var/lib/kubelet to the Snap's. This will be fixed with layouts when
11-
# this Snap is strictly confined.
12-
if test -L /var/lib/kubelet
13-
then
10+
# Try to symlink /var/lib/kubelet so that most kubelet device plugins work out of the box.
11+
if test -L /var/lib/kubelet; then
1412
unlink /var/lib/kubelet || true
1513
fi
1614

15+
# Try to symlink /var/lib/calico so that the Calico CNI plugin picks up the mtu configuration.
16+
if test -L /var/lib/calico; then
17+
unlink /var/lib/calico || true
18+
fi
19+
1720
pod_cidr="$(cat $SNAP_DATA/args/kube-proxy | grep "cluster-cidr" | tr "=" " "| gawk '{print $2}')"
1821
if [ -z "$pod_cidr" ]
1922
then

0 commit comments

Comments
 (0)