Skip to content

Commit

Permalink
incusd/cluster: Add lifecycle events for evacuation
Browse files Browse the repository at this point in the history
Signed-off-by: Stéphane Graber <stgraber@stgraber.org>
  • Loading branch information
stgraber committed Aug 5, 2024
1 parent a636b6e commit 6326d9b
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions cmd/incusd/api_cluster_evacuation.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
dbCluster "github.com/lxc/incus/v6/internal/server/db/cluster"
"github.com/lxc/incus/v6/internal/server/db/operationtype"
"github.com/lxc/incus/v6/internal/server/instance"
"github.com/lxc/incus/v6/internal/server/lifecycle"
"github.com/lxc/incus/v6/internal/server/operations"
"github.com/lxc/incus/v6/internal/server/response"
"github.com/lxc/incus/v6/internal/server/scriptlet"
Expand Down Expand Up @@ -147,6 +148,11 @@ func evacuateClusterMember(ctx context.Context, s *state.State, gateway *cluster
networkShutdown(s)

reverter.Success()

if mode != "heal" {
s.Events.SendLifecycle(api.ProjectDefaultName, lifecycle.ClusterMemberEvacuated.Event(name, op.Requestor(), nil))
}

return nil
}

Expand Down Expand Up @@ -458,6 +464,9 @@ func restoreClusterMember(d *Daemon, r *http.Request) response.Response {
}

reverter.Success()

s.Events.SendLifecycle(api.ProjectDefaultName, lifecycle.ClusterMemberRestored.Event(originName, op.Requestor(), nil))

return nil
}

Expand Down Expand Up @@ -675,6 +684,8 @@ func autoHealClusterTask(d *Daemon) (task.Func, task.Schedule) {
}

func healClusterMember(d *Daemon, op *operations.Operation, name string) error {
s := d.State()

logger.Info("Starting cluster healing", logger.Ctx{"server": name})
defer logger.Info("Completed cluster healing", logger.Ctx{"server": name})

Expand Down Expand Up @@ -744,15 +755,14 @@ func healClusterMember(d *Daemon, op *operations.Operation, name string) error {
// Attempt up to 5 evacuations.
var err error
for i := 0; i < 5; i++ {
err = evacuateClusterMember(context.Background(), d.State(), d.gateway, op, name, "heal", nil, migrateFunc)
err = evacuateClusterMember(context.Background(), s, d.gateway, op, name, "heal", nil, migrateFunc)
if err == nil {
s.Events.SendLifecycle(api.ProjectDefaultName, lifecycle.ClusterMemberHealed.Event(name, op.Requestor(), nil))

return nil
}
}

if err != nil {
logger.Error("Failed to heal cluster member", logger.Ctx{"server": name, "err": err})
}

logger.Error("Failed to heal cluster member", logger.Ctx{"server": name, "err": err})
return err
}

0 comments on commit 6326d9b

Please sign in to comment.