Path: blob/main/install/installer/pkg/config/v1/deprecations.go
2501 views
// Copyright (c) 2023 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 config56import (7"encoding/json"8"errors"9)1011type deprecatedField struct {12// Select the deprecated parameter. Returns whether param in use and it's value for the warning message - value should not be a pointer13Selector func(cfg *Config) (isInUse bool, msgValue any)14// Map the old value to the new value. If both are set, an error should be returned - this is optional15MapValue func(cfg *Config) error16}1718var deprecatedFields = map[string]deprecatedField{19"experimental.agentSmith": {20Selector: func(cfg *Config) (bool, any) {21val := cfg.Experimental.AgentSmith22return val != nil, val23},24MapValue: func(cfg *Config) error {25if cfg.Components != nil && cfg.Components.AgentSmith != nil {26return errors.New("cannot configure agent smith in both components and experimental")27}28if cfg.Components == nil {29cfg.Components = &Components{}30}31cfg.Components.AgentSmith = cfg.Experimental.AgentSmith32return nil33},34},35"experimental.common.podConfig": {36Selector: func(cfg *Config) (bool, any) {37val := cfg.Experimental.Common.PodConfig38// Output message as JSON39o, _ := json.Marshal(val)40return len(val) > 0, string(o)41},42MapValue: func(cfg *Config) error {43if cfg.Components != nil && cfg.Components.PodConfig != nil {44return errors.New("cannot set pod config in both components and experimental")45}46if cfg.Components == nil {47cfg.Components = &Components{}48}49// Need to convert types - same signature, but using the non-experimental object50cfg.Components.PodConfig = make(map[string]*PodConfig, 0)51for k, v := range cfg.Experimental.Common.PodConfig {52cfg.Components.PodConfig[k] = &PodConfig{53Replicas: v.Replicas,54Resources: v.Resources,55}56}57return nil58},59},60"experimental.ide.resolveLatest": {61Selector: func(cfg *Config) (bool, any) {62val := cfg.Experimental.IDE.ResolveLatest63return val != nil, *val64},65MapValue: func(cfg *Config) error {66if cfg.Components != nil && cfg.Components.IDE != nil && cfg.Components.IDE.ResolveLatest != nil {67return errors.New("cannot set resolve latest ide in both components and experimental")68}69if cfg.Components == nil {70cfg.Components = &Components{}71}72if cfg.Components.IDE == nil {73cfg.Components.IDE = &IDEComponents{}74}75cfg.Components.IDE.ResolveLatest = cfg.Experimental.IDE.ResolveLatest76return nil77},78},79"experimental.ide.ideMetrics.enabledErrorReporting": {80Selector: func(cfg *Config) (bool, any) {81val := cfg.Experimental.IDE.IDEMetricsConfig82return val != nil, val.EnabledErrorReporting83},84MapValue: func(cfg *Config) error {85if cfg.Components != nil && cfg.Components.IDE != nil && cfg.Components.IDE.Metrics != nil {86return errors.New("cannot set ide metrics in both component and experimental")87}88if cfg.Components == nil {89cfg.Components = &Components{}90}91if cfg.Components.IDE == nil {92cfg.Components.IDE = &IDEComponents{}93}94if cfg.Components.IDE.Metrics == nil {95cfg.Components.IDE.Metrics = &IDEMetrics{}96}97cfg.Components.IDE.Metrics.ErrorReportingEnabled = cfg.Experimental.IDE.IDEMetricsConfig.EnabledErrorReporting98return nil99},100},101"experimental.ide.ideProxy.serviceAnnotations": {102Selector: func(cfg *Config) (bool, any) {103val := cfg.Experimental.IDE.IDEProxyConfig.ServiceAnnotations104return len(val) > 0, val105},106MapValue: func(cfg *Config) error {107if cfg.Components != nil && cfg.Components.IDE != nil && cfg.Components.IDE.Proxy != nil && len(cfg.Components.IDE.Proxy.ServiceAnnotations) > 0 {108return errors.New("cannot set ide proxy service annotations in both components and experimental")109}110if cfg.Components == nil {111cfg.Components = &Components{}112}113if cfg.Components.IDE == nil {114cfg.Components.IDE = &IDEComponents{}115}116if cfg.Components.IDE.Proxy == nil {117cfg.Components.IDE.Proxy = &Proxy{}118}119cfg.Components.IDE.Proxy.ServiceAnnotations = cfg.Experimental.IDE.IDEProxyConfig.ServiceAnnotations120return nil121},122},123"experimental.ide.openvsxProxy.serviceAnnotations": {124Selector: func(cfg *Config) (bool, any) {125val := cfg.Experimental.IDE.VSXProxyConfig.ServiceAnnotations126return len(val) > 0, val127},128MapValue: func(cfg *Config) error {129if cfg.OpenVSX.Proxy != nil && len(cfg.OpenVSX.Proxy.ServiceAnnotations) > 0 {130return errors.New("cannot set openvsx proxy service annotations in both components and experimental")131}132if cfg.OpenVSX.Proxy == nil {133cfg.OpenVSX.Proxy = &OpenVSXProxy{}134}135cfg.OpenVSX.Proxy.ServiceAnnotations = cfg.Experimental.IDE.VSXProxyConfig.ServiceAnnotations136return nil137},138},139"experimental.webapp.proxy.serviceType": {140Selector: func(cfg *Config) (bool, any) {141val := cfg.Experimental.WebApp.ProxyConfig.ServiceType142return val != nil, *val143},144MapValue: func(cfg *Config) error {145if cfg.Components != nil && cfg.Components.Proxy != nil && cfg.Components.Proxy.Service != nil && cfg.Components.Proxy.Service.ServiceType != nil {146return errors.New("cannot set proxy service type in both components and experimental")147} else {148if cfg.Components == nil {149cfg.Components = &Components{}150}151if cfg.Components.Proxy == nil {152cfg.Components.Proxy = &ProxyComponent{}153}154if cfg.Components.Proxy.Service == nil {155cfg.Components.Proxy.Service = &ComponentTypeService{}156}157cfg.Components.Proxy.Service.ServiceType = cfg.Experimental.WebApp.ProxyConfig.ServiceType158}159return nil160},161},162"experimental.webapp.server.workspaceDefaults.workspaceImage": {163Selector: func(cfg *Config) (bool, any) {164workspaceImage := cfg.Experimental.WebApp.Server.WorkspaceDefaults.WorkspaceImage165return workspaceImage != "", workspaceImage166},167MapValue: func(cfg *Config) error {168if cfg.Workspace.WorkspaceImage != "" {169return errors.New("cannot set default workspace image in both workspaces and experimental")170}171cfg.Workspace.WorkspaceImage = cfg.Experimental.WebApp.Server.WorkspaceDefaults.WorkspaceImage172173return nil174},175},176"experimental.webapp.server.defaultBaseImageRegistryWhitelist": {177Selector: func(cfg *Config) (bool, any) {178registryAllowList := cfg.Experimental.WebApp.Server.DefaultBaseImageRegistryWhiteList179return registryAllowList != nil, registryAllowList180},181MapValue: func(cfg *Config) error {182if len(cfg.ContainerRegistry.PrivateBaseImageAllowList) > 0 {183return errors.New("cannot set allow list for private base image in both containerRegistry and experimental")184}185cfg.ContainerRegistry.PrivateBaseImageAllowList = cfg.Experimental.WebApp.Server.DefaultBaseImageRegistryWhiteList186187return nil188},189},190"objectStorage.maximumBackupCount": {191Selector: func(cfg *Config) (bool, any) {192val := cfg.ObjectStorage.MaximumBackupCount193return val != nil, *val194},195},196}197198// parseDeprecatedSelector recovers from a panic so we don't have to check for nested structs199func parseDeprecatedSelector(cfg *Config, field deprecatedField) (selected bool, val any) {200defer func() {201if r := recover(); r != nil {202selected = false203val = nil204}205}()206207return field.Selector(cfg)208}209210211