Skip to content

Commit

Permalink
BUG/MINOR: Fix nil pointer dereference in IngressServiceBackend
Browse files Browse the repository at this point in the history
In Ingress Spec of Networking/v1 API, Service field in Ingress Backend
is a pointer so a non nil check is required before dereference.
  • Loading branch information
Mo3m3n committed Dec 1, 2021
1 parent 4ec62d2 commit faab78d
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions controller/store/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,15 +287,18 @@ func (n ingressNetworkingV1Strategy) ConvertIngress() *Ingress {
if k8sPath.PathType != nil {
pathType = string(*k8sPath.PathType)
}
paths[pathType+"-"+k8sPath.Path] = &IngressPath{
pathKey := pathType + "-" + k8sPath.Path
paths[pathKey] = &IngressPath{
Path: k8sPath.Path,
PathTypeMatch: pathType,
SvcNamespace: n.ig.GetNamespace(),
SvcName: k8sPath.Backend.Service.Name,
SvcPortInt: int64(k8sPath.Backend.Service.Port.Number),
SvcPortString: k8sPath.Backend.Service.Port.Name,
Status: "",
}
if k8sPath.Backend.Service != nil {
paths[pathKey].SvcName = k8sPath.Backend.Service.Name
paths[pathKey].SvcPortInt = int64(k8sPath.Backend.Service.Port.Number)
paths[pathKey].SvcPortString = k8sPath.Backend.Service.Port.Name
}
}
if rule, ok := rules[k8sRule.Host]; ok {
for path, ingressPath := range paths {
Expand All @@ -315,14 +318,17 @@ func (n ingressNetworkingV1Strategy) ConvertIngress() *Ingress {
if ingressBackend == nil {
return nil
}
return &IngressPath{
ingPath := &IngressPath{
SvcNamespace: n.ig.GetNamespace(),
SvcName: ingressBackend.Service.Name,
SvcPortInt: int64(ingressBackend.Service.Port.Number),
SvcPortString: ingressBackend.Service.Port.Name,
IsDefaultBackend: true,
Status: "",
}
if ingressBackend.Service != nil {
ingPath.SvcName = ingressBackend.Service.Name
ingPath.SvcPortInt = int64(ingressBackend.Service.Port.Number)
ingPath.SvcPortString = ingressBackend.Service.Port.Name
}
return ingPath
}(n.ig.Spec.DefaultBackend),
TLS: func(ingressTLS []networkingv1.IngressTLS) map[string]*IngressTLS {
tls := make(map[string]*IngressTLS)
Expand Down

0 comments on commit faab78d

Please sign in to comment.