apisix-ingress-controller icon indicating copy to clipboard operation
apisix-ingress-controller copied to clipboard

bug: update apisixroute.yaml spec.http.name from a981a76 to api,Sometimes two routes are generated

Open LivesMountain opened this issue 2 years ago • 5 comments

Issue description

update apisixroute.yaml spec.http.name from a981a76 to api,Sometimes two routes are generated

kubectl get ar -A |grep screensaver ,only one data image

However, there are two data on dashboard, apisix-Ingress-Controller's log is missing, so I can't find the problem now . image

Etcd has some of the same data,Id and name are different routes/5341fe35 {"status":1,"uris":["/business-screensaver/"],"hosts":[""],"upstream_id":"e0a2d230","desc":"Created by apisix-ingress-controller, DO NOT modify it manually","update_time":1650358919,"create_time":1650358919,"priority":0,"id":"5341fe35","name":"*-business-screensaver_api","labels":{"managed-by":"apisix-ingress-controller"},"plugins":{"proxy-rewrite":{"regex_uri":["***business-screensaver/(.)","/$1"]}}}

routes/31f041fe {"status":1,"uris":["/business-screensaver/"],"hosts":["***"],"upstream_id":"e0a2d230","desc":"Created by apisix-ingress-controller, DO NOT modify it manually","update_time":1649379005,"create_time":1649379005,"priority":0,"id":"31f041fe","name":"*****business-screensaver_a981a76","labels":{"managed-by":"apisix-ingress-controller"},"plugins":{"proxy-rewrite":{"regex_uri":["^***business-screensaver/(.)","/$1"]}}}

Currently, only this route is found to be faulty. All other routes change spec.http.name to API, and only change the original data a981a76 does not generate a new route entry 。

It is not clear when apisix-Controller creates a new route entry, and when does it modify the original data

At present, only the phenomenon can be seen, but it is not clear how to troubleshoot and reappear,Ask for Help

Environment

  • your apisix-ingress-controller version (output of apisix-ingress-controller version --long):
  • 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

{{- if .Values.apisixroute.enabled -}}
apiVersion: apisix.apache.org/v2beta3
kind: ApisixRoute
metadata:
  name: {{ include "test.fullname" . }}
spec:
  http:
  - name: a981a76
    match:
      hosts:
      - "{{ .Values.apisixroute.host }}"
      paths:
      - "{{ .Values.apisixroute.path }}*"
    plugins: 
    - name: proxy-rewrite
      enable: true 
      config: 
        regex_uri: ["^{{ .Values.apisixroute.path }}(.*)", "/$1"]
    backends:
    - serviceName: "{{ include "test.fullname" . }}"
      servicePort: 80
{{- end -}}
{{- if .Values.apisixroute.enabled -}}
apiVersion: apisix.apache.org/v2beta3
kind: ApisixRoute
metadata:
  name: {{ include "test.fullname" . }}
spec:
  http:
  - name: api
    match:
      hosts:
      - "{{ .Values.apisixroute.host }}"
      paths:
      - "{{ .Values.apisixroute.path }}*"
    plugins: 
    - name: proxy-rewrite
      enable: true 
      config: 
        regex_uri: ["^{{ .Values.apisixroute.path }}(.*)", "/$1"]
    backends:
    - serviceName: "{{ include "test.fullname" . }}"
      servicePort: 80
{{- end -}}

Render yamL1 template with helm changed to render YamL2 template with helm

Actual result

The dashboard produces two identical servername and path image image

Etcd has some of the same data,Id and name are different routes/5341fe35 {"status":1,"uris":["/business-screensaver/"],"hosts":[""],"upstream_id":"e0a2d230","desc":"Created by apisix-ingress-controller, DO NOT modify it manually","update_time":1650358919,"create_time":1650358919,"priority":0,"id":"5341fe35","name":"*-business-screensaver_api","labels":{"managed-by":"apisix-ingress-controller"},"plugins":{"proxy-rewrite":{"regex_uri":["***business-screensaver/(.)","/$1"]}}}

routes/31f041fe {"status":1,"uris":["/business-screensaver/"],"hosts":["***"],"upstream_id":"e0a2d230","desc":"Created by apisix-ingress-controller, DO NOT modify it manually","update_time":1649379005,"create_time":1649379005,"priority":0,"id":"31f041fe","name":"*****business-screensaver_a981a76","labels":{"managed-by":"apisix-ingress-controller"},"plugins":{"proxy-rewrite":{"regex_uri":["^***business-screensaver/(.)","/$1"]}}}

Error log

