Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Knative/OpenShift client environment check #28172

Merged

Conversation

michalvavrik
Copy link
Contributor

@michalvavrik michalvavrik commented Sep 23, 2022

fixes: #28171

According to https://github.com/fabric8io/kubernetes-client/blob/master/doc/MIGRATION-v6.md#adapt-changes, isAdaptable method semantic has changed (and the method is deprecated) and it's causing failures in Quarkus QE Test Suite. AFAIK originally isAdaptable check wasn't strict (contains, endsWith), so you could have ApiGroups like (see below) and check would succeed fabric8io/kubernetes-client@bb6115a#diff-a23a9372cb2d1a1c4121272460b2c8e2f8dd79bf5722b8b2a36ba5d4578cef75 . Now, check fails if there is no group that strictly matches APIGroup knative.dev. That's however not necessary for our app to work, f.e. our APIGroups are:

  • serving.knative.dev
  • serving.knative.dev/v1
  • serving.knative.dev/v1
  • serving.knative.dev/v1beta1
  • serving.knative.dev/v1alpha1
  • autoscaling.internal.knative.dev
  • autoscaling.internal.knative.dev/v1alpha1
  • autoscaling.internal.knative.dev/v1alpha1
  • caching.internal.knative.dev
  • caching.internal.knative.dev/v1alpha1
  • caching.internal.knative.dev/v1alpha1
  • networking.internal.knative.dev
  • networking.internal.knative.dev/v1alpha1
  • networking.internal.knative.dev/v1alpha1
  • operator.knative.dev
  • operator.knative.dev/v1alpha1
  • operator.knative.dev/v1alpha1

When Quarkus is not performing strict tests for knative.dev, our app is working and check performed is same as before.

Copy link
Contributor

@Sgitario Sgitario left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Many many thanks for your pull request!

Spites I understand this is broken and that there might not have a better solution, I think these changes are a bit fragile (I mean checking the coordinates of the fabric8:openshift-client artifact).

About the problem itself, I don't fully follow what exactly changed in regards to the isAdaptable method. @manusa can you help here?

Also, I'm not sure if this is possible, but adding some tests would help.

Anyway, let's wait for @manusa's feedback.

@michalvavrik
Copy link
Contributor Author

michalvavrik commented Sep 23, 2022

@Sgitario I'll try to write a test then (I've already tried, but sure, there must be a way...). As for isAdaptable, all I know is what changed fabric8io/kubernetes-client@bb6115a#diff-d3ca8c6252f8f76bcd09c8faa8b0039c49886b929de4388ed0ca05df521f01c1L37 and it does cause troubles. And this PR is what I understood a migration guide suggest. It's very much possible I misunderstood it! Let's here from expert.

@michalvavrik
Copy link
Contributor Author

michalvavrik commented Sep 23, 2022

My understanding is that isAdaptable is now calling OC, which is surplus to requirements when just checking if we can adapt client to KnativeClient (ex. from test I wrote, not from reproducer):

...
Caused by: io.quarkus.builder.BuildException: Build failure: Build failed due to errors
	[error]: Build step io.quarkus.kubernetes.deployment.KnativeDeployer#checkEnvironment threw an exception: io.fabric8.kubernetes.client.KubernetesClientException: An error has occurred.
	at io.fabric8.kubernetes.client.KubernetesClientException.launderThrowable(KubernetesClientException.java:129)
	at io.fabric8.kubernetes.client.KubernetesClientException.launderThrowable(KubernetesClientException.java:122)
	at io.fabric8.kubernetes.client.dsl.internal.OperationSupport.restCall(OperationSupport.java:779)
	at io.fabric8.kubernetes.client.BaseClient.getApiGroup(BaseClient.java:242)
	at io.fabric8.kubernetes.client.BaseClient.hasApiGroup(BaseClient.java:158)
	at io.fabric8.kubernetes.client.extension.ClientAdapter.hasApiGroup(ClientAdapter.java:73)
	at io.fabric8.knative.client.DefaultKnativeClient.isSupported(DefaultKnativeClient.java:244)
	at io.fabric8.kubernetes.client.BaseClient.isAdaptable(BaseClient.java:176)
	at io.quarkus.kubernetes.deployment.KnativeDeployer.lambda$checkEnvironment$0(KnativeDeployer.java:26)
	at java.base/java.util.Optional.ifPresent(Optional.java:178)
	at io.quarkus.kubernetes.deployment.KnativeDeployer.checkEnvironment(KnativeDeployer.java:21)

...

If we could judge from ex. thrown Knative was requested as a deployment, but the target cluster is not a Knative cluster, than isAdaptable should still be called, or hasApiGroup("knative.dev", true) etc.

