-
Notifications
You must be signed in to change notification settings - Fork 784
/
step_helm_install.go
117 lines (100 loc) · 3.03 KB
/
step_helm_install.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
package helm
import (
"fmt"
"github.com/jenkins-x/jx/v2/pkg/cmd/opts/step"
"github.com/jenkins-x/jx/v2/pkg/cmd/helper"
"github.com/jenkins-x/jx/v2/pkg/helm"
"github.com/jenkins-x/jx-logging/pkg/log"
"github.com/jenkins-x/jx/v2/pkg/cmd/opts"
"github.com/jenkins-x/jx/v2/pkg/cmd/templates"
"github.com/jenkins-x/jx/v2/pkg/util"
"github.com/spf13/cobra"
)
// StepHelmInstallOptions contains the command line flags
type StepHelmInstallOptions struct {
StepHelmOptions
Name string
Namespace string
Version string
Values []string
ValueStrings []string
ValuesFiles []string
}
var (
StepHelmInstallLong = templates.LongDesc(`
Installs the given chart
`)
StepHelmInstallExample = templates.Examples(`
# installs a helm chart
jx step helm install foo/bar
`)
)
func NewCmdStepHelmInstall(commonOpts *opts.CommonOptions) *cobra.Command {
options := StepHelmInstallOptions{
StepHelmOptions: StepHelmOptions{
StepOptions: step.StepOptions{
CommonOptions: commonOpts,
},
},
}
cmd := &cobra.Command{
Use: "install",
Short: "Installs the given chart",
Aliases: []string{""},
Long: StepHelmInstallLong,
Example: StepHelmInstallExample,
Run: func(cmd *cobra.Command, args []string) {
options.Cmd = cmd
options.Args = args
err := options.Run()
helper.CheckErr(err)
},
}
options.addStepHelmFlags(cmd)
cmd.Flags().StringVarP(&options.Name, "name", "n", "", "The name of the release to install")
cmd.Flags().StringVarP(&options.Version, "version", "v", "", "The version to install. Defaults to the latest")
cmd.Flags().StringVarP(&options.Namespace, "namespace", "", "", "The namespace to install into. Defaults to the current namespace")
cmd.Flags().StringArrayVarP(&options.Values, "set", "", []string{}, "The values to override in the helm chart")
cmd.Flags().StringArrayVarP(&options.ValueStrings, "set-string", "", []string{}, "The STRING values to override in the helm chart")
cmd.Flags().StringArrayVarP(&options.ValuesFiles, "set-file", "", []string{}, "The values files to override values in the helm chart")
return cmd
}
func (o *StepHelmInstallOptions) Run() error {
args := o.Args
if len(args) == 0 {
return fmt.Errorf("Missing chart argument")
}
err := o.RegisterReleaseCRD()
if err != nil {
return err
}
chart := args[0]
releaseName := o.Name
ns := o.Namespace
if ns == "" {
_, ns, err = o.KubeClientAndNamespace()
if err != nil {
return err
}
}
version := o.Version
if o.Version == "" {
version = ""
}
SetValues, setStrings := o.getChartValues(ns)
helmOptions := helm.InstallChartOptions{
Chart: chart,
ReleaseName: releaseName,
Version: version,
Ns: ns,
SetValues: append(SetValues, o.Values...),
SetStrings: append(setStrings, o.ValueStrings...),
ValueFiles: o.ValuesFiles,
}
err = o.InstallChartWithOptions(helmOptions)
if err != nil {
return err
}
log.Logger().Infof("Installed chart %s with name %s into namespace %s", util.ColorInfo(chart), util.ColorInfo(releaseName), util.ColorInfo(ns))
return nil
}