/
beacon_exec_client_config_driver.go
196 lines (180 loc) · 6.13 KB
/
beacon_exec_client_config_driver.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
package ethereum_beacon_cookbooks
import (
"errors"
client_consts "github.com/zeus-fyi/zeus/cookbooks/ethereum/beacons/constants"
hestia_req_types "github.com/zeus-fyi/zeus/pkg/hestia/client/req_types"
filepaths "github.com/zeus-fyi/zeus/pkg/utils/file_io/lib/v0/paths"
zeus_cluster_config_drivers "github.com/zeus-fyi/zeus/zeus/cluster_config_drivers"
"github.com/zeus-fyi/zeus/zeus/workload_config_drivers/config_overrides"
"github.com/zeus-fyi/zeus/zeus/workload_config_drivers/topology_workloads"
"github.com/zeus-fyi/zeus/zeus/workload_config_drivers/zk8s_templates"
"github.com/zeus-fyi/zeus/zeus/z_client/zeus_req_types"
v1Core "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
const (
zeusExecClient = "zeus-exec-client"
execClientDiskName = "exec-client-storage"
execClientDiskSizeEphemeral = "10Gi"
execClientDiskSizeGoerli = "500Gi"
execClientDiskSizeMainnet = "2Ti"
execClientEphemeralRequestCPU = "2.5"
execClientEphemeralRequestMemory = "4Gi"
execClientMainnetCPU = "6"
execClientMainnetCPUMemory = "20Gi"
hercules = "hercules"
herculesEphemeral = "herculesEphemeral"
GethEphemeral = "gethEphemeral"
GethGoerli = "gethGoerli"
GethMainnet = "geth"
downloadGethEphemeral = "downloadGethEphemeral"
gethDockerImage = "ethereum/client-go:v1.13.5"
gethDockerImageCapella = "ethpandaops/geth:master"
rethDockerImage = "ghcr.io/paradigmxyz/reth:v0.1.0-alpha.13"
rethMainnet = "reth"
rethDownload = "downloadReth"
execClientRethDiskSizeMainnet = "3Ti"
)
func GetExecClientNetworkConfig(beaconConfig BeaconConfig) zeus_cluster_config_drivers.ComponentBaseDefinition {
dockerImage := ""
cmConfig := ""
diskSize := execClientDiskSizeMainnet
herculesStartup := hercules + ".sh"
downloadStartup := download + ".sh"
cpuSize := execClientMainnetCPU
memSize := execClientMainnetCPUMemory
switch beaconConfig.ExecClient {
case client_consts.Geth:
switch beaconConfig.Network {
case hestia_req_types.Ephemery, "ephemeral":
cpuSize = execClientEphemeralRequestCPU
memSize = execClientEphemeralRequestMemory
dockerImage = gethDockerImageCapella
diskSize = execClientDiskSizeEphemeral
cmConfig = GethEphemeral
herculesStartup = herculesEphemeral + ".sh"
downloadStartup = downloadGethEphemeral + ".sh"
case hestia_req_types.Mainnet:
cmConfig = GethMainnet
dockerImage = gethDockerImage
}
case client_consts.Reth:
diskSize = execClientRethDiskSizeMainnet
cmConfig = rethMainnet
dockerImage = rethDockerImage
downloadStartup = rethDownload + ".sh"
}
cp := filepaths.Path{
PackageName: "",
DirIn: "./ethereum/beacons/infra/exec_client",
DirOut: "./ethereum/outputs",
FnIn: beaconConfig.ExecClient, // filename for your gzip workload
FnOut: "",
Env: "",
}
initContDriver := config_overrides.ContainerDriver{
IsInitContainer: true,
}
if beaconConfig.WithChoreography {
initContDriver.AppendEnvVars = []v1Core.EnvVar{BearerTokenSecretFromChoreography}
}
rr := v1Core.ResourceRequirements{
Requests: v1Core.ResourceList{
"cpu": resource.MustParse(cpuSize),
"memory": resource.MustParse(memSize),
},
Limits: v1Core.ResourceList{
"cpu": resource.MustParse(cpuSize),
"memory": resource.MustParse(memSize),
},
}
pvcTemp := zk8s_templates.PVCTemplate{
Name: execClientDiskName,
StorageSizeRequest: diskSize,
}
sbCfg := zeus_cluster_config_drivers.ClusterSkeletonBaseDefinition{
SkeletonBaseChart: zeus_req_types.TopologyCreateRequest{},
SkeletonBaseNameChartPath: cp,
TopologyConfigDriver: &config_overrides.TopologyConfigDriver{
ConfigMapDriver: &config_overrides.ConfigMapDriver{
ConfigMap: v1Core.ConfigMap{
ObjectMeta: metav1.ObjectMeta{Name: "cm-exec-client"},
},
SwapKeys: map[string]string{
"start.sh": cmConfig + ".sh",
hercules + ".sh": herculesStartup,
download + ".sh": downloadStartup,
},
},
StatefulSetDriver: &config_overrides.StatefulSetDriver{
ContainerDrivers: map[string]config_overrides.ContainerDriver{
initSnapshots: initContDriver,
zeusExecClient: {
Container: v1Core.Container{
Name: zeusExecClient,
Image: dockerImage,
Resources: rr,
},
},
},
PVCDriver: &config_overrides.PersistentVolumeClaimsConfigDriver{
PersistentVolumeClaimDrivers: map[string]v1Core.PersistentVolumeClaim{
execClientDiskName: zk8s_templates.GetPvcTemplate(pvcTemp),
}},
},
}}
execCompBase := zeus_cluster_config_drivers.ComponentBaseDefinition{
SkeletonBases: map[string]zeus_cluster_config_drivers.ClusterSkeletonBaseDefinition{
beaconConfig.ExecClient: sbCfg,
},
}
return execCompBase
}
func EphemeralExecClientGethConfig(inf topology_workloads.TopologyBaseInfraWorkload) {
if inf.ConfigMap != nil {
m := make(map[string]string)
m = inf.ConfigMap.Data
vSrc, ok := inf.ConfigMap.Data[GethEphemeral+".sh"]
if ok {
m[start+".sh"] = vSrc
} else {
err := errors.New("key not found")
panic(err)
}
vSrc, ok = inf.ConfigMap.Data[downloadGethEphemeral+".sh"]
if ok {
m[download+".sh"] = vSrc
} else {
err := errors.New("key not found")
panic(err)
}
vSrc, ok = inf.ConfigMap.Data[herculesEphemeral+".sh"]
if ok {
m[hercules+".sh"] = vSrc
} else {
err := errors.New("key not found")
panic(err)
}
}
if inf.StatefulSet != nil {
for i, c := range inf.StatefulSet.Spec.Template.Spec.Containers {
if c.Name == zeusExecClient {
inf.StatefulSet.Spec.Template.Spec.Containers[i].Image = gethDockerImageCapella
}
}
for i, v := range inf.StatefulSet.Spec.VolumeClaimTemplates {
if v.Name == execClientDiskName {
q, err := resource.ParseQuantity(execClientDiskSizeEphemeral)
if err != nil {
panic(err)
}
for j, _ := range inf.StatefulSet.Spec.VolumeClaimTemplates[i].Spec.Resources.Requests {
tmp := inf.StatefulSet.Spec.VolumeClaimTemplates[i].Spec.Resources.Requests[j]
tmp.Set(q.Value())
inf.StatefulSet.Spec.VolumeClaimTemplates[i].Spec.Resources.Requests[j] = tmp
}
}
}
}
}