Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/install/installer/pkg/config/v1/config.go
2501 views
1
// Copyright (c) 2021 Gitpod GmbH. All rights reserved.
2
// Licensed under the GNU Affero General Public License (AGPL).
3
// See License.AGPL.txt in the project root for license information.
4
5
package config
6
7
import (
8
"time"
9
10
agentSmith "github.com/gitpod-io/gitpod/agent-smith/pkg/config"
11
"github.com/gitpod-io/gitpod/common-go/util"
12
"github.com/gitpod-io/gitpod/installer/pkg/config"
13
"github.com/gitpod-io/gitpod/installer/pkg/config/v1/experimental"
14
"github.com/gitpod-io/gitpod/installer/pkg/containerd"
15
"github.com/gitpod-io/gitpod/ws-daemon/pkg/cpulimit"
16
17
corev1 "k8s.io/api/core/v1"
18
"k8s.io/apimachinery/pkg/api/resource"
19
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
20
"k8s.io/utils/pointer"
21
)
22
23
func init() {
24
config.AddVersion("v1", version{})
25
}
26
27
type version struct{}
28
29
func (v version) Factory() interface{} {
30
return &Config{
31
AuthProviders: []ObjectRef{},
32
BlockNewUsers: BlockNewUsers{
33
Enabled: false,
34
Passlist: []string{},
35
},
36
}
37
}
38
39
var (
40
defaultRepositoryUrl = config.GitpodContainerRegistry
41
)
42
43
const (
44
defaultOpenVSXURL = "https://open-vsx.org"
45
defaultMetadataRegion = "local"
46
)
47
48
func (v version) Defaults(in interface{}) error {
49
cfg, ok := in.(*Config)
50
if !ok {
51
return config.ErrInvalidType
52
}
53
54
cfg.Kind = InstallationFull
55
cfg.Repository = defaultRepositoryUrl
56
cfg.Observability = Observability{
57
LogLevel: LogLevelInfo,
58
}
59
cfg.Certificate.Kind = ObjectRefSecret
60
cfg.Certificate.Name = "https-certificates"
61
cfg.Database.InCluster = pointer.Bool(true)
62
cfg.Metadata.Region = defaultMetadataRegion
63
cfg.Metadata.InstallationShortname = InstallationShortNameOldDefault // TODO(gpl): we're tied to "default" here because that's what we put into static bridges in the past
64
cfg.ObjectStorage.InCluster = pointer.Bool(true)
65
cfg.ObjectStorage.Resources = &Resources{
66
Requests: corev1.ResourceList{
67
corev1.ResourceMemory: resource.MustParse("2Gi"),
68
},
69
}
70
cfg.ContainerRegistry.InCluster = pointer.Bool(true)
71
cfg.ContainerRegistry.PrivateBaseImageAllowList = []string{}
72
cfg.Workspace.Resources.Requests = corev1.ResourceList{
73
corev1.ResourceCPU: resource.MustParse("1000m"),
74
corev1.ResourceMemory: resource.MustParse("2Gi"),
75
}
76
cfg.Workspace.Runtime.FSShiftMethod = FSShiftShiftFS
77
cfg.Workspace.Runtime.ContainerDSocketDir = containerd.ContainerdSocketLocationDefault.String()
78
cfg.Workspace.Runtime.ContainerDRuntimeDir = containerd.ContainerdLocationDefault.String()
79
cfg.Workspace.MaxLifetime = util.Duration(36 * time.Hour)
80
cfg.OpenVSX.URL = defaultOpenVSXURL
81
cfg.DisableDefinitelyGP = true
82
83
return nil
84
}
85
86
// Looks for deprecated parameters
87
func (v version) CheckDeprecated(rawCfg interface{}) (map[string]interface{}, []string) {
88
warnings := make(map[string]interface{}, 0) // A warning is for when a deprecated field is used
89
conflicts := make([]string, 0)
90
cfg := rawCfg.(*Config) // A conflict is for when both the deprecated and current field is used
91
92
for key, field := range deprecatedFields {
93
// Check if the deprecated field is in use
94
inUse, val := parseDeprecatedSelector(cfg, field)
95
96
if inUse {
97
// Deprecated field in use - print the value to the warnings
98
warnings[key] = val
99
100
if field.MapValue != nil {
101
// There's a MapValue field
102
if err := field.MapValue(cfg); err != nil {
103
// There's a conflict on the mapped value - set in both old and new places
104
conflicts = append(conflicts, err.Error())
105
}
106
}
107
}
108
}
109
110
return warnings, conflicts
111
}
112
113
// Config defines the v1 version structure of the gitpod config file
114
type Config struct {
115
// Installation type to run - for most users, this will be Full
116
Kind InstallationKind `json:"kind" validate:"required,installation_kind"`
117
// The domain to deploy to
118
Domain string `json:"domain" validate:"required,fqdn"`
119
Metadata Metadata `json:"metadata"`
120
Repository string `json:"repository" validate:"required,ascii"`
121
122
Observability Observability `json:"observability"`
123
Analytics *Analytics `json:"analytics,omitempty"`
124
125
Database Database `json:"database" validate:"required"`
126
127
ObjectStorage ObjectStorage `json:"objectStorage" validate:"required"`
128
129
ContainerRegistry ContainerRegistry `json:"containerRegistry" validate:"required"`
130
131
Certificate ObjectRef `json:"certificate" validate:"required"`
132
133
HTTPProxy *ObjectRef `json:"httpProxy,omitempty"`
134
135
ImagePullSecrets []ObjectRef `json:"imagePullSecrets,omitempty"`
136
137
Workspace Workspace `json:"workspace" validate:"required"`
138
139
OpenVSX OpenVSX `json:"openVSX"`
140
141
AuthProviders []ObjectRef `json:"authProviders" validate:"dive"`
142
BlockNewUsers BlockNewUsers `json:"blockNewUsers"`
143
144
SSHGatewayHostKey *ObjectRef `json:"sshGatewayHostKey,omitempty"`
145
146
SSHGatewayCAKey *ObjectRef `json:"sshGatewayCAKey,omitempty"`
147
148
DisableDefinitelyGP bool `json:"disableDefinitelyGp"`
149
150
CustomCACert *ObjectRef `json:"customCACert,omitempty"`
151
152
DropImageRepo *bool `json:"dropImageRepo,omitempty"`
153
154
Customization *[]Customization `json:"customization,omitempty"`
155
156
Components *Components `json:"components,omitempty"`
157
158
Experimental *experimental.Config `json:"experimental,omitempty"`
159
}
160
161
type Metadata struct {
162
// Location for your objectStorage provider
163
Region string `json:"region" validate:"required"`
164
// InstallationShortname establishes the "identity" of the (application) cluster.
165
InstallationShortname string `json:"shortname"`
166
}
167
168
const (
169
InstallationShortNameOldDefault string = "default"
170
)
171
172
type Observability struct {
173
LogLevel LogLevel `json:"logLevel" validate:"required,log_level"`
174
Tracing *Tracing `json:"tracing,omitempty"`
175
}
176
177
type Analytics struct {
178
SegmentKey string `json:"segmentKey"`
179
Writer string `json:"writer"`
180
SegmentEndpoint string `json:"segmentEndpoint,omitempty"`
181
}
182
183
type Tracing struct {
184
Endpoint *string `json:"endpoint,omitempty"`
185
AgentHost *string `json:"agentHost,omitempty"`
186
// Name of the kubernetes secret to use for Jaeger authentication
187
// The secret should contains two definitions: JAEGER_USER and JAEGER_PASSWORD
188
SecretName *string `json:"secretName,omitempty"`
189
}
190
191
type Database struct {
192
InCluster *bool `json:"inCluster,omitempty"`
193
External *DatabaseExternal `json:"external,omitempty"`
194
CloudSQL *DatabaseCloudSQL `json:"cloudSQL,omitempty"`
195
SSL *SSLOptions `json:"ssl,omitempty"`
196
}
197
198
type DatabaseExternal struct {
199
Certificate ObjectRef `json:"certificate"`
200
}
201
202
type DatabaseCloudSQL struct {
203
ServiceAccount ObjectRef `json:"serviceAccount"`
204
Instance string `json:"instance" validate:"required"`
205
}
206
207
type SSLOptions struct {
208
CaCert *ObjectRef `json:"caCert,omitempty"`
209
}
210
211
type ObjectStorage struct {
212
InCluster *bool `json:"inCluster,omitempty"`
213
S3 *ObjectStorageS3 `json:"s3,omitempty"`
214
CloudStorage *ObjectStorageCloudStorage `json:"cloudStorage,omitempty"`
215
// DEPRECATED
216
MaximumBackupCount *int `json:"maximumBackupCount,omitempty"`
217
BlobQuota *int64 `json:"blobQuota,omitempty"`
218
Resources *Resources `json:"resources,omitempty"`
219
}
220
221
type ObjectStorageS3 struct {
222
Endpoint string `json:"endpoint" validate:"required"`
223
Credentials *ObjectRef `json:"credentials"`
224
225
BucketName string `json:"bucket" validate:"required"`
226
227
AllowInsecureConnection bool `json:"allowInsecureConnection"`
228
}
229
230
type ObjectStorageCloudStorage struct {
231
ServiceAccount ObjectRef `json:"serviceAccount" validate:"required"`
232
Project string `json:"project" validate:"required"`
233
}
234
235
type InstallationKind string
236
237
const (
238
InstallationIDE InstallationKind = "IDE"
239
InstallationWebApp InstallationKind = "WebApp"
240
InstallationMeta InstallationKind = "Meta" // IDE plus WebApp components
241
InstallationWorkspace InstallationKind = "Workspace"
242
InstallationFull InstallationKind = "Full"
243
)
244
245
type ObjectRef struct {
246
Kind ObjectRefKind `json:"kind" validate:"required,objectref_kind"`
247
Name string `json:"name" validate:"required"`
248
}
249
250
type ObjectRefKind string
251
252
const (
253
ObjectRefSecret ObjectRefKind = "secret"
254
)
255
256
type ContainerRegistry struct {
257
InCluster *bool `json:"inCluster,omitempty" validate:"required"`
258
External *ContainerRegistryExternal `json:"external,omitempty" validate:"required_if=InCluster false"`
259
S3Storage *S3Storage `json:"s3storage,omitempty"`
260
261
PrivateBaseImageAllowList []string `json:"privateBaseImageAllowList"`
262
EnableAdditionalECRAuth bool `json:"enableAdditionalECRAuth"`
263
264
SubassemblyBucket string `json:"subassemblyBucket"`
265
}
266
267
type ContainerRegistryExternal struct {
268
URL string `json:"url" validate:"required"`
269
Certificate *ObjectRef `json:"certificate,omitempty"`
270
Credentials *ObjectRef `json:"credentials,omitempty"`
271
}
272
273
type S3Storage struct {
274
Bucket string `json:"bucket" validate:"required"`
275
Region string `json:"region" validate:"required"`
276
Endpoint string `json:"endpoint" validate:"required"`
277
Certificate *ObjectRef `json:"certificate,omitempty"`
278
}
279
280
type ServiceAnnotations map[string]string
281
282
type LogLevel string
283
284
// Taken from github.com/gitpod-io/gitpod/components/gitpod-protocol/src/util/logging.ts
285
const (
286
LogLevelTrace LogLevel = "trace"
287
LogLevelDebug LogLevel = "debug"
288
LogLevelInfo LogLevel = "info"
289
LogLevelWarning LogLevel = "warning"
290
LogLevelError LogLevel = "error"
291
LogLevelFatal LogLevel = "fatal"
292
LogLevelPanic LogLevel = "panic"
293
)
294
295
type Resources struct {
296
// todo(sje): add custom validation to corev1.ResourceList
297
Requests corev1.ResourceList `json:"requests" validate:"required"`
298
Limits corev1.ResourceList `json:"limits,omitempty"`
299
}
300
301
type WorkspaceRuntime struct {
302
// File system
303
FSShiftMethod FSShiftMethod `json:"fsShiftMethod" validate:"required,fs_shift_method"`
304
// The location of containerd socket on the host machine
305
ContainerDRuntimeDir string `json:"containerdRuntimeDir" validate:"required,startswith=/"`
306
// The location of containerd socket on the host machine
307
ContainerDSocketDir string `json:"containerdSocketDir" validate:"required,startswith=/"`
308
}
309
310
type WorkspaceResources struct {
311
Requests corev1.ResourceList `json:"requests" validate:"required"`
312
Limits WorkspaceLimits `json:"limits,omitempty"`
313
}
314
315
type WorkspaceLimits struct {
316
Cpu WorkspaceCpuLimits `json:"cpu"`
317
Memory string `json:"memory"`
318
Storage string `json:"storage"`
319
EphemeralStorage string `json:"ephemeral-storage"`
320
}
321
322
type WorkspaceCpuLimits struct {
323
Buckets []cpulimit.Bucket `json:"buckets"`
324
MinLimit string `json:"min"`
325
BurstLimit string `json:"burst"`
326
}
327
328
type WorkspaceTemplates struct {
329
Default *corev1.Pod `json:"default"`
330
Prebuild *corev1.Pod `json:"prebuild"`
331
ImageBuild *corev1.Pod `json:"imagebuild"`
332
Regular *corev1.Pod `json:"regular"`
333
}
334
335
type Workspace struct {
336
Runtime WorkspaceRuntime `json:"runtime" validate:"required"`
337
Resources Resources `json:"resources" validate:"required"`
338
Templates *WorkspaceTemplates `json:"templates,omitempty"`
339
340
// MaxLifetime is the maximum time a workspace is allowed to run. After that, the workspace times out despite activity
341
MaxLifetime util.Duration `json:"maxLifetime" validate:"required"`
342
343
// TimeoutDefault is the default timeout of a regular workspace
344
TimeoutDefault *util.Duration `json:"timeoutDefault,omitempty"`
345
346
// TimeoutExtended is the workspace timeout that a user can extend to for one workspace
347
TimeoutExtended *util.Duration `json:"timeoutExtended,omitempty"`
348
349
// 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)
350
TimeoutAfterClose *util.Duration `json:"timeoutAfterClose,omitempty"`
351
352
WorkspaceImage string `json:"workspaceImage,omitempty"`
353
}
354
355
type OpenVSX struct {
356
URL string `json:"url" validate:"url"`
357
Proxy *OpenVSXProxy `json:"proxy,omitempty"`
358
}
359
360
type OpenVSXProxy struct {
361
DisablePVC bool `json:"disablePVC"`
362
Proxy `json:",inline"`
363
}
364
365
type Proxy struct {
366
ServiceAnnotations ServiceAnnotations `json:"serviceAnnotations"`
367
}
368
369
type FSShiftMethod string
370
371
const (
372
FSShiftShiftFS FSShiftMethod = "shiftfs"
373
)
374
375
type BlockNewUsers struct {
376
Enabled bool `json:"enabled"`
377
// Passlist []string `json:"passlist" validate:"min=1,unique,dive,fqdn"`
378
Passlist []string `json:"passlist" validate:"block_new_users_passlist"`
379
}
380
381
// AuthProviderConfigs this only contains what is necessary for validation
382
type AuthProviderConfigs struct {
383
ID string `json:"id" validate:"required"`
384
Host string `json:"host" validate:"required"`
385
Type string `json:"type" validate:"required"`
386
OAuth OAuth `json:"oauth" validate:"required"`
387
}
388
389
// OAuth this only contains what is necessary for validation
390
type OAuth struct {
391
ClientId string `json:"clientId" validate:"required"`
392
ClientSecret string `json:"clientSecret" validate:"required"`
393
CallBackUrl string `json:"callBackUrl" validate:"required"`
394
}
395
396
// Customization is a stripped-down version of the Kubernetes YAML
397
type Customization struct {
398
metav1.TypeMeta `json:",inline"`
399
Metadata metav1.ObjectMeta `json:"metadata"`
400
Spec CustomizationSpec `json:"spec,omitempty"`
401
}
402
403
type CustomizationSpec struct {
404
Env []corev1.EnvVar `json:"env"`
405
}
406
407
type Components struct {
408
AgentSmith *agentSmith.Config `json:"agentSmith,omitempty"`
409
IDE *IDEComponents `json:"ide"`
410
PodConfig map[string]*PodConfig `json:"podConfig,omitempty"`
411
Proxy *ProxyComponent `json:"proxy,omitempty"`
412
}
413
414
type IDEComponents struct {
415
Metrics *IDEMetrics `json:"metrics,omitempty"`
416
Proxy *Proxy `json:"proxy,omitempty"`
417
ResolveLatest *bool `json:"resolveLatest,omitempty"`
418
}
419
420
type IDEMetrics struct {
421
ErrorReportingEnabled bool `json:"errorReportingEnabled,omitempty"`
422
}
423
424
type PodConfig struct {
425
Replicas *int32 `json:"replicas,omitempty"`
426
Resources map[string]*corev1.ResourceRequirements `json:"resources,omitempty"`
427
}
428
429
type ProxyComponent struct {
430
Service *ComponentTypeService `json:"service,omitempty"`
431
}
432
433
type ComponentTypeService struct {
434
ServiceType *corev1.ServiceType `json:"serviceType,omitempty" validate:"omitempty,service_config_type"`
435
}
436
437