FesonX opened a new issue #892:
URL: https://github.com/apache/apisix-ingress-controller/issues/892
### 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
- your apisix-ingress-controller version (output of
apisix-ingress-controller version --long):
> apache/apisix-ingress-controller:1.4.0
- your Kubernetes cluster version (output of kubectl version):
> Server Version: version.Info{Major:"1", Minor:"22+",
GitVersion:"v1.22.3-aliyun.1",
GitCommit:"2d7fa03ee32075acb101bc7286176439c3edddf1", GitTreeState:"clean",
BuildDate:"2022-01-18T14:15:16Z", GoVersion:"go1.16.9", Compiler:"gc",
Platform:"linux/amd64"}
- if you run apisix-ingress-controller in Bare-metal environment, also show
your OS version (uname -a):
### Minimal test code / Steps to reproduce
1. Create a httpbin service in namespace called demo
```bash
kubectl -n demo run httpbin --image-pull-policy=IfNotPresent --image
kennethreitz/httpbin --port 80
kubectl -n demo expose pod httpbin --port 80
```
2. 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`
```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
```
3. create and then delete the ingress.
```bash
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 [31merror[0m 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 [31merror[0m ingress/ingress.go:131 failed
to translate ingress {"error": "endpoints: endpoints \"httpbin\" not
found", "ingress": {}}
2022-03-01T16:43:53+08:00 [33mwarn[0m 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.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]