diff --git a/install/installer/pkg/components/ws-manager/configmap.go b/install/installer/pkg/components/ws-manager/configmap.go index 46d91f4516ee24..55607359d2c895 100644 --- a/install/installer/pkg/components/ws-manager/configmap.go +++ b/install/installer/pkg/components/ws-manager/configmap.go @@ -7,6 +7,7 @@ package wsmanager import ( "fmt" "path/filepath" + "strings" "time" wsdaemon "github.com/gitpod-io/gitpod/installer/pkg/components/ws-daemon" @@ -89,6 +90,7 @@ func configmap(ctx *common.RenderContext) ([]runtime.Object, error) { if err != nil { return err } + classes[k] = &config.WorkspaceClass{ Container: config.ContainerConfiguration{ Requests: &config.ResourceConfiguration{ @@ -105,7 +107,10 @@ func configmap(ctx *common.RenderContext) ([]runtime.Object, error) { Templates: tplsCfg, PVC: config.PVCConfiguration(c.PVC), } - tpls = append(tpls, ctpls...) + + for k, v := range ctpls { + tpls[fixTemplateClass(k)] = v + } } return nil }) @@ -210,12 +215,21 @@ func configmap(ctx *common.RenderContext) ([]runtime.Object, error) { "config.json": string(fc), }, }, + &corev1.ConfigMap{ + TypeMeta: common.TypeMetaConfigmap, + ObjectMeta: metav1.ObjectMeta{ + Name: WorkspaceTemplateConfigMap, + Namespace: ctx.Namespace, + Labels: common.DefaultLabels(Component), + }, + Data: tpls, + }, } - res = append(res, tpls...) + return res, nil } -func buildWorkspaceTemplates(ctx *common.RenderContext, cfgTpls *configv1.WorkspaceTemplates, className string) (config.WorkspacePodTemplateConfiguration, []runtime.Object, error) { +func buildWorkspaceTemplates(ctx *common.RenderContext, cfgTpls *configv1.WorkspaceTemplates, className string) (config.WorkspacePodTemplateConfiguration, map[string]string, error) { var ( cfg config.WorkspacePodTemplateConfiguration tpls = make(map[string]string) @@ -243,19 +257,13 @@ func buildWorkspaceTemplates(ctx *common.RenderContext, cfgTpls *configv1.Worksp return cfg, nil, fmt.Errorf("unable to marshal %s workspace template: %w", op.Name, err) } fn := filepath.Join(className, op.Name+".yaml") - *op.Path = filepath.Join(WorkspaceTemplatePath, fn) + *op.Path = filepath.Join(WorkspaceTemplatePath, fixTemplateClass(fn)) tpls[fn] = string(fc) } - return cfg, []runtime.Object{ - &corev1.ConfigMap{ - TypeMeta: common.TypeMetaConfigmap, - ObjectMeta: metav1.ObjectMeta{ - Name: WorkspaceTemplateConfigMap, - Namespace: ctx.Namespace, - Labels: common.DefaultLabels(Component), - }, - Data: tpls, - }, - }, nil + return cfg, tpls, nil +} + +func fixTemplateClass(input string) string { + return strings.ReplaceAll(input, "/", "-") } diff --git a/install/installer/pkg/components/ws-manager/configmap_test.go b/install/installer/pkg/components/ws-manager/configmap_test.go index eb0c6e59599ba5..c6190c3932038a 100644 --- a/install/installer/pkg/components/ws-manager/configmap_test.go +++ b/install/installer/pkg/components/ws-manager/configmap_test.go @@ -13,7 +13,6 @@ import ( "github.com/google/go-cmp/cmp" corev1 "k8s.io/api/core/v1" - "k8s.io/apimachinery/pkg/runtime" "k8s.io/utils/pointer" ) @@ -29,13 +28,17 @@ func TestBuildWorkspaceTemplates(t *testing.T) { Expectation Expectation }{ { - Name: "no templates", - Expectation: Expectation{}, + Name: "no templates", + Expectation: Expectation{ + Data: map[string]bool{}, + }, }, { - Name: "empty templates", - Config: &configv1.WorkspaceTemplates{}, - Expectation: Expectation{}, + Name: "empty templates", + Config: &configv1.WorkspaceTemplates{}, + Expectation: Expectation{ + Data: map[string]bool{}, + }, }, { Name: "default tpl", @@ -95,7 +98,7 @@ func TestBuildWorkspaceTemplates(t *testing.T) { t.Run(test.Name, func(t *testing.T) { var ( act Expectation - objs []runtime.Object + data map[string]string err error ) @@ -103,29 +106,18 @@ func TestBuildWorkspaceTemplates(t *testing.T) { test.ContainerRegistry = &configv1.ContainerRegistry{InCluster: pointer.Bool(true)} } - act.TplConfig, objs, err = buildWorkspaceTemplates(&common.RenderContext{Config: configv1.Config{ + act.TplConfig, data, err = buildWorkspaceTemplates(&common.RenderContext{Config: configv1.Config{ ContainerRegistry: *test.ContainerRegistry, }}, test.Config, "") if err != nil { t.Error(err) } - if len(objs) < 1 { - t.Fatalf("received zero runtime objects") - return - } - cfgmap, ok := objs[0].(*corev1.ConfigMap) - if !ok { - t.Fatalf("buildWorkspaceTemplates did not return a configMap") - return - } - if len(cfgmap.Data) > 0 { - dt := make(map[string]bool) - for k := range cfgmap.Data { - dt[k] = true - } - act.Data = dt + dt := make(map[string]bool) + for k := range data { + dt[k] = true } + act.Data = dt if diff := cmp.Diff(test.Expectation, act); diff != "" { t.Errorf("Expectation mismatch (-want +got):\n%s", diff)