Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[installer] Allow more parts of the server config to vary #9630

Merged
merged 4 commits into from
Apr 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 29 additions & 3 deletions install/installer/pkg/components/server/configmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,32 @@ func configmap(ctx *common.RenderContext) ([]runtime.Object, error) {
return nil
})

disableDynamicAuthProviderLogin := false
_ = ctx.WithExperimental(func(cfg *experimental.Config) error {
if cfg.WebApp != nil && cfg.WebApp.Server != nil {
disableDynamicAuthProviderLogin = cfg.WebApp.Server.DisableDynamicAuthProviderLogin
}
return nil
})

enableLocalApp := true
_ = ctx.WithExperimental(func(cfg *experimental.Config) error {
if cfg.WebApp != nil && cfg.WebApp.Server != nil {
enableLocalApp = cfg.WebApp.Server.EnableLocalApp
}
return nil
})

defaultBaseImageRegistryWhitelist := []string{}
_ = ctx.WithExperimental(func(cfg *experimental.Config) error {
if cfg.WebApp != nil && cfg.WebApp.Server != nil {
if cfg.WebApp.Server.DefaultBaseImageRegistryWhiteList != nil {
defaultBaseImageRegistryWhitelist = cfg.WebApp.Server.DefaultBaseImageRegistryWhiteList
}
}
return nil
})

