@@ -17,6 +17,7 @@ import (
17
17
storageconfig "github.com/gitpod-io/gitpod/content-service/api/config"
18
18
"github.com/gitpod-io/gitpod/installer/pkg/common"
19
19
configv1 "github.com/gitpod-io/gitpod/installer/pkg/config/v1"
20
+ "github.com/gitpod-io/gitpod/installer/pkg/config/v1/experimental"
20
21
"github.com/gitpod-io/gitpod/ws-manager/api/config"
21
22
22
23
corev1 "k8s.io/api/core/v1"
@@ -25,7 +26,11 @@ import (
25
26
)
26
27
27
28
func configmap (ctx * common.RenderContext ) ([]runtime.Object , error ) {
28
- templatesCfg , tpls , err := buildWorkspaceTemplates (ctx )
29
+ cfgTpls := ctx .Config .Workspace .Templates
30
+ if cfgTpls == nil {
31
+ cfgTpls = & configv1.WorkspaceTemplates {}
32
+ }
33
+ templatesCfg , tpls , err := buildWorkspaceTemplates (ctx , cfgTpls , "" )
29
34
if err != nil {
30
35
return nil , err
31
36
}
@@ -48,6 +53,60 @@ func configmap(ctx *common.RenderContext) ([]runtime.Object, error) {
48
53
customCASecret = ctx .Config .CustomCACert .Name
49
54
}
50
55
56
+ classes := map [string ]* config.WorkspaceClass {
57
+ "" : {
58
+ Container : config.ContainerConfiguration {
59
+ Requests : & config.ResourceConfiguration {
60
+ CPU : quantityString (ctx .Config .Workspace .Resources .Requests , corev1 .ResourceCPU ),
61
+ Memory : quantityString (ctx .Config .Workspace .Resources .Requests , corev1 .ResourceMemory ),
62
+ EphemeralStorage : quantityString (ctx .Config .Workspace .Resources .Requests , corev1 .ResourceEphemeralStorage ),
63
+ },
64
+ Limits : & config.ResourceConfiguration {
65
+ CPU : quantityString (ctx .Config .Workspace .Resources .Limits , corev1 .ResourceCPU ),
66
+ Memory : quantityString (ctx .Config .Workspace .Resources .Limits , corev1 .ResourceMemory ),
67
+ EphemeralStorage : quantityString (ctx .Config .Workspace .Resources .Limits , corev1 .ResourceEphemeralStorage ),
68
+ },
69
+ },
70
+ Templates : templatesCfg ,
71
+ },
72
+ }
73
+ err = ctx .WithExperimental (func (ucfg * experimental.Config ) error {
74
+ if ucfg .Workspace == nil {
75
+ return nil
76
+ }
77
+ for k , c := range ucfg .Workspace .WorkspaceClasses {
78
+ tplsCfg , ctpls , err := buildWorkspaceTemplates (ctx , & configv1.WorkspaceTemplates {
79
+ Default : c .Templates .Default ,
80
+ Prebuild : c .Templates .Prebuild ,
81
+ ImageBuild : c .Templates .ImageBuild ,
82
+ Regular : c .Templates .Regular ,
83
+ }, k )
84
+ if err != nil {
85
+ return err
86
+ }
87
+ classes [k ] = & config.WorkspaceClass {
88
+ Container : config.ContainerConfiguration {
89
+ Requests : & config.ResourceConfiguration {
90
+ CPU : quantityString (c .Resources .Requests , corev1 .ResourceCPU ),
91
+ Memory : quantityString (c .Resources .Requests , corev1 .ResourceMemory ),
92
+ EphemeralStorage : quantityString (c .Resources .Requests , corev1 .ResourceEphemeralStorage ),
93
+ },
94
+ Limits : & config.ResourceConfiguration {
95
+ CPU : quantityString (c .Resources .Limits , corev1 .ResourceCPU ),
96
+ Memory : quantityString (c .Resources .Limits , corev1 .ResourceMemory ),
97
+ EphemeralStorage : quantityString (c .Resources .Limits , corev1 .ResourceEphemeralStorage ),
98
+ },
99
+ },
100
+ Templates : tplsCfg ,
101
+ }
102
+ tpls = append (tpls , ctpls ... )
103
+ }
104
+ return nil
105
+ })
106
+ if err != nil {
107
+ return nil , err
108
+ }
109
+
51
110
wsmcfg := config.ServiceConfiguration {
52
111
Manager : config.Configuration {
53
112
Namespace : ctx .Namespace ,
@@ -65,21 +124,7 @@ func configmap(ctx *common.RenderContext) ([]runtime.Object, error) {
65
124
PrivateKey : "/ws-daemon-tls-certs/tls.key" ,
66
125
},
67
126
},
68
- Container : config.AllContainerConfiguration {
69
- Workspace : config.ContainerConfiguration {
70
- Requests : config.ResourceConfiguration {
71
- CPU : quantityString (ctx .Config .Workspace .Resources .Requests , corev1 .ResourceCPU ),
72
- Memory : quantityString (ctx .Config .Workspace .Resources .Requests , corev1 .ResourceMemory ),
73
- EphemeralStorage : quantityString (ctx .Config .Workspace .Resources .Requests , corev1 .ResourceEphemeralStorage ),
74
- },
75
- Limits : config.ResourceConfiguration {
76
- CPU : quantityString (ctx .Config .Workspace .Resources .Limits , corev1 .ResourceCPU ),
77
- Memory : quantityString (ctx .Config .Workspace .Resources .Limits , corev1 .ResourceMemory ),
78
- EphemeralStorage : quantityString (ctx .Config .Workspace .Resources .Requests , corev1 .ResourceEphemeralStorage ),
79
- },
80
- Image : "OVERWRITTEN-IN-REQUEST" ,
81
- },
82
- },
127
+ WorkspaceClasses : classes ,
83
128
HeartbeatInterval : util .Duration (30 * time .Second ),
84
129
GitpodHostURL : "https://" + ctx .Config .Domain ,
85
130
WorkspaceClusterHost : fmt .Sprintf ("ws.%s" , ctx .Config .Domain ),
@@ -89,7 +134,6 @@ func configmap(ctx *common.RenderContext) ([]runtime.Object, error) {
89
134
WorkspaceURLTemplate : fmt .Sprintf ("https://{{ .Prefix }}.ws.%s" , ctx .Config .Domain ),
90
135
WorkspacePortURLTemplate : fmt .Sprintf ("https://{{ .WorkspacePort }}-{{ .Prefix }}.ws.%s" , ctx .Config .Domain ),
91
136
WorkspaceHostPath : wsdaemon .HostWorkingArea ,
92
- WorkspacePodTemplate : templatesCfg ,
93
137
Timeouts : config.WorkspaceTimeoutConfiguration {
94
138
AfterClose : timeoutAfterClose ,
95
139
HeadlessWorkspace : util .Duration (1 * time .Hour ),
@@ -165,14 +209,13 @@ func configmap(ctx *common.RenderContext) ([]runtime.Object, error) {
165
209
return res , nil
166
210
}
167
211
168
- func buildWorkspaceTemplates (ctx * common.RenderContext ) (config.WorkspacePodTemplateConfiguration , []runtime.Object , error ) {
212
+ func buildWorkspaceTemplates (ctx * common.RenderContext , cfgTpls * configv1. WorkspaceTemplates , className string ) (config.WorkspacePodTemplateConfiguration , []runtime.Object , error ) {
169
213
var (
170
214
cfg config.WorkspacePodTemplateConfiguration
171
215
tpls = make (map [string ]string )
172
216
)
173
- cfgTpls := ctx .Config .Workspace .Templates
174
217
if cfgTpls == nil {
175
- cfgTpls = & configv1.WorkspaceTemplates {}
218
+ cfgTpls = new ( configv1.WorkspaceTemplates )
176
219
}
177
220
178
221
ops := []struct {
@@ -184,7 +227,6 @@ func buildWorkspaceTemplates(ctx *common.RenderContext) (config.WorkspacePodTemp
184
227
{Name : "imagebuild" , Path : & cfg .ImagebuildPath , Tpl : cfgTpls .ImageBuild },
185
228
{Name : "prebuild" , Path : & cfg .PrebuildPath , Tpl : cfgTpls .Prebuild },
186
229
{Name : "regular" , Path : & cfg .RegularPath , Tpl : cfgTpls .Regular },
187
- {Name : "probe" , Path : & cfg .ProbePath , Tpl : cfgTpls .Probe },
188
230
}
189
231
for _ , op := range ops {
190
232
if op .Tpl == nil {
@@ -194,7 +236,7 @@ func buildWorkspaceTemplates(ctx *common.RenderContext) (config.WorkspacePodTemp
194
236
if err != nil {
195
237
return cfg , nil , fmt .Errorf ("unable to marshal %s workspace template: %w" , op .Name , err )
196
238
}
197
- fn := op .Name + ".yaml"
239
+ fn := filepath . Join ( className , op .Name + ".yaml" )
198
240
* op .Path = filepath .Join (WorkspaceTemplatePath , fn )
199
241
tpls [fn ] = string (fc )
200
242
}
0 commit comments