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]: build the config #12687

Merged
merged 3 commits into from
Sep 20, 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
35 changes: 35 additions & 0 deletions install/installer/cmd/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Cmd

Publicly available commands are part of our user contract. They use [Cobra](https://cobra.dev/) to build the Golang CLI commands.

## Commands

### config

These are designed to manipulate configuration files and generate a configuration file that can be used to install Gitpod.

#### init

> This replaces `init`, which is now deprecated

This should be run first. This will generate a new `gitpod.config.yaml` file with the default values configured.

#### build-from-envvars

This builds the config from environment variables.

#### cluster

Cluster commands are designed to deploy a Kubernetes resource to the cluster and generate the config value based upon the result. Typically (although not exclusively), these will be Jobs.

##### shiftfs

Detects whether ShiftFS is supported on the cluster for building images. If not, this will default to Fuse.

#### files

Files commands are designed to be run against the file structure. They may be run directly on the node, or by mounting the file system as a volume in a pod.

##### containerd

Detects the containerd settings for a cluster. This will return the location of the containerd socket and the path to the directory.
40 changes: 40 additions & 0 deletions install/installer/cmd/config_build-from-envvars.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// 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 cmd

import (
"github.com/gitpod-io/gitpod/installer/pkg/config"
"github.com/spf13/cobra"
)

// configBuildFromEnvvarsCmd represents the validate command
var configBuildFromEnvvarsCmd = &cobra.Command{
Use: "build-from-envvars",
Short: "Build configuration from environment variables",
RunE: func(cmd *cobra.Command, args []string) error {
if _, err := configFileExistsAndInit(); err != nil {
return err
}

_, version, cfg, err := loadConfig(configOpts.ConfigFile)
if err != nil {
return err
}

apiVersion, err := config.LoadConfigVersion(version)
if err != nil {
return err
}

if err := apiVersion.BuildFromEnvvars(cfg); err != nil {
return err
}

return saveConfigFile(cfg)
},
}

func init() {
configCmd.AddCommand(configBuildFromEnvvarsCmd)
}
2 changes: 1 addition & 1 deletion install/installer/cmd/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ func init() {
}

renderCmd.PersistentFlags().StringVarP(&renderOpts.ConfigFN, "config", "c", getEnvvar("GITPOD_INSTALLER_CONFIG", filepath.Join(dir, "gitpod.config.yaml")), "path to the config file, use - for stdin")
renderCmd.PersistentFlags().StringVarP(&renderOpts.Namespace, "namespace", "n", "default", "namespace to deploy to")
renderCmd.PersistentFlags().StringVarP(&renderOpts.Namespace, "namespace", "n", getEnvvar("NAMESPACE", "default"), "namespace to deploy to")
renderCmd.Flags().BoolVar(&renderOpts.ValidateConfigDisabled, "no-validation", false, "if set, the config will not be validated before running")
renderCmd.Flags().BoolVar(&renderOpts.UseExperimentalConfig, "use-experimental-config", false, "enable the use of experimental config that is prone to be changed")
renderCmd.Flags().StringVar(&renderOpts.FilesDir, "output-split-files", "", "path to output individual Kubernetes manifests to")
Expand Down
2 changes: 1 addition & 1 deletion install/installer/cmd/validate_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,5 +111,5 @@ func init() {

validateClusterCmd.PersistentFlags().StringVar(&validateClusterOpts.Kube.Config, "kubeconfig", "", "path to the kubeconfig file")
validateClusterCmd.PersistentFlags().StringVarP(&validateClusterOpts.Config, "config", "c", getEnvvar("GITPOD_INSTALLER_CONFIG", filepath.Join(dir, "gitpod.config.yaml")), "path to the config file")
validateClusterCmd.PersistentFlags().StringVarP(&validateClusterOpts.Namespace, "namespace", "n", "default", "namespace to deploy to")
validateClusterCmd.PersistentFlags().StringVarP(&validateClusterOpts.Namespace, "namespace", "n", getEnvvar("NAMESPACE", "default"), "namespace to deploy to")
}
1 change: 1 addition & 0 deletions install/installer/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ require (
github.com/go-redis/redis/v7 v7.4.1 // indirect
github.com/go-redis/redis/v8 v8.11.5 // indirect
github.com/go-sql-driver/mysql v1.6.0 // indirect
github.com/go-test/deep v1.0.8
github.com/gobwas/glob v0.2.3 // indirect
github.com/goccy/go-yaml v1.9.5 // indirect
github.com/godbus/dbus/v5 v5.0.6 // indirect
Expand Down
2 changes: 2 additions & 0 deletions install/installer/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions install/installer/pkg/config/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ type ConfigVersion interface {
// CheckDeprecated checks for deprecated config params.
// Returns key/value pair of deprecated params/values and any error messages (used for conflicting params)
CheckDeprecated(cfg interface{}) (map[string]interface{}, []string)

// BuildFromEnvvars builds the configuration file from assigned envvars
BuildFromEnvvars(cfg interface{}) error
}

// AddVersion adds a new version.
Expand Down
13 changes: 10 additions & 3 deletions install/installer/pkg/config/v1/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,28 @@ func (v version) Factory() interface{} {
},
}
}

const (
defaultRepositoryUrl = "eu.gcr.io/gitpod-core-dev/build"
defaultOpenVSXURL = "https://open-vsx.org"
defaultMetadataRegion = "local"
)

func (v version) Defaults(in interface{}) error {
cfg, ok := in.(*Config)
if !ok {
return config.ErrInvalidType
}

cfg.Kind = InstallationFull
cfg.Repository = "eu.gcr.io/gitpod-core-dev/build"
cfg.Repository = defaultRepositoryUrl
cfg.Observability = Observability{
LogLevel: LogLevelInfo,
}
cfg.Certificate.Kind = ObjectRefSecret
cfg.Certificate.Name = "https-certificates"
cfg.Database.InCluster = pointer.Bool(true)
cfg.Metadata.Region = "local"
cfg.Metadata.Region = defaultMetadataRegion
cfg.Metadata.InstallationShortname = InstallationShortNameOldDefault // TODO(gpl): we're tied to "default" here because that's what we put into static bridges in the past
cfg.ObjectStorage.InCluster = pointer.Bool(true)
cfg.ObjectStorage.Resources = &Resources{
Expand All @@ -69,7 +76,7 @@ func (v version) Defaults(in interface{}) error {
cfg.Workspace.PVC.Size = resource.MustParse("30Gi")
cfg.Workspace.PVC.StorageClass = ""
cfg.Workspace.PVC.SnapshotClass = ""
cfg.OpenVSX.URL = "https://open-vsx.org"
cfg.OpenVSX.URL = defaultOpenVSXURL
cfg.DisableDefinitelyGP = true

return nil
Expand Down
Loading