Skip to content

Commit

Permalink
[installer]: add function to allow customization in helm
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon Emms authored and nandajavarma committed Jun 28, 2022
1 parent 67ac64a commit c31f960
Showing 1 changed file with 57 additions and 1 deletion.
58 changes: 57 additions & 1 deletion install/installer/pkg/helm/helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,20 @@ import (
"os"
"os/signal"
"path/filepath"
"sigs.k8s.io/yaml"
"strings"
"syscall"

"sigs.k8s.io/yaml"

"github.com/gitpod-io/gitpod/installer/pkg/common"
"github.com/gitpod-io/gitpod/installer/third_party/charts"
"helm.sh/helm/v3/pkg/action"
"helm.sh/helm/v3/pkg/chart/loader"
"helm.sh/helm/v3/pkg/downloader"
"helm.sh/helm/v3/pkg/getter"
"helm.sh/helm/v3/pkg/release"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// TemplateConfig
Expand Down Expand Up @@ -209,3 +212,56 @@ func ImportTemplate(chart *charts.Chart, templateCfg TemplateConfig, pkgConfig P
return append(templates, rel.Manifest), nil
}
}

// CustomizeAnnotation check for customized annotations and output in Helm format
func CustomizeAnnotation(registryValues []string, prefix string, ctx *common.RenderContext, component string, typeMeta metav1.TypeMeta, existingAnnotations ...func() map[string]string) []string {
annotations := common.CustomizeAnnotation(ctx, component, common.TypeMetaDeployment, existingAnnotations...)
if len(annotations) > 0 {
for k, v := range annotations {
registryValues = append(registryValues, KeyValue(fmt.Sprintf("%s.%s", prefix, k), v))
}
}

return registryValues
}

// CustomizeLabel check for customized labels and output in Helm format - also removes the default labels, which conflict with Helm
func CustomizeLabel(registryValues []string, prefix string, ctx *common.RenderContext, component string, typeMeta metav1.TypeMeta, existingLabels ...func() map[string]string) []string {
labels := common.CustomizeLabel(ctx, component, common.TypeMetaDeployment, existingLabels...)

// Remove the default labels
for k := range common.DefaultLabels(component) {
delete(labels, k)
}

if len(labels) > 0 {
for k, v := range labels {
registryValues = append(registryValues, KeyValue(fmt.Sprintf("%s.%s", prefix, k), v))
}
}

return registryValues
}

// CustomizeEnvvar check for customized envvars and output in Helm format - assumes name/value only
func CustomizeEnvvar(registryValues []string, prefix string, ctx *common.RenderContext, component string, existingEnvvars ...[]corev1.EnvVar) []string {
// Helm is unlikely to have any existing envvars, so treat them as optional
envvars := common.CustomizeEnvvar(ctx, component, func() []corev1.EnvVar {
envs := make([]corev1.EnvVar, 0)

for _, e := range existingEnvvars {
envs = append(envs, e...)
}

return envs
}())

if len(envvars) > 0 {
for k, v := range envvars {
registryValues = append(registryValues, KeyValue(fmt.Sprintf("%s[%d].name", prefix, k), v.Name))
registryValues = append(registryValues, KeyValue(fmt.Sprintf("%s[%d].value", prefix, k), v.Value))
}
}

return registryValues
}

0 comments on commit c31f960

Please sign in to comment.