Skip to content

Commit

Permalink
only stop and restart rancher-wins if the service exists, if the curr…
Browse files Browse the repository at this point in the history
…ent version wins.exe does not exist proceed with upgrade
  • Loading branch information
HarrisonWAffel committed Jan 7, 2025
1 parent 681f0b3 commit 73a96a2
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 14 deletions.
11 changes: 11 additions & 0 deletions suc/pkg/host/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,17 @@ func getRancherWinsVersionFromBinary(path string) (string, error) {
return parseWinsVersion(string(out))
}

func confirmWinsBinaryIsInstalled() (bool, error) {
_, err := os.Stat(defaultWinsPath)
if err != nil {
if errors.Is(err, os.ErrNotExist) {
return false, nil
}
return false, fmt.Errorf("could not determine if installed wins binary exists: %v", err)
}
return true, nil
}

func confirmWinsBinaryVersion(desiredVersion string, path string) error {
installedVersion, err := getRancherWinsVersionFromBinary(path)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion suc/pkg/host/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func TestParseWinsVersion(t *testing.T) {
errExpected: true,
},
{
name: "unepxected format output",
name: "unexpected format output",
winsOutput: "rancher-wins version",
expectedVersion: "",
errExpected: true,
Expand Down
34 changes: 21 additions & 13 deletions suc/pkg/host/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,21 @@ func UpgradeRancherWinsBinary() (bool, error) {
return false, fmt.Errorf("will not attempt to upgrade wins.exe version, refusing to install embedded dirty version (version: %s)", desiredVersion)
}

currentVersion, err := getRancherWinsVersionFromBinary(defaultWinsPath)
binaryExists, err := confirmWinsBinaryIsInstalled()
if err != nil {
return false, fmt.Errorf("could not determine current wins.exe version: %w", err)
return false, err
}

if currentVersion == desiredVersion {
logrus.Debugf("wins.exe is up to date (%s)", currentVersion)
return false, nil
if binaryExists {
currentVersion, err := getRancherWinsVersionFromBinary(defaultWinsPath)
if err != nil {
return false, fmt.Errorf("could not determine current wins.exe version: %w", err)
}

if currentVersion == desiredVersion {
logrus.Debugf("wins.exe is up to date (%s)", currentVersion)
return false, nil
}
}

restartService, upgradeErr := updateBinaries(desiredVersion)
Expand Down Expand Up @@ -72,16 +79,17 @@ func updateBinaries(desiredVersion string) (bool, error) {
}

logrus.Info("Stopping rancher-wins...")
rw, _, err := service.OpenRancherWinsService()
rw, rwExists, err := service.OpenRancherWinsService()
if err != nil {
return false, fmt.Errorf("failed to open rancher-wins service while attempting to upgrade binary: %w", err)
}

// The service needs to be stopped before we can modify
// the binary it uses
err = rw.Stop()
if err != nil {
return false, fmt.Errorf("failed to stop rancher-wins service while attempting to upgrade binary: %w", err)
if rwExists {
// The service needs to be stopped before we can modify the binary it uses
err = rw.Stop()
if err != nil {
return false, fmt.Errorf("failed to stop rancher-wins service while attempting to upgrade binary: %w", err)
}
}

logrus.Infof("Copying %s to %s", updatedBinaryPath, defaultWinsPath)
Expand All @@ -107,7 +115,7 @@ func updateBinaries(desiredVersion string) (bool, error) {
return false, err
}

err = confirmWinsBinaryVersion(desiredVersion, getWinsUsrLocalBinBinary())
err = confirmWinsBinaryVersion(desiredVersion, usrLocalBinPath)
if err != nil {
return false, err
}
Expand All @@ -119,5 +127,5 @@ func updateBinaries(desiredVersion string) (bool, error) {
}

logrus.Infof("Successfully upgraded wins.exe to version %s", desiredVersion)
return true, nil
return rwExists, nil
}

0 comments on commit 73a96a2

Please sign in to comment.