github.com/olli-ai/jx/v2@v2.0.400-0.20210921045218-14731b4dd448/pkg/cmd/get/get_addon.go (about) 1 package get 2 3 import ( 4 "github.com/jenkins-x/jx-logging/pkg/log" 5 "github.com/olli-ai/jx/v2/pkg/addon" 6 "github.com/olli-ai/jx/v2/pkg/cmd/helper" 7 "github.com/spf13/cobra" 8 9 "github.com/olli-ai/jx/v2/pkg/cmd/opts" 10 "github.com/olli-ai/jx/v2/pkg/cmd/templates" 11 "github.com/olli-ai/jx/v2/pkg/kube" 12 ) 13 14 // GetAddonOptions the command line options 15 type GetAddonOptions struct { 16 Options 17 } 18 19 var ( 20 get_addon_long = templates.LongDesc(` 21 Display the available addons 22 23 `) 24 25 get_addon_example = templates.Examples(` 26 # List all the possible addons 27 jx get addon 28 `) 29 ) 30 31 // NewCmdGetAddon creates the command 32 func NewCmdGetAddon(commonOpts *opts.CommonOptions) *cobra.Command { 33 options := &GetAddonOptions{ 34 Options: Options{ 35 CommonOptions: commonOpts, 36 }, 37 } 38 39 cmd := &cobra.Command{ 40 Use: "addons [flags]", 41 Short: "Lists the addons", 42 Long: get_addon_long, 43 Example: get_addon_example, 44 Aliases: []string{"addon", "add-on"}, 45 Run: func(cmd *cobra.Command, args []string) { 46 options.Cmd = cmd 47 options.Args = args 48 err := options.Run() 49 helper.CheckErr(err) 50 }, 51 } 52 53 return cmd 54 } 55 56 // Run implements this command 57 func (o *GetAddonOptions) Run() error { 58 59 addonConfig, err := addon.LoadAddonsConfig() 60 if err != nil { 61 return err 62 } 63 addonEnabled := map[string]bool{} 64 for _, addon := range addonConfig.Addons { 65 if addon.Enabled { 66 addonEnabled[addon.Name] = true 67 } 68 } 69 _, ns, err := o.KubeClientAndNamespace() 70 if err != nil { 71 return err 72 } 73 releases, sortedKeys, err := o.Helm().ListReleases(ns) 74 if err != nil { 75 log.Logger().Warnf("Failed to find Helm installs: %s", err) 76 } 77 78 table := o.CreateTable() 79 table.AddRow("NAME", "CHART", "ENABLED", "STATUS", "VERSION") 80 for _, k := range sortedKeys { 81 release := releases[k] 82 if addonName, ok := kube.AddonCharts[release.ReleaseName]; ok { 83 enableText := "" 84 if addonEnabled[release.ReleaseName] { 85 enableText = "yes" 86 } 87 table.AddRow(release.ReleaseName, addonName, enableText, release.Status, release.ChartVersion) 88 } 89 } 90 table.Render() 91 return nil 92 }