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 99b6ac3 commit 89bdd2a
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions controller/store/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,18 +262,21 @@ func (n ingressNetworkingV1Strategy) ConvertIngress() *Ingress {
continue
}
for _, k8sPath := range k8sRule.HTTP.Paths {
prefix := ""
var pathType string
if k8sPath.PathType != nil {
prefix = string(*k8sPath.PathType)
pathType = string(*k8sPath.PathType)
}
paths[prefix+"-"+k8sPath.Path] = &IngressPath{
pathKey := pathType + "-" + k8sPath.Path
paths[pathKey] = &IngressPath{
Path: k8sPath.Path,
ExactPathMatch: k8sPath.PathType != nil && *k8sPath.PathType == networkingv1.PathTypeExact,
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 @@ -293,13 +296,16 @@ func (n ingressNetworkingV1Strategy) ConvertIngress() *Ingress {
if ingressBackend == nil {
return nil
}
return &IngressPath{
SvcName: ingressBackend.Service.Name,
SvcPortInt: int64(ingressBackend.Service.Port.Number),
SvcPortString: ingressBackend.Service.Port.Name,
ingPath := &IngressPath{
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 89bdd2a

Please sign in to comment.