forked from codefresh-io/venona
-
Notifications
You must be signed in to change notification settings - Fork 0
/
store.go
232 lines (197 loc) · 5.07 KB
/
store.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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
package store
import (
"fmt"
"github.com/codefresh-io/go-sdk/pkg/codefresh"
"github.com/codefresh-io/venona/venonactl/pkg/certs"
k8sApi "k8s.io/api/core/v1"
)
const (
ModeInCluster = "InCluster"
ApplicationName = "runner"
MonitorApplicationName = "monitor"
AppProxyApplicationName = "app-proxy"
EngineAppName = "codefresh-engine"
NetworkTesterName = "cf-venona-network-tester"
)
var (
store *Values
)
type (
Values struct {
AppName string
Mode string
Image *Image
DockerRegistry string
AgentToken string
ServerCert *certs.ServerCert
CodefreshAPI *CodefreshAPI
KubernetesAPI *KubernetesAPI
Runner Runner
VolumeProvisioner VolumeProvisioner
LocalVolumeMonitor LocalVolumeMonitor
Monitor Monitor
AppProxy AppProxy
AgentAPI *AgentAPI
ClusterInCodefresh string
DryRun bool
Verbose bool
Insecure bool
RuntimeEnvironment string
Version *Version
ClusterId string
Helm3 bool
// need for define if monitor use cluster role or just role
UseNamespaceWithRole bool
AdditionalEnvVars map[string]string
}
KubernetesAPI struct {
ConfigPath string
Namespace string
ContextName string
InCluster bool
NodeSelector string
Tolerations []k8sApi.Toleration
}
CodefreshAPI struct {
Host string
Token string
Client codefresh.Codefresh
BuildNodeSelector map[string]string
}
AgentAPI struct {
Token string
Id string
}
Image struct {
Name string
Tag string
}
Version struct {
Current *CurrentVersion
}
CurrentVersion struct {
Version string
Commit string
Date string
}
Runner struct {
Resources map[string]interface{}
}
VolumeProvisioner struct {
Resources map[string]interface{}
}
LocalVolumeMonitor struct {
Resources map[string]interface{}
}
Monitor struct {
Resources map[string]interface{}
}
AppProxy struct {
Resources map[string]interface{}
}
)
func GetStore() *Values {
if store == nil {
store = &Values{}
return store
}
return store
}
func (s *Values) BuildValues() map[string]interface{} {
return map[string]interface{}{
"AppName": ApplicationName,
"ClusterId": s.ClusterId,
"Version": s.Version.Current.Version,
"CodefreshHost": s.CodefreshAPI.Host,
"Token": s.CodefreshAPI.Token,
"Mode": ModeInCluster,
"Verbose": s.Verbose,
"Insecure": s.Insecure,
"Image": map[string]string{
"Name": "codefresh/venona",
"Tag": s.Version.Current.Version,
},
"AdditionalEnvVars": s.AdditionalEnvVars,
"Namespace": s.KubernetesAPI.Namespace,
"ConfigPath": s.KubernetesAPI.ConfigPath,
"Context": s.KubernetesAPI.ContextName,
"NodeSelector": s.KubernetesAPI.NodeSelector,
"DockerRegistry": s.DockerRegistry,
"Tolerations": s.KubernetesAPI.Tolerations,
"AgentToken": s.AgentAPI.Token,
"AgentId": s.AgentAPI.Id,
"ServerCert": map[string]string{
"Cert": "",
"Key": "",
"Ca": "",
},
"Runner": map[string]interface{}{
"Resources": s.Runner.Resources,
},
"CreateRbac": true,
"Storage": map[string]interface{}{
"Backend": "local",
"CreateStorageClass": true,
"StorageClassName": fmt.Sprintf("dind-local-volumes-%s-%s", ApplicationName, s.KubernetesAPI.Namespace),
"LocalVolumeParentDir": "/var/lib/codefresh/dind-volumes",
"AvailabilityZone": "",
"GoogleServiceAccount": "",
"AwsAccessKeyId": "",
"AwsSecretAccessKey": "",
"VolumeProvisioner": map[string]interface{}{
"Image": "codefresh/dind-volume-provisioner:1.33.3",
"NodeSelector": s.KubernetesAPI.NodeSelector,
"Resources": s.VolumeProvisioner.Resources,
"MountAzureJson": false,
},
"LocalVolumeMonitor": map[string]interface{}{
"Resources": s.LocalVolumeMonitor.Resources,
"Image": map[string]string{
"Name": "codefresh/dind-volume-utils",
"Tag": "1.29.4",
},
},
"VolumeCleaner": map[string]interface{}{
"Image": map[string]string{
"Name": "codefresh/dind-volume-cleanup",
"Tag": "1.2.0",
},
},
},
"Monitor": map[string]interface{}{
"Enabled": true,
"UseNamespaceWithRole": s.UseNamespaceWithRole,
//TODO: need verify it on cluster level
"RbacEnabled": true,
"Helm3": s.Helm3,
"AppName": MonitorApplicationName,
"Image": map[string]string{
"Name": "codefresh/agent",
"Tag": "stable",
},
"Resources": s.Monitor.Resources,
},
"AppProxy": map[string]interface{}{
"AppName": AppProxyApplicationName,
"Image": map[string]string{
"Name": "codefresh/cf-app-proxy",
"Tag": "latest",
},
"Resources": s.AppProxy.Resources,
"Ingress": map[string]interface{}{
"Host": "",
"IngressClass": "",
},
},
"Runtime": map[string]interface{}{
"EngineAppName": EngineAppName,
},
"NetworkTester": map[string]interface{}{
"PodName": NetworkTesterName,
"Image": map[string]string{
"Name": "codefresh/cf-venona-network-tester",
"Tag": "latest",
},
},
}
}