feat: allow to filter machines for global service deployments

This commit is contained in:
Pavel Sviderski
2025-02-17 20:26:40 +10:00
parent 8610322682
commit e13408d79f
6 changed files with 227 additions and 10 deletions
+11 -1
View File
@@ -4,6 +4,7 @@ import (
"context"
"errors"
"fmt"
"slices"
"uncloud/internal/api"
"uncloud/internal/machine/api/pb"
"uncloud/internal/secret"
@@ -19,7 +20,10 @@ type Strategy interface {
// RollingStrategy implements a rolling update deployment pattern where containers are updated one at a time
// to minimize service disruption.
type RollingStrategy struct{}
type RollingStrategy struct {
// MachineFilter optionally restricts which machines participate in this deployment.
MachineFilter MachineFilter
}
func (s *RollingStrategy) Plan(
ctx context.Context, cli *Client, svc *api.Service, spec api.ServiceSpec,
@@ -72,6 +76,12 @@ func (s *RollingStrategy) planGlobal(
if err != nil {
return plan, fmt.Errorf("list machines: %w", err)
}
// Filter machines if a machine filter is provided.
if s.MachineFilter != nil {
machines = slices.DeleteFunc(machines, func(m *pb.MachineMember) bool {
return !s.MachineFilter(m.Machine)
})
}
// TODO: figure out how to return a warning if there are machines down. Embed the machinesDown in the plan?
// WARNING: failed to run a service container on machine '%s' which is Down.