Path: blob/main/install/installer/pkg/components/ws-proxy/configmap.go
2501 views
// Copyright (c) 2021 Gitpod GmbH. All rights reserved.1// Licensed under the GNU Affero General Public License (AGPL).2// See License.AGPL.txt in the project root for license information.34package wsproxy56import (7"fmt"8"time"910"github.com/gitpod-io/gitpod/installer/pkg/components/workspace"11wsmanagermk2 "github.com/gitpod-io/gitpod/installer/pkg/components/ws-manager-mk2"12configv1 "github.com/gitpod-io/gitpod/installer/pkg/config/v1"13"github.com/gitpod-io/gitpod/installer/pkg/config/v1/experimental"1415"github.com/gitpod-io/gitpod/common-go/baseserver"16"github.com/gitpod-io/gitpod/common-go/util"17"github.com/gitpod-io/gitpod/installer/pkg/common"18"github.com/gitpod-io/gitpod/ws-proxy/pkg/config"19"github.com/gitpod-io/gitpod/ws-proxy/pkg/proxy"2021corev1 "k8s.io/api/core/v1"22metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"23"k8s.io/apimachinery/pkg/runtime"24)2526func configmap(ctx *common.RenderContext) ([]runtime.Object, error) {27header := HostHeader28blobServeHost := fmt.Sprintf("ide.%s", ctx.Config.Domain)29gitpodInstallationHostName := ctx.Config.Domain3031installationShortNameSuffix := ""32if ctx.Config.Metadata.InstallationShortname != "" && ctx.Config.Metadata.InstallationShortname != configv1.InstallationShortNameOldDefault {33installationShortNameSuffix = "-" + ctx.Config.Metadata.InstallationShortname34}3536gitpodInstallationWorkspaceHostSuffix := fmt.Sprintf(".ws%s.%s", installationShortNameSuffix, ctx.Config.Domain)37gitpodInstallationWorkspaceHostSuffixRegex := fmt.Sprintf("\\.ws[^\\.]*\\.%s", ctx.Config.Domain)3839wsManagerConfig := &config.WorkspaceManagerConn{40Addr: fmt.Sprintf("ws-manager-mk2:%d", wsmanagermk2.RPCPort),41TLS: struct {42CA string "json:\"ca\""43Cert string "json:\"crt\""44Key string "json:\"key\""45}{46CA: "/ws-manager-client-tls-certs/ca.crt",47Cert: "/ws-manager-client-tls-certs/tls.crt",48Key: "/ws-manager-client-tls-certs/tls.key",49},50}5152ctx.WithExperimental(func(ucfg *experimental.Config) error {53if ucfg.Workspace == nil {54return nil55}56if ucfg.Workspace.WSProxy.IngressHeader != "" {57header = ucfg.Workspace.WSProxy.IngressHeader58}59if ucfg.Workspace.WSProxy.BlobServeHost != "" {60blobServeHost = ucfg.Workspace.WSProxy.BlobServeHost61}62if ucfg.Workspace.WSProxy.GitpodInstallationHostName != "" {63gitpodInstallationHostName = ucfg.Workspace.WSProxy.GitpodInstallationHostName64}65if ucfg.Workspace.WSProxy.GitpodInstallationWorkspaceHostSuffix != "" {66gitpodInstallationWorkspaceHostSuffix = ucfg.Workspace.WSProxy.GitpodInstallationWorkspaceHostSuffix67}68if ucfg.Workspace.WSProxy.GitpodInstallationWorkspaceHostSuffixRegex != "" {69gitpodInstallationWorkspaceHostSuffixRegex = ucfg.Workspace.WSProxy.GitpodInstallationWorkspaceHostSuffixRegex70}7172return nil73})7475// todo(sje): wsManagerProxy seems to be unused76wspcfg := config.Config{77Namespace: ctx.Namespace,78Ingress: proxy.HostBasedIngressConfig{79HTTPAddress: fmt.Sprintf("0.0.0.0:%d", HTTPProxyPort),80HTTPSAddress: fmt.Sprintf("0.0.0.0:%d", HTTPSProxyPort),81Header: header,82},83Proxy: proxy.Config{84HTTPS: struct {85Key string `json:"key"`86Certificate string `json:"crt"`87}{88Key: "/mnt/certificates/tls.key",89Certificate: "/mnt/certificates/tls.crt",90},91TransportConfig: &proxy.TransportConfig{92ConnectTimeout: util.Duration(time.Second * 10),93IdleConnTimeout: util.Duration(time.Minute),94MaxIdleConns: 0,95MaxIdleConnsPerHost: 100,96},97BlobServer: &proxy.BlobServerConfig{98Scheme: "https",99Host: blobServeHost,100PathPrefix: "/blobserve",101},102GitpodInstallation: &proxy.GitpodInstallation{103Scheme: "https",104HostName: gitpodInstallationHostName,105WorkspaceHostSuffix: gitpodInstallationWorkspaceHostSuffix,106WorkspaceHostSuffixRegex: gitpodInstallationWorkspaceHostSuffixRegex,107},108WorkspacePodConfig: &proxy.WorkspacePodConfig{109TheiaPort: workspace.ContainerPort,110IDEDebugPort: workspace.IDEDebugPort,111SupervisorPort: workspace.SupervisorPort,112SupervisorDebugPort: workspace.SupervisorDebugPort,113DebugWorkspaceProxyPort: workspace.DebugWorkspaceProxyPort,114SupervisorImage: ctx.ImageName(ctx.Config.Repository, workspace.SupervisorImage, ctx.VersionManifest.Components.Workspace.Supervisor.Version),115},116BuiltinPages: proxy.BuiltinPagesConfig{117Location: "/app/public",118},119},120PProfAddr: common.LocalhostAddressFromPort(baseserver.BuiltinDebugPort),121PrometheusAddr: common.LocalhostPrometheusAddr(),122ReadinessProbeAddr: fmt.Sprintf(":%v", ReadinessPort),123WorkspaceManager: wsManagerConfig,124}125126if ctx.Config.SSHGatewayCAKey != nil {127wspcfg.Proxy.SSHGatewayCAKeyFile = "/mnt/ca-key/ca.key"128}129130fc, err := common.ToJSONString(wspcfg)131if err != nil {132return nil, fmt.Errorf("failed to marshal ws-proxy config: %w", err)133}134135return []runtime.Object{136&corev1.ConfigMap{137TypeMeta: common.TypeMetaConfigmap,138ObjectMeta: metav1.ObjectMeta{139Name: Component,140Namespace: ctx.Namespace,141Labels: common.CustomizeLabel(ctx, Component, common.TypeMetaConfigmap),142Annotations: common.CustomizeAnnotation(ctx, Component, common.TypeMetaConfigmap),143},144Data: map[string]string{145"config.json": string(fc),146},147},148}, nil149}150151152