Ocelot icon indicating copy to clipboard operation
Ocelot copied to clipboard

After updating to kube 15.0.6, no redirect working

Open rakkum opened this issue 4 years ago • 22 comments

Expected Behavior / New Feature

We had 14.0.11 installed for our gateway service running in Azure K8s, version 1.15.7. After updating to 15.0.6 no reroutes are working. There should be no regressions when doing this update.

Actual Behavior / Motivation for New Feature

Looking at the logs, it shows these errors: Unable to find service discovery provider for type: kube

Here is the Global config: "GlobalConfiguration": { "ServiceDiscoveryProvider": { "Host": "unused", "Port": 443, "Token": "unused", "Namespace": "XXX", "Type": "kube" } }

Since we use rbac with least accessabiliy we have the following definition for the access rights.

apiVersion: v1
kind: ServiceAccount
metadata:
  namespace: XXX
  name: api-serviceaccount
---
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
  namespace: XXX
  name: service-reader
rules:
- apiGroups: [""] # "" indicates the core API group
  resources: ["services", "endpoints", "pods"]
  verbs: ["get", "watch", "list"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
  name: read-services
  namespace: XXX
subjects:
- kind: ServiceAccount
  name: api-serviceaccount
  namespace: XXX
  apiGroup: ""
roleRef:
  kind: Role #this must be Role or ClusterRole
  name: service-reader
  apiGroup: rbac.authorization.k8s.io

Any other information thats needed? Everything else we kept the same, its really only the nuget update and the user account changes.

Steps to Reproduce the Problem

  1. Build a system using 14.x.x for k8s and define a reroute.
  2. Update the kubernetes nuget to 15.06
  3. Verify that the reroute is still working

Specifications

  • Version: 15.0.6
  • Platform: net core 3.1
  • Subsystem: kube

rakkum avatar Apr 14 '20 22:04 rakkum

The way I see it, this commit https://github.com/ThreeMammals/Ocelot/commit/6e5471a714dddb0a3a40fbb97eac2810cee1c78d renamed service discovery providers and now they are rejected here https://github.com/ThreeMammals/Ocelot/blob/master/src/Ocelot/ServiceDiscovery/ServiceDiscoveryProviderFactory.cs#L57. This should be broken for all service discovery providers as they were renamed in multiple places.

The way I got it to work was to create proxy providers with proper names, like they used to have: https://gist.github.com/molesinski/c949264d2d287e13c8c7477eb0632221

molesinski avatar Apr 15 '20 15:04 molesinski

Thanks for the solution! Looks like a pretty major bug to me.

Looking at it briefly, would setting the type in GlobalConfiguration to KubernetesServiceDiscoveryProvider work? Guess is should right?

rakkum avatar Apr 15 '20 16:04 rakkum

No, it wouldn't, because here it still is looking for old type name, which is "pollkube": https://github.com/ThreeMammals/Ocelot/blob/master/src/Ocelot.Provider.Kubernetes/KubernetesProviderFactory.cs#L30

molesinski avatar Apr 15 '20 21:04 molesinski

Ok, pollkube will remain broken but the default implementation should work or am i overlooking something?

rakkum avatar Apr 16 '20 10:04 rakkum

I can confirm that molesinski's solution works. I will still keep this open though because this should be fixed at library level.

rakkum avatar Apr 17 '20 06:04 rakkum

I'm also receiving this issue trying out the latest version of Ocelot. I agree this seems like a major bug that should be fixed asap.

jcfore21 avatar Apr 20 '20 15:04 jcfore21

I can indeed confirm that version 15.x doesn't work. When going back to 14.1.3 all works fine!

lery12 avatar Apr 20 '20 17:04 lery12

Same problem. Please, fix it!

MrImpossibru avatar Apr 22 '20 15:04 MrImpossibru

I have tried the 15.x and indeed it does not work with provider type "kube" or "pollkube" via appsettings.json. So I rolled back to 14.1.3.

I know it is a major change version. Shouldn't it have a documentation for what has changed?

elvishsu66 avatar Apr 27 '20 16:04 elvishsu66

I just started a new project with 16.0.1 and am getting this error so still not fixed. Should I downgrade to 14.1.3? The documentation is also wrong, I just wasted a whole day because I assumed I must be doing something wrong because it's never worked for me.

a-jackson avatar Jun 09 '20 13:06 a-jackson

If you dont use k8s you can downgrade to 14.x otherwise you should use 16.x and apply the fix that is described in this thread. Otherwise the traffic load balancing will not work correctly.

rakkum avatar Jun 09 '20 13:06 rakkum

Thanks. I missed the fix on first read through. I'll give that a go.

a-jackson avatar Jun 09 '20 13:06 a-jackson

I can confirm that molesinski's solution works. I will still keep this open though because this should be fixed at library level.

Um, I am trying to use @molesinski's fix for v16.0.1, but it doesn't work for me.

What I've done is - Added OcelotBuilderExtensions molesinski's from to my solution, then

            services
                .AddOcelot()
                .AddKubernetesFixed(); // https://github.com/ThreeMammals/Ocelot/issues/1199

Am I missing something?

elvishsu66 avatar Jun 26 '20 10:06 elvishsu66

Found out the reason from https://github.com/ThreeMammals/Ocelot/commit/3439be89271bb37b170429d69ca74978c941432e It turns out that v16.0.1 has changed the ReRoutes to Routes.

elvishsu66 avatar Jun 26 '20 12:06 elvishsu66

@elvishsu66 so you used ReRoutes in the config instead of Routes? If so its not a related issue. It was a breaking change from older versions to v16.

rakkum avatar Jun 26 '20 12:06 rakkum

@elvishsu66 so you used ReRoutes in the config instead of Routes? If so its not a related issue. It was a breaking change from older versions to v16.

Yes, @rakkum, that was my mistake. @molesinski's fix works for me as well.

elvishsu66 avatar Jul 08 '20 22:07 elvishsu66

Run into the same problem.Hope to repair as soon as possible.

344089386 avatar Aug 11 '20 03:08 344089386

I am also having this same issue in version 17.0 as well. Any timeline when this will be implemented in the library?

raymak23 avatar Dec 13 '20 16:12 raymak23

@molesinski - your solution worked for me in new version 17.0 of Ocelot package. Thanks so much.

raymak23 avatar Dec 13 '20 17:12 raymak23

The way I see it, this commit 6e5471a renamed service discovery providers and now they are rejected here https://github.com/ThreeMammals/Ocelot/blob/master/src/Ocelot/ServiceDiscovery/ServiceDiscoveryProviderFactory.cs#L57. This should be broken for all service discovery providers as they were renamed in multiple places.

The way I got it to work was to create proxy providers with proper names, like they used to have: https://gist.github.com/molesinski/c949264d2d287e13c8c7477eb0632221

How do you implement this code? How do you make ocelot use the OcelotBuilderExtensions.

default-kaas avatar May 28 '21 12:05 default-kaas

@molesinski - your solution worked for me in new version 17.0 of Ocelot package. Thanks so much.

How did you implement it, can simply add it to your project. Or do you need to change a file. Or do you need to give it to ocelot in the Startup.cs.

default-kaas avatar May 28 '21 12:05 default-kaas

Is there any chance this fix will be merged into develop branch?

MrDaedra avatar Jul 22 '22 11:07 MrDaedra

@molesinski commented on Apr 15, 2020

Thanks for your interest in Ocelot! Why not to create a PR?

raman-m avatar Sep 21 '23 20:09 raman-m

@rakkum @molesinski @elvishsu66 @MrDaedra and other people I am very sorry, guys, you have experienced such problems with K8s provider all these 3-4 years. Yes, the problem was introduced in 15.0.0 release by Tom in the commit https://github.com/ThreeMammals/Ocelot/commit/6e5471a714dddb0a3a40fbb97eac2810cee1c78d 🤯 , see my comment

raman-m avatar Mar 23 '24 16:03 raman-m

Fixed by #1954 on Feb 12 Fixed in version 23.0.0, released on Feb 13

raman-m avatar Mar 23 '24 16:03 raman-m