5
5
6
6
K3S_VERSION=v1.28.5+k3s1
7
7
KUBEVIRT_VERSION=v1.1.0
8
- LONGHORN_VERSION=v1.6.2
9
8
CDI_VERSION=v1.54.0
10
9
NODE_IP=" "
11
10
MAX_K3S_RESTARTS=10
@@ -18,6 +17,11 @@ HOSTNAME=""
18
17
VMICONFIG_FILENAME=" /run/zedkube/vmiVNC.run"
19
18
VNC_RUNNING=false
20
19
20
+ # shellcheck source=pkg/kube/descheduler-utils.sh
21
+ . /usr/bin/descheduler-utils.sh
22
+ # shellcheck source=pkg/kube/longhorn-utils.sh
23
+ . /usr/bin/longhorn-utils.sh
24
+
21
25
logmsg () {
22
26
local MSG
23
27
local TIME
@@ -220,40 +224,6 @@ config_cluster_roles() {
220
224
touch /var/lib/debuguser-initialized
221
225
}
222
226
223
- apply_longhorn_disk_config () {
224
- node=$1
225
- kubectl label node " $node " node.longhorn.io/create-default-disk=' config'
226
- kubectl annotate node " $node " node.longhorn.io/default-disks-config=' [ { "path":"/persist/vault/volumes", "allowScheduling":true }]'
227
- }
228
-
229
- check_overwrite_nsmounter () {
230
- # ## REMOVE ME+
231
- # When https://github.com/longhorn/longhorn/issues/6857 is resolved, remove this 'REMOVE ME' section
232
- # In addition to pkg/kube/nsmounter and the copy of it in pkg/kube/Dockerfile
233
- longhornCsiPluginPods=$( kubectl -n longhorn-system get pod -o json | jq -r ' .items[] | select(.metadata.labels.app=="longhorn-csi-plugin" and .status.phase=="Running") | .metadata.name' )
234
- for csiPod in $longhornCsiPluginPods ; do
235
- if ! kubectl -n longhorn-system exec " pod/${csiPod} " --container=longhorn-csi-plugin -- ls /usr/local/sbin/nsmounter.updated > /dev/null 2> @1; then
236
- if kubectl -n longhorn-system exec -i " pod/${csiPod} " --container=longhorn-csi-plugin -- tee /usr/local/sbin/nsmounter < /usr/bin/nsmounter; then
237
- logmsg " Updated nsmounter in longhorn pod ${csiPod} "
238
- kubectl -n longhorn-system exec " pod/${csiPod} " --container=longhorn-csi-plugin -- touch /usr/local/sbin/nsmounter.updated
239
- fi
240
- fi
241
- done
242
- # ## REMOVE ME-
243
- }
244
-
245
- # A spot to do persistent configuration of longhorn
246
- # These are applied once per cluster
247
- longhorn_post_install_config () {
248
- # Wait for longhorn objects to be available before patching them
249
- lhSettingsAvailable=$( kubectl -n longhorn-system get settings -o json | jq ' .items | length>0' )
250
- if [ " $lhSettingsAvailable " != " true" ]; then
251
- return
252
- fi
253
- kubectl -n longhorn-system patch settings.longhorn.io/upgrade-checker -p ' [{"op":"replace","path":"/value","value":"false"}]' --type json
254
- touch /var/lib/longhorn_configured
255
- }
256
-
257
227
check_start_k3s () {
258
228
pgrep -f " k3s server" > /dev/null 2>&1
259
229
if [ $? -eq 1 ]; then
@@ -283,6 +253,48 @@ check_start_k3s() {
283
253
return 0
284
254
}
285
255
256
+ external_boot_image_import () {
257
+ # NOTE: https://kubevirt.io/user-guide/virtual_machines/boot_from_external_source/
258
+ # Install external-boot-image image to our eve user containerd registry.
259
+ # This image contains just kernel and initrd to bootstrap a container image as a VM.
260
+ # This is very similar to what we do on kvm based eve to start container as a VM.
261
+
262
+ boot_img_path=" /etc/external-boot-image.tar"
263
+
264
+ # Is containerd up?
265
+ if ! /var/lib/k3s/bin/k3s ctr -a /run/containerd-user/containerd.sock info > /dev/null 2>&1 ; then
266
+ logmsg " k3s-containerd not yet running for image import"
267
+ return 1
268
+ fi
269
+
270
+ eve_external_boot_img_name=" docker.io/lfedge/eve-external-boot-image"
271
+ eve_external_boot_img_tag=$( cat /run/eve-release)
272
+ eve_external_boot_img=" ${eve_external_boot_img_name} :${eve_external_boot_img_tag} "
273
+ if /var/lib/k3s/bin/k3s crictl --runtime-endpoint=unix:///run/containerd-user/containerd.sock inspecti " $eve_external_boot_img " ; then
274
+ # Already imported
275
+ return 0
276
+ fi
277
+
278
+ import_name_tag=$( tar -xOf " $boot_img_path " manifest.json | jq -r ' .[0].RepoTags[0]' )
279
+ import_name=$( echo " $import_name_tag " | cut -d ' :' -f 1)
280
+ if [ " $import_name " != " $eve_external_boot_img_name " ]; then
281
+ logmsg " external-boot-image.tar is corrupt"
282
+ return 1
283
+ fi
284
+
285
+ if ! /var/lib/k3s/bin/k3s ctr -a /run/containerd-user/containerd.sock image import " $boot_img_path " ; then
286
+ logmsg " import $boot_img_path failed"
287
+ return 1
288
+ fi
289
+
290
+ if ! /var/lib/k3s/bin/k3s ctr -a /run/containerd-user/containerd.sock image tag " $import_name_tag " " $eve_external_boot_img " ; then
291
+ logmsg " re-tag external-boot-image failed"
292
+ return 1
293
+ fi
294
+ logmsg " Successfully installed external-boot-image $import_name_tag as $eve_external_boot_img "
295
+ return 0
296
+ }
297
+
286
298
check_start_containerd () {
287
299
# Needed to get the pods to start
288
300
if [ ! -L /usr/bin/runc ]; then
@@ -299,23 +311,6 @@ check_start_containerd() {
299
311
containerd_pid=$!
300
312
logmsg " Started k3s-containerd at pid:$containerd_pid "
301
313
fi
302
- if [ -f /etc/external-boot-image.tar ]; then
303
- # NOTE: https://kubevirt.io/user-guide/virtual_machines/boot_from_external_source/
304
- # Install external-boot-image image to our eve user containerd registry.
305
- # This image contains just kernel and initrd to bootstrap a container image as a VM.
306
- # This is very similar to what we do on kvm based eve to start container as a VM.
307
- logmsg " Trying to install new external-boot-image"
308
- # This import happens once per reboot
309
- if ctr -a /run/containerd-user/containerd.sock image import /etc/external-boot-image.tar; then
310
- eve_external_boot_img_tag=$( cat /run/eve-release)
311
- eve_external_boot_img=docker.io/lfedge/eve-external-boot-image:" $eve_external_boot_img_tag "
312
- import_tag=$( tar -xOf /etc/external-boot-image.tar manifest.json | jq -r ' .[0].RepoTags[0]' )
313
- ctr -a /run/containerd-user/containerd.sock image tag " $import_tag " " $eve_external_boot_img "
314
-
315
- logmsg " Successfully installed external-boot-image $import_tag as $eve_external_boot_img "
316
- rm -f /etc/external-boot-image.tar
317
- fi
318
- fi
319
314
}
320
315
trigger_k3s_selfextraction () {
321
316
# Analysis of the k3s source shows nearly any cli command will first self-extract a series of binaries.
@@ -440,6 +435,9 @@ if [ ! -f /var/lib/all_components_initialized ]; then
440
435
sleep 1
441
436
442
437
check_start_containerd
438
+ if ! external_boot_image_import; then
439
+ continue
440
+ fi
443
441
if ! check_start_k3s; then
444
442
continue
445
443
fi
@@ -497,22 +495,30 @@ if [ ! -f /var/lib/all_components_initialized ]; then
497
495
continue
498
496
fi
499
497
500
- if [ ! -f /var/lib/longhorn_initialized ]; then
501
- wait_for_item " longhorn"
502
- logmsg " Installing longhorn version ${LONGHORN_VERSION} "
503
- apply_longhorn_disk_config " $HOSTNAME "
504
- lhCfgPath=/var/lib/lh-cfg-${LONGHORN_VERSION} .yaml
505
- if [ ! -e $lhCfgPath ]; then
506
- curl -k https://raw.githubusercontent.com/longhorn/longhorn/${LONGHORN_VERSION} /deploy/longhorn.yaml > " $lhCfgPath "
507
- fi
508
- if ! grep -q ' create-default-disk-labeled-nodes: true' " $lhCfgPath " ; then
509
- sed -i ' / default-setting.yaml: |-/a\ create-default-disk-labeled-nodes: true' " $lhCfgPath "
510
- fi
511
- kubectl apply -f " $lhCfgPath "
512
- touch /var/lib/longhorn_initialized
498
+ #
499
+ # Longhorn
500
+ #
501
+ wait_for_item " longhorn"
502
+ if ! longhorn_install " $HOSTNAME " ; then
503
+ continue
504
+ fi
505
+ if ! longhorn_is_ready; then
506
+ # It can take a moment for the new pods to get to ContainerCreating
507
+ # Just back off until they are caught by the earlier are_all_pods_ready
508
+ sleep 30
509
+ continue
510
+ fi
511
+ logmsg " longhorn ready"
512
+
513
+ #
514
+ # Descheduler
515
+ #
516
+ wait_for_item " descheduler"
517
+ if ! descheduler_install; then
518
+ continue
513
519
fi
514
520
515
- if [ -f /var/lib/k3s_initialized ] && [ -f /var/lib/kubevirt_initialized ] && [ -f /var/lib/longhorn_initialized ] ; then
521
+ if [ -f /var/lib/k3s_initialized ] && [ -f /var/lib/kubevirt_initialized ]; then
516
522
logmsg " All components initialized"
517
523
touch /var/lib/all_components_initialized
518
524
fi
541
547
cp /var/lib/rancher/k3s/user.yaml /run/.kube/k3s/user.yaml
542
548
fi
543
549
else
544
- if [ -e /var/lib/longhorn_initialized ] ; then
550
+ if longhorn_is_ready ; then
545
551
check_overwrite_nsmounter
546
552
fi
547
553
if [ ! -e /var/lib/longhorn_configured ]; then
0 commit comments