in cost-optimization/gke-shift-left-cost/api/cost.go [156:179]
func (c *CostRange) Subtract(costRangePrev CostRange) DiffCostRange {
diff := CostRange{Kind: c.Kind}
diff.MinRequested = c.MinRequested - costRangePrev.MinRequested
diff.MaxRequested = c.MaxRequested - costRangePrev.MaxRequested
diff.HPABuffer = c.HPABuffer - costRangePrev.HPABuffer
diff.MinLimited = c.MinLimited - costRangePrev.MinLimited
diff.MaxLimited = c.MaxLimited - costRangePrev.MaxLimited
diffP := CostRange{Kind: c.Kind}
diffP.MinRequested = diff.MinRequested * 100 / c.MinRequested
diffP.MaxRequested = diff.MaxRequested * 100 / c.MaxRequested
diffP.HPABuffer = diff.HPABuffer * 100 / c.HPABuffer
diffP.MinLimited = diff.MinLimited * 100 / c.MinLimited
diffP.MaxLimited = diff.MaxLimited * 100 / c.MaxLimited
return DiffCostRange{
Kind: c.Kind,
CostCurr: *c,
CostPrev: costRangePrev,
DiffValue: diff,
DiffPercentage: diffP,
}
}