Skip to content

Commit c31f960

Browse files
Simon Emmsnandajavarma
Simon Emms
authored andcommitted
[installer]: add function to allow customization in helm
1 parent 67ac64a commit c31f960

File tree

1 file changed

+57
-1
lines changed

1 file changed

+57
-1
lines changed

install/installer/pkg/helm/helm.go

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,20 @@ import (
1111
"os"
1212
"os/signal"
1313
"path/filepath"
14-
"sigs.k8s.io/yaml"
1514
"strings"
1615
"syscall"
1716

17+
"sigs.k8s.io/yaml"
18+
1819
"github.com/gitpod-io/gitpod/installer/pkg/common"
1920
"github.com/gitpod-io/gitpod/installer/third_party/charts"
2021
"helm.sh/helm/v3/pkg/action"
2122
"helm.sh/helm/v3/pkg/chart/loader"
2223
"helm.sh/helm/v3/pkg/downloader"
2324
"helm.sh/helm/v3/pkg/getter"
2425
"helm.sh/helm/v3/pkg/release"
26+
corev1 "k8s.io/api/core/v1"
27+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2528
)
2629

2730
// TemplateConfig
@@ -209,3 +212,56 @@ func ImportTemplate(chart *charts.Chart, templateCfg TemplateConfig, pkgConfig P
209212
return append(templates, rel.Manifest), nil
210213
}
211214
}
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

Comments
 (0)