-
Notifications
You must be signed in to change notification settings - Fork 784
/
step_helm_install.go
96 lines (84 loc) · 2.41 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
package cmd
import (
"fmt"
"github.com/jenkins-x/jx/pkg/jx/cmd/templates"
"github.com/jenkins-x/jx/pkg/log"
"github.com/jenkins-x/jx/pkg/util"
"github.com/spf13/cobra"
)
// StepHelmInstallOptions contains the command line flags
type StepHelmInstallOptions struct {
StepHelmOptions
Name string
Namespace string
Version string
Values []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 *CommonOptions) *cobra.Command {
options := StepHelmInstallOptions{
StepHelmOptions: StepHelmOptions{
StepOptions: 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()
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.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 = ""
}
err = o.Helm().InstallChart(chart, releaseName, ns, version, -1, o.Values, o.ValuesFiles, "", "", "")
if err != nil {
return err
}
log.Infof("Installed chart %s with name %s into namespace %s\n", util.ColorInfo(chart), util.ColorInfo(releaseName), util.ColorInfo(ns))
return nil
}