@michalvavrik michalvavrik force-pushed the feature/fix-knative-client-validation branch from 75d15be to 04ca353 Compare September 23, 2022 13:31
@michalvavrik
Copy link
Contributor Author

michalvavrik commented Sep 23, 2022

@Sgitario I changed PR and its description. This fix should not require tests (that if you think about it are hard to do; mocks might do). I'd suggest to wait for response to @manusa and eventually close this PR if it's wrong/someone else provides better one.

@michalvavrik michalvavrik changed the title Fix Knative/OpenShift client environment check Fix Knative client environment check Sep 23, 2022
@quarkus-bot

This comment has been minimized.

@michalvavrik michalvavrik force-pushed the feature/fix-knative-client-validation branch 2 times, most recently from 9db9481 to 985a52d Compare September 23, 2022 14:31
@michalvavrik michalvavrik changed the title Fix Knative client environment check Fix Knative/OpenShift client environment check Sep 23, 2022
@manusa
Copy link
Contributor

manusa commented Sep 23, 2022

Couldn't read the code changes yet, but a quick note on the isAdaptable, and in general Adapt, behavioral changes:

Adapt Changes
Client.isAdaptable and Client.adapt will check first if the existing client is an instance of the desired type.
Client.adapt will no longer perform the isAdaptable check - that is you may freely adapt from one Client to another as long as the extension exists. If you need to make a specific check of support, please use the Client.supports method.

You can read more about them at our Migration Guide.

This means that the behavior for this method has changed completely for version 6.

The isAdaptable method is deprecated and should no longer be used.

If you need to check if the cluster supports the operations that the derived client supports (in this case I guess KnativeClient or OpenShiftClient), you should use the .isSupported() method instead. (kubernetesClient.adapt(KnativeClient.class).isSupported())

In addition, you can use the .supports(Class<R> type) with any of our generated model classes, or the .hasApiGroup(String apiGroup, boolean exact) method.

@michalvavrik
Copy link
Contributor Author

@Sgitario I want to urge you in no way, just give me a hint what's next (or ETA) as if you need a time, I'm going to disable QE tests, thanks a lot

@manusa
Copy link
Contributor

manusa commented Sep 26, 2022

Just a quick note that today is a bank holiday in Barcelona

@michalvavrik
Copy link
Contributor Author

Ah, thank you @manusa

Copy link
Contributor

@Sgitario Sgitario left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apart from the comments, the changes look good to me.
Many thanks @michalvavrik !

@michalvavrik michalvavrik force-pushed the feature/fix-knative-client-validation branch from 985a52d to 621fc75 Compare September 27, 2022 08:51
@michalvavrik
Copy link
Contributor Author

Thank you for the review.

@Sgitario
Copy link
Contributor

Many thanks @michalvavrik . lgtm now
@geoand are you ok with merging this one?

Copy link
Contributor

@geoand geoand left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like you folks have figured it out.

Feel free to merge when CI is green

@geoand geoand added the triage/waiting-for-ci Ready to merge when CI successfully finishes label Sep 27, 2022
@quarkus-bot
Copy link

quarkus-bot bot commented Sep 27, 2022

Failing Jobs - Building 621fc75

Status Name Step Failures Logs Raw logs
✔️ JVM Tests - JDK 11
✔️ JVM Tests - JDK 17
JVM Tests - JDK 17 MacOS M1 ⚠️ Check → Logs Raw logs
✔️ JVM Tests - JDK 18

@Sgitario
Copy link
Contributor

Failures are unrelated to this PR. Merging.

@Sgitario Sgitario merged commit 463f9a6 into quarkusio:main Sep 27, 2022
@quarkus-bot quarkus-bot bot added this to the 2.14 - main milestone Sep 27, 2022
@quarkus-bot quarkus-bot bot added kind/bugfix and removed triage/waiting-for-ci Ready to merge when CI successfully finishes labels Sep 27, 2022
@michalvavrik michalvavrik deleted the feature/fix-knative-client-validation branch September 27, 2022 14:49
@gsmet
Copy link
Member

gsmet commented Sep 28, 2022

@Sgitario @geoand @michalvavrik I think this should be backported, right?

@michalvavrik
Copy link
Contributor Author

This behavior comes from switch to Kubernetes client 6.1.1, thus 2.13 should not be affected.

@gsmet
Copy link
Member

gsmet commented Sep 28, 2022

OK, perfect, thanks!

@manusa
Copy link
Contributor

manusa commented Feb 20, 2023

Note that these methods will need refactoring when bumping the client to 6.5 or at most 6.6

fabric8io/kubernetes-client#4869

@geoand
Copy link
Contributor

geoand commented Feb 20, 2023

Thanks for the heads up!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

KnativeDeployer environment check is breaking the build
5 participants