Skip to content

WIP: [Installer]: add a render apply command #8379

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

Closed
wants to merge 2 commits into from
Closed
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
71 changes: 71 additions & 0 deletions components/installer/cmd/render_apply.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// Copyright (c) 2022 Gitpod GmbH. All rights reserved.
// Licensed under the GNU Affero General Public License (AGPL).
// See License-AGPL.txt in the project root for license information.

package cmd

import (
"fmt"
"github.com/gitpod-io/gitpod/installer/pkg/helm"
"github.com/pkg/errors"
"github.com/spf13/cobra"
"helm.sh/helm/v3/pkg/chart"
)

var renderApplyOpts struct {
WriteOnly bool
}

var applyCmd = &cobra.Command{
Use: "apply",
Short: "Applies a configuration to your cluster",
RunE: func(cmd *cobra.Command, args []string) error {
// Get the version manifest
versionMF, err := getVersionManifest()
if err != nil {
return err
}

// Render the Kubernetes objects
objs, err := runRenderCmd()
if err != nil {
return err
}

// In a temp dir, build a Helm release
dir, err := helm.CreateHelmChart(
chart.Metadata{
APIVersion: "v2",
Name: "Gitpod",
Description: "Always ready-to-code",
Version: "1.0.0",
AppVersion: versionMF.Version,
},
objs,
)
if err != nil {
return err
}

if renderApplyOpts.WriteOnly {
fmt.Println(fmt.Sprintf(`Installer config rendered to %s.

This can now be installed using Helm.`, *dir))
return nil
}

// Install/upgrade the Helm release
err = helm.InstallOrUpgrade("gitpod", renderOpts.Namespace, *dir)
if err != nil {
return errors.Wrap(err, "INSTALLATION FAILED")
}

return nil
},
}

func init() {
renderCmd.AddCommand(applyCmd)

applyCmd.Flags().BoolVar(&renderApplyOpts.WriteOnly, "write-only", false, "if set, the config will be written to disk only and will not be installed")
}
43 changes: 26 additions & 17 deletions install/installer/cmd/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,7 @@ A config file is required which can be generated with the init command.`,
# Install Gitpod into a non-default namespace.
gitpod-installer render --config config.yaml --namespace gitpod | kubectl apply -f -`,
RunE: func(cmd *cobra.Command, args []string) error {
_, cfgVersion, cfg, err := loadConfig(renderOpts.ConfigFN)
if err != nil {
return err
}

if cfg.Experimental != nil {
if renderOpts.UseExperimentalConfig {
fmt.Fprintf(os.Stderr, "rendering using experimental config - here be dragons\n")
} else {
fmt.Fprintf(os.Stderr, "config contains experimental options - ignoring them\n")
cfg.Experimental = nil
}
}

yaml, err := renderKubernetesObjects(cfgVersion, cfg)
yaml, err := runRenderCmd()
if err != nil {
return err
}
Expand All @@ -65,6 +51,29 @@ A config file is required which can be generated with the init command.`,
},
}

func runRenderCmd() ([]string, error) {
_, cfgVersion, cfg, err := loadConfig(renderOpts.ConfigFN)
if err != nil {
return nil, err
}

if cfg.Experimental != nil {
if renderOpts.UseExperimentalConfig {
fmt.Fprintf(os.Stderr, "rendering using experimental config - here be dragons\n")
} else {
fmt.Fprintf(os.Stderr, "config contains experimental options - ignoring them\n")
cfg.Experimental = nil
}
}

yaml, err := renderKubernetesObjects(cfgVersion, cfg)
if err != nil {
return nil, err
}

return yaml, nil
}

func loadConfig(cfgFN string) (rawCfg interface{}, cfgVersion string, cfg *configv1.Config, err error) {
rawCfg, cfgVersion, err = config.Load(cfgFN)
if err != nil {
Expand Down Expand Up @@ -177,6 +186,6 @@ func init() {

renderCmd.PersistentFlags().StringVarP(&renderOpts.ConfigFN, "config", "c", os.Getenv("GITPOD_INSTALLER_CONFIG"), "path to the config file")
renderCmd.PersistentFlags().StringVarP(&renderOpts.Namespace, "namespace", "n", "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, "danger-use-unsupported-config", false, "enable use of unsupported config")
renderCmd.PersistentFlags().BoolVar(&renderOpts.ValidateConfigDisabled, "no-validation", false, "if set, the config will not be validated before running")
renderCmd.PersistentFlags().BoolVar(&renderOpts.UseExperimentalConfig, "danger-use-unsupported-config", false, "enable use of unsupported config")
}
6 changes: 2 additions & 4 deletions install/installer/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ require (
sigs.k8s.io/yaml v1.2.0
)

require github.com/pkg/errors v0.9.1

require (
cloud.google.com/go v0.83.0 // indirect
cloud.google.com/go/storage v1.15.0 // indirect
Expand All @@ -52,7 +54,6 @@ require (
github.com/Microsoft/hcsshim v0.8.18 // indirect
github.com/PuerkitoBio/purell v1.1.1 // indirect
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect
github.com/StackExchange/wmi v0.0.0-20210224194228-fe8f1750fd46 // indirect
github.com/allegro/bigcache v1.2.1 // indirect
github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d // indirect
github.com/beorn7/perks v1.0.1 // indirect
Expand Down Expand Up @@ -93,7 +94,6 @@ require (
github.com/gitpod-io/gitpod/registry-facade v0.0.0-00010101000000-000000000000 // indirect
github.com/go-errors/errors v1.0.1 // indirect
github.com/go-logr/logr v0.4.0 // indirect
github.com/go-ole/go-ole v1.2.5 // indirect
github.com/go-openapi/jsonpointer v0.19.5 // indirect
github.com/go-openapi/jsonreference v0.19.5 // indirect
github.com/go-openapi/swag v0.19.14 // indirect
Expand Down Expand Up @@ -164,7 +164,6 @@ require (
github.com/opencontainers/selinux v1.8.2 // indirect
github.com/opentracing/opentracing-go v1.2.0 // indirect
github.com/peterbourgon/diskv v2.0.1+incompatible // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_golang v1.11.0 // indirect
github.com/prometheus/client_model v0.2.0 // indirect
Expand All @@ -174,7 +173,6 @@ require (
github.com/rubenv/sql-migrate v0.0.0-20210614095031-55d5740dbbcc // indirect
github.com/russross/blackfriday v1.5.2 // indirect
github.com/seccomp/libseccomp-golang v0.9.1 // indirect
github.com/shirou/gopsutil v2.20.9+incompatible // indirect
github.com/shopspring/decimal v1.2.0 // indirect
github.com/sirupsen/logrus v1.8.1 // indirect
github.com/spf13/cast v1.3.1 // indirect
Expand Down
Loading