Skip to content

Commit

Permalink
microcloud/service: Fix semver comparison
Browse files Browse the repository at this point in the history
Signed-off-by: Max Asnaashari <[email protected]>
  • Loading branch information
masnax committed May 3, 2024
1 parent 24dea29 commit 4363c0f
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions microcloud/service/lxd.go
Original file line number Diff line number Diff line change
Expand Up @@ -428,11 +428,14 @@ func (s *LXDService) Restart(ctx context.Context, timeoutSeconds int) error {

// As of LXD 5.21, the LXD snap should support content interfaces to automatically detect the presence of MicroOVN and MicroCeph.
// For older LXDs, we must restart to trigger the snap's detection of MicroOVN and MicroCeph to properly set up LXD's snap environment to work with them.
if semver.Compare(semver.Canonical(fmt.Sprintf("v%s", server.Environment.ServerVersion)), semver.Canonical(fmt.Sprintf("v%s", lxdMinVersion))) < 0 {
// semver.Compare will return 1 if the first argument is larger, 0 if the arguments are the same, and -1 if the first argument is smaller.
lxdVersion := semver.Canonical(fmt.Sprintf("v%s", server.Environment.ServerVersion))
expectedVersion := semver.Canonical(fmt.Sprintf("v%s", lxdMinVersion))
if semver.Compare(lxdVersion, expectedVersion) >= 0 {
return nil
}

logger.Warnf("Detected LXD older than %s, attempting restart to detect MicroOVN and MicroCeph integration", lxdMinVersion)
logger.Warnf("Detected LXD at version %q (older than %q), attempting restart to detect MicroOVN and MicroCeph integration", lxdVersion, expectedVersion)

_, _, err = c.RawQuery("PUT", "/internal/shutdown", nil, "")
if err != nil && err.Error() != "Shutdown already in progress" {
Expand Down

0 comments on commit 4363c0f

Please sign in to comment.