Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only restart LXD if version is less than 5.21 #286

Merged
merged 1 commit into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 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,19 @@ 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)
}

// 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 {
tomponline marked this conversation as resolved.
Show resolved Hide resolved
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
Loading