Skip to content

Commit

Permalink
[RELEASE STABLE] Hotfix for Volume Mount.
Browse files Browse the repository at this point in the history
  • Loading branch information
antony-jr committed Nov 7, 2023
1 parent fcb3bc2 commit 08f6c10
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 8 deletions.
22 changes: 14 additions & 8 deletions internal/cmd/get/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -407,8 +407,13 @@ Local Recipe:
_ = tuiSpinnerMsg.StopMessage()
fmt.Printf(" %s Created Server\n", checkMark)
}

volDevice, err := helpers.GetVolumeLinuxDeviceForServer(client, serverName)
if err != nil {
return err
}
fmt.Printf(" %s Volume Device: %s\n", checkMark, volDevice)

volDevice := currentBuildServer.Volumes[0].LinuxDevice
err = doInitialize(ipAddr, config.SSHPrivateKey, volDevice, varsFilePath, fileUploads, usedGit, gitUrl, gitBranch, dir, argv.TestingBinary)
if err != nil {
return err
Expand Down Expand Up @@ -511,10 +516,11 @@ Local Recipe:
tries = 0
defer os.Remove(varsFilePath)

volDevice := ""
if currentBuildServer != nil {
volDevice = currentBuildServer.Volumes[0].LinuxDevice
volDevice, err := helpers.GetVolumeLinuxDeviceForServer(client, serverName)
if err != nil {
return err
}
fmt.Printf(" %s Volume Device: %s\n", checkMark, volDevice)

err = doInitialize(ipAddr, config.SSHPrivateKey, volDevice, varsFilePath, fileUploads, usedGit, gitUrl, gitBranch, dir, argv.TestingBinary)
if err != nil {
Expand Down Expand Up @@ -937,21 +943,21 @@ func doInitialize(ipAddr string,
if volumeLinuxDevice != "" {
spinnerMsg.ShowMessage("Mounting Volume... ")

mountStatus, err := tryExec("mountpoint /ham-build")
mountStatus, err := tryExec("mountpoint /ham-build || true")
if err != nil {
return err
}

if strings.Contains(mountStatus, "not a mountpoint") {
_, err = tryExec(fmt.Sprintf("mkfs.ext4 %s", volumeLinuxDevice))
_, err = tryExec(fmt.Sprintf("mkfs.ext4 -F %s", volumeLinuxDevice))
if err != nil {
return err
return errors.New("Volume Mkfs Failed")
}

_, err = tryExec(fmt.Sprintf("mount -o discard,defaults %s /ham-build", volumeLinuxDevice))

if err != nil {
return err
return errors.New("Volume Mount Failed")
}

}
Expand Down
20 changes: 20 additions & 0 deletions internal/helpers/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,26 @@ func DeleteServer(sclient *hcloud.ServerClient, serverName string) error {
return errors.New("Server Not Found")
}

func GetVolumeLinuxDeviceForServer(client *hcloud.Client, serverName string) (string, error) {
volName := fmt.Sprintf("%s-vol", serverName)
vols, err := client.Volume.All(
context.Background(),
)

if err != nil {
return "", err
}

for _, volume := range vols {
if volume.Name == volName {
return volume.LinuxDevice, nil
}
}

return "", errors.New("No Such Volume")

}

func DeleteVolume(vclient *hcloud.VolumeClient, serverName string) error {
volName := fmt.Sprintf("%s-vol", serverName)
vols, err := vclient.All(
Expand Down

0 comments on commit 08f6c10

Please sign in to comment.