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

Instance: Fix placement when moving within same cluster group #12148

Merged
merged 2 commits into from
Aug 17, 2023
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
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.
tomponline marked this conversation as resolved.
Show resolved Hide resolved
// 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
Loading