-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy pathconfig.go
435 lines (344 loc) · 14 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
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
// Copyright (c) 2021 Gitpod GmbH. All rights reserved.
// Licensed under the GNU Affero General Public License (AGPL).
// See License.AGPL.txt in the project root for license information.
package config
import (
"time"
agentSmith "github.com/gitpod-io/gitpod/agent-smith/pkg/config"
"github.com/gitpod-io/gitpod/common-go/util"
"github.com/gitpod-io/gitpod/installer/pkg/config"
"github.com/gitpod-io/gitpod/installer/pkg/config/v1/experimental"
"github.com/gitpod-io/gitpod/installer/pkg/containerd"
"github.com/gitpod-io/gitpod/ws-daemon/pkg/cpulimit"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/utils/pointer"
)
func init() {
config.AddVersion("v1", version{})
}
type version struct{}
func (v version) Factory() interface{} {
return &Config{
AuthProviders: []ObjectRef{},
BlockNewUsers: BlockNewUsers{
Enabled: false,
Passlist: []string{},
},
}
}
var (
defaultRepositoryUrl = config.GitpodContainerRegistry
)
const (
defaultOpenVSXURL = "https://open-vsx.org"
defaultMetadataRegion = "local"
)
func (v version) Defaults(in interface{}) error {
cfg, ok := in.(*Config)
if !ok {
return config.ErrInvalidType
}
cfg.Kind = InstallationFull
cfg.Repository = defaultRepositoryUrl
cfg.Observability = Observability{
LogLevel: LogLevelInfo,
}
cfg.Certificate.Kind = ObjectRefSecret
cfg.Certificate.Name = "https-certificates"
cfg.Database.InCluster = pointer.Bool(true)
cfg.Metadata.Region = defaultMetadataRegion
cfg.Metadata.InstallationShortname = InstallationShortNameOldDefault // TODO(gpl): we're tied to "default" here because that's what we put into static bridges in the past
cfg.ObjectStorage.InCluster = pointer.Bool(true)
cfg.ObjectStorage.Resources = &Resources{
Requests: corev1.ResourceList{
corev1.ResourceMemory: resource.MustParse("2Gi"),
},
}
cfg.ContainerRegistry.InCluster = pointer.Bool(true)
cfg.ContainerRegistry.PrivateBaseImageAllowList = []string{}
cfg.Workspace.Resources.Requests = corev1.ResourceList{
corev1.ResourceCPU: resource.MustParse("1000m"),
corev1.ResourceMemory: resource.MustParse("2Gi"),
}
cfg.Workspace.Runtime.FSShiftMethod = FSShiftShiftFS
cfg.Workspace.Runtime.ContainerDSocketDir = containerd.ContainerdSocketLocationDefault.String()
cfg.Workspace.Runtime.ContainerDRuntimeDir = containerd.ContainerdLocationDefault.String()
cfg.Workspace.MaxLifetime = util.Duration(36 * time.Hour)
cfg.OpenVSX.URL = defaultOpenVSXURL
cfg.DisableDefinitelyGP = true
return nil
}
// Looks for deprecated parameters
func (v version) CheckDeprecated(rawCfg interface{}) (map[string]interface{}, []string) {
warnings := make(map[string]interface{}, 0) // A warning is for when a deprecated field is used
conflicts := make([]string, 0)
cfg := rawCfg.(*Config) // A conflict is for when both the deprecated and current field is used
for key, field := range deprecatedFields {
// Check if the deprecated field is in use
inUse, val := parseDeprecatedSelector(cfg, field)
if inUse {
// Deprecated field in use - print the value to the warnings
warnings[key] = val
if field.MapValue != nil {
// There's a MapValue field
if err := field.MapValue(cfg); err != nil {
// There's a conflict on the mapped value - set in both old and new places
conflicts = append(conflicts, err.Error())
}
}
}
}
return warnings, conflicts
}
// Config defines the v1 version structure of the gitpod config file
type Config struct {
// Installation type to run - for most users, this will be Full
Kind InstallationKind `json:"kind" validate:"required,installation_kind"`
// The domain to deploy to
Domain string `json:"domain" validate:"required,fqdn"`
Metadata Metadata `json:"metadata"`
Repository string `json:"repository" validate:"required,ascii"`
Observability Observability `json:"observability"`
Analytics *Analytics `json:"analytics,omitempty"`
Database Database `json:"database" validate:"required"`
ObjectStorage ObjectStorage `json:"objectStorage" validate:"required"`
ContainerRegistry ContainerRegistry `json:"containerRegistry" validate:"required"`
Certificate ObjectRef `json:"certificate" validate:"required"`
HTTPProxy *ObjectRef `json:"httpProxy,omitempty"`
ImagePullSecrets []ObjectRef `json:"imagePullSecrets,omitempty"`
Workspace Workspace `json:"workspace" validate:"required"`
OpenVSX OpenVSX `json:"openVSX"`
AuthProviders []ObjectRef `json:"authProviders" validate:"dive"`
BlockNewUsers BlockNewUsers `json:"blockNewUsers"`
SSHGatewayHostKey *ObjectRef `json:"sshGatewayHostKey,omitempty"`
SSHGatewayCAKey *ObjectRef `json:"sshGatewayCAKey,omitempty"`
DisableDefinitelyGP bool `json:"disableDefinitelyGp"`
CustomCACert *ObjectRef `json:"customCACert,omitempty"`
DropImageRepo *bool `json:"dropImageRepo,omitempty"`
Customization *[]Customization `json:"customization,omitempty"`
Components *Components `json:"components,omitempty"`
Experimental *experimental.Config `json:"experimental,omitempty"`
}
type Metadata struct {
// Location for your objectStorage provider
Region string `json:"region" validate:"required"`
// InstallationShortname establishes the "identity" of the (application) cluster.
InstallationShortname string `json:"shortname"`
}
const (
InstallationShortNameOldDefault string = "default"
)
type Observability struct {
LogLevel LogLevel `json:"logLevel" validate:"required,log_level"`
Tracing *Tracing `json:"tracing,omitempty"`
}
type Analytics struct {
SegmentKey string `json:"segmentKey"`
Writer string `json:"writer"`
SegmentEndpoint string `json:"segmentEndpoint,omitempty"`
}
type Tracing struct {
Endpoint *string `json:"endpoint,omitempty"`
AgentHost *string `json:"agentHost,omitempty"`
// Name of the kubernetes secret to use for Jaeger authentication
// The secret should contains two definitions: JAEGER_USER and JAEGER_PASSWORD
SecretName *string `json:"secretName,omitempty"`
}
type Database struct {
InCluster *bool `json:"inCluster,omitempty"`
External *DatabaseExternal `json:"external,omitempty"`
CloudSQL *DatabaseCloudSQL `json:"cloudSQL,omitempty"`
SSL *SSLOptions `json:"ssl,omitempty"`
}
type DatabaseExternal struct {
Certificate ObjectRef `json:"certificate"`
}
type DatabaseCloudSQL struct {
ServiceAccount ObjectRef `json:"serviceAccount"`
Instance string `json:"instance" validate:"required"`
}
type SSLOptions struct {
CaCert *ObjectRef `json:"caCert,omitempty"`
}
type ObjectStorage struct {
InCluster *bool `json:"inCluster,omitempty"`
S3 *ObjectStorageS3 `json:"s3,omitempty"`
CloudStorage *ObjectStorageCloudStorage `json:"cloudStorage,omitempty"`
// DEPRECATED
MaximumBackupCount *int `json:"maximumBackupCount,omitempty"`
BlobQuota *int64 `json:"blobQuota,omitempty"`
Resources *Resources `json:"resources,omitempty"`
}
type ObjectStorageS3 struct {
Endpoint string `json:"endpoint" validate:"required"`
Credentials *ObjectRef `json:"credentials"`
BucketName string `json:"bucket" validate:"required"`
AllowInsecureConnection bool `json:"allowInsecureConnection"`
}
type ObjectStorageCloudStorage struct {
ServiceAccount ObjectRef `json:"serviceAccount" validate:"required"`
Project string `json:"project" validate:"required"`
}
type InstallationKind string
const (
InstallationIDE InstallationKind = "IDE"
InstallationWebApp InstallationKind = "WebApp"
InstallationMeta InstallationKind = "Meta" // IDE plus WebApp components
InstallationWorkspace InstallationKind = "Workspace"
InstallationFull InstallationKind = "Full"
)
type ObjectRef struct {
Kind ObjectRefKind `json:"kind" validate:"required,objectref_kind"`
Name string `json:"name" validate:"required"`
}
type ObjectRefKind string
const (
ObjectRefSecret ObjectRefKind = "secret"
)
type ContainerRegistry struct {
InCluster *bool `json:"inCluster,omitempty" validate:"required"`
External *ContainerRegistryExternal `json:"external,omitempty" validate:"required_if=InCluster false"`
S3Storage *S3Storage `json:"s3storage,omitempty"`
PrivateBaseImageAllowList []string `json:"privateBaseImageAllowList"`
EnableAdditionalECRAuth bool `json:"enableAdditionalECRAuth"`
SubassemblyBucket string `json:"subassemblyBucket"`
}
type ContainerRegistryExternal struct {
URL string `json:"url" validate:"required"`
Certificate *ObjectRef `json:"certificate,omitempty"`
Credentials *ObjectRef `json:"credentials,omitempty"`
}
type S3Storage struct {
Bucket string `json:"bucket" validate:"required"`
Region string `json:"region" validate:"required"`
Endpoint string `json:"endpoint" validate:"required"`
Certificate *ObjectRef `json:"certificate,omitempty"`
}
type ServiceAnnotations map[string]string
type LogLevel string
// Taken from github.com/gitpod-io/gitpod/components/gitpod-protocol/src/util/logging.ts
const (
LogLevelTrace LogLevel = "trace"
LogLevelDebug LogLevel = "debug"
LogLevelInfo LogLevel = "info"
LogLevelWarning LogLevel = "warning"
LogLevelError LogLevel = "error"
LogLevelFatal LogLevel = "fatal"
LogLevelPanic LogLevel = "panic"
)
type Resources struct {
// todo(sje): add custom validation to corev1.ResourceList
Requests corev1.ResourceList `json:"requests" validate:"required"`
Limits corev1.ResourceList `json:"limits,omitempty"`
}
type WorkspaceRuntime struct {
// File system
FSShiftMethod FSShiftMethod `json:"fsShiftMethod" validate:"required,fs_shift_method"`
// The location of containerd socket on the host machine
ContainerDRuntimeDir string `json:"containerdRuntimeDir" validate:"required,startswith=/"`
// The location of containerd socket on the host machine
ContainerDSocketDir string `json:"containerdSocketDir" validate:"required,startswith=/"`
}
type WorkspaceResources struct {
Requests corev1.ResourceList `json:"requests" validate:"required"`
Limits WorkspaceLimits `json:"limits,omitempty"`
}
type WorkspaceLimits struct {
Cpu WorkspaceCpuLimits `json:"cpu"`
Memory string `json:"memory"`
Storage string `json:"storage"`
EphemeralStorage string `json:"ephemeral-storage"`
}
type WorkspaceCpuLimits struct {
Buckets []cpulimit.Bucket `json:"buckets"`
MinLimit string `json:"min"`
BurstLimit string `json:"burst"`
}
type WorkspaceTemplates struct {
Default *corev1.Pod `json:"default"`
Prebuild *corev1.Pod `json:"prebuild"`
ImageBuild *corev1.Pod `json:"imagebuild"`
Regular *corev1.Pod `json:"regular"`
}
type Workspace struct {
Runtime WorkspaceRuntime `json:"runtime" validate:"required"`
Resources Resources `json:"resources" validate:"required"`
Templates *WorkspaceTemplates `json:"templates,omitempty"`
// MaxLifetime is the maximum time a workspace is allowed to run. After that, the workspace times out despite activity
MaxLifetime util.Duration `json:"maxLifetime" validate:"required"`
// TimeoutDefault is the default timeout of a regular workspace
TimeoutDefault *util.Duration `json:"timeoutDefault,omitempty"`
// TimeoutExtended is the workspace timeout that a user can extend to for one workspace
TimeoutExtended *util.Duration `json:"timeoutExtended,omitempty"`
// TimeoutAfterClose is the time a workspace timed out after it has been closed (“closed” means that it does not get a heartbeat from an IDE anymore)
TimeoutAfterClose *util.Duration `json:"timeoutAfterClose,omitempty"`
WorkspaceImage string `json:"workspaceImage,omitempty"`
}
type OpenVSX struct {
URL string `json:"url" validate:"url"`
Proxy *OpenVSXProxy `json:"proxy,omitempty"`
}
type OpenVSXProxy struct {
DisablePVC bool `json:"disablePVC"`
Proxy `json:",inline"`
}
type Proxy struct {
ServiceAnnotations ServiceAnnotations `json:"serviceAnnotations"`
}
type FSShiftMethod string
const (
FSShiftShiftFS FSShiftMethod = "shiftfs"
)
type BlockNewUsers struct {
Enabled bool `json:"enabled"`
// Passlist []string `json:"passlist" validate:"min=1,unique,dive,fqdn"`
Passlist []string `json:"passlist" validate:"block_new_users_passlist"`
}
// AuthProviderConfigs this only contains what is necessary for validation
type AuthProviderConfigs struct {
ID string `json:"id" validate:"required"`
Host string `json:"host" validate:"required"`
Type string `json:"type" validate:"required"`
OAuth OAuth `json:"oauth" validate:"required"`
}
// OAuth this only contains what is necessary for validation
type OAuth struct {
ClientId string `json:"clientId" validate:"required"`
ClientSecret string `json:"clientSecret" validate:"required"`
CallBackUrl string `json:"callBackUrl" validate:"required"`
}
// Customization is a stripped-down version of the Kubernetes YAML
type Customization struct {
metav1.TypeMeta `json:",inline"`
Metadata metav1.ObjectMeta `json:"metadata"`
Spec CustomizationSpec `json:"spec,omitempty"`
}
type CustomizationSpec struct {
Env []corev1.EnvVar `json:"env"`
}
type Components struct {
AgentSmith *agentSmith.Config `json:"agentSmith,omitempty"`
IDE *IDEComponents `json:"ide"`
PodConfig map[string]*PodConfig `json:"podConfig,omitempty"`
Proxy *ProxyComponent `json:"proxy,omitempty"`
}
type IDEComponents struct {
Metrics *IDEMetrics `json:"metrics,omitempty"`
Proxy *Proxy `json:"proxy,omitempty"`
ResolveLatest *bool `json:"resolveLatest,omitempty"`
}
type IDEMetrics struct {
ErrorReportingEnabled bool `json:"errorReportingEnabled,omitempty"`
}
type PodConfig struct {
Replicas *int32 `json:"replicas,omitempty"`
Resources map[string]*corev1.ResourceRequirements `json:"resources,omitempty"`
}
type ProxyComponent struct {
Service *ComponentTypeService `json:"service,omitempty"`
}
type ComponentTypeService struct {
ServiceType *corev1.ServiceType `json:"serviceType,omitempty" validate:"omitempty,service_config_type"`
}