Skip to content

Commit

Permalink
fix fabric8io#3973: using consistent resource terminology throughout (f…
Browse files Browse the repository at this point in the history
…abric8io#3994)

also making PodResource non-generic
  • Loading branch information
shawkins committed Mar 25, 2022
1 parent 49db1af commit bb9a613
Show file tree
Hide file tree
Showing 51 changed files with 808 additions and 596 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ And Store.getKey can be used rather than directly referencing static Cache funct
* Fix #3407: Added Itemable.withItem to directly associate a resource with the DSL. It can be used as an alternative to Loadable.load when you already have the item. There is also client.resourceList(...).getResources() - that will provide the resource list as Resources. This allows you to implement composite operations easily with lambda: client.resourceList(...).getResources().forEach(r -> r.delete());
* Fix #3922: added Client.supports and Client.hasApiGroup methods
* KubernetesMockServer has new methods - unsupported and reset - to control what apis are unsupported and to reset its state.
* Fix #3407 #3973: Added Resourceable.resource to directly associate a resource with the DSL. It can be used as an alternative to Loadable.load when you already have the item.
There is also client.resourceList(...).resources() and client.configMaps().resources() - that will provide a Resource stream.
This allows you to implement composite operations easily with lambda: client.secrets().resources().forEach(r -> r.delete());

