diff --git a/README.md b/README.md index 7aeb9869dcb865f32dbbd584cf4baaccb6b39906..2a2f96eb80c4401e536fe6b6790b1e43f8aa4c2b 100644 --- a/README.md +++ b/README.md @@ -113,7 +113,7 @@ In case of a new major version, there might be manual steps that you need to fol ### From v1 to v2 -There are two breaking changes between v1.6 and v2.0 that require user intervention. Please take care to follow these steps, as otherwise the update might fail. +There are three breaking changes between v1.6 and v2.0 that require user intervention. Please take care to follow these steps, as otherwise the update might fail. **Before the rollout**: @@ -138,6 +138,15 @@ There are two breaking changes between v1.6 and v2.0 that require user intervent $ kubectl delete daemonset -n kube-system hcloud-csi-node ``` +4. We changed the way the device path of mounted volumes is communicated to the node service. This requires changes to the `VolumeAttachment` objects, where we need to add information to the `status.attachmentMetadata` field. Execute the linked script to automatically add the required information. This requires `kubectl` version `v1.24+`, even if your cluster is running v1.23. + + ```shell + $ kubectl version + $ curl https://raw.githubusercontent.com/hetznercloud/csi-driver/main/docs/v2-fix-volumeattachments/fix-volumeattachments.sh ./fix-volumeattachments.sh + $ chmod +x ./fix-volumeattachments.sh + $ ./fix-volumeattachments.sh + ``` + **Rollout the new manifest**: ```shell diff --git a/docs/v2-fix-volumeattachments/fix-volumeattachments.sh b/docs/v2-fix-volumeattachments/fix-volumeattachments.sh new file mode 100755 index 0000000000000000000000000000000000000000..25e7e7e1b5a9504dac23160a714aaa73f00a0ee9 --- /dev/null +++ b/docs/v2-fix-volumeattachments/fix-volumeattachments.sh @@ -0,0 +1,74 @@ +#!/usr/bin/env bash +set -e -o pipefail + +if [ "$DEBUG" != "" ]; +then + set -x +fi + +DIR="./hcloud-csi-fix-volumeattachments" +echo "[INFO] Creating a new directory to write logs: ${DIR}" +mkdir --parents "${DIR}" + +# Logging utility +LOG_FILE="${DIR}/logs.txt" +write_log() { + echo "$1" + echo "$1" >> "${LOG_FILE}" +} + +# Verify dependencies +verify_installed() { + cmd="$1" + if ! command -v "$cmd" &> /dev/null + then + write_log "[ERR] For the script to run successfully, \"${cmd}\" is required, but it could not be found. Please make sure it is installed." + exit + fi +} + +verify_installed kubectl +verify_installed grep + +VOLUME_ATTACHMENTS=$( + kubectl get volumeattachment \ + -o custom-columns=NAME:.metadata.name,ATTACHER:.spec.attacher,DEVICEPATH:.status.attachmentMetadata.devicePath \ + | { grep -E 'csi\.hetzner\.cloud.*<none>' --color=never || true; } \ + | cut --fields=1 --delimiter=' ' +) + +if [[ -z "$VOLUME_ATTACHMENTS" ]]; then + write_log "[INFO] No affected VolumeAttachments found, exiting." + exit 0 +fi + +for VOLUME_ATTACHMENT in "$VOLUME_ATTACHMENTS"; do + write_log "[INFO] Processing VolumeAttachment $VOLUME_ATTACHMENT" + + + PV_NAME=$( + kubectl get volumeattachment \ + -o=jsonpath="{.spec.source.persistentVolumeName}" \ + "$VOLUME_ATTACHMENT" + ) + + VOLUME_ID=$( + kubectl get persistentvolume \ + -o=jsonpath="{.spec.csi.volumeHandle}" \ + "$PV_NAME" + ) + + write_log "[INFO] VolumeAttachment $VOLUME_ATTACHMENT uses volume $VOLUME_ID" + + DEVICE_PATH="/dev/disk/by-id/scsi-0HC_Volume_${VOLUME_ID}" + + kubectl patch volumeattachment \ + --subresource=status \ + --type=strategic \ + -p "{\"status\":{\"attachmentMetadata\": {\"devicePath\":\"${DEVICE_PATH}\"}}}" \ + "$VOLUME_ATTACHMENT" + + write_log "[INFO] Patched VolumeAttachment $VOLUME_ATTACHMENT" +done + +write_log "[INFO] Finished processing all VolumeAttachments!"