From e0f6731368d7d92dfca85b00f1ee766c17660e0f Mon Sep 17 00:00:00 2001 From: Praveen Kumar Date: Mon, 26 Jun 2023 15:06:58 +0530 Subject: [PATCH] disk-resize: remove runGrowPart helper we did refactor 655822fb480f77ae9e18a4ee3ae8b15ed60584b4 and because of this now disk resize steps executed even there is no free space in the disk. Before this refactor we used to return early as soon as there is a specfic exit code from `growpart` command in case no free space on disk. With this PR we are reverting this functionality to make sure we return early if there is no space on disk to grow. --- pkg/crc/machine/start.go | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/pkg/crc/machine/start.go b/pkg/crc/machine/start.go index 689fbad80a..3fb980612c 100644 --- a/pkg/crc/machine/start.go +++ b/pkg/crc/machine/start.go @@ -117,8 +117,17 @@ func growRootFileSystem(sshRunner *crcssh.Runner, preset crcPreset.Preset) error return err } - if err := runGrowpart(sshRunner, rootPart); err != nil { - return err + // with '/dev/[sv]da4' as input, run 'growpart /dev/[sv]da 4' + if _, _, err := sshRunner.RunPrivileged(fmt.Sprintf("Growing %s partition", rootPart), "/usr/bin/growpart", rootPart[:len("/dev/.da")], rootPart[len("/dev/.da"):]); err != nil { + var exitErr *ssh.ExitError + if !errors.As(err, &exitErr) { + return err + } + if exitErr.ExitStatus() != 1 { + return err + } + logging.Debugf("No free space after %s, nothing to do", rootPart) + return nil } if preset == crcPreset.Microshift { @@ -160,21 +169,6 @@ func getrootPartition(sshRunner *crcssh.Runner, preset crcPreset.Preset) (string return rootPart, nil } -func runGrowpart(sshRunner *crcssh.Runner, rootPart string) error { - // with '/dev/[sv]da4' as input, run 'growpart /dev/[sv]da 4' - if _, _, err := sshRunner.RunPrivileged(fmt.Sprintf("Growing %s partition", rootPart), "/usr/bin/growpart", rootPart[:len("/dev/.da")], rootPart[len("/dev/.da"):]); err != nil { - var exitErr *ssh.ExitError - if !errors.As(err, &exitErr) { - return err - } - if exitErr.ExitStatus() != 1 { - return err - } - logging.Debugf("No free space after %s, nothing to do", rootPart) - } - return nil -} - func growLVForMicroshift(sshRunner *crcssh.Runner, lvFullName string, rootPart string) error { if _, _, err := sshRunner.RunPrivileged("Resizing the physical volume(PV)", "/usr/sbin/pvresize", "--devices", rootPart, rootPart); err != nil { return err