cmssczy opened a new issue #924: URL: https://github.com/apache/apisix-ingress-controller/issues/924
### Issue description Create a ApisixRoute resource before start the apisix-ingress-controller and set the `backends` with a nonexistent service name. Then start the apisix-ingress-controller and it will panic. The root cause is the failure of type assertion. https://github.com/apache/apisix-ingress-controller/blob/c9e0c965cd2226e2c44aa4e692a8bf57d1586aa3/pkg/ingress/apisix_route.go#L267 Actually the type of this obj is `*types.Event` but not `string`. https://github.com/apache/apisix-ingress-controller/blob/c9e0c965cd2226e2c44aa4e692a8bf57d1586aa3/pkg/ingress/apisix_route.go#L353-L359 After I check the other resources' logic, I find that sometimes we push `string` to workqueue, but sometimes we push `*types.Event`. How to evaluate the benefits of doing so? Why did we use different method to handle different resources? ### Environment - your apisix-ingress-controller version (output of apisix-ingress-controller version --long):apisix-ingress-controller version 1.4.0-c9e0c96-go1.17.7 - your Kubernetes cluster version (output of kubectl version): - 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 ApisixRoute resource before start the apisix-ingress-controller and set the `backends` with a nonexistent service name 2. Start apisix-ingress-controller ### Actual result The process will panic. ### Error log ``` 2022-03-17T20:43:20+08:00 error translation/apisix_route.go:344 failed to get service port in backend {"backend": {"serviceName":"httpbin","servicePort":80,"weight":null}, "apisix_route": {"kind":"ApisixRoute","apiVersion":"apisix.apache.org/v2beta3","metadata":{"name":"httpbin-route","namespace":"default","uid":"5d4a8c99-649e-4ac7-bc71-59c4422d93cb","resourceVersion":"5298724","generation":1,"creationTimestamp":"2022-03-17T12:34:03Z","annotations":{"kubectl.kubernetes.io/last-applied-configuration":"{\"apiVersion\":\"apisix.apache.org/v2beta3\",\"kind\":\"ApisixRoute\",\"metadata\":{\"annotations\":{},\"name\":\"httpbin-route\",\"namespace\":\"default\"},\"spec\":{\"http\":[{\"backends\":[{\"serviceName\":\"httpbin\",\"servicePort\":80}],\"match\":{\"hosts\":[\"httpbin.com\"],\"paths\":[\"/headers\"]},\"name\":\"rule1\"}]}}\n"},"managedFields":[{"manager":"kubectl-client-side-apply","operation":"Update","apiVersion":"apisix.apache.org/v2beta3","time":"2022-03-17T12:34:03Z","field sType":"FieldsV1","fieldsV1":{"f:metadata":{"f:annotations":{".":{},"f:kubectl.kubernetes.io/last-applied-configuration":{}}},"f:spec":{".":{},"f:http":{}}}}]},"spec":{"http":[{"name":"rule1","match":{"paths":["/headers"],"hosts":["httpbin.com"]},"backends":[{"serviceName":"httpbin","servicePort":80,"weight":null}],"websocket":false,"authentication":{"enable":false,"type":"","keyauth":{}}}]},"status":{}}, "error": "service \"httpbin\" not found"} 2022-03-17T20:43:20+08:00 error ingress/apisix_route.go:174 failed to translate ApisixRoute v2beta3 {"error": "service \"httpbin\" not found", "object": {}} panic: interface conversion: interface {} is kube.ApisixRouteEvent, not string goroutine 281 [running]: github.com/apache/apisix-ingress-controller/pkg/ingress.(*apisixRouteController).handleSyncErr(0xc00029a380, {0x16cff20, 0xc000781830}, {0x1c8bc00, 0xc000390f00}) /root/apisix/apisix-ingress-controller/pkg/ingress/apisix_route.go:267 +0x18c9 github.com/apache/apisix-ingress-controller/pkg/ingress.(*apisixRouteController).runWorker(0xc00029a380, {0x1cbd710, 0xc0000a8c40}) /root/apisix/apisix-ingress-controller/pkg/ingress/apisix_route.go:84 +0x92 created by github.com/apache/apisix-ingress-controller/pkg/ingress.(*apisixRouteController).run /root/apisix/apisix-ingress-controller/pkg/ingress/apisix_route.go:71 +0x265 ``` ### Expected result _No response_ -- 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]
