فهرست منبع

Merge pull request #2035 from opencost/sean/allocation-filter-nil-check

Add nil checks for allocation field map
Sean Holcomb 2 سال پیش
والد
کامیت
84a583b10c
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")
 	}