Skip to content

Commit c366861

Browse files
author
Simon Emms
committed
[installer]: give the RepoName function access to the config
1 parent d26fc6b commit c366861

File tree

4 files changed

+88
-11
lines changed

4 files changed

+88
-11
lines changed

install/installer/cmd/mirror_list.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,9 @@ func generateMirrorList(cfgVersion string, cfg *configv1.Config) ([]mirrorListRe
139139

140140
images = append(images, mirrorListRepo{
141141
Original: img,
142-
Target: target,
142+
Target: common.RepoName("", target, &configv1.Config{
143+
Repository: targetRepo,
144+
}),
143145
})
144146
}
145147

install/installer/pkg/common/ca.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func InternalCAContainer(ctx *RenderContext, mod ...func(*corev1.Container)) *co
3939
res := &corev1.Container{
4040
Name: "update-ca-certificates",
4141
// It's not possible to use images based on alpine due to errors running update-ca-certificates
42-
Image: ImageName(ctx.Config.Repository, "ca-updater", ctx.VersionManifest.Components.CAUpdater.Version),
42+
Image: ImageName(ctx.Config.Repository, "ca-updater", ctx.VersionManifest.Components.CAUpdater.Version, &ctx.Config),
4343
ImagePullPolicy: corev1.PullIfNotPresent,
4444
Command: []string{
4545
"bash", "-c",

install/installer/pkg/common/common.go

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ func DatabaseEnv(cfg *config.Config) (res []corev1.EnvVar) {
248248
func DatabaseWaiterContainer(ctx *RenderContext) *corev1.Container {
249249
return &corev1.Container{
250250
Name: "database-waiter",
251-
Image: ImageName(ctx.Config.Repository, "service-waiter", ctx.VersionManifest.Components.ServiceWaiter.Version),
251+
Image: ImageName(ctx.Config.Repository, "service-waiter", ctx.VersionManifest.Components.ServiceWaiter.Version, &ctx.Config),
252252
Args: []string{
253253
"-v",
254254
"database",
@@ -266,7 +266,7 @@ func DatabaseWaiterContainer(ctx *RenderContext) *corev1.Container {
266266
func MessageBusWaiterContainer(ctx *RenderContext) *corev1.Container {
267267
return &corev1.Container{
268268
Name: "msgbus-waiter",
269-
Image: ImageName(ctx.Config.Repository, "service-waiter", ctx.VersionManifest.Components.ServiceWaiter.Version),
269+
Image: ImageName(ctx.Config.Repository, "service-waiter", ctx.VersionManifest.Components.ServiceWaiter.Version, &ctx.Config),
270270
Args: []string{
271271
"-v",
272272
"messagebus",
@@ -284,7 +284,7 @@ func MessageBusWaiterContainer(ctx *RenderContext) *corev1.Container {
284284
func KubeRBACProxyContainer(ctx *RenderContext) *corev1.Container {
285285
return &corev1.Container{
286286
Name: "kube-rbac-proxy",
287-
Image: ImageName(ThirdPartyContainerRepo(ctx.Config.Repository, KubeRBACProxyRepo), KubeRBACProxyImage, KubeRBACProxyTag),
287+
Image: ImageName(ThirdPartyContainerRepo(ctx.Config.Repository, KubeRBACProxyRepo), KubeRBACProxyImage, KubeRBACProxyTag, &ctx.Config),
288288
Args: []string{
289289
"--v=5",
290290
"--logtostderr",
@@ -339,7 +339,7 @@ func Affinity(orLabels ...string) *corev1.Affinity {
339339
}
340340
}
341341

342-
func RepoName(repo, name string) string {
342+
func RepoName(repo, name string, cfg *config.Config) string {
343343
var ref string
344344
if repo == "" {
345345
ref = name
@@ -350,11 +350,26 @@ func RepoName(repo, name string) string {
350350
if err != nil {
351351
panic(fmt.Sprintf("cannot parse image repo %s: %v", ref, err))
352352
}
353-
return pref.String()
353+
354+
prefString := pref.String()
355+
356+
if cfg.Repository != GitpodContainerRegistry {
357+
// If not in the Gitpod registry, don't use namespaces unless specified in the config.
358+
// This is to match the KOTS registry format of no namespace in the name
359+
s := strings.Split(prefString, "/")
360+
361+
noNamespace := []string{
362+
cfg.Repository,
363+
s[len(s)-1],
364+
}
365+
return strings.Join(noNamespace, "/")
366+
}
367+
368+
return prefString
354369
}
355370

356-
func ImageName(repo, name, tag string) string {
357-
ref := fmt.Sprintf("%s:%s", RepoName(repo, name), tag)
371+
func ImageName(repo, name, tag string, cfg *config.Config) string {
372+
ref := fmt.Sprintf("%s:%s", RepoName(repo, name, cfg), tag)
358373
pref, err := reference.ParseNamed(ref)
359374
if err != nil {
360375
panic(fmt.Sprintf("cannot parse image ref %s: %v", ref, err))

install/installer/pkg/common/common_test.go

Lines changed: 62 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@
55
package common_test
66

77
import (
8-
"github.com/gitpod-io/gitpod/installer/pkg/common"
98
"testing"
109

10+
"github.com/gitpod-io/gitpod/installer/pkg/common"
11+
"github.com/gitpod-io/gitpod/installer/pkg/config/v1"
12+
1113
"github.com/google/go-cmp/cmp"
1214
)
1315

@@ -20,6 +22,7 @@ func TestRepoName(t *testing.T) {
2022
Repo string
2123
Name string
2224
Expectation Expectation
25+
CfgRepo string
2326
}{
2427
{
2528
Name: "gitpod-io/workspace-full",
@@ -41,6 +44,54 @@ func TestRepoName(t *testing.T) {
4144
Panics: true,
4245
},
4346
},
47+
// Custom repo, no namespace
48+
{
49+
Name: "gitpod-io/workspace-full",
50+
Expectation: Expectation{
51+
Result: "some.registry.com/workspace-full",
52+
},
53+
CfgRepo: "some.registry.com",
54+
},
55+
{
56+
Repo: "some-repo.com",
57+
Name: "some-image",
58+
Expectation: Expectation{
59+
Result: "some.registry.com/some-image",
60+
},
61+
CfgRepo: "some.registry.com",
62+
},
63+
{
64+
Repo: "some-repo",
65+
Name: "not@avalid#image-name",
66+
Expectation: Expectation{
67+
Panics: true,
68+
},
69+
CfgRepo: "some.registry.com",
70+
},
71+
// Custom repo, namespace
72+
{
73+
Name: "gitpod-io/workspace-full",
74+
Expectation: Expectation{
75+
Result: "some.registry.com/gitpod/workspace-full",
76+
},
77+
CfgRepo: "some.registry.com/gitpod",
78+
},
79+
{
80+
Repo: "some-repo.com",
81+
Name: "some-image",
82+
Expectation: Expectation{
83+
Result: "some.registry.com/gitpod/some-image",
84+
},
85+
CfgRepo: "some.registry.com/gitpod",
86+
},
87+
{
88+
Repo: "some-repo",
89+
Name: "not@avalid#image-name",
90+
Expectation: Expectation{
91+
Panics: true,
92+
},
93+
CfgRepo: "some.registry.com/gitpod",
94+
},
4495
}
4596

4697
for _, test := range tests {
@@ -52,7 +103,16 @@ func TestRepoName(t *testing.T) {
52103
act.Panics = true
53104
}
54105
}()
55-
act.Result = common.RepoName(test.Repo, test.Name)
106+
cfg := config.Config{
107+
Repository: func() string {
108+
if test.CfgRepo == "" {
109+
return common.GitpodContainerRegistry
110+
}
111+
112+
return test.CfgRepo
113+
}(),
114+
}
115+
act.Result = common.RepoName(test.Repo, test.Name, &cfg)
56116
}()
57117

58118
if diff := cmp.Diff(test.Expectation, act); diff != "" {

0 commit comments

Comments
 (0)