github.com/olli-ai/jx/v2@v2.0.400-0.20210921045218-14731b4dd448/pkg/cmd/create/create_addon_kubeless.go (about) 1 package create 2 3 import ( 4 "strings" 5 6 "github.com/olli-ai/jx/v2/pkg/cmd/create/options" 7 8 "github.com/olli-ai/jx/v2/pkg/cmd/helper" 9 10 "github.com/olli-ai/jx/v2/pkg/helm" 11 12 "github.com/pkg/errors" 13 "github.com/spf13/cobra" 14 15 "github.com/olli-ai/jx/v2/pkg/cmd/opts" 16 "github.com/olli-ai/jx/v2/pkg/cmd/templates" 17 "github.com/olli-ai/jx/v2/pkg/kube" 18 "github.com/olli-ai/jx/v2/pkg/util" 19 ) 20 21 const ( 22 defaultKubelessNamespace = "kubeless" 23 defaultKubelessReleaseName = "kubeless" 24 defaultKubelessVersion = "" 25 ) 26 27 var ( 28 createAddonKubelessLong = templates.LongDesc(` 29 Creates the kubeless addon for serverless on Kubernetes 30 `) 31 32 createAddonKubelessExample = templates.Examples(` 33 # Create the kubeless addon in the ` + defaultKubelessNamespace + ` namespace 34 jx create addon kubeless 35 36 # Create the kubeless addon in a custom namespace 37 jx create addon kubeless -n mynamespace 38 `) 39 ) 40 41 // CreateAddonKubelessOptions the options for the create spring command 42 type CreateAddonKubelessOptions struct { 43 CreateAddonOptions 44 45 Chart string 46 } 47 48 // NewCmdCreateAddonKubeless creates a command object for the "create" command 49 func NewCmdCreateAddonKubeless(commonOpts *opts.CommonOptions) *cobra.Command { 50 options := &CreateAddonKubelessOptions{ 51 CreateAddonOptions: CreateAddonOptions{ 52 CreateOptions: options.CreateOptions{ 53 CommonOptions: commonOpts, 54 }, 55 }, 56 } 57 58 cmd := &cobra.Command{ 59 Use: "kubeless", 60 Short: "Create a kubeless addon for hosting Git repositories", 61 Aliases: []string{"env"}, 62 Long: createAddonKubelessLong, 63 Example: createAddonKubelessExample, 64 Run: func(cmd *cobra.Command, args []string) { 65 options.Cmd = cmd 66 options.Args = args 67 err := options.Run() 68 helper.CheckErr(err) 69 }, 70 } 71 72 options.addFlags(cmd, defaultKubelessNamespace, defaultKubelessReleaseName, defaultKubelessVersion) 73 74 cmd.Flags().StringVarP(&options.Chart, optionChart, "c", kube.ChartKubeless, "The name of the chart to use") 75 return cmd 76 } 77 78 // Run implements the command 79 func (o *CreateAddonKubelessOptions) Run() error { 80 if o.ReleaseName == "" { 81 return util.MissingOption(optionRelease) 82 } 83 if o.Chart == "" { 84 return util.MissingOption(optionChart) 85 } 86 err := o.EnsureHelm() 87 if err != nil { 88 return errors.Wrap(err, "failed to ensure that Helm is present") 89 } 90 values := []string{"rbac.create=true"} 91 setValues := strings.Split(o.SetValues, ",") 92 values = append(values, setValues...) 93 helmOptions := helm.InstallChartOptions{ 94 ReleaseName: o.ReleaseName, 95 Chart: o.Chart, 96 Version: o.Version, 97 Ns: o.Namespace, 98 SetValues: values, 99 } 100 err = o.InstallChartWithOptions(helmOptions) 101 if err != nil { 102 return err 103 } 104 return nil 105 }