There is no error log [GIN] 2022/04/27 - 20:44:33 | 200 | 27.103µs | 169.254.1.1 | GET "/healthz" [GIN] 2022/04/27 - 20:44:43 | 200 | 30.804µs | 169.254.1.1 | GET "/healthz" [GIN] 2022/04/27 - 20:44:43 | 200 | 26.288µs | 169.254.1.1 | GET "/healthz" [GIN] 2022/04/27 - 20:44:53 | 200 | 27.1µs | 169.254.1.1 | GET "/healthz" [GIN] 2022/04/27 - 20:44:53 | 200 | 27.51µs | 169.254.1.1 | GET "/healthz" [GIN] 2022/04/27 - 20:45:03 | 200 | 29.087µs | 169.254.1.1 | GET "/healthz" [GIN] 2022/04/27 - 20:45:03 | 200 | 24.202µs | 169.254.1.1 | GET "/healthz" [GIN] 2022/04/27 - 20:45:13 | 200 | 24.406µs | 169.254.1.1 | GET "/healthz" [GIN] 2022/04/27 - 20:45:13 | 200 | 28.976µs | 169.254.1.1 | GET "/healthz" W0427 20:45:16.346147 1 warnings.go:70] apisix.apache.org/v2beta1 ApisixRoute is deprecated; use apisix.apache.org/v2beta3 ApisixRoute [GIN] 2022/04/27 - 20:45:23 | 200 | 29.95µs | 169.254.1.1 | GET "/healthz" [GIN] 2022/04/27 - 20:45:23 | 200 | 24.161µs | 169.254.1.1 | GET "/healthz" [GIN] 2022/04/27 - 20:45:33 | 200 | 34.457µs | 169.254.1.1 | GET "/healthz" [GIN] 2022/04/27 - 20:45:33 | 200 | 24.054µs | 169.254.1.1 | GET "/healthz" [GIN] 2022/04/27 - 20:45:43 | 200 | 26.65µs | 169.254.1.1 | GET "/healthz" [GIN] 2022/04/27 - 20:45:43 | 200 | 24.778µs | 169.254.1.1 | GET "/healthz" [GIN] 2022/04/27 - 20:45:53 | 200 | 31.825µs | 169.254.1.1 | GET "/healthz" [GIN] 2022/04/27 - 20:45:53 | 200 | 21.546µs | 169.254.1.1 | GET "/healthz" [GIN] 2022/04/27 - 20:46:03 | 200 | 28.885µs | 169.254.1.1 | GET "/healthz" [GIN] 2022/04/27 - 20:46:03 | 200 | 23.01µs | 169.254.1.1 | GET "/healthz" [GIN] 2022/04/27 - 20:46:13 | 200 | 24.818µs | 169.254.1.1 | GET "/healthz" [GIN] 2022/04/27 - 20:46:13 | 200 | 22.304µs | 169.254.1.1 | GET "/healthz"

Expected result

Update the apisixRoute spec.http.name field and only one route appears

LivesMountain avatar Apr 27 '22 13:04 LivesMountain

apisix-ingress-controller version 1.4.0 apisix version 2.13.1 etcdctl version: 3.4.18

LivesMountain avatar Apr 27 '22 13:04 LivesMountain

This is not a bug, this is a concrete implementation.

For now we will use this name to construct the final route name.

If you update the ApisixRoute resource directly, since the metadata.name has not changed, it will only synchronize the route according to the current configuration.

But the APISIX Ingress controller will not delete the original route information in APISIX, which is very dangerous. Unless you delete the ApisixRoute resource and re-create it with a new configuration.

tao12345666333 avatar Apr 28 '22 08:04 tao12345666333

I did not modify metadata.name ,I changed spec.http.name。 apisixroute1.yaml

apiVersion: apisix.apache.org/v2beta3
kind: ApisixRoute
metadata:
  name: nginx
  namespace: default
spec:
  http:
  - name: a981a76
    match:
      hosts:
      - "test.apisixroute.com"
      paths:
      - "/*"
    backends:
    - serviceName: nginx
      servicePort: 80

kubectl apply -f apisixroute1.yaml kubectl describe ar nginx image dashboard 1651650709

apisixroute2.yaml

apiVersion: apisix.apache.org/v2beta3
kind: ApisixRoute
metadata:
  name: nginx
  namespace: default
spec:
  http:
  - name: api
    match:
      hosts:
      - "test.apisixroute.com"
      paths:
      - "/*"
    backends:
    - serviceName: nginx
      servicePort: 80

kubectl apply -f apisixroute2.yaml kubectl describe ar nginx image dashboard image The above is normal In practice, however,in some cases,apisixRoute update will result in two route records in etcd,It looks like a new route record was created instead of updating the old route image

LivesMountain avatar May 04 '22 08:05 LivesMountain

If you update the ApisixRoute resource directly, since the metadata.name has not changed, it will only synchronize the route according to the current configuration.

But the APISIX Ingress controller will not delete the original route information in APISIX, which is very dangerous. Unless you delete the ApisixRoute resource and re-create it with a new configuration.

Please read my previous comment

tao12345666333 avatar May 04 '22 15:05 tao12345666333

This issue has been marked as stale due to 90 days of inactivity. It will be closed in 30 days if no further activity occurs. If this issue is still relevant, please simply write any comment. Even if closed, you can still revive the issue at any time or discuss it on the [email protected] list. Thank you for your contributions.

github-actions[bot] avatar Aug 04 '22 01:08 github-actions[bot]

This issue has been closed due to lack of activity. If you think that is incorrect, or the issue requires additional review, you can revive the issue at any time.

github-actions[bot] avatar Sep 03 '22 01:09 github-actions[bot]