apache / apisix-ingress-controller

APISIX Ingress Controller for Kubernetes
https://apisix.apache.org/
Apache License 2.0
1.02k stars 344 forks source link

bug: IngressController crash when backend service not found #892

Closed FesonX closed 2 years ago

FesonX commented 2 years ago

Issue description

I create an Ingress reference a service httpbin NOT exists in current namespace.

After a create the resource and delete, the APISIX Ingress Controller service panic and restart.

Environment

Minimal test code / Steps to reproduce

  1. Create a httpbin service in namespace called demo
kubectl -n demo run httpbin --image-pull-policy=IfNotPresent --image kennethreitz/httpbin --port 80
kubectl -n demo expose pod httpbin --port 80
  1. Switch to a namespace called apisix, and I forgot to create Ingress resource with explicit namespace option.

The ingress service like this, which doesn't have a namespace in metadata, save it as ingress-example.yaml

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: httpserver-ingress
spec:
  # apisix-ingress-controller is only interested in Ingress
  # resources with the matched ingressClass name, in our case,
  # it's apisix.
  ingressClassName: apisix
  rules:
  - host: local.httpbin.org
    http:
      paths:
      - backend:
          service:
            name: httpbin
            port:
              number: 80
        path: /
        pathType: Prefix
  1. create and then delete the ingress.
    kubectl create -f ingress-example.yaml
    kubectl delete -f ingress-example.yaml

Actual result

the APISIX Ingress Controller service panic and restart.

Error log

2022-03-01T16:43:53+08:00   error  translation/ingress.go:86   failed to translate ingress backend to upstream {"error": "endpoints: endpoints \"httpbin\" not found", "ingress": "&Ingress{ObjectMeta:{httpserver-ingress  apisix  30a87b4b-5238-4ed3-9522-6a053979277b 24129335 1 2022-03-01 16:43:46 +0800 HKT <nil> <nil> map[] map[] [] []  [{kubectl-create Update [networking.k8s.io/v1](http://networking.k8s.io/v1) 2022-03-01 16:43:46 +0800 HKT FieldsV1 {\"f:spec\":{\"f:ingressClassName\":{},\"f:rules\":{}}} }]},Spec:IngressSpec{DefaultBackend:nil,TLS:[]IngressTLS{},Rules:[]IngressRule{IngressRule{Host:[local.httpbin.org](http://local.httpbin.org/),IngressRuleValue:IngressRuleValue{HTTP:&HTTPIngressRuleValue{Paths:[]HTTPIngressPath{HTTPIngressPath{Path:/,Backend:IngressBackend{Resource:nil,Service:&IngressServiceBackend{Name:httpbin,Port:ServiceBackendPort{Name:,Number:80,},},},PathType:*Prefix,},},},},},},IngressClassName:*apisix,},Status:IngressStatus{LoadBalancer:{[]},},}"}
2022-03-01T16:43:53+08:00   error  ingress/ingress.go:131  failed to translate ingress {"error": "endpoints: endpoints \"httpbin\" not found", "ingress": {}}
2022-03-01T16:43:53+08:00   warn   ingress/ingress.go:231  sync ingress failed, will retry {"object": {"Type":3,"Object":{"Key":"apisix/httpserver-ingress","GroupVersion":"networking/v1","OldObject":null},"Tombstone":{}}, "error": "[ingress.networking.k8s.io](http://ingress.networking.k8s.io/) \"httpserver-ingress\" not found"}
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x20 pc=0x18cb92c]

goroutine 271 [running]:
[github.com/apache/apisix-ingress-controller/pkg/ingress.(*ingressController).handleSyncErr](http://github.com/apache/apisix-ingress-controller/pkg/ingress.(*ingressController).handleSyncErr)(0xc000689e60, 0x198c020, 0xc000aca150, 0x1f9e100, 0xc000a88a00)
    /build/controller/pkg/ingress/ingress.go:237 +0x7ac
[github.com/apache/apisix-ingress-controller/pkg/ingress.(*ingressController).runWorker](http://github.com/apache/apisix-ingress-controller/pkg/ingress.(*ingressController).runWorker)(0xc000689e60, 0x1fd9bf0, 0xc00052e040)
    /build/controller/pkg/ingress/ingress.go:81 +0xcc
created by [github.com/apache/apisix-ingress-controller/pkg/ingress.(*ingressController).run](http://github.com/apache/apisix-ingress-controller/pkg/ingress.(*ingressController).run)
    /build/controller/pkg/ingress/ingress.go:68 +0x230

Expected result

A more CLEAER error message describe the absent service.

tao12345666333 commented 2 years ago

Thanks for your report.

It's has been fixed. #872

Duplicate #855

I will close this one. Feel free to reopen it, if you have any question