From 4d22ce0982b27cf38fff2d2093eb5d08f97f1255 Mon Sep 17 00:00:00 2001
From: Sheogorath <sheogorath@shivering-isles.com>
Date: Sat, 26 Mar 2022 14:03:16 +0100
Subject: [PATCH] fix(system-upgrade): Fix ever expanding fstab line

This patch fixes a bug, where the longhorn fstab entry grows
indefinitely every time the lvm setup script is run. This is due to a
bug in the sed script that replaces only the first part of the fstab
entry instead of the entire line.
---
 infrastructure/system-upgrades/longhorn-lvm.yaml | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/infrastructure/system-upgrades/longhorn-lvm.yaml b/infrastructure/system-upgrades/longhorn-lvm.yaml
index dd91a558f..689930773 100644
--- a/infrastructure/system-upgrades/longhorn-lvm.yaml
+++ b/infrastructure/system-upgrades/longhorn-lvm.yaml
@@ -19,7 +19,7 @@ stringData:
       echo "Failed to find volume group" >&2
       exit 1
     fi
-    
+
     # Setup LVM volume (size)
     # Since Volume can already exist, we should make sure, we set their size on update
     if lvs "$VG_NAME" | grep "${LV_NAME}"; then
@@ -27,40 +27,40 @@ stringData:
     else
       lvcreate --size "$(cat "$secrets/volumesize")" --name "${LV_NAME}" "${VG_NAME}"
     fi
-    
+
     # Setup filesystem
     # After a volume creation or adjustment of the volume size
     # the filesystem will require either creation or adjustment.
     if ! file -L -s "/dev/$VG_NAME/$LV_NAME" | grep XFS; then
       mkfs.xfs "/dev/$VG_NAME/$LV_NAME"
     fi
-    
+
     # Setup SELinux labels
     # cri-o while running SELinux enabled, will require container_file_t to function
     # properly with non-privileged containers.
     if ! matchpathcon '/var/lib/longhorn' | grep "container_file_t"; then
       semanage fcontext -a -t container_file_t "/var/lib/longhorn(/.*)?"
     fi
-    
+
     # Prepare mountpoint
     mkdir -p /var/lib/longhorn
     # Prepare and setup mountpoint
     if ! mountpoint /var/lib/longhorn; then
       mount "/dev/$VG_NAME/$LV_NAME" /var/lib/longhorn
     fi
-    
+
     # GrowFS since we can't do it earlier as it needs to be mounted
     xfs_growfs "/dev/$VG_NAME/$LV_NAME"
 
     if ! ls -laZ /var/lib/longhorn | grep "container_file_t"; then
       restorecon /var/lib/longhorn
     fi
-    
+
     # Persist mountpoint
     if ! grep '/var/lib/longhorn' /etc/fstab; then
       echo "/dev/mapper/${VG_NAME}-${LV_NAME}    /var/lib/longhorn           xfs     defaults,x-systemd.device-timeout=0 0 0" >> /etc/fstab
     else
-      sed -i "s%/dev/mapper/${VG_NAME}-${LV_NAME}*%/dev/mapper/${VG_NAME}-${LV_NAME}    /var/lib/longhorn           xfs     defaults,x-systemd.device-timeout=0 0 0%" /etc/fstab
+      sed -i "s%^/dev/mapper/${VG_NAME}-${LV_NAME}.*%/dev/mapper/${VG_NAME}-${LV_NAME}    /var/lib/longhorn           xfs     defaults,x-systemd.device-timeout=0 0 0%" /etc/fstab
     fi
     systemctl daemon-reload
 ---
-- 
GitLab