Skip to content

Commit

Permalink
Add option to show only pods exceeding requests (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
howardjohn authored and mergify[bot] committed Jul 10, 2019
1 parent 166a48b commit 1ce8701
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 0 deletions.
9 changes: 9 additions & 0 deletions cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ var (
showNodes = false
verbose = false
aggregation = "POD"
onlyWarnings = false
)

func init() {
Expand All @@ -46,6 +47,13 @@ func init() {
verbose,
"show full resource names",
)
rootCmd.PersistentFlags().BoolVarP(
&onlyWarnings,
"warnings",
"w",
onlyWarnings,
"only show resources using excessive resources",
)
rootCmd.PersistentFlags().StringVarP(
&aggregation,
"by",
Expand Down Expand Up @@ -75,6 +83,7 @@ var rootCmd = &cobra.Command{
Verbose: verbose,
ShowNodes: showNodes,
ColoredOutput: color,
OnlyWarnings: onlyWarnings,
}
return client.Run(args)
},
Expand Down
1 change: 1 addition & 0 deletions pkg/model/args.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ type Args struct {
Verbose bool
ShowNodes bool
ColoredOutput bool
OnlyWarnings bool
}

type Aggregation int
Expand Down
7 changes: 7 additions & 0 deletions pkg/model/podresource.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ func (p *PodResource) Memory() *Resource {
return res
}

func (r *Resource) ExceedsRequest() bool {
if r.Request == 0 {
return false
}
return r.Usage > r.Request
}

func MergePodResources(resources ...map[string]*PodResource) (map[string]*PodResource, error) {
merged := map[string]*PodResource{}
for _, resource := range resources {
Expand Down
3 changes: 3 additions & 0 deletions pkg/writer/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ func Write(response map[string]*model.PodResource, args *model.Args) error {

var allRows []*ResourceRow
for _, pod := range resources {
if args.OnlyWarnings && !(pod.Cpu().ExceedsRequest() || pod.Memory().ExceedsRequest()) {
continue
}
allRows = append(allRows, PodToRows(pod)...)
}

Expand Down

0 comments on commit 1ce8701

Please sign in to comment.