forked from orange-cloudfoundry/k3s-boshrelease
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpre-start.erb
77 lines (63 loc) · 2.68 KB
/
pre-start.erb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/bin/bash
export JOB_DIR="/var/vcap/jobs/k3s-server"
/var/vcap/packages/k3s/k3s check-config
# Setup ssh env vars
${JOB_DIR}/bin/setup-user-env
#FIXME: exit on error earlier
set -e
# rename existing /var/vcap/store/k3s-server to k3s-datadir if exists
if [ -d /var/vcap/store/k3s-server ]; then
# Note: potential remaining leaky open files should not be affected by the mv, according to https://unix.stackexchange.com/a/29227/381792
mv --no-target-directory /var/vcap/store/k3s-server /var/vcap/store/k3s-datadir
fi
# persistent dir for k3s datadir
mkdir -p /var/vcap/store/k3s-datadir
# Prepare a persistent directory so /etc/rancher/node paswword file is kept on bosh recreate
mkdir -p /etc
mkdir -p /var/vcap/store/k3s-node/etc/rancher
ln -sf /var/vcap/store/k3s-node/etc/rancher /etc/rancher
# Fix cert chmod
chmod go-r /var/vcap/jobs/k3s-server/config/datastore-*
# Copy additional manifest file
mkdir -p /var/vcap/store/k3s-datadir/server-manifests
cp -f ${JOB_DIR}/config/additional-manifest.yaml /var/vcap/store/k3s-datadir/server/manifests/additional-manifest.yaml
#copy images to containerd expected location (datadir/images) for airgap start.
# see https://rancher.com/docs/k3s/latest/en/installation/airgap/
mkdir -p /var/vcap/store/k3s-datadir/agent/images
cp /var/vcap/packages/k3s-images/k3s-airgap-images-amd64.tar.gz /var/vcap/store/k3s-datadir/agent/images
gunzip -f /var/vcap/store/k3s-datadir/agent/images/k3s-airgap-images-amd64.tar.gz
set -e
# Set overlay IP
OVERLAY_IP="<%= spec.ip %>"
<% if spec.ip != spec.networks.marshal_dump.values.first.ip %>
OVERLAY_IP="<%= spec.networks.marshal_dump.values.last.ip %>"
<% end %>
<% if spec.ip != spec.networks.marshal_dump.values.last.ip %>
OVERLAY_IP="<%= spec.networks.marshal_dump.values.first.ip %>"
<% end %>
# Disable VxLAN harware options on private interface
# (see: https://github.com/orange-cloudfoundry/paas-templates/issues/2062)
INTERFACE="$(ip --brief address show | grep "${OVERLAY_IP}" | awk '{print $1}')"
#clean previous patch services
! rm -f /etc/systemd/system/ethtool-patch-*.service
<% p('k3s.disable-vxlan-hardware-options').each do |option| %>
#--- Disable hardware option on private interface
OPTION="<%= option %>"
if [ "${OPTION}" != "" ] ; then
serviceFile="ethtool-patch-${INTERFACE}-${OPTION}.service"
cat > /etc/systemd/system/${serviceFile} << EOF
[Unit]
Description=Turn off ${OPTION} on ${INTERFACE}
After=sys-subsystem-net-devices-${INTERFACE}.device
[Install]
WantedBy=sys-subsystem-net-devices-${INTERFACE}.device
[Service]
Type=oneshot
ExecStart=/sbin/ethtool -K ${INTERFACE} ${OPTION} off
EOF
#--- Start service
/usr/bin/systemctl enable ${serviceFile}
/usr/bin/systemctl start ${serviceFile}
fi
<% end %>
exit 0