Skip to content

Commit 6513ae2

Browse files
authored
Merge pull request #832 from tariq1890/vpa_bug_fix
add nil guard checks when querying VPA objects
2 parents 66ac307 + 47f19a7 commit 6513ae2

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

internal/store/verticalpodautoscaler.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ var (
6060
GenerateFunc: wrapVPAFunc(func(a *autoscaling.VerticalPodAutoscaler) *metric.Family {
6161
ms := []*metric.Metric{}
6262

63-
if a.Spec.UpdatePolicy.UpdateMode == nil {
63+
if a.Spec.UpdatePolicy == nil || a.Spec.UpdatePolicy.UpdateMode == nil {
6464
return &metric.Family{
6565
Metrics: ms,
6666
}
@@ -96,6 +96,12 @@ var (
9696
Help: "Minimum resources the VerticalPodAutoscaler can set for containers matching the name.",
9797
GenerateFunc: wrapVPAFunc(func(a *autoscaling.VerticalPodAutoscaler) *metric.Family {
9898
ms := []*metric.Metric{}
99+
if a.Spec.ResourcePolicy == nil || a.Spec.ResourcePolicy.ContainerPolicies == nil {
100+
return &metric.Family{
101+
Metrics: ms,
102+
}
103+
}
104+
99105
for _, c := range a.Spec.ResourcePolicy.ContainerPolicies {
100106
ms = append(ms, vpaResourcesToMetrics(c.ContainerName, c.MinAllowed)...)
101107

@@ -111,6 +117,12 @@ var (
111117
Help: "Maximum resources the VerticalPodAutoscaler can set for containers matching the name.",
112118
GenerateFunc: wrapVPAFunc(func(a *autoscaling.VerticalPodAutoscaler) *metric.Family {
113119
ms := []*metric.Metric{}
120+
if a.Spec.ResourcePolicy == nil || a.Spec.ResourcePolicy.ContainerPolicies == nil {
121+
return &metric.Family{
122+
Metrics: ms,
123+
}
124+
}
125+
114126
for _, c := range a.Spec.ResourcePolicy.ContainerPolicies {
115127
ms = append(ms, vpaResourcesToMetrics(c.ContainerName, c.MaxAllowed)...)
116128
}

0 commit comments

Comments
 (0)