apisix-ingress-controller
apisix-ingress-controller copied to clipboard
bug: Unable to update reserved routes using SDK
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{})
}
cc @kayx23 @Revolyssup
No knowledge of this sorry, let's wait for others to pitch in.
I'll take a loot at it tomorrow. Currently I am busy with other tasks. Thanks for reporting.
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 When you check the error and response of .Update(), what do you see?
@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
@Revolyssup You can try using a very long host field, it will not take effect
@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?
I used the SDK to update URI field where the Host was long as you suggested and it was updated successfully.
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.
I know he can successfully generate it, but he cannot work, and I am not sure if it is a bug in Apisix
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?
@DokiDoki1103 Any updates?
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.