#### _**Note**_: Breaking changes in the API
Please see the [migration guide](doc/MIGRATION-v6.md)
Expand Down
11 changes: 8 additions & 3 deletions doc/MIGRATION-v6.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
- [Adapt Changes](#adapt-changes)
- [Deprecations](#deprecations)
- [Object sorting](#object-sorting)
- [Boolean Changes](#boolean-changes)
- [DSL Interface Changes](#dsl-interface-changes)
- [evict Changes](#evict-changes)

## Namespace Changes
Expand Down Expand Up @@ -192,10 +192,15 @@ Client.adapt will no longer perform the isAdaptable check - that is you may free

KubernetesList and Template will no longer automatically sort their objects by default. You may use the HasMetadataComparator to sort the items as needed.

## Boolean Changes
## DSL Interface Changes

The usage of Boolean in the api was removed where it was not a nullable value. Please expect a boolean primitive from methods such as delete, copy, or as an argument in Loggable.getLog
- The usage of Boolean in the api was removed where it was not a nullable value. Please expect a boolean primitive from methods such as delete, copy, or as an argument in Loggable.getLog

- WatchListDeletable now takes three type parameters to include the Resource type.

- PodResource is no longer generic.

## Evict Changes

Evictable.evict will throw an exception rather than returning false if the pod is not found. This ensures that false strictly means that the evict failed.

Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public ClusterServiceClassResource useServiceClass(String externalName) {
+ "found for ClusterServiceBroker: " + item.getMetadata().getName());
}
ClusterServiceClass c = list.get(0);
return client.adapt(ServiceCatalogClient.class).clusterServiceClasses().withItem(c);
return client.adapt(ServiceCatalogClient.class).clusterServiceClasses().resource(c);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public ClusterServicePlanResource usePlan(String externalName) {
+ " and ClusterServiceClass: " + item.getSpec().getExternalName() + ".");
}
ClusterServicePlan plan = list.get(0);
return client.adapt(ServiceCatalogClient.class).clusterServicePlans().withItem(plan);
return client.adapt(ServiceCatalogClient.class).clusterServicePlans().resource(plan);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public ServiceInstance instantiate(String... args) {
@Override
public ServiceInstanceResource instantiateAnd(String... args) {
ServiceInstance item = instantiate(args);
return client.adapt(ServiceCatalogClient.class).serviceInstances().withItem(item);
return client.adapt(ServiceCatalogClient.class).serviceInstances().resource(item);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,13 @@ public interface KubernetesClient extends Client {
* specific to CustomResource.
*
* <p>
* Note: your CustomResource POJO (T in this context) must implement
* {@link io.fabric8.kubernetes.api.model.Namespaced} if it is a namespace-scoped resource.
* Note: your CustomResource POJO (T in this context) must implement
* {@link io.fabric8.kubernetes.api.model.Namespaced} if it is a namespace-scoped resource.
* </p>
*
* @param resourceType Class for CustomResource
* @param <T> T type represents CustomResource type. If it's a namespaced resource, it must implement
* {@link io.fabric8.kubernetes.api.model.Namespaced}
* {@link io.fabric8.kubernetes.api.model.Namespaced}
* @return returns a MixedOperation object with which you can do basic CustomResource operations
* @deprecated use {@link #resources(Class)} instead
*/
Expand All @@ -147,14 +147,15 @@ public interface KubernetesClient extends Client {
* Typed API for managing resources. Any properly annotated POJO can be utilized as a resource.
*
* <p>
* Note: your resource POJO (T in this context) must implement
* {@link io.fabric8.kubernetes.api.model.Namespaced} if it is a namespace-scoped resource.
* Note: your resource POJO (T in this context) must implement
* {@link io.fabric8.kubernetes.api.model.Namespaced} if it is a namespace-scoped resource.
* </p>
*
* @param resourceType Class for resource
* @param <T> T type represents resource type. If it's a namespaced resource, it must implement
* {@link io.fabric8.kubernetes.api.model.Namespaced}
* @return returns a MixedOperation object with which you can do basic resource operations. If the class is a known type the dsl operation logic will be used.
* {@link io.fabric8.kubernetes.api.model.Namespaced}
* @return returns a MixedOperation object with which you can do basic resource operations. If the class is a known type the
* dsl operation logic will be used.
*/
default <T extends HasMetadata> MixedOperation<T, KubernetesResourceList<T>, Resource<T>> resources(Class<T> resourceType) {
return resources(resourceType, null);
Expand All @@ -166,31 +167,33 @@ default <T extends HasMetadata> MixedOperation<T, KubernetesResourceList<T>, Res
* specific to CustomResource.
*
* <p>
* Note: your CustomResource POJO (T in this context) must implement
* {@link io.fabric8.kubernetes.api.model.Namespaced} if it is a namespace-scoped resource.
* Note: your CustomResource POJO (T in this context) must implement
* {@link io.fabric8.kubernetes.api.model.Namespaced} if it is a namespace-scoped resource.
* </p>
*
* @param resourceType Class for CustomResource
* @param listClass Class for list object for CustomResource
* @param <T> T type represents CustomResource type. If it's a namespace-scoped resource, it must implement
* {@link io.fabric8.kubernetes.api.model.Namespaced}
* {@link io.fabric8.kubernetes.api.model.Namespaced}
* @param <L> L type represents CustomResourceList type
* @return returns a MixedOperation object with which you can do basic CustomResource operations
* @deprecated use {@link #resources(Class, Class)} instead
*/
@Deprecated
<T extends CustomResource, L extends KubernetesResourceList<T>> MixedOperation<T, L, Resource<T>> customResources(Class<T> resourceType, Class<L> listClass);
<T extends CustomResource, L extends KubernetesResourceList<T>> MixedOperation<T, L, Resource<T>> customResources(
Class<T> resourceType, Class<L> listClass);

/**
* Typed API for managing CustomResources. You would need to provide POJOs for
* CustomResource into this and with it you would be able to instantiate a client
* specific to CustomResource.
*
* <p>
* Note: your CustomResource POJO (T in this context) must implement
* <a href="https://github.com/fabric8io/kubernetes-client/blob/master/kubernetes-model-generator/kubernetes-model-core/src/main/java/io/fabric8/kubernetes/api/model/Namespaced.java">
* io.fabric8.kubernetes.api.model.Namespaced
* </a> if it is a Namespaced scoped resource.
* Note: your CustomResource POJO (T in this context) must implement
* <a href=
* "https://github.com/fabric8io/kubernetes-client/blob/master/kubernetes-model-generator/kubernetes-model-core/src/main/java/io/fabric8/kubernetes/api/model/Namespaced.java">
* io.fabric8.kubernetes.api.model.Namespaced
* </a> if it is a Namespaced scoped resource.
* </p>
*
* @deprecated Since 5.x versions of client {@link CustomResourceDefinitionContext} is now configured via annotations
Expand All @@ -199,12 +202,13 @@ default <T extends HasMetadata> MixedOperation<T, KubernetesResourceList<T>, Res
* @param resourceType Class for CustomResource
* @param listClass Class for list object for CustomResource
* @param <T> T type represents CustomResource type. If it's Namespaced resource, it must implement
* io.fabric8.kubernetes.api.model.Namespaced
* io.fabric8.kubernetes.api.model.Namespaced
* @param <L> L type represents CustomResourceList type
* @return returns a MixedOperation object with which you can do basic CustomResource operations
*/
@Deprecated
<T extends HasMetadata, L extends KubernetesResourceList<T>> MixedOperation<T, L, Resource<T>> customResources(ResourceDefinitionContext context, Class<T> resourceType, Class<L> listClass);
<T extends HasMetadata, L extends KubernetesResourceList<T>> MixedOperation<T, L, Resource<T>> customResources(
ResourceDefinitionContext context, Class<T> resourceType, Class<L> listClass);

/**
* Semi-Typed API for managing {@link GenericKubernetesResource}s which can represent any resource.
Expand All @@ -226,7 +230,8 @@ default MixedOperation<GenericKubernetesResource, GenericKubernetesResourceList,
* @param kind the resource kind
* @return returns a MixedOperation object with which you can do basic resource operations.
*/
MixedOperation<GenericKubernetesResource, GenericKubernetesResourceList, Resource<GenericKubernetesResource>> genericKubernetesResources(String apiVersion, String kind);
MixedOperation<GenericKubernetesResource, GenericKubernetesResourceList, Resource<GenericKubernetesResource>> genericKubernetesResources(
String apiVersion, String kind);

/**
* Discovery API entrypoint for APIGroup discovery.k8s.io
Expand Down Expand Up @@ -389,7 +394,8 @@ default MixedOperation<GenericKubernetesResource, GenericKubernetesResourceList,
* @param items a collection containing HasMetadata values
* @return operations object for Kubernetes list
*/
NamespaceListVisitFromServerGetDeleteRecreateWaitApplicable<HasMetadata> resourceList(Collection<? extends HasMetadata> items);
NamespaceListVisitFromServerGetDeleteRecreateWaitApplicable<HasMetadata> resourceList(
Collection<? extends HasMetadata> items);

/**
* KubernetesResource operations. You can pass any Kubernetes resource as a HasMetadata object and do
Expand Down Expand Up @@ -429,7 +435,7 @@ default MixedOperation<GenericKubernetesResource, GenericKubernetesResourceList,
*
* @return NonNamespaceOperation object for Namespace related operations
*/
NonNamespaceOperation< Namespace, NamespaceList, Resource<Namespace>> namespaces();
NonNamespaceOperation<Namespace, NamespaceList, Resource<Namespace>> namespaces();

/**
* API entrypoint for node related operations in Kubernetes. Node (core/v1)
Expand Down Expand Up @@ -457,7 +463,7 @@ default MixedOperation<GenericKubernetesResource, GenericKubernetesResourceList,
*
* @return MixedOperation object for Pod related operations
*/
MixedOperation<Pod, PodList, PodResource<Pod>> pods();
MixedOperation<Pod, PodList, PodResource> pods();

/**
* API entrypoint for ReplicationController related operations. ReplicationController (core/v1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@
*/
package io.fabric8.kubernetes.client.dsl;

public interface FilterWatchListDeletable<T, L> extends Filterable<FilterWatchListDeletable<T, L>>, WatchListDeletable<T, L> {

public interface FilterWatchListDeletable<T, L, R>
extends Filterable<FilterWatchListDeletable<T, L, R>>, WatchListDeletable<T, L, R> {

/**
* Accumulate a filter on the context, when done {@link FilterNested#endFilter()} or and must be called
*
* @return a {@link FilterNested}
*/
FilterNested<FilterWatchListDeletable<T, L>> withNewFilter();
FilterNested<FilterWatchListDeletable<T, L, R>> withNewFilter();

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@
*/
package io.fabric8.kubernetes.client.dsl;

public interface FilterWatchListMultiDeletable<T, L> extends FilterWatchListDeletable<T, L>, MultiDeleteable<T> {
public interface FilterWatchListMultiDeletable<T, L, R> extends FilterWatchListDeletable<T, L, R>, MultiDeleteable<T> {

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,20 @@
import io.fabric8.kubernetes.client.FromServerGettable;

import java.util.List;
import java.util.stream.Stream;

public interface ListVisitFromServerGetDeleteRecreateWaitApplicable<T> extends Visitable<ListVisitFromServerGetDeleteRecreateWaitApplicable<T>>,
FromServerGettable<List<T>>,
Waitable<List<T>, T>,
ListVisitFromServerWritable<T>,
DryRunable<ListVisitFromServerWritable<T>> {

public interface ListVisitFromServerGetDeleteRecreateWaitApplicable<T>
extends Visitable<ListVisitFromServerGetDeleteRecreateWaitApplicable<T>>,
FromServerGettable<List<T>>,
Waitable<List<T>, T>,
ListVisitFromServerWritable<T>,
DryRunable<ListVisitFromServerWritable<T>> {

/**
* Get each item as as a {@link Resource}
* @return the resources
*
* @return the {@link Resource} steam
*/
List<? extends Resource<T>> getResources();
Stream<? extends Resource<T>> resources();

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,13 @@

package io.fabric8.kubernetes.client.dsl;

import java.util.List;
import java.util.stream.Stream;

public interface NamespaceListVisitFromServerGetDeleteRecreateWaitApplicable<T> extends
ListVisitFromServerGetDeleteRecreateWaitApplicable<T>,
Namespaceable<ListVisitFromServerGetDeleteRecreateWaitApplicable<T>>
{
ListVisitFromServerGetDeleteRecreateWaitApplicable<T>,
Namespaceable<ListVisitFromServerGetDeleteRecreateWaitApplicable<T>> {

@Override
List<NamespaceableResource<T>> getResources();
Stream<NamespaceableResource<T>> resources();

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,19 @@
/**
* The entry point to client operations that are either "cross namespace resources", or are available in the invocation chain
* after a namespace has already been specified.
*
*
* @param <T> The Kubernetes resource type.
* @param <L> The list variant of the Kubernetes resource type.
* @param <R> The resource operations.
*/
public interface NonNamespaceOperation<T, L, R> extends
Nameable<R>,
FilterWatchListMultiDeletable<T, L>,
FilterWatchListMultiDeletable<T, L, R>,
Createable<T>,
CreateOrReplaceable<T>,
DryRunable<WritableOperation<T>>,
Replaceable<T>,
StatusReplaceable<T>,
Loadable<R>,
Itemable<T, R> {
Resourceable<T, R> {
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@

/**
* The entry point to client operations.
*
*
* @param <T> The Kubernetes resource type.
* @param <L> The list variant of the Kubernetes resource type.
* @param <R> The resource operations.
*/
public interface Operation<T, L, R>
extends
AnyNamespaceable<FilterWatchListMultiDeletable<T, L>>,
AnyNamespaceable<FilterWatchListMultiDeletable<T, L, R>>,
Namespaceable<NonNamespaceOperation<T, L, R>>,
FilterWatchListMultiDeletable<T, L>,
FilterWatchListMultiDeletable<T, L, R>,
Loadable<R>,
Itemable<T, R> {
Resourceable<T, R> {
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package io.fabric8.kubernetes.client.dsl;

import io.fabric8.kubernetes.api.model.Pod;
import io.fabric8.kubernetes.client.LocalPortForward;
import io.fabric8.kubernetes.client.PortForward;

Expand All @@ -25,10 +26,10 @@
import java.nio.channels.ReadableByteChannel;
import java.nio.channels.WritableByteChannel;

public interface PodResource<T> extends Resource<T>,
Loggable<LogWatch>,
Containerable<String, ContainerResource<LogWatch, InputStream, PipedOutputStream, OutputStream, PipedInputStream, String, ExecWatch, InputStream>>,
ContainerResource<LogWatch, InputStream, PipedOutputStream, OutputStream, PipedInputStream, String, ExecWatch, InputStream>,
PortForwardable<PortForward, LocalPortForward, ReadableByteChannel, WritableByteChannel>,
Evictable{
public interface PodResource extends Resource<Pod>,
Loggable<LogWatch>,
Containerable<String, ContainerResource<LogWatch, InputStream, PipedOutputStream, OutputStream, PipedInputStream, String, ExecWatch, InputStream>>,
ContainerResource<LogWatch, InputStream, PipedOutputStream, OutputStream, PipedInputStream, String, ExecWatch, InputStream>,
PortForwardable<PortForward, LocalPortForward, ReadableByteChannel, WritableByteChannel>,
Evictable {
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
*/
package io.fabric8.kubernetes.client.dsl;

public interface Itemable<T, R> {
public interface Resourceable<T, R> {

R withItem(T item);
R resource(T item);

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,20 @@
import io.fabric8.kubernetes.client.PropagationPolicyConfigurable;
import io.fabric8.kubernetes.client.Watcher;

public interface WatchListDeletable<T, L> extends Watchable<Watcher<T>>, Versionable<WatchAndWaitable<T>>, Listable<L>, Deletable,
GracePeriodConfigurable<Deletable>,
PropagationPolicyConfigurable<EditReplacePatchDeletable<T>>,
StatusUpdatable<T>,
Informable<T>
{
import java.util.stream.Stream;

public interface WatchListDeletable<T, L, R>
extends Watchable<Watcher<T>>, Versionable<WatchAndWaitable<T>>, Listable<L>, Deletable,
GracePeriodConfigurable<Deletable>,
PropagationPolicyConfigurable<EditReplacePatchDeletable<T>>,
StatusUpdatable<T>,
Informable<T> {

/**
* Perform a list operation and return the items as a stream of {@link Resource}s
*
* @return the {@link Resource} steam
*/
Stream<R> resources();

}
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@
/**
* Class for Default Kubernetes Client implementing KubernetesClient interface.
* It is thread safe.
*
*
* @deprecated direct usage should no longer be needed. Please use the {@link KubernetesClientBuilder} instead.
*/
@Deprecated
Expand Down Expand Up @@ -381,7 +381,7 @@ public MixedOperation<PersistentVolumeClaim, PersistentVolumeClaimList, Resource
* {@inheritDoc}
*/
@Override
public MixedOperation<Pod, PodList, PodResource<Pod>> pods() {
public MixedOperation<Pod, PodList, PodResource> pods() {
return new PodOperationsImpl(this);
}

Expand Down

0 comments on commit bb9a613

Please sign in to comment.