Path: blob/main/install/installer/cmd/validate_config.go
2498 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 cmd56import (7"fmt"8"os"9"path/filepath"1011"github.com/gitpod-io/gitpod/common-go/log"12"github.com/gitpod-io/gitpod/installer/pkg/config"13"github.com/spf13/cobra"14)1516var validateConfigOpts struct {17Config string18}1920// validateConfigCmd represents the cluster command21var validateConfigCmd = &cobra.Command{22Use: "config",23Short: "Validate the deployment configuration",24RunE: func(cmd *cobra.Command, args []string) error {25if validateConfigOpts.Config == "" {26log.Fatal("missing --config")27}28_, cfgVersion, cfg, err := loadConfig(validateConfigOpts.Config)29if err != nil {30return err31}3233if err = runConfigValidation(cfgVersion, cfg); err != nil {34return err35}3637return nil38},39}4041// runConfigValidation this will run the validation and print any validation errors42// It's silent if everything is fine43func runConfigValidation(version string, cfg interface{}) error {44apiVersion, err := config.LoadConfigVersion(version)45if err != nil {46return err47}4849res, err := config.Validate(apiVersion, cfg)50if err != nil {51return err52}53res.Marshal(os.Stdout)54if len(res.Fatal) > 0 {55return fmt.Errorf("configuration invalid")56}5758return nil59}6061func init() {62validateCmd.AddCommand(validateConfigCmd)6364dir, err := os.Getwd()65if err != nil {66log.WithError(err).Fatal("Failed to get working directory")67}6869validateCmd.PersistentFlags().StringVarP(&validateConfigOpts.Config, "config", "c", getEnvvar("GITPOD_INSTALLER_CONFIG", filepath.Join(dir, "gitpod.config.yaml")), "path to the config file")70}717273