Skip to content

Commit

Permalink
Merge pull request #12148 from roosterfish/fix_mv_instance_placement
Browse files Browse the repository at this point in the history
Instance: Fix placement when moving within same cluster group
  • Loading branch information
tomponline authored Aug 17, 2023
2 parents 38f2a06 + 58e3e9b commit 37eab80
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
12 changes: 11 additions & 1 deletion lxd/instance_post.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,18 @@ func instancePost(d *Daemon, r *http.Request) response.Response {

// If no member was selected yet, pick the member with the least number of instances.
if targetMemberInfo == nil {
var filteredCandidateMembers []db.NodeInfo

// The instance might already be placed on the node with least number of instances.
// Therefore remove it from the list of possible candidates if existent.
for _, candidateMember := range candidateMembers {
if candidateMember.Name != inst.Location() {
filteredCandidateMembers = append(filteredCandidateMembers, candidateMember)
}
}

err := s.DB.Cluster.Transaction(r.Context(), func(ctx context.Context, tx *db.ClusterTx) error {
targetMemberInfo, err = tx.GetNodeWithLeastInstances(ctx, candidateMembers)
targetMemberInfo, err = tx.GetNodeWithLeastInstances(ctx, filteredCandidateMembers)
return err
})
if err != nil {
Expand Down
4 changes: 4 additions & 0 deletions test/suites/clustering_move.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,12 @@ test_clustering_move() {
LXD_DIR="${LXD_ONE_DIR}" lxc info c1 | grep -q "Location: node1"

# c1 can be moved within the same cluster group if it has multiple members
current_location="$(LXD_DIR="${LXD_ONE_DIR}" lxc query /1.0/instances/c1 | jq -r '.location')"
LXD_DIR="${LXD_ONE_DIR}" lxc move c1 --target=@default
LXD_DIR="${LXD_ONE_DIR}" lxc query /1.0/instances/c1 | jq -re ".location != \"$current_location\""
current_location="$(LXD_DIR="${LXD_ONE_DIR}" lxc query /1.0/instances/c1 | jq -r '.location')"
LXD_DIR="${LXD_ONE_DIR}" lxc move c1 --target=@default
LXD_DIR="${LXD_ONE_DIR}" lxc query /1.0/instances/c1 | jq -re ".location != \"$current_location\""

# c1 cannot be moved within the same cluster group if it has a single member
LXD_DIR="${LXD_ONE_DIR}" lxc move c1 --target=@foobar3
Expand Down

0 comments on commit 37eab80

Please sign in to comment.