Просмотр исходного кода

Add nil checks for allocation field map

Signed-off-by: Sean Holcomb <seanholcomb@gmail.com>
Sean Holcomb 2 лет назад
Родитель
Сommit
6e19671f29
1 измененных файлов с 6 добавлено и 0 удалено
  1. 6 0
      pkg/kubecost/allocationmatcher.go

+ 6 - 0
pkg/kubecost/allocationmatcher.go

@@ -46,6 +46,12 @@ func NewAllocationMatchCompiler(labelConfig *LabelConfig) *matcher.MatchCompiler
 
 // Maps fields from an allocation to a string value based on an identifier
 func allocationFieldMap(a *Allocation, identifier ast.Identifier) (string, error) {
+	if a == nil {
+		return "", fmt.Errorf("cannot map to nil allocation")
+	}
+	if a.Properties == nil {
+		return "", fmt.Errorf("cannot map to nil properties")
+	}
 	if identifier.Field == nil {
 		return "", fmt.Errorf("cannot map field from identifier with nil field")
 	}