top.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*
  2. Copyright 2016 The Kubernetes Authors.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package cmd
  14. import (
  15. "io"
  16. cmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"
  17. "github.com/renstrom/dedent"
  18. "github.com/spf13/cobra"
  19. )
  20. // TopOptions contains all the options for running the top cli command.
  21. type TopOptions struct{}
  22. var (
  23. topLong = dedent.Dedent(`
  24. Display Resource (CPU/Memory/Storage) usage.
  25. The top command allows you to see the resource consumption for nodes or pods.`)
  26. )
  27. func NewCmdTop(f *cmdutil.Factory, out io.Writer) *cobra.Command {
  28. options := &TopOptions{}
  29. cmd := &cobra.Command{
  30. Use: "top",
  31. Short: "Display Resource (CPU/Memory/Storage) usage",
  32. Long: topLong,
  33. Run: func(cmd *cobra.Command, args []string) {
  34. if err := options.RunTop(f, cmd, args, out); err != nil {
  35. cmdutil.CheckErr(err)
  36. }
  37. },
  38. }
  39. // create subcommands
  40. cmd.AddCommand(NewCmdTopNode(f, out))
  41. cmd.AddCommand(NewCmdTopPod(f, out))
  42. return cmd
  43. }
  44. func (o TopOptions) RunTop(f *cmdutil.Factory, cmd *cobra.Command, args []string, out io.Writer) error {
  45. return cmd.Help()
  46. }