githubApp := GitHubApp{}
_ = ctx.WithExperimental(func(cfg *experimental.Config) error {
if cfg.WebApp != nil && cfg.WebApp.Server != nil && cfg.WebApp.Server.GithubApp != nil {
Expand Down Expand Up @@ -95,7 +121,7 @@ func configmap(ctx *common.RenderContext) ([]runtime.Object, error) {
MinAgeDays: 14,
MinAgePrebuildDays: 7,
},
EnableLocalApp: true,
EnableLocalApp: enableLocalApp,
AuthProviderConfigFiles: func() []string {
providers := make([]string, 0)

Expand All @@ -106,13 +132,13 @@ func configmap(ctx *common.RenderContext) ([]runtime.Object, error) {

return providers
}(),
DisableDynamicAuthProviderLogin: false,
DisableDynamicAuthProviderLogin: disableDynamicAuthProviderLogin,
MaxEnvvarPerUserCount: 4048,
MaxConcurrentPrebuildsPerRef: 10,
IncrementalPrebuilds: IncrementalPrebuilds{CommitHistory: 100, RepositoryPasslist: []string{}},
BlockNewUsers: ctx.Config.BlockNewUsers,
MakeNewUsersAdmin: false,
DefaultBaseImageRegistryWhitelist: []string{},
DefaultBaseImageRegistryWhitelist: defaultBaseImageRegistryWhitelist,
RunDbDeleter: true,
OAuthServer: OAuthServer{
Enabled: true,
Expand Down
115 changes: 115 additions & 0 deletions install/installer/pkg/components/server/configmap_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
// 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 server

import (
"encoding/json"
"testing"

"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/assert"
"github.com/stretchr/testify/require"
corev1 "k8s.io/api/core/v1"
)

func TestConfigMap(t *testing.T) {
type Expectation struct {
EnableLocalApp bool
DisableDynamicAuthProviderLogin bool
DefaultBaseImageRegistryWhiteList []string
WorkspaceImage string
JWTSecret string
SessionSecret string
GitHubApp experimental.GithubApp
}

expectation := Expectation{
EnableLocalApp: true,
DisableDynamicAuthProviderLogin: true,
DefaultBaseImageRegistryWhiteList: []string{"some-registry"},
WorkspaceImage: "some-workspace-image",
JWTSecret: "some-jwt-secret",
SessionSecret: "some-session-secret",
GitHubApp: experimental.GithubApp{
AppId: 123,
AuthProviderId: "some-auth-provider-id",
BaseUrl: "some-base-url",
CertPath: "some-cert-path",
Enabled: true,
LogLevel: "some-log-level",
MarketplaceName: "some-marketplace-name",
WebhookSecret: "some-webhook-secret",
CertSecretName: "some-cert-secret-name",
},
}

ctx, err := common.NewRenderContext(config.Config{
Experimental: &experimental.Config{
WebApp: &experimental.WebAppConfig{
Server: &experimental.ServerConfig{
DisableDynamicAuthProviderLogin: expectation.DisableDynamicAuthProviderLogin,
EnableLocalApp: expectation.EnableLocalApp,
DefaultBaseImageRegistryWhiteList: expectation.DefaultBaseImageRegistryWhiteList,
WorkspaceDefaults: experimental.WorkspaceDefaults{
WorkspaceImage: expectation.WorkspaceImage,
},
OAuthServer: experimental.OAuthServer{
JWTSecret: expectation.JWTSecret,
},
Session: experimental.Session{
Secret: expectation.SessionSecret,
},
GithubApp: &expectation.GitHubApp,
},
},
},
}, versions.Manifest{}, "test_namespace")

require.NoError(t, err)
objs, err := configmap(ctx)
if err != nil {
t.Errorf("failed to generate configmap: %s\n", err)
}

configmap, ok := objs[0].(*corev1.ConfigMap)
if !ok {
t.Fatalf("rendering configmap did not return a configMap")
return
}

configJson, ok := configmap.Data["config.json"]
if ok == false {
t.Errorf("no %q key found in configmap data", "config.json")
}

var config ConfigSerialized
if err := json.Unmarshal([]byte(configJson), &config); err != nil {
t.Errorf("failed to unmarshal config json: %s", err)
}

actual := Expectation{
DisableDynamicAuthProviderLogin: config.DisableDynamicAuthProviderLogin,
EnableLocalApp: config.EnableLocalApp,
DefaultBaseImageRegistryWhiteList: config.DefaultBaseImageRegistryWhitelist,
WorkspaceImage: config.WorkspaceDefaults.WorkspaceImage,
JWTSecret: config.OAuthServer.JWTSecret,
SessionSecret: config.Session.Secret,
GitHubApp: experimental.GithubApp{
AppId: config.GitHubApp.AppId,
AuthProviderId: config.GitHubApp.AuthProviderId,
BaseUrl: config.GitHubApp.BaseUrl,
CertPath: config.GitHubApp.CertPath,
Enabled: config.GitHubApp.Enabled,
LogLevel: config.GitHubApp.LogLevel,
MarketplaceName: config.GitHubApp.MarketplaceName,
WebhookSecret: config.GitHubApp.WebhookSecret,
CertSecretName: config.GitHubApp.CertSecretName,
},
}

assert.Equal(t, expectation, actual)
}
51 changes: 31 additions & 20 deletions install/installer/pkg/config/v1/experimental/experimental.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,27 +70,38 @@ type WebAppConfig struct {
UsePodAffinity bool `json:"usePodAffinity"`
}

type WorkspaceDefaults struct {
WorkspaceImage string `json:"workspaceImage"`
}

type OAuthServer struct {
JWTSecret string `json:"jwtSecret"`
}

type Session struct {
Secret string `json:"secret"`
}

type GithubApp struct {
AppId int32 `json:"appId"`
AuthProviderId string `json:"authProviderId"`
BaseUrl string `json:"baseUrl"`
CertPath string `json:"certPath"`
Enabled bool `json:"enabled"`
LogLevel string `json:"logLevel"`
MarketplaceName string `json:"marketplaceName"`
WebhookSecret string `json:"webhookSecret"`
CertSecretName string `json:"certSecretName"`
}

type ServerConfig struct {
WorkspaceDefaults struct {
WorkspaceImage string `json:"workspaceImage"`
} `json:"workspaceDefaults"`
OAuthServer struct {
JWTSecret string `json:"jwtSecret"`
} `json:"oauthServer"`
Session struct {
Secret string `json:"secret"`
} `json:"session"`
GithubApp *struct {
AppId int32 `json:"appId"`
AuthProviderId string `json:"authProviderId"`
BaseUrl string `json:"baseUrl"`
CertPath string `json:"certPath"`
Enabled bool `json:"enabled"`
LogLevel string `json:"logLevel"`
MarketplaceName string `json:"marketplaceName"`
WebhookSecret string `json:"webhookSecret"`
CertSecretName string `json:"certSecretName"`
} `json:"githubApp"`
WorkspaceDefaults WorkspaceDefaults `json:"workspaceDefaults"`
OAuthServer OAuthServer `json:"oauthServer"`
Session Session `json:"session"`
GithubApp *GithubApp `json:"githubApp"`
DisableDynamicAuthProviderLogin bool `json:"disableDynamicAuthProviderLogin"`
EnableLocalApp bool `json:"enableLocalApp"`
DefaultBaseImageRegistryWhiteList []string `json:"defaultBaseImageRegistryWhitelist"`
}

type PublicAPIConfig struct {
Expand Down