apache / apisix-ingress-controller

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

bug: apisix-ingress-controller start panic #913

Closed Belyenochi closed 2 years ago

Belyenochi commented 2 years ago

Issue description

apisix ingress controller start panic

Environment

Minimal test code / Steps to reproduce

  1. Make sure that the apisix related CRD has been installed in the cluster
  2. kubectl apply -f apisix-route.yaml
    apiVersion: apisix.apache.org/v2beta1
    kind: ApisixRoute
    metadata:
    name: foo-bar-route
    spec:
    http:
    - name: foo
    match:
      hosts:
      - foo.com
      paths:
      - "/foo*"
    backend:
     serviceName: foo
     servicePort: 80
    - name: bar
    match:
      paths:
        - "/bar"
    backend:
      serviceName: bar
      servicePort: 80
  3. start local apisix-ingress-controller
    ingress
    \
    --kubeconfig
    /path/to/kubeconfig
    \
    --http-listen
    :8082
    \
    --log-output
    stderr
    \
    --default-apisix-cluster-base-url
    http://127.0.0.1:9180/apisix/admin # 127.0.0.1:9180 need to be replaced
    --default-apisix-cluster-admin-key
    edd1c9f034335f136f87ad84b625c8f1

Actual result

local apisix-ingress-controller panic

Error log

2022-03-10T12:14:32+08:00 warn api/server.go:75 failed to load x509 key pair, will not start admission server {"Error": "open /etc/webhook/certs/cert.pem: no such file or directory", "CertFilePath": "/etc/webhook/certs/cert.pem", "KeyFilePath": "/etc/webhook/certs/key.pem"} I0310 12:14:32.866418 19515 leaderelection.go:248] attempting to acquire leader lease default/ingress-apisix-leader... 2022-03-10T12:14:35+08:00 info ingress/controller.go:320 LeaderElection {"message": " became leader", "event_type": "Normal"} I0310 12:14:35.634105 19515 leaderelection.go:258] successfully acquired lease default/ingress-apisix-leader 2022-03-10T12:14:35+08:00 info ingress/controller.go:406 controller tries to leading ... {"namespace": "default", "pod": ""} 2022-03-10T12:14:37+08:00 warn apisix/cluster.go:332 waiting cluster default to ready, it may takes a while 2022-03-10T12:14:37+08:00 info apisix/cluster.go:160 syncing cache {"cluster": "default"} 2022-03-10T12:14:37+08:00 info apisix/cluster.go:372 syncing schema {"cluster": "default"} 2022-03-10T12:14:40+08:00 info apisix/cluster.go:164 cache synced {"cost_time": "3.733667121s", "cluster": "default"} 2022-03-10T12:14:40+08:00 warn apisix/cluster.go:343 cluster default now is ready, cost time 3.733716272s 2022-03-10T12:14:41+08:00 info ingress/namespace.go:70 label selector watching namespaces {"namespaces": ["allns-r7sel9-0", "apisix", "cattle-prometheus", "cattle-system", "chaos-testing", "chaosblade", "default", "elastic-system", "ingress-apisix-e2e-tests-default-760463000", "ingress-apisix-e2e-tests-default-825238000", "ingress-nginx", "kafka", "kruise-system", "kube-node-lease", "kube-public", "kube-system", "leaf", "local-path-storage", "logging", "mcloud-cat", "middleware-paas", "minio", "monitoring", "nacos", "nacos-2", "nacos-3", "nacos-4", "nacos-5", "nacos-6", "nacos-test", "pvc-exporter", "pxc1", "redis", "security-scan", "syu-t", "syu-t2", "thrift", "xxl-job", "xxl-job1", "xxl-job2", "zookeeper"]} I0310 12:14:42.501579 19515 request.go:665] Waited for 1.000136347s due to client-side throttling, not priority and fairness, request: GET:https://mke.my.myorg/k8s/clusters/c-dx6gd/apis/apisix.apache.org/v2beta3/namespaces/nacos-4/apisixroutes panic: runtime error: index out of range [0] with length 0

goroutine 157 [running]: github.com/apache/apisix-ingress-controller/pkg/kube/translation.(translator).translateHTTPRouteV2beta3NotStrictly(0x0, 0xc00092c200, 0xc0008771e0) /Users/jasonzhu/opensource/2022/apisix-ingress-controller/pkg/kube/translation/apisix_route.go:936 +0x899 github.com/apache/apisix-ingress-controller/pkg/kube/translation.(translator).TranslateRouteV2beta3NotStrictly(0x0, 0x0) /Users/jasonzhu/opensource/2022/apisix-ingress-controller/pkg/kube/translation/apisix_route.go:314 +0x72 github.com/apache/apisix-ingress-controller/pkg/ingress.(Controller).CompareResources.func1.1({0xc000417b24, 0x7}) /Users/jasonzhu/opensource/2022/apisix-ingress-controller/pkg/ingress/compare.go:78 +0x852 created by github.com/apache/apisix-ingress-controller/pkg/ingress.(Controller).CompareResources.func1 /Users/jasonzhu/opensource/2022/apisix-ingress-controller/pkg/ingress/compare.go:68 +0x248

Expected result

No response

tao12345666333 commented 2 years ago

Can you check the commit id?

Belyenochi commented 2 years ago

Can you check the commit id?

75098d1

Belyenochi commented 2 years ago

I found a fact that the CR I created is v2beta1, but can be obtained from the List method of ApisixV2Beta3, maybe the incompatible Beta1 and Beta3 CRD formats are causing the problem.

Belyenochi commented 2 years ago

Maybe we should update this document.

tao12345666333 commented 2 years ago

spec.http[].backend has been removed. we should use spec.http[].backends .

tao12345666333 commented 2 years ago

Here's a configuration that determines how to handle CRs. The CR version you are using needs to be the same as here.

https://github.com/apache/apisix-ingress-controller/blob/75098d1e4b26136de3164a3aabd6ed018ffdcd6b/conf/config-default.yaml#L73-L74

Maybe we should update this document.

Sure, I have created an issue, it is suitable for newbies to get involved in this project https://github.com/apache/apisix-ingress-controller/issues/915

tao12345666333 commented 2 years ago

I think we can close this one.