Skip to content

Commit

Permalink
microcloud/service: Don't restart LXD unless API version is less than…
Browse files Browse the repository at this point in the history
… that of 5.21

Signed-off-by: Max Asnaashari <[email protected]>
  • Loading branch information
masnax committed Apr 17, 2024
1 parent 9a50ff6 commit 6f994ba
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
14 changes: 13 additions & 1 deletion microcloud/service/lxd.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ import (
"strings"
"time"

lxd "github.com/canonical/lxd/client"
"github.com/canonical/lxd/client"
"github.com/canonical/lxd/lxd/util"
"github.com/canonical/lxd/shared"
"github.com/canonical/lxd/shared/api"
"github.com/canonical/lxd/shared/logger"
"github.com/canonical/microcluster/microcluster"
"golang.org/x/mod/semver"

"github.com/canonical/microcloud/microcloud/api/types"
"github.com/canonical/microcloud/microcloud/mdns"
Expand Down Expand Up @@ -420,6 +421,17 @@ func (s *LXDService) Restart(ctx context.Context, timeoutSeconds int) error {
return fmt.Errorf("Detected pre-existing LXD storage pools. LXD might have already been initialized")
}

server, _, err := c.GetServer()
if err != nil {
return fmt.Errorf("Failed to get LXD server information: %w", err)
}

if semver.Compare(semver.Canonical(fmt.Sprintf("v%s", server.Environment.ServerVersion)), semver.Canonical(fmt.Sprintf("v%s", lxdMinVersion))) < 0 {
return nil
}

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

_, _, err = c.RawQuery("PUT", "/internal/shutdown", nil, "")
if err != nil && err.Error() != "Shutdown already in progress" {
return fmt.Errorf("Failed to send shutdown request to LXD: %w", err)
Expand Down
3 changes: 3 additions & 0 deletions microcloud/service/lxd_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import (
"github.com/canonical/lxd/shared/api"
)

// lxdMinVersion is the minimum version of LXD that fully supports all MicroCloud features.
const lxdMinVersion = "5.21"

// DefaultPendingFanNetwork returns the default Ubuntu Fan network configuration when
// creating a pending network on a specific cluster member target.
func (s LXDService) DefaultPendingFanNetwork() api.NetworksPost {
Expand Down

0 comments on commit 6f994ba

Please sign in to comment.