Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/install/installer/cmd/validate_config.go
2498 views
1
// Copyright (c) 2021 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/config"
14
"github.com/spf13/cobra"
15
)
16
17
var validateConfigOpts struct {
18
Config string
19
}
20
21
// validateConfigCmd represents the cluster command
22
var validateConfigCmd = &cobra.Command{
23
Use: "config",
24
Short: "Validate the deployment configuration",
25
RunE: func(cmd *cobra.Command, args []string) error {
26
if validateConfigOpts.Config == "" {
27
log.Fatal("missing --config")
28
}
29
_, cfgVersion, cfg, err := loadConfig(validateConfigOpts.Config)
30
if err != nil {
31
return err
32
}
33
34
if err = runConfigValidation(cfgVersion, cfg); err != nil {
35
return err
36
}
37
38
return nil
39
},
40
}
41
42
// runConfigValidation this will run the validation and print any validation errors
43
// It's silent if everything is fine
44
func runConfigValidation(version string, cfg interface{}) error {
45
apiVersion, err := config.LoadConfigVersion(version)
46
if err != nil {
47
return err
48
}
49
50
res, err := config.Validate(apiVersion, cfg)
51
if err != nil {
52
return err
53
}
54
res.Marshal(os.Stdout)
55
if len(res.Fatal) > 0 {
56
return fmt.Errorf("configuration invalid")
57
}
58
59
return nil
60
}
61
62
func init() {
63
validateCmd.AddCommand(validateConfigCmd)
64
65
dir, err := os.Getwd()
66
if err != nil {
67
log.WithError(err).Fatal("Failed to get working directory")
68
}
69
70
validateCmd.PersistentFlags().StringVarP(&validateConfigOpts.Config, "config", "c", getEnvvar("GITPOD_INSTALLER_CONFIG", filepath.Join(dir, "gitpod.config.yaml")), "path to the config file")
71
}
72
73