@@ -11,17 +11,20 @@ import (
11
11
"os"
12
12
"os/signal"
13
13
"path/filepath"
14
- "sigs.k8s.io/yaml"
15
14
"strings"
16
15
"syscall"
17
16
17
+ "sigs.k8s.io/yaml"
18
+
18
19
"github.com/gitpod-io/gitpod/installer/pkg/common"
19
20
"github.com/gitpod-io/gitpod/installer/third_party/charts"
20
21
"helm.sh/helm/v3/pkg/action"
21
22
"helm.sh/helm/v3/pkg/chart/loader"
22
23
"helm.sh/helm/v3/pkg/downloader"
23
24
"helm.sh/helm/v3/pkg/getter"
24
25
"helm.sh/helm/v3/pkg/release"
26
+ corev1 "k8s.io/api/core/v1"
27
+ metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
25
28
)
26
29
27
30
// TemplateConfig
@@ -209,3 +212,56 @@ func ImportTemplate(chart *charts.Chart, templateCfg TemplateConfig, pkgConfig P
209
212
return append (templates , rel .Manifest ), nil
210
213
}
211
214
}
215
+
216
+ // CustomizeAnnotation check for customized annotations and output in Helm format
217
+ func CustomizeAnnotation (registryValues []string , prefix string , ctx * common.RenderContext , component string , typeMeta metav1.TypeMeta , existingAnnotations ... func () map [string ]string ) []string {
218
+ annotations := common .CustomizeAnnotation (ctx , component , common .TypeMetaDeployment , existingAnnotations ... )
219
+ if len (annotations ) > 0 {
220
+ for k , v := range annotations {
221
+ registryValues = append (registryValues , KeyValue (fmt .Sprintf ("%s.%s" , prefix , k ), v ))
222
+ }
223
+ }
224
+
225
+ return registryValues
226
+ }
227
+
228
+ // CustomizeLabel check for customized labels and output in Helm format - also removes the default labels, which conflict with Helm
229
+ func CustomizeLabel (registryValues []string , prefix string , ctx * common.RenderContext , component string , typeMeta metav1.TypeMeta , existingLabels ... func () map [string ]string ) []string {
230
+ labels := common .CustomizeLabel (ctx , component , common .TypeMetaDeployment , existingLabels ... )
231
+
232
+ // Remove the default labels
233
+ for k := range common .DefaultLabels (component ) {
234
+ delete (labels , k )
235
+ }
236
+
237
+ if len (labels ) > 0 {
238
+ for k , v := range labels {
239
+ registryValues = append (registryValues , KeyValue (fmt .Sprintf ("%s.%s" , prefix , k ), v ))
240
+ }
241
+ }
242
+
243
+ return registryValues
244
+ }
245
+
246
+ // CustomizeEnvvar check for customized envvars and output in Helm format - assumes name/value only
247
+ func CustomizeEnvvar (registryValues []string , prefix string , ctx * common.RenderContext , component string , existingEnvvars ... []corev1.EnvVar ) []string {
248
+ // Helm is unlikely to have any existing envvars, so treat them as optional
249
+ envvars := common .CustomizeEnvvar (ctx , component , func () []corev1.EnvVar {
250
+ envs := make ([]corev1.EnvVar , 0 )
251
+
252
+ for _ , e := range existingEnvvars {
253
+ envs = append (envs , e ... )
254
+ }
255
+
256
+ return envs
257
+ }())
258
+
259
+ if len (envvars ) > 0 {
260
+ for k , v := range envvars {
261
+ registryValues = append (registryValues , KeyValue (fmt .Sprintf ("%s[%d].name" , prefix , k ), v .Name ))
262
+ registryValues = append (registryValues , KeyValue (fmt .Sprintf ("%s[%d].value" , prefix , k ), v .Value ))
263
+ }
264
+ }
265
+
266
+ return registryValues
267
+ }
0 commit comments