Skip to content

Commit

Permalink
Add non-parallel hosts.Each
Browse files Browse the repository at this point in the history
Signed-off-by: Kimmo Lehto <[email protected]>
  • Loading branch information
kke committed Nov 9, 2023
1 parent ed5b8fb commit 1e90e9e
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions pkg/apis/k0sctl.k0sproject.io/v1beta1/cluster/hosts.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,19 @@ func (hosts Hosts) Workers() Hosts {
return hosts.WithRole("worker")
}

// Each runs a function (or multiple functions chained) on every Host.
func (hosts Hosts) Each(filters ...func(h *Host) error) error {
for _, filter := range filters {
for _, h := range hosts {
if err := filter(h); err != nil {
return err
}
}
}

return nil
}

// ParallelEach runs a function (or multiple functions chained) on every Host parallelly.
// Any errors will be concatenated and returned.
func (hosts Hosts) ParallelEach(filters ...func(h *Host) error) error {
Expand Down

0 comments on commit 1e90e9e

Please sign in to comment.