Skip to content

Commit faab78d

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 4ec62d2 commit faab78d

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

controller/store/convert.go

+14-8
Original file line numberDiff line numberDiff line change
@@ -287,15 +287,18 @@ func (n ingressNetworkingV1Strategy) ConvertIngress() *Ingress {
287287
if k8sPath.PathType != nil {
288288
pathType = string(*k8sPath.PathType)
289289
}
290-
paths[pathType+"-"+k8sPath.Path] = &IngressPath{
290+
pathKey := pathType + "-" + k8sPath.Path
291+
paths[pathKey] = &IngressPath{
291292
Path: k8sPath.Path,
292293
PathTypeMatch: pathType,
293294
SvcNamespace: n.ig.GetNamespace(),
294-
SvcName: k8sPath.Backend.Service.Name,
295-
SvcPortInt: int64(k8sPath.Backend.Service.Port.Number),
296-
SvcPortString: k8sPath.Backend.Service.Port.Name,
297295
Status: "",
298296
}
297+
if k8sPath.Backend.Service != nil {
298+
paths[pathKey].SvcName = k8sPath.Backend.Service.Name
299+
paths[pathKey].SvcPortInt = int64(k8sPath.Backend.Service.Port.Number)
300+
paths[pathKey].SvcPortString = k8sPath.Backend.Service.Port.Name
301+
}
299302
}
300303
if rule, ok := rules[k8sRule.Host]; ok {
301304
for path, ingressPath := range paths {
@@ -315,14 +318,17 @@ func (n ingressNetworkingV1Strategy) ConvertIngress() *Ingress {
315318
if ingressBackend == nil {
316319
return nil
317320
}
318-
return &IngressPath{
321+
ingPath := &IngressPath{
319322
SvcNamespace: n.ig.GetNamespace(),
320-
SvcName: ingressBackend.Service.Name,
321-
SvcPortInt: int64(ingressBackend.Service.Port.Number),
322-
SvcPortString: ingressBackend.Service.Port.Name,
323323
IsDefaultBackend: true,
324324
Status: "",
325325
}
326+
if ingressBackend.Service != nil {
327+
ingPath.SvcName = ingressBackend.Service.Name
328+
ingPath.SvcPortInt = int64(ingressBackend.Service.Port.Number)
329+
ingPath.SvcPortString = ingressBackend.Service.Port.Name
330+
}
331+
return ingPath
326332
}(n.ig.Spec.DefaultBackend),
327333
TLS: func(ingressTLS []networkingv1.IngressTLS) map[string]*IngressTLS {
328334
tls := make(map[string]*IngressTLS)

0 commit comments

Comments
 (0)