Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix limit and request availability with -a with json and yaml #174

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 25 additions & 12 deletions pkg/capacity/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,14 @@ type listContainer struct {
}

type listResourceOutput struct {
Requests string `json:"requests"`
RequestsPct string `json:"requestsPercent"`
Limits string `json:"limits"`
LimitsPct string `json:"limitsPercent"`
Utilization string `json:"utilization,omitempty"`
UtilizationPct string `json:"utilizationPercent,omitempty"`
Requests string `json:"requests"`
RequestsPct string `json:"requestsPercent"`
RequestsAvailable string `json:"requestsAvailable,omitempty"`
Limits string `json:"limits"`
LimitsPct string `json:"limitsPercent"`
LimitsAvailable string `json:"limitsAvailable,omitempty"`
Utilization string `json:"utilization,omitempty"`
UtilizationPct string `json:"utilizationPercent,omitempty"`
}

type listClusterMetrics struct {
Expand All @@ -64,12 +66,13 @@ type listClusterTotals struct {
}

type listPrinter struct {
cm *clusterMetric
showPods bool
showContainers bool
showUtil bool
showPodCount bool
sortBy string
cm *clusterMetric
showPods bool
showContainers bool
showUtil bool
showPodCount bool
sortBy string
availableFormat bool
}

func (lp listPrinter) Print(outputType string) {
Expand Down Expand Up @@ -156,6 +159,16 @@ func (lp *listPrinter) buildListResourceOutput(item *resourceMetric) *listResour
LimitsPct: percentCalculator(item.limit),
}

if lp.availableFormat {
available := item.allocatable.DeepCopy()
available.Sub(item.request)
out.RequestsAvailable = valueCalculator(available)

available = item.allocatable.DeepCopy()
available.Sub(item.limit)
out.LimitsAvailable = valueCalculator(available)
}

if lp.showUtil {
out.Utilization = valueCalculator(item.utilization)
out.UtilizationPct = percentCalculator(item.utilization)
Expand Down
13 changes: 7 additions & 6 deletions pkg/capacity/printer.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,13 @@ func SupportedOutputs() []string {
func printList(cm *clusterMetric, showContainers, showPods, showUtil, showPodCount, showNamespace bool, output, sortBy string, availableFormat bool) {
if output == JSONOutput || output == YAMLOutput {
lp := &listPrinter{
cm: cm,
showPods: showPods,
showUtil: showUtil,
showContainers: showContainers,
showPodCount: showPodCount,
sortBy: sortBy,
cm: cm,
showPods: showPods,
showUtil: showUtil,
showContainers: showContainers,
showPodCount: showPodCount,
sortBy: sortBy,
availableFormat: availableFormat,
}
lp.Print(output)
} else if output == TableOutput {
Expand Down
Loading