Skip to content
Draft
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
1 change: 1 addition & 0 deletions pkg/kube/cluster-init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ setup_prereqs () {
wait_for_device_name
chmod o+rw /dev/null
wait_for_vault
migrate_var_lib
mount_kube_root
# We need /var/lib to be mounted before we go for network connection check.
check_network_connection
Expand Down
22 changes: 21 additions & 1 deletion pkg/kube/cluster-utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@

LOG_SIZE=$((5*1024*1024))
K3s_LOG_FILE="k3s.log"
SAVE_KUBE_VAR_LIB_DIR="/persist/kube-save-var-lib"
LEGACY_SAVE_KUBE_VAR_LIB_DIR="/persist/kube-save-var-lib"
SAVE_KUBE_VAR_LIB_DIR="/persist/vault/kube-save-var-lib"
K3S_SERVER_CMD="k3s server"
# shellcheck disable=SC2034
K3S_STOP_FLAG="/var/lib/k3s-stop"
Expand Down Expand Up @@ -240,6 +241,25 @@ restore_var_lib() {
fi
}

# Migrate to secure vault
migrate_var_lib() {
if [ ! -d "$LEGACY_SAVE_KUBE_VAR_LIB_DIR" ]; then
return
fi
if [ -d "$SAVE_KUBE_VAR_LIB_DIR" ]; then
return
fi
logmsg "migrating $LEGACY_SAVE_KUBE_VAR_LIB_DIR to $SAVE_KUBE_VAR_LIB_DIR"
if ! cp -a "$LEGACY_SAVE_KUBE_VAR_LIB_DIR" "$SAVE_KUBE_VAR_LIB_DIR"; then
logmsg "ERROR: failed to migrate $LEGACY_SAVE_KUBE_VAR_LIB_DIR to $SAVE_KUBE_VAR_LIB_DIR"
rm -rf "$SAVE_KUBE_VAR_LIB_DIR"
return
fi
logmsg "migrated $LEGACY_SAVE_KUBE_VAR_LIB_DIR to $SAVE_KUBE_VAR_LIB_DIR"
rm -r "$LEGACY_SAVE_KUBE_VAR_LIB_DIR"
logmsg "removed $LEGACY_SAVE_KUBE_VAR_LIB_DIR"
}

# when transitioning from single node to cluster mode, the k3s.yaml file may need
# to change with new certificates
check_kubeconfig_yaml_files() {
Expand Down
Loading