Skip to content

Commit 2d73165

Browse files
Simon Emmsroboquat
authored andcommitted
[installer]: allow use of external container registry
1 parent 6509092 commit 2d73165

File tree

8 files changed

+166
-151
lines changed

8 files changed

+166
-151
lines changed

installer/pkg/components/blobserve/configmap.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ func configmap(ctx *common.RenderContext) ([]runtime.Object, error) {
7878
MaxSize: MaxSizeBytes,
7979
},
8080
},
81-
// todo(sje): make conditional on the workspace having a pull secret
8281
AuthCfg: "/mnt/pull-secret.json",
8382
PProfAddr: ":6060",
8483
PrometheusAddr: "127.0.0.1:9500",

installer/pkg/components/blobserve/deployment.go

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

77
import (
8+
"fmt"
89
"github.com/gitpod-io/gitpod/installer/pkg/common"
910
dockerregistry "github.com/gitpod-io/gitpod/installer/pkg/components/docker-registry"
1011
appsv1 "k8s.io/api/apps/v1"
@@ -18,55 +19,27 @@ import (
1819
func deployment(ctx *common.RenderContext) ([]runtime.Object, error) {
1920
labels := common.DefaultLabels(Component)
2021

22+
volumeName := "pull-secret"
23+
var secretName string
24+
if pointer.BoolDeref(ctx.Config.ContainerRegistry.InCluster, false) {
25+
secretName = dockerregistry.BuiltInRegistryAuth
26+
} else if ctx.Config.ContainerRegistry.External != nil {
27+
secretName = ctx.Config.ContainerRegistry.External.Certificate.Name
28+
} else {
29+
return nil, fmt.Errorf("%s: invalid container registry config", Component)
30+
}
31+
2132
var hashObj []runtime.Object
2233
if objs, err := configmap(ctx); err != nil {
2334
return nil, err
2435
} else {
2536
hashObj = append(hashObj, objs...)
2637
}
2738

28-
volumes := []corev1.Volume{{
29-
Name: "cache",
30-
VolumeSource: corev1.VolumeSource{EmptyDir: &corev1.EmptyDirVolumeSource{}},
31-
}, {
32-
Name: "config",
33-
VolumeSource: corev1.VolumeSource{
34-
ConfigMap: &corev1.ConfigMapVolumeSource{
35-
LocalObjectReference: corev1.LocalObjectReference{Name: Component},
36-
},
37-
},
38-
}}
39-
40-
volumeMounts := []corev1.VolumeMount{
41-
{
42-
Name: "config",
43-
MountPath: "/mnt/config",
44-
ReadOnly: true,
45-
}, {
46-
Name: "cache",
47-
MountPath: "/mnt/cache",
48-
},
49-
}
50-
51-
if pointer.BoolDeref(ctx.Config.ContainerRegistry.InCluster, false) {
52-
volumeName := "pull-secret"
53-
volumes = append(volumes, corev1.Volume{
54-
Name: volumeName,
55-
VolumeSource: corev1.VolumeSource{Secret: &corev1.SecretVolumeSource{
56-
SecretName: dockerregistry.BuiltInRegistryAuth,
57-
}},
58-
})
59-
volumeMounts = append(volumeMounts, corev1.VolumeMount{
60-
Name: volumeName,
61-
MountPath: "/mnt/pull-secret.json",
62-
SubPath: ".dockerconfigjson",
63-
})
64-
65-
if objs, err := common.DockerRegistryHash(ctx); err != nil {
66-
return nil, err
67-
} else {
68-
hashObj = append(hashObj, objs...)
69-
}
39+
if objs, err := common.DockerRegistryHash(ctx); err != nil {
40+
return nil, err
41+
} else {
42+
hashObj = append(hashObj, objs...)
7043
}
7144

7245
configHash, err := common.ObjectHash(hashObj, nil)
@@ -99,7 +72,22 @@ func deployment(ctx *common.RenderContext) ([]runtime.Object, error) {
9972
Affinity: &corev1.Affinity{},
10073
ServiceAccountName: Component,
10174
EnableServiceLinks: pointer.Bool(false),
102-
Volumes: volumes,
75+
Volumes: []corev1.Volume{{
76+
Name: "cache",
77+
VolumeSource: corev1.VolumeSource{EmptyDir: &corev1.EmptyDirVolumeSource{}},
78+
}, {
79+
Name: "config",
80+
VolumeSource: corev1.VolumeSource{
81+
ConfigMap: &corev1.ConfigMapVolumeSource{
82+
LocalObjectReference: corev1.LocalObjectReference{Name: Component},
83+
},
84+
},
85+
}, {
86+
Name: volumeName,
87+
VolumeSource: corev1.VolumeSource{Secret: &corev1.SecretVolumeSource{
88+
SecretName: secretName,
89+
}},
90+
}},
10391
Containers: []corev1.Container{{
10492
Name: Component,
10593
Args: []string{"run", "-v", "/mnt/config/config.json"},
@@ -123,7 +111,18 @@ func deployment(ctx *common.RenderContext) ([]runtime.Object, error) {
123111
common.DefaultEnv(&ctx.Config),
124112
common.TracingEnv(&ctx.Config),
125113
),
126-
VolumeMounts: volumeMounts,
114+
VolumeMounts: []corev1.VolumeMount{{
115+
Name: "config",
116+
MountPath: "/mnt/config",
117+
ReadOnly: true,
118+
}, {
119+
Name: "cache",
120+
MountPath: "/mnt/cache",
121+
}, {
122+
Name: volumeName,
123+
MountPath: "/mnt/pull-secret.json",
124+
SubPath: ".dockerconfigjson",
125+
}},
127126
}, *common.KubeRBACProxyContainer()},
128127
},
129128
},

installer/pkg/components/image-builder-mk3/configmap.go

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"fmt"
1010
dockerregistry "github.com/gitpod-io/gitpod/installer/pkg/components/docker-registry"
1111
"k8s.io/utils/pointer"
12+
"strings"
1213
"time"
1314

1415
"github.com/gitpod-io/gitpod/common-go/util"
@@ -23,6 +24,15 @@ import (
2324
)
2425

2526
func configmap(ctx *common.RenderContext) ([]runtime.Object, error) {
27+
var registryName string
28+
if pointer.BoolDeref(ctx.Config.ContainerRegistry.InCluster, false) {
29+
registryName = fmt.Sprintf("%s.%s", dockerregistry.RegistryName, ctx.Config.Domain)
30+
} else if ctx.Config.ContainerRegistry.External != nil {
31+
registryName = strings.TrimSuffix(ctx.Config.ContainerRegistry.External.URL, "/")
32+
} else {
33+
return nil, fmt.Errorf("%s: invalid container registry config", Component)
34+
}
35+
2636
orchestrator := config.Configuration{
2737
WorkspaceManager: config.WorkspaceManagerConfig{
2838
Address: fmt.Sprintf("%s:%d", wsmanager.Component, wsmanager.RPCPort),
@@ -32,28 +42,13 @@ func configmap(ctx *common.RenderContext) ([]runtime.Object, error) {
3242
PrivateKey: "/wsman-certs/tls.key",
3343
},
3444
},
35-
BuilderImage: common.ImageName(ctx.Config.Repository, BuilderImage, ctx.VersionManifest.Components.ImageBuilderMk3.BuilderImage.Version),
36-
BuilderAuthKeyFile: "/config/authkey",
45+
AuthFile: PullSecretFile,
46+
BaseImageRepository: fmt.Sprintf("%s/base-images", registryName),
47+
BuilderImage: common.ImageName(ctx.Config.Repository, BuilderImage, ctx.VersionManifest.Components.ImageBuilderMk3.BuilderImage.Version),
48+
BuilderAuthKeyFile: "/config/authkey",
49+
WorkspaceImageRepository: fmt.Sprintf("%s/workspace-images", registryName),
3750
}
3851

39-
var baseImageRepo string
40-
var workspaceImgRepo string
41-
if pointer.BoolDeref(ctx.Config.ContainerRegistry.InCluster, false) {
42-
// todo(sje): handle external registry
43-
registryName := fmt.Sprintf("%s.%s", dockerregistry.RegistryName, ctx.Config.Domain)
44-
45-
baseImageRepo = fmt.Sprintf("%s/base-images", registryName)
46-
workspaceImgRepo = fmt.Sprintf("%s/workspace-images", registryName)
47-
48-
orchestrator.AuthFile = PullSecretFile
49-
} else {
50-
// todo(sje): handle outside cluster values for image builder mk3
51-
return nil, fmt.Errorf("in cluster container currently only supported option")
52-
}
53-
54-
orchestrator.BaseImageRepository = baseImageRepo
55-
orchestrator.WorkspaceImageRepository = workspaceImgRepo
56-
5752
imgcfg := config.ServiceConfig{
5853
Orchestrator: orchestrator,
5954
RefCache: config.RefCacheConfig{

installer/pkg/components/image-builder-mk3/deployment.go

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -34,27 +34,21 @@ func deployment(ctx *common.RenderContext) ([]runtime.Object, error) {
3434
hashObj = append(hashObj, objs...)
3535
}
3636

37-
var volumes []corev1.Volume
38-
var volumeMounts []corev1.VolumeMount
39-
37+
var secretName string
4038
if pointer.BoolDeref(ctx.Config.ContainerRegistry.InCluster, false) {
41-
volumeMounts = append(volumeMounts, corev1.VolumeMount{
42-
Name: "pull-secret",
43-
MountPath: PullSecretFile,
44-
SubPath: ".dockerconfigjson",
45-
})
46-
volumes = append(volumes, corev1.Volume{
47-
Name: "pull-secret",
48-
VolumeSource: corev1.VolumeSource{Secret: &corev1.SecretVolumeSource{
49-
SecretName: dockerregistry.BuiltInRegistryAuth,
50-
}},
51-
})
52-
if objs, err := common.DockerRegistryHash(ctx); err != nil {
53-
return nil, err
54-
} else {
55-
hashObj = append(hashObj, objs...)
56-
}
39+
secretName = dockerregistry.BuiltInRegistryAuth
40+
} else if ctx.Config.ContainerRegistry.External != nil {
41+
secretName = ctx.Config.ContainerRegistry.External.Certificate.Name
42+
} else {
43+
return nil, fmt.Errorf("%s: invalid container registry config", Component)
44+
}
45+
46+
if objs, err := common.DockerRegistryHash(ctx); err != nil {
47+
return nil, err
48+
} else {
49+
hashObj = append(hashObj, objs...)
5750
}
51+
5852
configHash, err := common.ObjectHash(hashObj, nil)
5953
if err != nil {
6054
return nil, err
@@ -87,7 +81,7 @@ func deployment(ctx *common.RenderContext) ([]runtime.Object, error) {
8781
DNSPolicy: "ClusterFirst",
8882
RestartPolicy: "Always",
8983
TerminationGracePeriodSeconds: pointer.Int64(30),
90-
Volumes: append([]corev1.Volume{{
84+
Volumes: []corev1.Volume{{
9185
Name: "configuration",
9286
VolumeSource: corev1.VolumeSource{
9387
ConfigMap: &corev1.ConfigMapVolumeSource{
@@ -108,7 +102,12 @@ func deployment(ctx *common.RenderContext) ([]runtime.Object, error) {
108102
SecretName: wsmanager.TLSSecretNameClient,
109103
},
110104
},
111-
}}, volumes...),
105+
}, {
106+
Name: "pull-secret",
107+
VolumeSource: corev1.VolumeSource{Secret: &corev1.SecretVolumeSource{
108+
SecretName: secretName,
109+
}},
110+
}},
112111
Containers: []corev1.Container{{
113112
Name: Component,
114113
Image: common.ImageName(ctx.Config.Repository, Component, ctx.VersionManifest.Components.ImageBuilderMk3.Version),
@@ -136,7 +135,7 @@ func deployment(ctx *common.RenderContext) ([]runtime.Object, error) {
136135
Privileged: pointer.Bool(false),
137136
RunAsUser: pointer.Int64(33333),
138137
},
139-
VolumeMounts: append([]corev1.VolumeMount{{
138+
VolumeMounts: []corev1.VolumeMount{{
140139
Name: "configuration",
141140
MountPath: "/config/image-builder.json",
142141
SubPath: "image-builder.json",
@@ -148,7 +147,11 @@ func deployment(ctx *common.RenderContext) ([]runtime.Object, error) {
148147
Name: "wsman-tls-certs",
149148
MountPath: "/wsman-certs",
150149
ReadOnly: true,
151-
}}, volumeMounts...),
150+
}, {
151+
Name: "pull-secret",
152+
MountPath: PullSecretFile,
153+
SubPath: ".dockerconfigjson",
154+
}},
152155
}, *common.KubeRBACProxyContainer()},
153156
},
154157
},

installer/pkg/components/proxy/configmap.go

Lines changed: 41 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"encoding/base64"
1111
"fmt"
1212
minioComponent "github.com/gitpod-io/gitpod/installer/pkg/components/minio"
13+
openvsxproxy "github.com/gitpod-io/gitpod/installer/pkg/components/openvsx-proxy"
1314
"text/template"
1415

1516
"github.com/gitpod-io/gitpod/installer/pkg/common"
@@ -18,6 +19,7 @@ import (
1819
corev1 "k8s.io/api/core/v1"
1920
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2021
"k8s.io/apimachinery/pkg/runtime"
22+
"k8s.io/utils/pointer"
2123
)
2224

2325
//go:embed templates/configmap/vhost.docker-registry.tpl
@@ -88,36 +90,9 @@ func configmap(ctx *common.RenderContext) ([]runtime.Object, error) {
8890
return nil, err
8991
}
9092

91-
// todo(sje) make conditional
92-
// todo(sje): allow value to be set via config
93-
username := ctx.Values.InternalRegistryUsername
94-
if username == "" {
95-
return nil, fmt.Errorf("unknown value: internal registry username")
96-
}
97-
98-
password := ctx.Values.InternalRegistryPassword
99-
if password == "" {
100-
return nil, fmt.Errorf("unknown value: internal registry password")
101-
}
102-
103-
hashedPassword, err := bcrypt.GenerateFromPassword([]byte(password), bcrypt.DefaultCost)
104-
if err != nil {
105-
return nil, err
106-
}
107-
108-
dockerRegistry, err := renderTemplate(vhostDockerRegistry, dockerRegistryTpl{
109-
Domain: ctx.Config.Domain,
110-
ReverseProxy: fmt.Sprintf("https://%s.%s.%s", common.DockerRegistryName, ctx.Namespace, kubeDomain),
111-
Username: username,
112-
Password: base64.StdEncoding.EncodeToString(hashedPassword),
113-
})
114-
if err != nil {
115-
return nil, err
116-
}
117-
11893
openVSX, err := renderTemplate(vhostOpenVSXTmpl, openVSXTpl{
11994
Domain: ctx.Config.Domain,
120-
RepoURL: fmt.Sprintf("openvsx-proxy.%s.%s:%d", ctx.Namespace, kubeDomain, 8080), // todo(sje): get port from (future) config
95+
RepoURL: fmt.Sprintf("openvsx-proxy.%s.%s:%d", ctx.Namespace, kubeDomain, openvsxproxy.ServicePort),
12196
})
12297
if err != nil {
12398
return nil, err
@@ -140,6 +115,43 @@ func configmap(ctx *common.RenderContext) ([]runtime.Object, error) {
140115
return nil, err
141116
}
142117

118+
data := map[string]string{
119+
"vhost.empty": *empty,
120+
"vhost.minio": *minio,
121+
"vhost.open-vsx": *openVSX,
122+
"vhost.payment-endpoint": *paymentEndpoint,
123+
"vhost.kedge": *kedge,
124+
}
125+
126+
if pointer.BoolDeref(ctx.Config.ContainerRegistry.InCluster, false) {
127+
username := ctx.Values.InternalRegistryUsername
128+
if username == "" {
129+
return nil, fmt.Errorf("unknown value: internal registry username")
130+
}
131+
132+
password := ctx.Values.InternalRegistryPassword
133+
if password == "" {
134+
return nil, fmt.Errorf("unknown value: internal registry password")
135+
}
136+
137+
hashedPassword, err := bcrypt.GenerateFromPassword([]byte(password), bcrypt.DefaultCost)
138+
if err != nil {
139+
return nil, err
140+
}
141+
142+
dockerRegistry, err := renderTemplate(vhostDockerRegistry, dockerRegistryTpl{
143+
Domain: ctx.Config.Domain,
144+
ReverseProxy: fmt.Sprintf("https://%s.%s.%s", common.DockerRegistryName, ctx.Namespace, kubeDomain),
145+
Username: username,
146+
Password: base64.StdEncoding.EncodeToString(hashedPassword),
147+
})
148+
if err != nil {
149+
return nil, err
150+
}
151+
152+
data["vhost.docker-registry"] = *dockerRegistry
153+
}
154+
143155
return []runtime.Object{
144156
&corev1.ConfigMap{
145157
TypeMeta: common.TypeMetaConfigmap,
@@ -148,14 +160,7 @@ func configmap(ctx *common.RenderContext) ([]runtime.Object, error) {
148160
Namespace: ctx.Namespace,
149161
Labels: common.DefaultLabels(Component),
150162
},
151-
Data: map[string]string{
152-
"vhost.empty": *empty,
153-
"vhost.minio": *minio,
154-
"vhost.docker-registry": *dockerRegistry,
155-
"vhost.open-vsx": *openVSX,
156-
"vhost.payment-endpoint": *paymentEndpoint,
157-
"vhost.kedge": *kedge,
158-
},
163+
Data: data,
159164
},
160165
}, nil
161166
}

installer/pkg/components/registry-facade/configmap.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ func configmap(ctx *common.RenderContext) ([]runtime.Object, error) {
4848
Type: "image",
4949
}},
5050
},
51-
// todo(sje): only enabled if the pullSecret is not nil in daemonset
5251
AuthCfg: "/mnt/pull-secret.json",
5352
PProfAddr: ":6060",
5453
PrometheusAddr: "127.0.0.1:9500",

0 commit comments

Comments
 (0)