-
Notifications
You must be signed in to change notification settings - Fork 74
/
generic_phase.go
67 lines (54 loc) · 1.82 KB
/
generic_phase.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package phase
import (
"fmt"
"github.com/k0sproject/k0sctl/analytics"
"github.com/k0sproject/k0sctl/pkg/apis/k0sctl.k0sproject.io/v1beta1"
"github.com/k0sproject/k0sctl/pkg/apis/k0sctl.k0sproject.io/v1beta1/cluster"
)
// GenericPhase is a basic phase which gets a config via prepare, sets it into p.Config
type GenericPhase struct {
analytics.Phase
Config *v1beta1.Cluster
manager *Manager
}
// GetConfig is an accessor to phase Config
func (p *GenericPhase) GetConfig() *v1beta1.Cluster {
return p.Config
}
// Prepare the phase
func (p *GenericPhase) Prepare(c *v1beta1.Cluster) error {
p.Config = c
return nil
}
// Wet is a shorthand for manager.Wet
func (p *GenericPhase) Wet(host fmt.Stringer, msg string, funcs ...errorfunc) error {
return p.manager.Wet(host, msg, funcs...)
}
// IsWet returns true if manager is in dry-run mode
func (p *GenericPhase) IsWet() bool {
return !p.manager.DryRun
}
// DryMsg is a shorthand for manager.DryMsg
func (p *GenericPhase) DryMsg(host fmt.Stringer, msg string) {
p.manager.DryMsg(host, msg)
}
// DryMsgf is a shorthand for manager.DryMsg + fmt.Sprintf
func (p *GenericPhase) DryMsgf(host fmt.Stringer, msg string, args ...any) {
p.manager.DryMsg(host, fmt.Sprintf(msg, args...))
}
// SetManager adds a reference to the phase manager
func (p *GenericPhase) SetManager(m *Manager) {
p.manager = m
}
func (p *GenericPhase) parallelDo(hosts cluster.Hosts, funcs ...func(h *cluster.Host) error) error {
if p.manager.Concurrency == 0 {
return hosts.ParallelEach(funcs...)
}
return hosts.BatchedParallelEach(p.manager.Concurrency, funcs...)
}
func (p *GenericPhase) parallelDoUpload(hosts cluster.Hosts, funcs ...func(h *cluster.Host) error) error {
if p.manager.Concurrency == 0 {
return hosts.ParallelEach(funcs...)
}
return hosts.BatchedParallelEach(p.manager.ConcurrentUploads, funcs...)
}