-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
59 lines (50 loc) · 1.94 KB
/
main.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
package node_deployer
import (
"strconv"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
"github.com/rswanson/node_deployer/consensusClient"
"github.com/rswanson/node_deployer/executionClient"
)
type EthereumNode struct {
ExecutionClient *executionClient.ExecutionClientComponent
ConsensusClient *consensusClient.ConsensusClientComponent
pulumi.ResourceState
}
type EthereumNodeArgs struct {
ExecutionClientArgs *executionClient.ExecutionClientComponentArgs
ConsensusClientArgs *consensusClient.ConsensusClientComponentArgs
Replicas int
}
func NewEthereumNode(ctx *pulumi.Context, name string, args *EthereumNodeArgs, opts ...pulumi.ResourceOption) (*EthereumNode, error) {
if args == nil {
args = &EthereumNodeArgs{}
}
executionClient, err := executionClient.NewExecutionClientComponent(ctx, name+"-executionClient", args.ExecutionClientArgs, opts...)
if err != nil {
ctx.Log.Error("Error creating execution client", nil)
return nil, err
}
consensusClient, err := consensusClient.NewConsensusClientComponent(ctx, name+"-consensusClient", args.ConsensusClientArgs, opts...)
if err != nil {
ctx.Log.Error("Error creating consensus client", nil)
return nil, err
}
return &EthereumNode{
ExecutionClient: executionClient,
ConsensusClient: consensusClient,
}, nil
}
func EthereumNodeFactory(ctx *pulumi.Context, name string, args *EthereumNodeArgs, opts ...pulumi.ResourceOption) ([]*EthereumNode, error) {
// loop to create a number of EthereumNodes based on replicas
ethereumNodes := make([]*EthereumNode, 0)
for i := 0; i < args.Replicas; i++ {
args.ExecutionClientArgs.Name = args.ExecutionClientArgs.Name + "-" + strconv.Itoa(i)
args.ConsensusClientArgs.Name = args.ConsensusClientArgs.Name + "-" + strconv.Itoa(i)
ethereumNode, err := NewEthereumNode(ctx, name+"-"+strconv.Itoa(i), args, opts...)
if err != nil {
return nil, err
}
ethereumNodes = append(ethereumNodes, ethereumNode)
}
return ethereumNodes, nil
}