Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/install/installer/cmd/ideconfigmap.go
2498 views
1
// Copyright (c) 2024 Gitpod GmbH. All rights reserved.
2
// Licensed under the GNU Affero General Public License (AGPL).
3
// See License.AGPL.txt in the project root for license information.
4
5
package cmd
6
7
import (
8
"fmt"
9
"os"
10
"path/filepath"
11
12
"github.com/gitpod-io/gitpod/common-go/log"
13
"github.com/gitpod-io/gitpod/installer/pkg/common"
14
ide_service "github.com/gitpod-io/gitpod/installer/pkg/components/ide-service"
15
16
"github.com/spf13/cobra"
17
)
18
19
var ideOpts struct {
20
ConfigFN string
21
Namespace string
22
UseExperimentalConfig bool
23
}
24
25
// ideConfigmapCmd generates ide-configmap.json
26
var ideConfigmapCmd = &cobra.Command{
27
Use: "ide-configmap",
28
Hidden: true,
29
Short: "render ide-configmap.json",
30
RunE: func(cmd *cobra.Command, args []string) error {
31
renderCtx, err := getRenderCtx(ideOpts.ConfigFN, ideOpts.Namespace, ideOpts.UseExperimentalConfig)
32
if err != nil {
33
return err
34
}
35
36
ideConfig, err := ide_service.GenerateIDEConfigmap(renderCtx)
37
if err != nil {
38
return err
39
}
40
41
fc, err := common.ToJSONString(ideConfig)
42
if err != nil {
43
return fmt.Errorf("failed to marshal ide-config config: %w", err)
44
}
45
46
fmt.Println(string(fc))
47
return nil
48
},
49
}
50
51
func getRenderCtx(configFN, namespace string, useExperimentalConfig bool) (*common.RenderContext, error) {
52
_, _, cfg, err := loadConfig(configFN)
53
if err != nil {
54
return nil, err
55
}
56
57
if cfg.Experimental != nil {
58
if useExperimentalConfig {
59
fmt.Fprintf(os.Stderr, "rendering using experimental config\n")
60
} else {
61
fmt.Fprintf(os.Stderr, "ignoring experimental config. Use `--use-experimental-config` to include the experimental section in config\n")
62
cfg.Experimental = nil
63
}
64
}
65
versionMF, err := getVersionManifest()
66
if err != nil {
67
return nil, err
68
}
69
return common.NewRenderContext(*cfg, *versionMF, namespace)
70
}
71
72
func init() {
73
rootCmd.AddCommand(ideConfigmapCmd)
74
75
dir, err := os.Getwd()
76
if err != nil {
77
log.WithError(err).Fatal("Failed to get working directory")
78
}
79
80
ideConfigmapCmd.PersistentFlags().StringVarP(&ideOpts.ConfigFN, "config", "c", getEnvvar("GITPOD_INSTALLER_CONFIG", filepath.Join(dir, "gitpod.config.yaml")), "path to the config file, use - for stdin")
81
ideConfigmapCmd.PersistentFlags().StringVarP(&ideOpts.Namespace, "namespace", "n", getEnvvar("NAMESPACE", "default"), "namespace to deploy to")
82
ideConfigmapCmd.Flags().BoolVar(&ideOpts.UseExperimentalConfig, "use-experimental-config", false, "enable the use of experimental config that is prone to be changed")
83
}
84
85