-
Notifications
You must be signed in to change notification settings - Fork 807
/
config.go
308 lines (238 loc) · 8.13 KB
/
config.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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
/*
Copyright 2021 The KodeRover Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package config
import (
"errors"
"fmt"
"strconv"
"strings"
"github.com/spf13/viper"
configbase "github.com/koderover/zadig/v2/pkg/config"
"github.com/koderover/zadig/v2/pkg/setting"
)
func DefaultIngressClass() string {
return viper.GetString(setting.ENVDefaultIngressClass)
}
// 服务默认等待启动时间,默认5分钟
func ServiceStartTimeout() int {
serviceStartTimeout := viper.GetString(setting.ENVServiceStartTimeout)
if serviceStartTimeout == "" {
return 300
}
serviceStartTimeoutValue, err := strconv.ParseInt(serviceStartTimeout, 10, 32)
if err != nil || serviceStartTimeoutValue < 60 {
panic(errors.New("SERVICE_START_TIMEOUT is not int or less than 60"))
}
return int(serviceStartTimeoutValue)
}
// 环境默认回收天数,默认为0
func DefaultRecycleDay() int {
defaultRecycleDay := viper.GetString(setting.ENVDefaultEnvRecycleDay)
if defaultRecycleDay == "" {
return 0
}
defaultRecycleDayValue, err := strconv.ParseInt(defaultRecycleDay, 10, 32)
if err != nil {
panic(errors.New("DEFAULT_ENV_RECYCLE_DAY is not int"))
}
return int(defaultRecycleDayValue)
}
func PodName() string {
return viper.GetString(setting.ENVPodName)
}
func Namespace() string {
return viper.GetString(setting.ENVNamespace)
}
func LogLevel() int {
return viper.GetInt(setting.ENVLogLevel)
}
func CollieAPIAddress() string {
return configbase.CollieServiceAddress()
}
func MongoURI() string {
return configbase.MongoURI()
}
func MongoDatabase() string {
return configbase.MongoDatabase()
}
func HubServerAddress() string {
return configbase.HubServerServiceAddress()
}
func HubAgentImage() string {
return viper.GetString(setting.ENVHubAgentImage)
}
func ExecutorImage() string {
return viper.GetString(setting.ENVExecutorImage)
}
func KodespaceVersion() string {
return viper.GetString(setting.ENVKodespaceVersion)
}
func EnableTransaction() bool {
return viper.GetString(setting.ENVEnableTransaction) == "true"
}
// CleanIgnoredList is a list which will be ignored during environment cleanup.
func CleanSkippedList() []string {
return strings.Split(viper.GetString(setting.CleanSkippedList), ",")
}
// S3StoragePath returns a local path used to store downloaded code and other files
func S3StoragePath() string {
return "/app/data/workspace"
}
func Home() string {
return viper.GetString(setting.Home)
}
func EnableGitCheck() bool {
return true
}
func S3StorageAK() string {
return viper.GetString(setting.ENVS3StorageAK)
}
func S3StorageSK() string {
return viper.GetString(setting.ENVS3StorageSK)
}
func S3StorageBucket() string {
return viper.GetString(setting.ENVS3StorageBucket)
}
func S3StorageEndpoint() string {
return viper.GetString(setting.ENVS3StorageEndpoint)
}
func S3StorageProtocol() string {
return viper.GetString(setting.ENVS3StorageProtocol)
}
func SetProxy(HTTPSAddr, HTTPAddr, Socks5Addr string) {
viper.Set(setting.ProxyHTTPSAddr, HTTPSAddr)
viper.Set(setting.ProxyHTTPAddr, HTTPAddr)
viper.Set(setting.ProxySocks5Addr, Socks5Addr)
}
func ProxyHTTPSAddr() string {
return viper.GetString(setting.ProxyHTTPSAddr)
}
func ProxyHTTPAddr() string {
return viper.GetString(setting.ProxyHTTPAddr)
}
func KubeServerAddr() string {
return viper.GetString(setting.ENVKubeServerAddr)
}
func RegistryAddress() string {
return viper.GetString(setting.ENVAslanRegAddress)
}
func RegistryAccessKey() string {
return viper.GetString(setting.ENVAslanRegAccessKey)
}
func RegistrySecretKey() string {
return viper.GetString(setting.ENVAslanRegSecretKey)
}
func RegistryNamespace() string {
return viper.GetString(setting.ENVAslanRegNamespace)
}
func GithubSSHKey() string {
return viper.GetString(setting.ENVGithubSSHKey)
}
func GithubKnownHost() string {
return viper.GetString(setting.ENVGithubKnownHost)
}
func ReaperImage() string {
return viper.GetString(setting.ENVReaperImage)
}
func ReaperBinaryFile() string {
return viper.GetString(setting.ENVReaperBinaryFile)
}
func PredatorImage() string {
return viper.GetString(setting.ENVPredatorImage)
}
func PackagerImage() string {
return viper.GetString(setting.EnvPackagerImage)
}
func DockerHosts() []string {
return strings.Split(viper.GetString(setting.ENVDockerHosts), ",")
}
func UseClassicBuild() bool {
return viper.GetString(setting.ENVUseClassicBuild) == "true"
}
func CustomDNSNotSupported() bool {
return !(viper.GetString(setting.ENVCustomDNSNotSupported) == "true")
}
func OldEnvSupported() bool {
return viper.GetString(setting.ENVOldEnvSupported) == "true"
}
func ProxySocks5Addr() string {
return viper.GetString(setting.ProxySocks5Addr)
}
func JenkinsImage() string {
return viper.GetString(setting.JenkinsBuildImage)
}
func WebHookURL() string {
return fmt.Sprintf("%s/api/aslan/webhook", configbase.SystemAddress())
}
func ObjectStorageServicePath(project, service string, production bool) string {
if production {
return ObjectStorageProductionServicePath(project, service)
} else {
return ObjectStorageTestServicePath(project, service)
}
}
func ObjectStorageTestServicePath(project, service string) string {
return configbase.ObjectStorageServicePath(project, service)
}
func ObjectStorageProductionServicePath(project, service string) string {
return configbase.ObjectStorageProductionServicePath(project, service)
}
func LocalServicePath(project, service string, production bool) string {
if production {
return LocalProductionServicePath(project, service)
} else {
return LocalTestServicePath(project, service)
}
}
// LocalTestServicePath returns the path of the normal service with the latest version
func LocalTestServicePath(project, service string) string {
return configbase.LocalTestServicePathWithRevision(project, service, "latest")
}
// LocalProductionServicePath returns the path of the production service with the latest version
func LocalProductionServicePath(project, service string) string {
return configbase.LocalProductionServicePathWithRevision(project, service, "latest")
}
func LocalServicePathWithRevision(project, service string, version string, production bool) string {
if production {
return LocalProductionServicePathWithRevision(project, service, version)
} else {
return LocalTestServicePathWithRevision(project, service, version)
}
}
// LocalTestServicePathWithRevision returns the path of the normal service with the specific revision
func LocalTestServicePathWithRevision(project, service string, revision string) string {
return configbase.LocalTestServicePathWithRevision(project, service, revision)
}
// LocalProductionServicePathWithRevision returns the path of the normal service with the specific revision
func LocalProductionServicePathWithRevision(project, service string, version string) string {
return configbase.LocalProductionServicePathWithRevision(project, service, version)
}
// LocalDeliveryChartPathWithRevision returns the path of the normal service with the specific revision
func LocalDeliveryChartPathWithRevision(project, service string, revision int64) string {
return configbase.LocalTestServicePathWithRevision(project, service, fmt.Sprintf("delivery/%d", revision))
}
func LocalProductionDeliveryChartPathWithRevision(project, service string, revision int64) string {
return configbase.LocalProductionServicePathWithRevision(project, service, fmt.Sprintf("delivery/%d", revision))
}
func ServiceNameWithRevision(serviceName string, revision int64) string {
return fmt.Sprintf("%s-%d", serviceName, revision)
}
func ServiceAccountNameForUser(userID string) string {
return fmt.Sprintf("%s-sa", userID)
}
func DindImage() string {
return viper.GetString(setting.DindImage)
}
func Features() string {
return viper.GetString(setting.FeatureFlag)
}