-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy pathconfig.go
264 lines (211 loc) · 8.01 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
// 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 (
"github.com/gitpod-io/gitpod/installer/pkg/config"
"github.com/gitpod-io/gitpod/installer/pkg/config/v1/experimental"
"github.com/gitpod-io/gitpod/ws-daemon/pkg/cpulimit"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
"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{},
},
}
}
func (v version) Defaults(in interface{}) error {
cfg, ok := in.(*Config)
if !ok {
return config.ErrInvalidType
}
cfg.Kind = InstallationFull
cfg.Domain = "gitpod.example.com"
cfg.Repository = "eu.gcr.io/gitpod-core-dev/build"
cfg.Observability = Observability{
LogLevel: LogLevelInfo,
}
cfg.Certificate.Kind = ObjectRefSecret
cfg.Certificate.Name = "https-certificates"
cfg.Database.InCluster = pointer.Bool(true)
cfg.Metadata.Region = "local"
cfg.ObjectStorage.InCluster = pointer.Bool(true)
cfg.ContainerRegistry.InCluster = pointer.Bool(true)
cfg.Jaeger.InCluster = pointer.Bool(true)
cfg.Workspace.Resources.Requests = corev1.ResourceList{
corev1.ResourceCPU: resource.MustParse("1000m"),
corev1.ResourceMemory: resource.MustParse("2Gi"),
}
cfg.Workspace.Runtime.FSShiftMethod = FSShiftFuseFS
cfg.Workspace.Runtime.ContainerDSocket = "/run/containerd/containerd.sock"
cfg.Workspace.Runtime.ContainerDRuntimeDir = "/var/lib/containerd/io.containerd.runtime.v2.task/k8s.io"
cfg.OpenVSX.URL = "https://open-vsx.org"
return nil
}
type Config struct {
Kind InstallationKind `json:"kind" validate:"required,installation_kind"`
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"`
Jaeger Jaeger `json:"jaegerOperator" validate:"required"`
Certificate ObjectRef `json:"certificate" validate:"required"`
ImagePullSecrets []ObjectRef `json:"imagePullSecrets"`
Workspace Workspace `json:"workspace" validate:"required"`
OpenVSX OpenVSX `json:"openVSX"`
AuthProviders []ObjectRef `json:"authProviders" validate:"dive"`
BlockNewUsers BlockNewUsers `json:"blockNewUsers"`
License *ObjectRef `json:"license,omitempty"`
SSHGatewayHostKey *ObjectRef `json:"sshGatewayHostKey,omitempty"`
DisableDefinitelyGP bool `json:"disableDefinitelyGp,omitempty"`
Experimental *experimental.Config `json:"experimental,omitempty"`
}
type Metadata struct {
Region string `json:"region" validate:"required"`
}
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"`
}
type Tracing struct {
Endpoint *string `json:"endpoint,omitempty"`
AgentHost *string `json:"agentHost,omitempty"`
}
type Database struct {
InCluster *bool `json:"inCluster,omitempty"`
External *DatabaseExternal `json:"external,omitempty"`
CloudSQL *DatabaseCloudSQL `json:"cloudSQL,omitempty"`
}
type DatabaseExternal struct {
Certificate ObjectRef `json:"certificate"`
}
type DatabaseCloudSQL struct {
ServiceAccount ObjectRef `json:"serviceAccount"`
Instance string `json:"instance" validate:"required"`
}
type ObjectStorage struct {
InCluster *bool `json:"inCluster,omitempty"`
S3 *ObjectStorageS3 `json:"s3,omitempty"`
CloudStorage *ObjectStorageCloudStorage `json:"cloudStorage,omitempty"`
Azure *ObjectStorageAzure `json:"azure,omitempty"`
}
type ObjectStorageS3 struct {
Endpoint string `json:"endpoint" validate:"required"`
Credentials ObjectRef `json:"credentials" validate:"required"`
}
type ObjectStorageCloudStorage struct {
ServiceAccount ObjectRef `json:"serviceAccount" validate:"required"`
Project string `json:"project" validate:"required"`
}
type ObjectStorageAzure struct {
Credentials ObjectRef `json:"credentials" validate:"required"`
}
type InstallationKind string
const (
InstallationMeta InstallationKind = "Meta"
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"`
}
type ContainerRegistryExternal struct {
URL string `json:"url" validate:"required"`
Certificate ObjectRef `json:"certificate" validate:"required"`
}
type S3Storage struct {
Bucket string `json:"bucket" validate:"required"`
Certificate ObjectRef `json:"certificate" validate:"required"`
}
type Jaeger struct {
InCluster *bool `json:"inCluster,omitempty" validate:"required"`
}
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"`
DynamicLimits *struct {
CPU []cpulimit.Bucket // todo(sje): add custom validation
} `json:"dynamicLimits,omitempty"`
}
type WorkspaceRuntime struct {
FSShiftMethod FSShiftMethod `json:"fsShiftMethod" validate:"required,fs_shift_method"`
ContainerDRuntimeDir string `json:"containerdRuntimeDir" validate:"required,startswith=/"`
ContainerDSocket string `json:"containerdSocket" validate:"required,startswith=/"`
}
type WorkspaceTemplates struct {
Default *corev1.Pod `json:"default"`
Prebuild *corev1.Pod `json:"prebuild"`
Ghost *corev1.Pod `json:"ghost"`
ImageBuild *corev1.Pod `json:"imagebuild"`
Regular *corev1.Pod `json:"regular"`
Probe *corev1.Pod `json:"probe"`
}
type Workspace struct {
Runtime WorkspaceRuntime `json:"runtime" validate:"required"`
Resources Resources `json:"resources" validate:"required"`
Templates *WorkspaceTemplates `json:"templates,omitempty"`
}
type OpenVSX struct {
URL string `json:"url" validate:"url"`
}
type FSShiftMethod string
const (
FSShiftFuseFS FSShiftMethod = "fuse"
FSShiftShiftFS FSShiftMethod = "shiftfs"
)
type BlockNewUsers struct {
Enabled bool `json:"enabled"`
Passlist []string `json:"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"`
}