Following my post about writing custom middleware, I tried to write my own middleware for writing my req/res in kafka. I've managed to develop a good understanding of middlewares in traefik for a while and I was able to implement this middleware and test it to see if it's working.
I tested it with dynamic config file - defined a middleware e.g. 'my-mw' and assigned it to a router - and it worked as expected.
But then I tried to create a CRD Middleware for that and test an IngressRoute to see if they work but it didn't.
I don't know What am I missing that this doesn't work.
I also tried generating the deepcopy generated file things with k8s tag, etc. but I couldn't make it work.
I'd be very glad if someone could help me with this
To add the middlewares configuration, the Kubernetes CRD provider needs a specific development which can be summarized as follows:
- add the definition in the
- add the
// +k8s:deepcopy-gen=true just before the new structures
- Launch a
make generate-crd command
Then you can test/use it.
Actually I've already tried this.
I've looked into the code and figured this out. To be exact, I did the followings:
I've added my new struct in
pkg/config/dynamic/middlewares.go, where the rest of the middlewares exist. Then I added
// +k8s:deepcopy-gen=true just before it.
Then I added this new middleware to
Then I ran
After that, when I tried to create a new such middleware with CRD, I saw that traefik doesn't recognize it.
I also implemented that middleware code in a new folder in
pkg/middlewares, so that shouldn't be a problem.
Are there other steps which I'm missing? Like something to do in k8s in order for this to recognize it?
Thanks for your quick response.
Are the other middlewares available with in your kubernetes ?
To use the CRD you have to declare their definitions
Could you provide more information like logs or a list of available resources in your kubernetes cluster?
I already defined those CRD definitions in my cluster.
I tested PathPrefix as an example to check its functionality and it worked as expected.
I don't have cluster access to give you the resources in my cluster (Those CRD were added manually by admin and we don't have access to CRD mangement, we can only edit instances of those 4 CRD that traefik provided: IngressRoute, etc.)
I will try to provide logs as soon as possible. I am in the middle of something right now and after that, I will provide more info about it.
But as far as I remember (because I tested this about two weeks ago :D) it was one of two things:
- traefik logs that I don't recognize this middleware (more probably)
- traefik doesn't show anything
I will try to confirm which of these problem occurred later on.
So I tested it and I figured out that no logs (not even debug) are produced from traefik. As if it doesn't see it at all.
I also tried to create middleware in a dynamic config file and use that name in my IngressRoute, but it doesn't recognize it.
I don't know what to do!
I think one more step that we should have considered is adding our new middleware in
I suddenly came across it and saw that I missed this part!
I'll try it out to see if it works and let you know.