-
Notifications
You must be signed in to change notification settings - Fork 1
/
create_addon.go
87 lines (75 loc) · 2.08 KB
/
create_addon.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
package cmd
import (
"fmt"
"io"
cmdutil "github.com/jenkins-x/jx/pkg/jx/cmd/util"
"github.com/jenkins-x/jx/pkg/kube"
"github.com/jenkins-x/jx/pkg/util"
"github.com/spf13/cobra"
)
// CreateAddonOptions the options for the create spring command
type CreateAddonOptions struct {
CreateOptions
Namespace string
Version string
ReleaseName string
HelmUpdate bool
}
// NewCmdCreateAddon creates a command object for the "create" command
func NewCmdCreateAddon(f cmdutil.Factory, out io.Writer, errOut io.Writer) *cobra.Command {
options := &CreateAddonOptions{
CreateOptions: CreateOptions{
CommonOptions: CommonOptions{
Factory: f,
Out: out,
Err: errOut,
},
},
}
cmd := &cobra.Command{
Use: "addon",
Short: "Creates an addon",
Aliases: []string{"scm"},
Run: func(cmd *cobra.Command, args []string) {
options.Cmd = cmd
options.Args = args
err := options.Run()
cmdutil.CheckErr(err)
},
}
cmd.AddCommand(NewCmdCreateAddonCDX(f, out, errOut))
cmd.AddCommand(NewCmdCreateAddonGitea(f, out, errOut))
options.addFlags(cmd)
return cmd
}
func (options *CreateAddonOptions) addFlags(cmd *cobra.Command) {
cmd.Flags().StringVarP(&options.Namespace, "namespace", "n", "", "The Namespace to install into")
cmd.Flags().StringVarP(&options.ReleaseName, optionRelease, "r", "gitea", "The chart release name")
cmd.Flags().BoolVarP(&options.HelmUpdate, "helm-update", "", true, "Should we run helm update first to ensure we use the latest version")
}
// Run implements this command
func (o *CreateAddonOptions) Run() error {
args := o.Args
if len(args) == 0 {
return o.Cmd.Help()
}
for _, arg := range args {
err := o.CreateAddon(arg)
if err != nil {
return err
}
}
return nil
}
func (o *CreateAddonOptions) CreateAddon(arg string) error {
charts := kube.AddonCharts
chart := charts[arg]
if chart == "" {
return util.InvalidArg(arg, util.SortedMapKeys(charts))
}
err := o.installChart(arg, chart, o.Version, o.Namespace, o.HelmUpdate)
if err != nil {
return fmt.Errorf("Failed to install chart %s: %s", chart, err)
}
return nil
}