Skip to content

Commit 89bdd2a

Browse files
committed
BUG/MINOR: Fix nil pointer dereference in IngressServiceBackend
In Ingress Spec of Networking/v1 API, Service field in Ingress Backend is a pointer so a non nil check is required before dereference.
1 parent 99b6ac3 commit 89bdd2a

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

controller/store/convert.go

+16-10
Original file line numberDiff line numberDiff line change
@@ -262,18 +262,21 @@ func (n ingressNetworkingV1Strategy) ConvertIngress() *Ingress {
262262
continue
263263
}
264264
for _, k8sPath := range k8sRule.HTTP.Paths {
265-
prefix := ""
265+
var pathType string
266266
if k8sPath.PathType != nil {
267-
prefix = string(*k8sPath.PathType)
267+
pathType = string(*k8sPath.PathType)
268268
}
269-
paths[prefix+"-"+k8sPath.Path] = &IngressPath{
269+
pathKey := pathType + "-" + k8sPath.Path
270+
paths[pathKey] = &IngressPath{
270271
Path: k8sPath.Path,
271272
ExactPathMatch: k8sPath.PathType != nil && *k8sPath.PathType == networkingv1.PathTypeExact,
272-
SvcName: k8sPath.Backend.Service.Name,
273-
SvcPortInt: int64(k8sPath.Backend.Service.Port.Number),
274-
SvcPortString: k8sPath.Backend.Service.Port.Name,
275273
Status: "",
276274
}
275+
if k8sPath.Backend.Service != nil {
276+
paths[pathKey].SvcName = k8sPath.Backend.Service.Name
277+
paths[pathKey].SvcPortInt = int64(k8sPath.Backend.Service.Port.Number)
278+
paths[pathKey].SvcPortString = k8sPath.Backend.Service.Port.Name
279+
}
277280
}
278281
if rule, ok := rules[k8sRule.Host]; ok {
279282
for path, ingressPath := range paths {
@@ -293,13 +296,16 @@ func (n ingressNetworkingV1Strategy) ConvertIngress() *Ingress {
293296
if ingressBackend == nil {
294297
return nil
295298
}
296-
return &IngressPath{
297-
SvcName: ingressBackend.Service.Name,
298-
SvcPortInt: int64(ingressBackend.Service.Port.Number),
299-
SvcPortString: ingressBackend.Service.Port.Name,
299+
ingPath := &IngressPath{
300300
IsDefaultBackend: true,
301301
Status: "",
302302
}
303+
if ingressBackend.Service != nil {
304+
ingPath.SvcName = ingressBackend.Service.Name
305+
ingPath.SvcPortInt = int64(ingressBackend.Service.Port.Number)
306+
ingPath.SvcPortString = ingressBackend.Service.Port.Name
307+
}
308+
return ingPath
303309
}(n.ig.Spec.DefaultBackend),
304310
TLS: func(ingressTLS []networkingv1.IngressTLS) map[string]*IngressTLS {
305311
tls := make(map[string]*IngressTLS)

0 commit comments

Comments
 (0)