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

Be able to set route id in Kubernetes resource

Open frankkoornstra opened this issue 1 year ago • 9 comments

Description

When a route gets created from the Kubernetes resource there's no way to create the id deterministically (by providing a route_id for example) or to even get the id from the status of the resource; only when I log in to the dashboard, I can get the route id.

I need the route id to be able to programmatically create consumers that I want to restrict to a route with consumer-restrict through the Admin API . Also I need it to analyze my reported traffic in a completely different service.

I would be very happy if we could determine the id beforehand with an optional route_id in the spec. If that's not possible, could the id be returned in the status of the k8s resource?

frankkoornstra avatar Jun 28 '23 09:06 frankkoornstra

Here are a few clarifications:

  1. Do not mix declarative configuration and admin API

  2. It is not a good idea to rely on ids that have no clear meaning

But if you want to get the route id, it's a good idea to go back to status.

You can also check out the current build logic, it's fixed

tao12345666333 avatar Jun 28 '23 14:06 tao12345666333

Being able to determine the ID beforehand - let's say user-management - would save us a lot of trouble because we can rely on a naming convention and we'd now we'd have the right route. We'd also not have to communicate a random id to all the services that use it.

Re 1: I don't think I understand what you mean. The Admin API already exposes the possibility of determining the ID beforehand as far as I can see, it's just that the Ingress Controller does not make use of it. Re 2: I agree so that's why I want to make the ID mean something, say user-management, something I'd like to control from the k8s resource :smiley:

frankkoornstra avatar Jun 28 '23 14:06 frankkoornstra

@frankkoornstra are you planning to raise a PR?

shreemaan-abhishek avatar Jun 28 '23 16:06 shreemaan-abhishek

Because in a Kubernetes environment (through declarative configuration), its name is obviously more intuitive. However, we also need to consider isolation based on namespaces. Users may deploy the same content in multiple namespaces, so we cannot directly use its name as an ID. Therefore, we regenerate its ID.

tao12345666333 avatar Jun 29 '23 01:06 tao12345666333

For clarity: I'm not suggesting using the actual metadata.name of the k8s resource for its id, but instead introduce a (nullable) field in the spec, maybe spec.route_id that could be set to an arbitrary (but predetermined) value and would be used to make the id for the route. The maker of the ApisixRoute k8s resource would be responsible for making the id unique. If the spec field would be empty, we could fall back to the current id creation mechanism.

So you'd have something like this:


apiVersion: apisix.apache.org/v2
kind: ApisixRoute
metadata:
  name: echo
spec:
  route_id: echo-route    <-- This would become the id of the route
  http:
    - name: echo-free
      match:
...

@shreemaan-abhishek I don't have the faintest idea how to write Go so sorry to say that I can't raise a PR.

frankkoornstra avatar Jul 05 '23 12:07 frankkoornstra

After the APISIX Route is submitted as a k8s resource, the name of the generated apisix route is named using the following rule. How about using the same rule for the ID?

https://github.com/apache/apisix-ingress-controller/blob/e809cfbaaad6f6c3cbd23f5ec8e93bc1d87f543d/pkg/providers/apisix/translation/apisix_route.go#L157-L159 https://github.com/apache/apisix-ingress-controller/blob/master/pkg/types/apisix/v1/types.go#L619 https://github.com/apache/apisix-ingress-controller/blob/e809cfbaaad6f6c3cbd23f5ec8e93bc1d87f543d/pkg/types/apisix/v1/types.go#L619-L632

Gallardot avatar Jul 09 '23 08:07 Gallardot

That would definitely work :+1:

frankkoornstra avatar Jul 10 '23 08:07 frankkoornstra

This will be a break change. Is anyone willing to submit a PR to implement it?

tao12345666333 avatar Jul 17 '23 05:07 tao12345666333

I wish I could but am not capable in Go

frankkoornstra avatar Jul 25 '23 08:07 frankkoornstra