Skip to content

Commit

Permalink
Fix crash due to missing ingress http block
Browse files Browse the repository at this point in the history
It's acceptable although uncommon for an ingress to have a rule and a host,
but no HTTP block for that particular rule.
  • Loading branch information
Ergin Babani committed Jul 18, 2019
1 parent 66ac307 commit 4d0d772
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
14 changes: 8 additions & 6 deletions internal/store/ingress.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,14 @@ var (
GenerateFunc: wrapIngressFunc(func(i *v1beta1.Ingress) *metric.Family {
ms := []*metric.Metric{}
for _, rule := range i.Spec.Rules {
for _, path := range rule.HTTP.Paths {
ms = append(ms, &metric.Metric{
LabelKeys: []string{"host", "path", "service_name", "service_port"},
LabelValues: []string{rule.Host, path.Path, path.Backend.ServiceName, path.Backend.ServicePort.String()},
Value: 1,
})
if rule.HTTP != nil {
for _, path := range rule.HTTP.Paths {
ms = append(ms, &metric.Metric{
LabelKeys: []string{"host", "path", "service_name", "service_port"},
LabelValues: []string{rule.Host, path.Path, path.Backend.ServiceName, path.Backend.ServicePort.String()},
Value: 1,
})
}
}
}
return &metric.Family{
Expand Down
3 changes: 3 additions & 0 deletions internal/store/ingress_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@ func TestIngressStore(t *testing.T) {
},
},
},
{
Host: "somehost2",
},
},
},
},
Expand Down

0 comments on commit 4d0d772

Please sign in to comment.