2
0
Эх сурвалжийг харах

Merge pull request #1687 from kaelanspatel/kaelan-fix-asset-accumulate-panic

Fix panic in Asset/AllocSetRange NewAccumulation
Niko Kovacevic 3 жил өмнө
parent
commit
faad31e9be

+ 8 - 0
pkg/kubecost/allocation.go

@@ -2103,6 +2103,14 @@ func (asr *AllocationSetRange) NewAccumulation() (*AllocationSet, error) {
 	var allocSet *AllocationSet
 	var err error
 
+	if asr == nil {
+		return nil, fmt.Errorf("nil AllocationSetRange in accumulation")
+	}
+
+	if len(asr.Allocations) == 0 {
+		return nil, fmt.Errorf("AllocationSetRange has empty AssetSet in accumulation")
+	}
+
 	for _, as := range asr.Allocations {
 		if allocSet == nil {
 			allocSet = as.Clone()

+ 8 - 0
pkg/kubecost/asset.go

@@ -3249,6 +3249,14 @@ func (asr *AssetSetRange) NewAccumulation() (*AssetSet, error) {
 	var assetSet *AssetSet
 	var err error
 
+	if asr == nil {
+		return nil, fmt.Errorf("nil AssetSetRange in accumulation")
+	}
+
+	if len(asr.Assets) == 0 {
+		return nil, fmt.Errorf("AssetSetRange has empty AssetSet in accumulation")
+	}
+
 	for _, as := range asr.Assets {
 		if assetSet == nil {
 			assetSet = as.Clone()