Skip to content

Commit 0532649

Browse files
author
Simon Emms
committed
[installer]: configure helm dependencies to use custom container registry
1 parent 2c40a53 commit 0532649

File tree

9 files changed

+94
-24
lines changed

9 files changed

+94
-24
lines changed

installer/pkg/common/common.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,3 +509,17 @@ func RandomString(length int) (string, error) {
509509
}
510510
return string(b), nil
511511
}
512+
513+
// ThirdPartyContainerRepo returns the container registry to use for third-party containers.
514+
// If config registry is set to the Gitpod registry, the third-party registry is returned. If
515+
// config registry is different, that repository is returned and deployment expected to mirror
516+
// the images to their registry
517+
func ThirdPartyContainerRepo(configRegistry string, thirdPartyRegistry string) string {
518+
configRegistry = strings.TrimSuffix(configRegistry, "/")
519+
520+
if configRegistry == GitpodContainerRegistry {
521+
return thirdPartyRegistry
522+
}
523+
524+
return configRegistry
525+
}

installer/pkg/components/database/incluster/helm.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ var Helm = common.CompositeHelmFunc(
3333
helm.KeyValue("mysql.auth.username", Username),
3434
helm.KeyValue("mysql.initdbScriptsConfigMap", SQLInitScripts),
3535
helm.KeyValue("mysql.serviceAccount.name", Component),
36+
helm.ImagePullSecrets("mysql.image.pullSecrets", cfg),
37+
helm.KeyValue("mysql.image.registry", common.ThirdPartyContainerRepo(cfg.Config.Repository, "docker.io")),
38+
helm.ImagePullSecrets("mysql.metrics.image.pullSecrets", cfg),
39+
helm.KeyValue("mysql.metrics.image.registry", common.ThirdPartyContainerRepo(cfg.Config.Repository, "docker.io")),
40+
helm.ImagePullSecrets("mysql.volumePermissions.image.pullSecrets", cfg),
41+
helm.KeyValue("mysql.volumePermissions.image.registry", common.ThirdPartyContainerRepo(cfg.Config.Repository, "docker.io")),
3642
},
3743
// This is too complex to be sent as a string
3844
FileValues: []string{

installer/pkg/components/docker-registry/helm.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,21 @@ var Helm = common.CompositeHelmFunc(
2323
return nil, err
2424
}
2525

26+
repository := fmt.Sprintf("%s/registry", common.ThirdPartyContainerRepo(cfg.Config.Repository, "docker.io"))
27+
2628
registryValues := []string{
2729
helm.KeyValue(fmt.Sprintf("docker-registry.podAnnotations.%s", strings.Replace(common.AnnotationConfigChecksum, ".", "\\.", -1)), secretHash),
2830
helm.KeyValue("docker-registry.fullnameOverride", RegistryName),
2931
helm.KeyValue("docker-registry.service.port", strconv.Itoa(common.ProxyContainerHTTPSPort)),
3032
helm.KeyValue("docker-registry.tlsSecretName", BuiltInRegistryCerts),
33+
helm.KeyValue("docker-registry.image.repository", repository),
34+
}
35+
36+
if len(cfg.Config.ImagePullSecrets) > 0 {
37+
// This chart doesn't add in the "name/value" pair format
38+
for k, v := range cfg.Config.ImagePullSecrets {
39+
registryValues = append(registryValues, helm.KeyValue(fmt.Sprintf("docker-registry.imagePullSecrets[%d].name", k), v.Name))
40+
}
3141
}
3242

3343
inCluster := pointer.BoolDeref(cfg.Config.ContainerRegistry.InCluster, false)

installer/pkg/components/jaeger-operator/helm.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
package jaegeroperator
66

77
import (
8+
"fmt"
89
"github.com/gitpod-io/gitpod/installer/pkg/common"
910
"github.com/gitpod-io/gitpod/installer/pkg/helm"
1011
"github.com/gitpod-io/gitpod/installer/third_party/charts"
@@ -14,12 +15,17 @@ import (
1415

1516
var Helm = common.CompositeHelmFunc(
1617
helm.ImportTemplate(charts.JaegerOperator(), helm.TemplateConfig{}, func(cfg *common.RenderContext) (*common.HelmConfig, error) {
18+
repository := common.ThirdPartyContainerRepo(cfg.Config.Repository, "docker.io")
19+
image := "jaegertracing/jaeger-operator"
20+
1721
return &common.HelmConfig{
1822
Enabled: pointer.BoolDeref(cfg.Config.Jaeger.InCluster, false),
1923
Values: &values.Options{
2024
Values: []string{
2125
helm.KeyValue("jaeger-operator.crd.install", "true"),
2226
helm.KeyValue("jaeger-operator.rbac.clusterRole", "true"),
27+
helm.ImagePullSecrets("jaeger-operator.image.imagePullSecrets", cfg),
28+
helm.KeyValue("jaeger-operator.image.repository", fmt.Sprintf("%s/%s", repository, image)),
2329
},
2430
},
2531
}, nil

installer/pkg/components/minio/azure/minio.go

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,26 +12,29 @@ import (
1212
"helm.sh/helm/v3/pkg/cli/values"
1313
)
1414

15-
var Helm = func(apiPort int32, consolePort int32) common.HelmFunc {
15+
var Helm = func(apiPort int32, consolePort int32, commonHelmValues []string) common.HelmFunc {
1616
return common.CompositeHelmFunc(
1717
helm.ImportTemplate(charts.Minio(), helm.TemplateConfig{}, func(cfg *common.RenderContext) (*common.HelmConfig, error) {
1818
return &common.HelmConfig{
1919
Enabled: true,
2020
Values: &values.Options{
21-
Values: []string{
22-
helm.KeyValue("minio.gateway.enabled", "true"),
23-
helm.KeyValue("minio.gateway.auth.azure.accessKey", cfg.Values.StorageAccessKey), // Azure value actually taken from secret - used for console/API access
24-
helm.KeyValue("minio.gateway.auth.azure.secretKey", cfg.Values.StorageSecretKey), // Ditto
25-
helm.KeyValue("minio.gateway.auth.azure.storageAccountNameExistingSecret", cfg.Config.ObjectStorage.Azure.Credentials.Name),
26-
helm.KeyValue("minio.gateway.auth.azure.storageAccountNameExistingSecretKey", "accountName"),
27-
helm.KeyValue("minio.gateway.auth.azure.storageAccountKeyExistingSecret", cfg.Config.ObjectStorage.Azure.Credentials.Name),
28-
helm.KeyValue("minio.gateway.auth.azure.storageAccountKeyExistingSecretKey", "accountKey"),
29-
helm.KeyValue("minio.gateway.replicaCount", "2"),
30-
helm.KeyValue("minio.gateway.type", "azure"),
31-
helm.KeyValue("minio.persistence.enabled", "false"),
32-
helm.KeyValue("minio.service.ports.api", fmt.Sprintf("%d", apiPort)),
33-
helm.KeyValue("minio.service.ports.console", fmt.Sprintf("%d", consolePort)),
34-
},
21+
Values: append(
22+
[]string{
23+
helm.KeyValue("minio.gateway.enabled", "true"),
24+
helm.KeyValue("minio.gateway.auth.azure.accessKey", cfg.Values.StorageAccessKey), // Azure value actually taken from secret - used for console/API access
25+
helm.KeyValue("minio.gateway.auth.azure.secretKey", cfg.Values.StorageSecretKey), // Ditto
26+
helm.KeyValue("minio.gateway.auth.azure.storageAccountNameExistingSecret", cfg.Config.ObjectStorage.Azure.Credentials.Name),
27+
helm.KeyValue("minio.gateway.auth.azure.storageAccountNameExistingSecretKey", "accountName"),
28+
helm.KeyValue("minio.gateway.auth.azure.storageAccountKeyExistingSecret", cfg.Config.ObjectStorage.Azure.Credentials.Name),
29+
helm.KeyValue("minio.gateway.auth.azure.storageAccountKeyExistingSecretKey", "accountKey"),
30+
helm.KeyValue("minio.gateway.replicaCount", "2"),
31+
helm.KeyValue("minio.gateway.type", "azure"),
32+
helm.KeyValue("minio.persistence.enabled", "false"),
33+
helm.KeyValue("minio.service.ports.api", fmt.Sprintf("%d", apiPort)),
34+
helm.KeyValue("minio.service.ports.console", fmt.Sprintf("%d", consolePort)),
35+
},
36+
commonHelmValues...,
37+
),
3538
},
3639
}, nil
3740
}),

installer/pkg/components/minio/helm.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,24 @@ import (
1010
"github.com/gitpod-io/gitpod/installer/pkg/common"
1111
"github.com/gitpod-io/gitpod/installer/pkg/components/minio/azure"
1212
"github.com/gitpod-io/gitpod/installer/pkg/components/minio/incluster"
13+
"github.com/gitpod-io/gitpod/installer/pkg/helm"
1314
"k8s.io/utils/pointer"
1415
)
1516

1617
var Helm = common.CompositeHelmFunc(
1718
func(cfg *common.RenderContext) ([]string, error) {
19+
commonHelmValues := []string{
20+
helm.ImagePullSecrets("minio.image.pullSecrets", cfg),
21+
helm.KeyValue("minio.image.registry", common.ThirdPartyContainerRepo(cfg.Config.Repository, "docker.io")),
22+
helm.ImagePullSecrets("minio.volumePermissions.image.pullSecrets", cfg),
23+
helm.KeyValue("minio.volumePermissions.image.registry", common.ThirdPartyContainerRepo(cfg.Config.Repository, "docker.io")),
24+
}
25+
1826
if pointer.BoolDeref(cfg.Config.ObjectStorage.InCluster, false) {
19-
return incluster.Helm(ServiceAPIPort, ServiceConsolePort)(cfg)
27+
return incluster.Helm(ServiceAPIPort, ServiceConsolePort, commonHelmValues)(cfg)
2028
}
2129
if cfg.Config.ObjectStorage.Azure != nil {
22-
return azure.Helm(ServiceAPIPort, ServiceConsolePort)(cfg)
30+
return azure.Helm(ServiceAPIPort, ServiceConsolePort, commonHelmValues)(cfg)
2331
}
2432

2533
return nil, nil

installer/pkg/components/minio/incluster/minio.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
"helm.sh/helm/v3/pkg/cli/values"
1414
)
1515

16-
var Helm = func(apiPort int32, consolePort int32) common.HelmFunc {
16+
var Helm = func(apiPort int32, consolePort int32, commonHelmValues []string) common.HelmFunc {
1717
return common.CompositeHelmFunc(
1818
helm.ImportTemplate(charts.Minio(), helm.TemplateConfig{}, func(cfg *common.RenderContext) (*common.HelmConfig, error) {
1919
affinity, err := helm.AffinityYaml(cluster.AffinityLabelMeta)
@@ -29,12 +29,15 @@ var Helm = func(apiPort int32, consolePort int32) common.HelmFunc {
2929
return &common.HelmConfig{
3030
Enabled: true,
3131
Values: &values.Options{
32-
Values: []string{
33-
helm.KeyValue("minio.auth.rootUser", cfg.Values.StorageAccessKey),
34-
helm.KeyValue("minio.auth.rootPassword", cfg.Values.StorageSecretKey),
35-
helm.KeyValue("minio.service.ports.api", fmt.Sprintf("%d", apiPort)),
36-
helm.KeyValue("minio.service.ports.console", fmt.Sprintf("%d", consolePort)),
37-
},
32+
Values: append(
33+
[]string{
34+
helm.KeyValue("minio.auth.rootUser", cfg.Values.StorageAccessKey),
35+
helm.KeyValue("minio.auth.rootPassword", cfg.Values.StorageSecretKey),
36+
helm.KeyValue("minio.service.ports.api", fmt.Sprintf("%d", apiPort)),
37+
helm.KeyValue("minio.service.ports.console", fmt.Sprintf("%d", consolePort)),
38+
},
39+
commonHelmValues...,
40+
),
3841
// This is too complex to be sent as a string
3942
FileValues: []string{
4043
affinityTemplate,

installer/pkg/components/rabbitmq/helm.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,10 @@ var Helm = common.CompositeHelmFunc(
279279
helm.KeyValue("rabbitmq.auth.tls.existingSecret", TLSSecret),
280280
helm.KeyValue(fmt.Sprintf("rabbitmq.extraSecrets.%s.username", InClusterDbSecret), username),
281281
helm.KeyValue(fmt.Sprintf("rabbitmq.extraSecrets.%s.password", InClusterDbSecret), password),
282+
helm.ImagePullSecrets("rabbitmq.image.pullSecrets", cfg),
283+
helm.KeyValue("rabbitmq.image.registry", common.ThirdPartyContainerRepo(cfg.Config.Repository, "docker.io")),
284+
helm.ImagePullSecrets("volumePermissions.image.pullSecrets", cfg),
285+
helm.KeyValue("rabbitmq.volumePermissions.image.registry", common.ThirdPartyContainerRepo(cfg.Config.Repository, "docker.io")),
282286
},
283287
// This is too complex to be sent as a string
284288
FileValues: []string{

installer/pkg/helm/helm.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"os/signal"
1313
"path/filepath"
1414
"sigs.k8s.io/yaml"
15+
"strings"
1516
"syscall"
1617

1718
"github.com/gitpod-io/gitpod/installer/pkg/common"
@@ -121,6 +122,21 @@ func AffinityYaml(orLabels ...string) ([]byte, error) {
121122
return marshal, nil
122123
}
123124

125+
func ImagePullSecrets(key string, ctx *common.RenderContext) string {
126+
if len(ctx.Config.ImagePullSecrets) > 0 {
127+
var pullSecrets []string
128+
for _, i := range ctx.Config.ImagePullSecrets {
129+
pullSecrets = append(pullSecrets, i.Name)
130+
}
131+
132+
// Helm array nomenclature
133+
return KeyValue(key, fmt.Sprintf("{%s}", strings.Join(pullSecrets, ",")))
134+
}
135+
136+
// Nothing to be set
137+
return ""
138+
}
139+
124140
// ImportTemplate allows for Helm charts to be imported into the installer manifest
125141
func ImportTemplate(chart *charts.Chart, templateCfg TemplateConfig, pkgConfig PkgConfig) common.HelmFunc {
126142
return func(cfg *common.RenderContext) (r []string, err error) {

0 commit comments

Comments
 (0)