forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 1
/
top.go
63 lines (50 loc) · 1.79 KB
/
top.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
package top
import (
"io"
"github.com/spf13/cobra"
kcmd "k8s.io/kubernetes/pkg/kubectl/cmd"
"k8s.io/kubernetes/pkg/kubectl/cmd/templates"
cmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"
"github.com/openshift/origin/pkg/cmd/util/clientcmd"
)
const (
TopRecommendedName = "top"
DefaultHeapsterNamespace = "openshift-infra"
DefaultHeapsterScheme = "https"
DefaultHeapsterService = "heapster"
)
var topLong = templates.LongDesc(`
Show usage statistics of resources on the server
This command analyzes resources managed by the platform and presents current
usage statistics.`)
func NewCommandTop(name, fullName string, f *clientcmd.Factory, out, errOut io.Writer) *cobra.Command {
// Parent command to which all subcommands are added.
cmds := &cobra.Command{
Use: name,
Short: "Show usage statistics of resources on the server",
Long: topLong,
Run: cmdutil.DefaultSubCommandRun(errOut),
}
ocHeapsterTopOpts := kcmd.HeapsterTopOptions{
Namespace: DefaultHeapsterNamespace,
Scheme: DefaultHeapsterScheme,
Service: DefaultHeapsterService,
}
cmdTopNodeOpts := &kcmd.TopNodeOptions{
HeapsterOptions: ocHeapsterTopOpts,
}
cmdTopNode := kcmd.NewCmdTopNode(f, cmdTopNodeOpts, out)
cmdTopPodOpts := &kcmd.TopPodOptions{
HeapsterOptions: ocHeapsterTopOpts,
}
cmdTopPod := kcmd.NewCmdTopPod(f, cmdTopPodOpts, out)
cmds.AddCommand(NewCmdTopImages(f, fullName, TopImagesRecommendedName, out))
cmds.AddCommand(NewCmdTopImageStreams(f, fullName, TopImageStreamsRecommendedName, out))
cmdTopNode.Long = templates.LongDesc(cmdTopNode.Long)
cmdTopNode.Example = templates.Examples(cmdTopNode.Example)
cmdTopPod.Long = templates.LongDesc(cmdTopPod.Long)
cmdTopPod.Example = templates.Examples(cmdTopPod.Example)
cmds.AddCommand(cmdTopNode)
cmds.AddCommand(cmdTopPod)
return cmds
}