diff --git a/pkg/capacity/list.go b/pkg/capacity/list.go index 1aef8a20..4dcebc55 100644 --- a/pkg/capacity/list.go +++ b/pkg/capacity/list.go @@ -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 { @@ -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) { @@ -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) diff --git a/pkg/capacity/printer.go b/pkg/capacity/printer.go index f4b77b62..182808da 100644 --- a/pkg/capacity/printer.go +++ b/pkg/capacity/printer.go @@ -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 {