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 (extensions) : isSupported doesn't check all of the applicable API Groups (#4447) #4631

Merged
merged 1 commit into from Dec 12, 2022

Conversation

rohanKanojia
Copy link
Member

@rohanKanojia rohanKanojia commented Dec 2, 2022

Description

Fix #4447

  • Extension client interfaces should extend SupportTestingClient rather than implementations
  • Disable exact apiGroup match in isSupported method call in extension clients. This effects Istio, Knative and Tekton extensions that use more than one apiGroups

Signed-off-by: Rohan Kumar rohaan@redhat.com

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • Feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change
  • Chore (non-breaking change which doesn't affect codebase;
    test, version modification, documentation, etc.)

Checklist

  • Code contributed by me aligns with current project license: Apache 2.0
  • I Added CHANGELOG entry regarding this change
  • I have implemented unit tests to cover my changes
  • I have added/updated the javadocs and other documentation accordingly
  • No new bugs, code smells, etc. in SonarCloud report
  • I tested my code in Kubernetes
  • I tested my code in OpenShift

@rohanKanojia rohanKanojia marked this pull request as ready for review December 2, 2022 11:13
@shawkins
Copy link
Contributor

shawkins commented Dec 2, 2022

Extension client interfaces should extend SupportTestingClient rather than implementations

@rohanKanojia @manusa the intent moving forward was to only expose the explicit support testing for the openshift client -

For the extensions, this is supposed to be an implicit mechanism that provided the same functionality as how their adapter logic used to call ExtensionAdapterSupport.isAdaptable. I was thinking in future releases we'd simply remove these checks. Since the extensions can be multi-group / multi-version clients, it's best for the user to check for explicit support of a resource.

@manusa
Copy link
Member

manusa commented Dec 2, 2022

I'm not sure what happened here.
The scope of the issue (at least when I created it) was just to disable the exact flag from the isSupported method implementation.

I also feel kind of uncomfortable with the usage of an interface in production code that is specific for testing purposes.

Steven, could you please give a few bullet points on how we should move forward with the interface and its usage (more specific tasks).

@shawkins
Copy link
Contributor

shawkins commented Dec 2, 2022

Steven, could you please give a few bullet points on how we should move forward with the interface and its usage (more specific tasks).

We mostly wanted Client.isAdaptable to go away - it has been deprecated.

The client impls that implemented SupportTestingClient did so to support checking their support via Client.isAdaptable. The client interfaces that extend SupportTestingClient, which I think is just the OpenShiftClient, are supposed to have the isSupported as part of their public contract.

Rather than doing:

if (client.isAdaptable(OpenShiftClient.class)) {
  OpenShiftClient openShiftClient = client.adapt(OpenShiftClient.class); 
  ...
}

you are supposed to do:

OpenShiftClient openShiftClient = client.adapt(OpenShiftClient.class); 
if (openShiftClient.isSupported()) { 
  ...
}

There are several rationales:

  • we've made the adapt operation always work - it's free of support checks - so isAdaptable is no longer semantically meaningful
  • we need to think about why we're exposing XXXClient.isSupported - as mentioned for multi-group / multi-version clients it's not appropriately expressive.

@rohanKanojia
Copy link
Member Author

I think these extensions also use isAdaptable method:

I added interface because i noticed isAdaptable is deprecated and I could not find a way to do equivalent using new adapt method. What should be expected behavior of adapt method if underlying cluster doesn't support extension's apiGroup. Should it return null if it doesn't support?

@manusa
Copy link
Member

manusa commented Dec 2, 2022

I added interface because i noticed isAdaptable is deprecated and I could not find a way to do equivalent using new adapt method. What should be expected behavior of adapt method if underlying cluster doesn't support extension's apiGroup. Should it return null if it doesn't support?

adapt doesn't care about the cluster having support for a given API group, isSupported should be used instead.

@rohanKanojia
Copy link
Member Author

isSupported method is not available in current extension interfaces (KnativeClient, TektonClient etc.) .

@manusa
Copy link
Member

manusa commented Dec 2, 2022

I was asking more about the future steps with regard to the SupportTestingClient interface.

In any case, my suggestion for the current PR is just to make the mentioned checks not exact.

Then do whatever we want with the isAdaptable legacy stuff in the scope of a more detailed issue.

@manusa
Copy link
Member

manusa commented Dec 2, 2022

isSupported method is not available in current extension interfaces (KnativeClient, TektonClient etc.) .

SupportTestingClient.isSupported is only used in Client.isAdaptable BaseClient implementation which is deprecated, thus the interface is deprecated too.

For 4447 the only requirement is to make the implementation on the default extension client implementations not exact.

In a nutshell, the following statement is NOT OK:

  • Extension client interfaces should extend SupportTestingClient rather than implementations

We can later consider getting rid altogether of the interface and whatever implementation remains, but I would rather do that in the scope of a different issue where we can actually discuss the implications.

@shawkins
Copy link
Contributor

shawkins commented Dec 2, 2022

isSupported method is not available in current extension interfaces (KnativeClient, TektonClient etc.) .

Yes, and I think we want to keep it that way.

The openshift client support check is more unique - it's primarily checking the url, then looking for any openshift group. There's a case to be made that such a broad check is not needed there either - or at the very least needs more documentation. As reported in #4604 you can just as easily have a regular kubernetes cluster return true from this check by having any of the openshift crds/operators installed - but it's certainly not actually a general openshift cluster.

So rather than doing:

XXXClient myClient = client.adapt(XXXClient.class); 
if (XXXClient.isSupported()) { 
  ...
}

you are supposed to check down to a resource level:

if (client.supports(MyResource.class)) {
  ...
}

We can of course also entertain adding client.resource(class).supports().

…I Groups (fabric8io#4447)

+ Disable exact apiGroup match in isSupported method call in
  extension clients which use more than one apiGroup. This effects Istio,
  Knative and Tekton extensions that use more than one apiGroups

Signed-off-by: Rohan Kumar <rohaan@redhat.com>
@sonarcloud
Copy link

sonarcloud bot commented Dec 12, 2022

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

100.0% 100.0% Coverage
0.0% 0.0% Duplication

@manusa manusa added this to the 6.3.0 milestone Dec 12, 2022
@manusa manusa merged commit 09edb3d into fabric8io:master Dec 12, 2022
@rohanKanojia rohanKanojia deleted the pr/issue4447 branch December 12, 2022 10:26
@shawkins
Copy link
Contributor

@manusa in the last meeting we talked about whether it would make more sense here just to go ahead and remove the deprecated isAdaptable and all of these checks from the extensions. Would you rather that be a follow-on task instead?

@manusa
Copy link
Member

manusa commented Dec 12, 2022

Yes. This should be tackled separately. I just needed to release this one so the temp fix can be removed from Quarkus.

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

Successfully merging this pull request may close these issues.

KnativeClient.isSupported doesn't check all of the applicable API Groups
3 participants