diff --git a/install/installer/pkg/components/ws-manager-bridge/objects.go b/install/installer/pkg/components/ws-manager-bridge/objects.go index adf5ddeb65c461..d68e3a92ca6efb 100644 --- a/install/installer/pkg/components/ws-manager-bridge/objects.go +++ b/install/installer/pkg/components/ws-manager-bridge/objects.go @@ -9,7 +9,7 @@ import ( "github.com/gitpod-io/gitpod/installer/pkg/common" wsmanager "github.com/gitpod-io/gitpod/installer/pkg/components/ws-manager" - "github.com/gitpod-io/gitpod/installer/pkg/config/v1" + "github.com/gitpod-io/gitpod/installer/pkg/config/v1/experimental" ) var Objects = common.CompositeRenderFunc( @@ -20,9 +20,17 @@ var Objects = common.CompositeRenderFunc( ) func WSManagerList(ctx *common.RenderContext) []WorkspaceCluster { + skipSelf := false + _ = ctx.WithExperimental(func(cfg *experimental.Config) error { + if cfg.WebApp != nil && cfg.WebApp.WorkspaceManagerBridge != nil { + skipSelf = cfg.WebApp.WorkspaceManagerBridge.SkipSelf + } + return nil + }) + // Registering a local cluster ws-manager only makes sense when we actually deploy one, // (ie when we are doing a full self hosted installation rather than a SaaS install to gitpod.io). - if ctx.Config.Kind != config.InstallationFull { + if skipSelf { return []WorkspaceCluster{} } diff --git a/install/installer/pkg/components/ws-manager-bridge/objects_test.go b/install/installer/pkg/components/ws-manager-bridge/objects_test.go new file mode 100644 index 00000000000000..2f82fd28c164cf --- /dev/null +++ b/install/installer/pkg/components/ws-manager-bridge/objects_test.go @@ -0,0 +1,55 @@ +// Copyright (c) 2022 Gitpod GmbH. All rights reserved. +// Licensed under the MIT License. See License-MIT.txt in the project root for license information. + +package wsmanagerbridge + +import ( + "github.com/gitpod-io/gitpod/installer/pkg/common" + "github.com/gitpod-io/gitpod/installer/pkg/config/v1" + "github.com/gitpod-io/gitpod/installer/pkg/config/v1/experimental" + "github.com/gitpod-io/gitpod/installer/pkg/config/versions" + "github.com/stretchr/testify/require" + "testing" +) + +func TestWorkspaceManagerList_WhenSkipSelfIsSet(t *testing.T) { + testCases := []struct { + SkipSelf bool + ExpectWorkspaceClusters bool + }{ + {SkipSelf: true, ExpectWorkspaceClusters: false}, + {SkipSelf: false, ExpectWorkspaceClusters: true}, + } + + for _, testCase := range testCases { + ctx := renderContextWithConfig(t, testCase.SkipSelf) + + wsclusters := WSManagerList(ctx) + if testCase.ExpectWorkspaceClusters { + require.NotEmptyf(t, wsclusters, "expected to render workspace clusters when skipSelf=%v", testCase.SkipSelf) + } else { + require.Emptyf(t, wsclusters, "expected not to render workspace clusters when skipSelf=%v", testCase.SkipSelf) + } + } +} + +func renderContextWithConfig(t *testing.T, skipSelf bool) *common.RenderContext { + ctx, err := common.NewRenderContext(config.Config{ + Experimental: &experimental.Config{ + WebApp: &experimental.WebAppConfig{ + WorkspaceManagerBridge: &experimental.WsManagerBridgeConfig{ + SkipSelf: skipSelf, + }, + }, + }, + }, versions.Manifest{ + Components: versions.Components{ + PublicAPIServer: versions.Versioned{ + Version: "commit-test-latest", + }, + }, + }, "test-namespace") + require.NoError(t, err) + + return ctx +} diff --git a/install/installer/pkg/config/v1/experimental/experimental.go b/install/installer/pkg/config/v1/experimental/experimental.go index a26f7b61a82809..3d9c6f8beae932 100644 --- a/install/installer/pkg/config/v1/experimental/experimental.go +++ b/install/installer/pkg/config/v1/experimental/experimental.go @@ -91,10 +91,11 @@ type WorkspaceTemplates struct { } type WebAppConfig struct { - PublicAPI *PublicAPIConfig `json:"publicApi,omitempty"` - Server *ServerConfig `json:"server,omitempty"` - ProxyConfig *ProxyConfig `json:"proxy,omitempty"` - UsePodAntiAffinity bool `json:"usePodAntiAffinity"` + PublicAPI *PublicAPIConfig `json:"publicApi,omitempty"` + Server *ServerConfig `json:"server,omitempty"` + ProxyConfig *ProxyConfig `json:"proxy,omitempty"` + WorkspaceManagerBridge *WsManagerBridgeConfig `json:"wsManagerBridge,omitempty"` + UsePodAntiAffinity bool `json:"usePodAntiAffinity"` } type WorkspaceDefaults struct { @@ -121,6 +122,10 @@ type GithubApp struct { CertSecretName string `json:"certSecretName"` } +type WsManagerBridgeConfig struct { + SkipSelf bool `json:"skipSelf"` +} + type ServerConfig struct { WorkspaceDefaults WorkspaceDefaults `json:"workspaceDefaults"` OAuthServer OAuthServer `json:"oauthServer"`