Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/install/installer/pkg/config/v1/deprecations.go
2501 views
1
// Copyright (c) 2023 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
"encoding/json"
9
"errors"
10
)
11
12
type deprecatedField struct {
13
// Select the deprecated parameter. Returns whether param in use and it's value for the warning message - value should not be a pointer
14
Selector func(cfg *Config) (isInUse bool, msgValue any)
15
// Map the old value to the new value. If both are set, an error should be returned - this is optional
16
MapValue func(cfg *Config) error
17
}
18
19
var deprecatedFields = map[string]deprecatedField{
20
"experimental.agentSmith": {
21
Selector: func(cfg *Config) (bool, any) {
22
val := cfg.Experimental.AgentSmith
23
return val != nil, val
24
},
25
MapValue: func(cfg *Config) error {
26
if cfg.Components != nil && cfg.Components.AgentSmith != nil {
27
return errors.New("cannot configure agent smith in both components and experimental")
28
}
29
if cfg.Components == nil {
30
cfg.Components = &Components{}
31
}
32
cfg.Components.AgentSmith = cfg.Experimental.AgentSmith
33
return nil
34
},
35
},
36
"experimental.common.podConfig": {
37
Selector: func(cfg *Config) (bool, any) {
38
val := cfg.Experimental.Common.PodConfig
39
// Output message as JSON
40
o, _ := json.Marshal(val)
41
return len(val) > 0, string(o)
42
},
43
MapValue: func(cfg *Config) error {
44
if cfg.Components != nil && cfg.Components.PodConfig != nil {
45
return errors.New("cannot set pod config in both components and experimental")
46
}
47
if cfg.Components == nil {
48
cfg.Components = &Components{}
49
}
50
// Need to convert types - same signature, but using the non-experimental object
51
cfg.Components.PodConfig = make(map[string]*PodConfig, 0)
52
for k, v := range cfg.Experimental.Common.PodConfig {
53
cfg.Components.PodConfig[k] = &PodConfig{
54
Replicas: v.Replicas,
55
Resources: v.Resources,
56
}
57
}
58
return nil
59
},
60
},
61
"experimental.ide.resolveLatest": {
62
Selector: func(cfg *Config) (bool, any) {
63
val := cfg.Experimental.IDE.ResolveLatest
64
return val != nil, *val
65
},
66
MapValue: func(cfg *Config) error {
67
if cfg.Components != nil && cfg.Components.IDE != nil && cfg.Components.IDE.ResolveLatest != nil {
68
return errors.New("cannot set resolve latest ide in both components and experimental")
69
}
70
if cfg.Components == nil {
71
cfg.Components = &Components{}
72
}
73
if cfg.Components.IDE == nil {
74
cfg.Components.IDE = &IDEComponents{}
75
}
76
cfg.Components.IDE.ResolveLatest = cfg.Experimental.IDE.ResolveLatest
77
return nil
78
},
79
},
80
"experimental.ide.ideMetrics.enabledErrorReporting": {
81
Selector: func(cfg *Config) (bool, any) {
82
val := cfg.Experimental.IDE.IDEMetricsConfig
83
return val != nil, val.EnabledErrorReporting
84
},
85
MapValue: func(cfg *Config) error {
86
if cfg.Components != nil && cfg.Components.IDE != nil && cfg.Components.IDE.Metrics != nil {
87
return errors.New("cannot set ide metrics in both component and experimental")
88
}
89
if cfg.Components == nil {
90
cfg.Components = &Components{}
91
}
92
if cfg.Components.IDE == nil {
93
cfg.Components.IDE = &IDEComponents{}
94
}
95
if cfg.Components.IDE.Metrics == nil {
96
cfg.Components.IDE.Metrics = &IDEMetrics{}
97
}
98
cfg.Components.IDE.Metrics.ErrorReportingEnabled = cfg.Experimental.IDE.IDEMetricsConfig.EnabledErrorReporting
99
return nil
100
},
101
},
102
"experimental.ide.ideProxy.serviceAnnotations": {
103
Selector: func(cfg *Config) (bool, any) {
104
val := cfg.Experimental.IDE.IDEProxyConfig.ServiceAnnotations
105
return len(val) > 0, val
106
},
107
MapValue: func(cfg *Config) error {
108
if cfg.Components != nil && cfg.Components.IDE != nil && cfg.Components.IDE.Proxy != nil && len(cfg.Components.IDE.Proxy.ServiceAnnotations) > 0 {
109
return errors.New("cannot set ide proxy service annotations in both components and experimental")
110
}
111
if cfg.Components == nil {
112
cfg.Components = &Components{}
113
}
114
if cfg.Components.IDE == nil {
115
cfg.Components.IDE = &IDEComponents{}
116
}
117
if cfg.Components.IDE.Proxy == nil {
118
cfg.Components.IDE.Proxy = &Proxy{}
119
}
120
cfg.Components.IDE.Proxy.ServiceAnnotations = cfg.Experimental.IDE.IDEProxyConfig.ServiceAnnotations
121
return nil
122
},
123
},
124
"experimental.ide.openvsxProxy.serviceAnnotations": {
125
Selector: func(cfg *Config) (bool, any) {
126
val := cfg.Experimental.IDE.VSXProxyConfig.ServiceAnnotations
127
return len(val) > 0, val
128
},
129
MapValue: func(cfg *Config) error {
130
if cfg.OpenVSX.Proxy != nil && len(cfg.OpenVSX.Proxy.ServiceAnnotations) > 0 {
131
return errors.New("cannot set openvsx proxy service annotations in both components and experimental")
132
}
133
if cfg.OpenVSX.Proxy == nil {
134
cfg.OpenVSX.Proxy = &OpenVSXProxy{}
135
}
136
cfg.OpenVSX.Proxy.ServiceAnnotations = cfg.Experimental.IDE.VSXProxyConfig.ServiceAnnotations
137
return nil
138
},
139
},
140
"experimental.webapp.proxy.serviceType": {
141
Selector: func(cfg *Config) (bool, any) {
142
val := cfg.Experimental.WebApp.ProxyConfig.ServiceType
143
return val != nil, *val
144
},
145
MapValue: func(cfg *Config) error {
146
if cfg.Components != nil && cfg.Components.Proxy != nil && cfg.Components.Proxy.Service != nil && cfg.Components.Proxy.Service.ServiceType != nil {
147
return errors.New("cannot set proxy service type in both components and experimental")
148
} else {
149
if cfg.Components == nil {
150
cfg.Components = &Components{}
151
}
152
if cfg.Components.Proxy == nil {
153
cfg.Components.Proxy = &ProxyComponent{}
154
}
155
if cfg.Components.Proxy.Service == nil {
156
cfg.Components.Proxy.Service = &ComponentTypeService{}
157
}
158
cfg.Components.Proxy.Service.ServiceType = cfg.Experimental.WebApp.ProxyConfig.ServiceType
159
}
160
return nil
161
},
162
},
163
"experimental.webapp.server.workspaceDefaults.workspaceImage": {
164
Selector: func(cfg *Config) (bool, any) {
165
workspaceImage := cfg.Experimental.WebApp.Server.WorkspaceDefaults.WorkspaceImage
166
return workspaceImage != "", workspaceImage
167
},
168
MapValue: func(cfg *Config) error {
169
if cfg.Workspace.WorkspaceImage != "" {
170
return errors.New("cannot set default workspace image in both workspaces and experimental")
171
}
172
cfg.Workspace.WorkspaceImage = cfg.Experimental.WebApp.Server.WorkspaceDefaults.WorkspaceImage
173
174
return nil
175
},
176
},
177
"experimental.webapp.server.defaultBaseImageRegistryWhitelist": {
178
Selector: func(cfg *Config) (bool, any) {
179
registryAllowList := cfg.Experimental.WebApp.Server.DefaultBaseImageRegistryWhiteList
180
return registryAllowList != nil, registryAllowList
181
},
182
MapValue: func(cfg *Config) error {
183
if len(cfg.ContainerRegistry.PrivateBaseImageAllowList) > 0 {
184
return errors.New("cannot set allow list for private base image in both containerRegistry and experimental")
185
}
186
cfg.ContainerRegistry.PrivateBaseImageAllowList = cfg.Experimental.WebApp.Server.DefaultBaseImageRegistryWhiteList
187
188
return nil
189
},
190
},
191
"objectStorage.maximumBackupCount": {
192
Selector: func(cfg *Config) (bool, any) {
193
val := cfg.ObjectStorage.MaximumBackupCount
194
return val != nil, *val
195
},
196
},
197
}
198
199
// parseDeprecatedSelector recovers from a panic so we don't have to check for nested structs
200
func parseDeprecatedSelector(cfg *Config, field deprecatedField) (selected bool, val any) {
201
defer func() {
202
if r := recover(); r != nil {
203
selected = false
204
val = nil
205
}
206
}()
207
208
return field.Selector(cfg)
209
}
210
211