-
Notifications
You must be signed in to change notification settings - Fork 784
/
get_apps.go
123 lines (108 loc) · 2.74 KB
/
get_apps.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
118
119
120
121
122
123
package cmd
import (
"fmt"
"github.com/jenkins-x/jx/pkg/apps"
"github.com/jenkins-x/jx/pkg/helm"
"github.com/jenkins-x/jx/pkg/table"
"github.com/pkg/errors"
"github.com/spf13/cobra"
"k8s.io/client-go/kubernetes"
"github.com/jenkins-x/jx/pkg/apis/jenkins.io/v1"
"github.com/jenkins-x/jx/pkg/jx/cmd/templates"
)
// GetAppsOptions containers the CLI options
type GetAppsOptions struct {
GetOptions
Namespace string
GitOps bool
DevEnv *v1.Environment
}
var (
getAppsLong = templates.LongDesc(`
Display installed Apps
`)
getAppsExample = templates.Examples(`
# List all apps
jx get apps
# Display details about the app called cheese
jx get app cheese
`)
)
// NewCmdGetApps creates the new command for: jx get version
func NewCmdGetApps(commonOpts *CommonOptions) *cobra.Command {
options := &GetAppsOptions{
GetOptions: GetOptions{
CommonOptions: commonOpts,
},
}
cmd := &cobra.Command{
Use: "Apps",
Short: "Display one or more installed Apps",
Aliases: []string{"app", "apps"},
Long: getAppsLong,
Example: getAppsExample,
Run: func(cmd *cobra.Command, args []string) {
options.Cmd = cmd
options.Args = args
err := options.Run()
CheckErr(err)
},
}
options.addGetFlags(cmd)
return cmd
}
// Run implements this command
func (o *GetAppsOptions) Run() error {
kubeClient, err := o.KubeClient()
o.GitOps, o.DevEnv = o.GetDevEnv()
if err != nil {
return err
}
jxClient, _, err := o.JXClientAndDevNamespace()
if err != nil {
return errors.Wrapf(err, "getting jx client")
}
opts := apps.InstallOptions{
In: o.In,
DevEnv: o.DevEnv,
Verbose: o.Verbose,
Err: o.Err,
Out: o.Out,
GitOps: o.GitOps,
BatchMode: o.BatchMode,
Helmer: o.Helm(),
JxClient: jxClient,
}
apps, err := opts.GetApps(kubeClient, o.Namespace, o.Args)
if err != nil {
return err
}
if len(apps.Items) == 0 {
fmt.Fprint(o.Out, "No Apps found\n")
return nil
}
table := o.generateTable(apps, kubeClient)
table.Render()
return nil
}
func (o *GetAppsOptions) generateTable(apps *v1.AppList, kubeClient kubernetes.Interface) table.Table {
table := o.generateTableHeaders(apps)
for _, app := range apps.Items {
name := app.Labels[helm.LabelAppName]
if name != "" {
version := app.Labels[helm.LabelAppVersion]
description := app.Annotations[helm.AnnotationAppDescription]
repository := app.Annotations[helm.AnnotationAppRepository]
row := []string{name, version, description, repository}
table.AddRow(row...)
}
}
return table
}
func (o *GetAppsOptions) generateTableHeaders(apps *v1.AppList) table.Table {
t := o.createTable()
t.Out = o.CommonOptions.Out
titles := []string{"Name", "Version", "Description", "Chart Repository"}
t.AddRow(titles...)
return t
}