Skip to content

Commit

Permalink
fix fabric8io#4659: deprecating support testing client
Browse files Browse the repository at this point in the history
also adding a generic supports method
  • Loading branch information
shawkins authored and manusa committed Feb 20, 2023
1 parent f701b7b commit 963fecd
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#### Improvements
* Fix #3805: DeletionTimestamp and Finalizer support in Mock server.
* Fix #4644: generate CRDs in parallel and optimize code
* Fix #4659: added a generic support(apiversion, kind) method in addition to the class based check
* Fix #4739: honor optimistic concurrency control semantics in the mock server for `PUT` and `PATCH` requests.
* Fix #4747: migrate to SnakeYAML Engine
* Fix #4788: moved retry logic into the standard client so that it applies to all requests, including websockets
Expand All @@ -38,6 +39,7 @@
* Fix #4758: added support for pod ephemeral container operations

#### _**Note**_: Breaking changes
* Fix #4659: The SupportTestingClient interface has been deprecated. Please use one of the supports methods or getApiGroup to determine what is available on the api server.

### 6.4.1 (2023-01-31)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,19 @@ public interface Client extends Closeable {
*/
<R extends KubernetesResource> boolean supports(Class<R> type);

/**
* Checks the Kubernetes server for support for the given type.
*
* <p>
* The response is not cached, a new check will be performed for each method invocation. In case custom resource
* definition is installed in between invocations, this method might return different values.
*
* @param apiVersion the api/version. This should be fully qualified - that is for openshift, please include the api.
* @param kind the resource kind
* @return boolean value indicating whether this type is supported
*/
boolean supports(String apiVersion, String kind);

/**
* Checks for the api group. exact = false will scan all groups
* for a suffix match. exact = true will look only for that apiGroup.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ public <T extends KubernetesResource> boolean supports(Class<T> type) {
return client.supports(type);
}

@Override
public boolean supports(String apiVersion, String kind) {
return client.supports(apiVersion, kind);
}

@Override
public boolean hasApiGroup(String apiGroup, boolean exact) {
return client.hasApiGroup(apiGroup, exact);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@
* Moving forward only clients with special support needs, such as
* the openshift client should implement this interface. For those classes,
* this interface can be part of the public contract.
*
* @deprecated will be removed in future versions
*/
@Deprecated
public interface SupportTestingClient extends Client {

/**
Expand All @@ -34,7 +37,10 @@ public interface SupportTestingClient extends Client {
* {@link Client#hasApiGroup(String, boolean)} to be compatible with mock support
*
* @return true if supported
*
* @deprecated use {@link Client#supports(Class)} or {@link Client#supports(String, String)} instead
*/
@Deprecated
boolean isSupported();

}
Original file line number Diff line number Diff line change
Expand Up @@ -193,14 +193,21 @@ public <R extends KubernetesResource> boolean supports(Class<R> type) {
if (Utils.isNullOrEmpty(typeApiVersion) || Utils.isNullOrEmpty(typeKind)) {
return false;
}
final APIResourceList apiResources = getApiResources(ApiVersionUtil.joinApiGroupAndVersion(
HasMetadata.getGroup(type), HasMetadata.getVersion(type)));
return supports(ApiVersionUtil.joinApiGroupAndVersion(
HasMetadata.getGroup(type), HasMetadata.getVersion(type)), typeKind);
}

@Override
public boolean supports(String apiVersion, String kind) {
Utils.checkNotNull(kind, "kind cannot be null");
Utils.checkNotNull(apiVersion, "apiVersion cannot be null");
final APIResourceList apiResources = getApiResources(apiVersion);
if (apiResources == null) {
return false;
}
return apiResources.getResources()
.stream()
.anyMatch(r -> typeKind.equals(r.getKind()));
.anyMatch(r -> kind.equals(r.getKind()));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,16 @@ void supportsIngressInServer() {
}
}

@Test
void supportsGeneric() {
try (MockedConstruction<OperationSupport> ignore = mockConstruction(OperationSupport.class,
(mock, ctx) -> when(mock.restCall(APIResourceList.class, "/apis", "networking.k8s.io/v1"))
.thenReturn(new APIResourceListBuilder().addNewResource().withKind("Ingress").endResource().build()))) {
// When
final boolean result = baseClient.supports("networking.k8s.io/v1", "Ingress");
// Then
assertThat(result).isTrue();
}
}

}

0 comments on commit 963fecd

Please sign in to comment.