From 47f19a7b5f5bcf90905004bbdf709a9722fe4aa8 Mon Sep 17 00:00:00 2001 From: Tariq Ibrahim Date: Thu, 18 Jul 2019 12:25:49 -0700 Subject: [PATCH] add nil guard checks when querying VPA objects --- internal/store/verticalpodautoscaler.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/internal/store/verticalpodautoscaler.go b/internal/store/verticalpodautoscaler.go index 800f99c687..9a20a7f3c0 100644 --- a/internal/store/verticalpodautoscaler.go +++ b/internal/store/verticalpodautoscaler.go @@ -60,7 +60,7 @@ var ( GenerateFunc: wrapVPAFunc(func(a *autoscaling.VerticalPodAutoscaler) *metric.Family { ms := []*metric.Metric{} - if a.Spec.UpdatePolicy.UpdateMode == nil { + if a.Spec.UpdatePolicy == nil || a.Spec.UpdatePolicy.UpdateMode == nil { return &metric.Family{ Metrics: ms, } @@ -96,6 +96,12 @@ var ( Help: "Minimum resources the VerticalPodAutoscaler can set for containers matching the name.", GenerateFunc: wrapVPAFunc(func(a *autoscaling.VerticalPodAutoscaler) *metric.Family { ms := []*metric.Metric{} + if a.Spec.ResourcePolicy == nil || a.Spec.ResourcePolicy.ContainerPolicies == nil { + return &metric.Family{ + Metrics: ms, + } + } + for _, c := range a.Spec.ResourcePolicy.ContainerPolicies { ms = append(ms, vpaResourcesToMetrics(c.ContainerName, c.MinAllowed)...) @@ -111,6 +117,12 @@ var ( Help: "Maximum resources the VerticalPodAutoscaler can set for containers matching the name.", GenerateFunc: wrapVPAFunc(func(a *autoscaling.VerticalPodAutoscaler) *metric.Family { ms := []*metric.Metric{} + if a.Spec.ResourcePolicy == nil || a.Spec.ResourcePolicy.ContainerPolicies == nil { + return &metric.Family{ + Metrics: ms, + } + } + for _, c := range a.Spec.ResourcePolicy.ContainerPolicies { ms = append(ms, vpaResourcesToMetrics(c.ContainerName, c.MaxAllowed)...) }