Skip to content

Commit

Permalink
Merge pull request #832 from tariq1890/vpa_bug_fix
Browse files Browse the repository at this point in the history
add nil guard checks when querying VPA objects
  • Loading branch information
k8s-ci-robot committed Jul 18, 2019
2 parents 66ac307 + 47f19a7 commit 6513ae2
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion internal/store/verticalpodautoscaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down Expand Up @@ -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)...)

Expand All @@ -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)...)
}
Expand Down

0 comments on commit 6513ae2

Please sign in to comment.