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

Fix joining active OVN cluster #818

Merged
merged 3 commits into from
May 3, 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
39 changes: 25 additions & 14 deletions cmd/incusd/api_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,7 @@ func clusterPutJoin(d *Daemon, r *http.Request, req api.ClusterPut) response.Res

d.events.SetLocalLocation(d.serverName)

// Create all storage pools and networks.
err = clusterInitMember(localClient, client, req.MemberConfig)
if err != nil {
return fmt.Errorf("Failed to initialize member: %w", err)
Expand Down Expand Up @@ -765,13 +766,8 @@ func clusterPutJoin(d *Daemon, r *http.Request, req api.ClusterPut) response.Res
return err
}

// Start clustering tasks.
d.startClusterTasks()
revert.Add(func() { d.stopClusterTasks() })

// Handle optional service integration on cluster join
// Add the new node to the default cluster group.
err = s.DB.Cluster.Transaction(context.TODO(), func(ctx context.Context, tx *db.ClusterTx) error {
// Add the new node to the default cluster group.
err := tx.AddNodeToClusterGroup(ctx, "default", req.ServerName)
if err != nil {
return fmt.Errorf("Failed to add new member to the default cluster group: %w", err)
Expand All @@ -783,6 +779,11 @@ func clusterPutJoin(d *Daemon, r *http.Request, req api.ClusterPut) response.Res
return err
}

// Start clustering tasks.
d.startClusterTasks()
revert.Add(func() { d.stopClusterTasks() })

// Load the configuration.
var nodeConfig *node.Config
err = s.DB.Node.Transaction(context.TODO(), func(ctx context.Context, tx *db.NodeTx) error {
var err error
Expand Down Expand Up @@ -1045,6 +1046,11 @@ func clusterInitMember(d incus.InstanceServer, client incus.InstanceServer, memb
continue
}

// OVN networks don't need local creation.
if network.Type == "ovn" {
continue
}

post := api.InitNetworksProjectPost{
NetworksPost: api.NetworksPost{
NetworkPut: network.NetworkPut,
Expand Down Expand Up @@ -2422,13 +2428,13 @@ func internalClusterPostAccept(d *Daemon, r *http.Request) response.Response {
d.clusterMembershipMutex.Lock()
defer d.clusterMembershipMutex.Unlock()

// Check that the pools and networks provided by the joining node have
// configs that match the cluster ones.
// Make sure we have all the expected storage pools.
err = clusterCheckStoragePoolsMatch(r.Context(), s.DB.Cluster, req.StoragePools)
if err != nil {
return response.SmartError(err)
}

// Make sure we have all the expected networks.
err = clusterCheckNetworksMatch(r.Context(), s.DB.Cluster, req.Networks)
if err != nil {
return response.SmartError(err)
Expand Down Expand Up @@ -2844,20 +2850,25 @@ func clusterCheckNetworksMatch(ctx context.Context, clusterDB *db.Cluster, reqNe
}

for _, networkName := range networkNames {
found := false
_, network, _, err := tx.GetNetworkInAnyState(ctx, networkProjectName, networkName)
if err != nil {
return err
}

// OVN networks don't need local creation.
if network.Type == "ovn" {
continue
}

// Check that the network is present locally.
found := false
for _, reqNetwork := range reqNetworks {
if reqNetwork.Name != networkName || reqNetwork.Project != networkProjectName {
continue
}

found = true

_, network, _, err := tx.GetNetworkInAnyState(ctx, networkProjectName, networkName)
if err != nil {
return err
}

if reqNetwork.Type != network.Type {
return fmt.Errorf("Mismatching type for network %q in project %q", networkName, networkProjectName)
}
Expand Down
3 changes: 2 additions & 1 deletion internal/server/cluster/membership.go
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,8 @@ func Join(state *state.State, gateway *Gateway, networkCert *localtls.CertInfo,
for name, id := range network {
config, ok := networks[name]
if !ok {
return fmt.Errorf("Joining member has no config for network %s", name)
// Not all networks are present as virtual networks (OVN) don't need entries.
continue
}

err := tx.NetworkNodeJoin(id, node.ID)
Expand Down
2 changes: 1 addition & 1 deletion shared/archive/detect.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func DetectCompressionFile(f io.Reader) ([]string, string, []string, error) {
// bz2 - 2 bytes, 'BZ' signature/magic number
// gz - 2 bytes, 0x1f 0x8b
// lzma - 6 bytes, { [0x000, 0xE0], '7', 'z', 'X', 'Z', 0x00 } -
// xy - 6 bytes, header format { 0xFD, '7', 'z', 'X', 'Z', 0x00 }
// xz - 6 bytes, header format { 0xFD, '7', 'z', 'X', 'Z', 0x00 }
// tar - 263 bytes, trying to get ustar from 257 - 262
header := make([]byte, 263)
_, err := f.Read(header)
Expand Down
Loading