-
Notifications
You must be signed in to change notification settings - Fork 787
/
step_override_requirements.go
72 lines (58 loc) · 2.09 KB
/
step_override_requirements.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package step
import (
"github.com/jenkins-x/jx-logging/pkg/log"
"github.com/jenkins-x/jx/v2/pkg/cloud/gke"
"github.com/jenkins-x/jx/v2/pkg/cmd/helper"
"github.com/jenkins-x/jx/v2/pkg/cmd/opts"
"github.com/jenkins-x/jx/v2/pkg/config"
"github.com/pkg/errors"
"github.com/spf13/cobra"
)
// StepOverrideRequirementsOptions contains the command line flags
type StepOverrideRequirementsOptions struct {
*opts.CommonOptions
Dir string
}
// NewCmdStepOverrideRequirements creates the `jx step verify pod` command
func NewCmdStepOverrideRequirements(commonOpts *opts.CommonOptions) *cobra.Command {
options := &StepOverrideRequirementsOptions{
CommonOptions: commonOpts,
}
cmd := &cobra.Command{
Use: "override-requirements",
Short: "Overrides requirements with environment variables to be persisted in the `jx-requirements.yml`",
Run: func(cmd *cobra.Command, args []string) {
options.Cmd = cmd
options.Args = args
err := options.Run()
helper.CheckErr(err)
},
}
cmd.Flags().StringVarP(&options.Dir, "dir", "d", ".", "the directory to look for the install requirements file")
return cmd
}
// Run implements this command
func (o *StepOverrideRequirementsOptions) Run() error {
requirements, requirementsFileName, err := config.LoadRequirementsConfig(o.Dir, config.DefaultFailOnValidationError)
if err != nil {
return err
}
requirements, err = o.overrideRequirements(requirements, requirementsFileName)
if err != nil {
return err
}
return nil
}
// gatherRequirements gathers cluster requirements and connects to the cluster if required
func (o *StepOverrideRequirementsOptions) overrideRequirements(requirements *config.RequirementsConfig, requirementsFileName string) (*config.RequirementsConfig, error) {
log.Logger().Debug("Overriding Requirements...")
requirements.OverrideRequirementsFromEnvironment(func() gke.GClouder {
return o.GCloud()
})
log.Logger().Debugf("saving %s", requirementsFileName)
err := requirements.SaveConfig(requirementsFileName)
if err != nil {
return nil, errors.Wrapf(err, "save config %s", requirementsFileName)
}
return requirements, nil
}