-
Notifications
You must be signed in to change notification settings - Fork 2
/
cluster.go
69 lines (57 loc) · 1.11 KB
/
cluster.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
68
69
package kubo
import (
"context"
"github.com/guseggert/clustertest/cluster/basic"
"go.uber.org/zap"
)
var defaultLogger *zap.SugaredLogger
const defaultKuboVersion = "latest-release"
func init() {
l, err := zap.NewProduction()
if err != nil {
panic(err)
}
defaultLogger = l.Sugar()
}
func New(bc *basic.Cluster) *Cluster {
return &Cluster{
Cluster: bc,
Ctx: context.Background(),
}
}
func Must(err error) {
if err != nil {
panic(err)
}
}
func Must2[V any](v V, err error) V {
if err != nil {
panic(err)
}
return v
}
func (c *Cluster) Context(ctx context.Context) *Cluster {
newC := *c
newC.Ctx = ctx
newC.Cluster = newC.Cluster.Context(ctx)
return &newC
}
type Cluster struct {
*basic.Cluster
Ctx context.Context
}
func (c *Cluster) NewNodes(n int) ([]*Node, error) {
var kuboNodes []*Node
nodes, err := c.Cluster.NewNodes(n)
if err != nil {
return nil, err
}
for _, n := range nodes {
kn := newNode(n).WithNodeLogger(c.Log).Context(c.Ctx)
kuboNodes = append(kuboNodes, kn)
}
return kuboNodes, nil
}
func (c *Cluster) MustNewNodes(n int) []*Node {
return Must2(c.NewNodes(n))
}