Skip to content

Commit

Permalink
Merge pull request #302 from masnax/use-interface
Browse files Browse the repository at this point in the history
microcloud/service: Fix semver comparison
  • Loading branch information
masnax committed May 8, 2024
2 parents d5a3819 + 4363c0f commit 3e516f9
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 @@ -443,11 +443,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 3e516f9

Please sign in to comment.