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

bug: Unable to update reserved routes using SDK

Open DokiDoki1103 opened this issue 1 year ago • 13 comments

Current Behavior

After using SDK to update the route, I found that there was no departure watch mechanism and it did not take effect in a timely manner

But I can update using kubectl edit

May I ask why the use of SDK does not work ?

	c := handler.GetAPIGatewayHandler().GetClient().ApisixV2()
	tenant := r.Context().Value(ctxutil.ContextKey("tenant")).(*dbmodel.Tenants)
	list, _ := c.ApisixRoutes(tenant.Namespace).List(r.Context(), v1.ListOptions{
		LabelSelector: "service_alias=" + r.URL.Query().Get("service_alias"),
	})
	for _, item := range list.Items {
		var plugins = item.Spec.HTTP[0].Plugins
		var newPlugins = make([]v2.ApisixRoutePlugin, 0)
		for _, plugin := range plugins {
			if plugin.Name != ResponseRewrite {
				newPlugins = append(newPlugins, plugin)
			}
		}

		if r.URL.Query().Get("act") == "close" {
			newPlugins = append(newPlugins, v2.ApisixRoutePlugin{
				Name:   ResponseRewrite,
				Enable: true,
				Config: map[string]interface{}{
					"status_code": 404,
					"body":        "请打开对外访问",
				},
			})
		}
		item.Spec.HTTP[0].Plugins = newPlugins
		c.ApisixRoutes(tenant.Namespace).Update(r.Context(), &item, v1.UpdateOptions{})
		c.ApisixRoutes(tenant.Namespace).UpdateStatus(r.Context(), &item, v1.UpdateOptions{})
	}

DokiDoki1103 avatar Dec 14 '23 04:12 DokiDoki1103

cc @kayx23 @Revolyssup

DokiDoki1103 avatar Dec 14 '23 05:12 DokiDoki1103

No knowledge of this sorry, let's wait for others to pitch in.

kayx23 avatar Dec 14 '23 05:12 kayx23

I'll take a loot at it tomorrow. Currently I am busy with other tasks. Thanks for reporting.

Revolyssup avatar Dec 14 '23 07:12 Revolyssup

I need to add that this situation only occurs when two resources are updated simultaneously. If I only update one of the resources, it will work normally

[root@iZ0jlcmvdsbq3e5h9ronw8Z ~]# kubectl get apisixroutes.apisix.apache.org -n admin 
NAME                                              HOSTS                                                     URIS     AGE
180.grff3d3f.w51izhca.8.130.98.199.nip.iop-ps-s   ["80.grff3d3f.w51izhca.8.130.98.199.nip.io","lyck6.cn"]   ["/*"]   3s
1lyck6.cnp-ps-s                                   ["lyck6.cn"]                                              ["/*"]   3s

Look lyck6.cn is repetitive

I suspect it's due to the Host field being too long 80.grff3d3f.w51izhca.8.130.98.199.nip.io

Because I tested, if the host route is too long, it will not take effect. Is this a bug ?

DokiDoki1103 avatar Dec 14 '23 08:12 DokiDoki1103

@DokiDoki1103 When you check the error and response of .Update(), what do you see?

Revolyssup avatar Dec 18 '23 05:12 Revolyssup

@DokiDoki1103 When you check the error and response of .Update(), what do you see?

No errors were reported ,But I have pinpointed the problem, it's because the host field is too long

DokiDoki1103 avatar Dec 18 '23 06:12 DokiDoki1103

@Revolyssup You can try using a very long host field, it will not take effect

DokiDoki1103 avatar Dec 18 '23 06:12 DokiDoki1103

@DokiDoki1103 I need to be able to reproduce the issue. Can you paste the full route configuration which I can use to reproduce, for both cases when it works and when it doesnt?

Revolyssup avatar Dec 19 '23 20:12 Revolyssup

I used the SDK to update URI field where the Host was long as you suggested and it was updated successfully. Screenshot 2023-12-20 at 12 21 25 PM

Revolyssup avatar Dec 20 '23 06:12 Revolyssup

Are you sure there are no reported errors from Update(), please show the logs where you log the returned response and error. Also show the complete configuration that you used.

Revolyssup avatar Dec 20 '23 06:12 Revolyssup

I know he can successfully generate it, but he cannot work, and I am not sure if it is a bug in Apisix

DokiDoki1103 avatar Dec 20 '23 07:12 DokiDoki1103

I know he can successfully generate it, but he cannot work, and I am not sure if it is a bug in Apisix

Can you clarify what you said? What do you mean by "cannot work" and do you mean that update is successful in ingress but the configuration doesn't take effect in APISIX?

Revolyssup avatar Dec 20 '23 10:12 Revolyssup

@DokiDoki1103 Any updates?

Revolyssup avatar Jan 02 '24 20:01 Revolyssup

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 Apr 02 '24 01:04 github-actions[bot]