From f31e8811d1241e674cfca0404d8f62e7c3995f43 Mon Sep 17 00:00:00 2001 From: Steve Hawkins Date: Mon, 14 Feb 2022 08:08:48 -0500 Subject: [PATCH] fix #3845: adding an api only framework for extensions also deprecating extra ApiVersionUtil classes moving resource interfaces in service-catalog client from internal to dsl --- extensions/camel-k/client/pom.xml | 5 ++ .../camelk/client/DefaultCamelKClient.java | 24 ++----- .../camelk/client/V1APIGroupClient.java | 65 ++++++++++--------- .../camelk/client/V1alpha1APIGroupClient.java | 18 +++-- .../camelk/client/dsl/V1APIGroupDSL.java | 9 ++- .../camelk/client/util/ApiVersionUtil.java | 12 ++-- .../knative/client/util/ApiVersionUtil.java | 10 +-- .../client/DefaultServiceCatalogClient.java | 22 ++++--- .../client/ServiceCatalogClient.java | 10 +-- .../ClusterServiceBrokerResource.java | 2 +- .../ClusterServiceClassResource.java | 2 +- .../ClusterServicePlanResource.java | 2 +- .../ServiceBindingResource.java | 2 +- .../ServiceInstanceResource.java | 2 +- .../ClusterServiceBrokerOperationsImpl.java | 6 +- .../ClusterServiceClassOperationsImpl.java | 6 +- .../ClusterServicePlanOperationsImpl.java | 15 +++-- .../ServiceBindingOperationsImpl.java | 11 ++-- .../ServiceInstanceOperationsImpl.java | 11 ++-- .../client/util/ApiVersionUtil.java | 6 +- .../tekton/client/util/ApiVersionUtil.java | 8 ++- .../io/fabric8/kubernetes/client/Client.java | 41 ++++++++++++ .../kubernetes/client/ExtensionAdapter.java | 3 +- .../client/ExtensionAdapterSupport.java | 1 + .../client/dsl/NonNamespaceOperation.java | 2 + .../kubernetes/client/dsl/Operation.java | 2 + .../client/extension/ClientAdapter.java | 53 +++++++++++---- .../client/extension/ExtensibleResource.java | 63 ++++++++++++++++++ .../client/extension/ResourceAdapter.java | 45 ++++++++----- .../fabric8/kubernetes/client/BaseClient.java | 12 ++++ .../client/ResourcedHasMetadataOperation.java | 38 +++++++---- .../client/dsl/base/BaseOperation.java | 33 +++++----- .../client/dsl/base/HasMetadataOperation.java | 6 +- .../internal/HasMetadataOperationsImpl.java | 2 +- .../internal/batch/v1/JobOperationsImpl.java | 5 -- .../client/utils/PodOperationUtilTest.java | 5 +- 36 files changed, 376 insertions(+), 183 deletions(-) rename extensions/service-catalog/client/src/main/java/io/fabric8/servicecatalog/client/{internal => dsl}/ClusterServiceBrokerResource.java (97%) rename extensions/service-catalog/client/src/main/java/io/fabric8/servicecatalog/client/{internal => dsl}/ClusterServiceClassResource.java (95%) rename extensions/service-catalog/client/src/main/java/io/fabric8/servicecatalog/client/{internal => dsl}/ClusterServicePlanResource.java (96%) rename extensions/service-catalog/client/src/main/java/io/fabric8/servicecatalog/client/{internal => dsl}/ServiceBindingResource.java (94%) rename extensions/service-catalog/client/src/main/java/io/fabric8/servicecatalog/client/{internal => dsl}/ServiceInstanceResource.java (94%) create mode 100644 kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/extension/ExtensibleResource.java diff --git a/extensions/camel-k/client/pom.xml b/extensions/camel-k/client/pom.xml index eb736563ac2..f38507779f4 100644 --- a/extensions/camel-k/client/pom.xml +++ b/extensions/camel-k/client/pom.xml @@ -64,9 +64,14 @@ io.fabric8 camel-k-model-v1 + + io.fabric8 + kubernetes-client-api + io.fabric8 kubernetes-client + runtime org.junit.jupiter diff --git a/extensions/camel-k/client/src/main/java/io/fabric8/camelk/client/DefaultCamelKClient.java b/extensions/camel-k/client/src/main/java/io/fabric8/camelk/client/DefaultCamelKClient.java index 02dc43348a6..f10ba677e6a 100644 --- a/extensions/camel-k/client/src/main/java/io/fabric8/camelk/client/DefaultCamelKClient.java +++ b/extensions/camel-k/client/src/main/java/io/fabric8/camelk/client/DefaultCamelKClient.java @@ -17,15 +17,14 @@ import io.fabric8.camelk.client.dsl.V1APIGroupDSL; import io.fabric8.camelk.client.dsl.V1alpha1APIGroupDSL; -import io.fabric8.kubernetes.client.BaseClient; -import io.fabric8.kubernetes.client.ClientContext; +import io.fabric8.kubernetes.client.Client; import io.fabric8.kubernetes.client.Config; -import io.fabric8.kubernetes.client.ConfigBuilder; import io.fabric8.kubernetes.client.RequestConfig; import io.fabric8.kubernetes.client.WithRequestCallable; import io.fabric8.kubernetes.client.dsl.FunctionCallable; +import io.fabric8.kubernetes.client.extension.ClientAdapter; -public class DefaultCamelKClient extends BaseClient implements NamespacedCamelKClient { +public class DefaultCamelKClient extends ClientAdapter implements NamespacedCamelKClient { public DefaultCamelKClient() { super(); @@ -35,25 +34,16 @@ public DefaultCamelKClient(Config configuration) { super(configuration); } - public DefaultCamelKClient(ClientContext clientContext) { - super(clientContext); + public DefaultCamelKClient(Client client) { + super(client); } @Override - public NamespacedCamelKClient inAnyNamespace() { - return inNamespace(null); + protected DefaultCamelKClient newInstance(Client client) { + return new DefaultCamelKClient(client); } @Override - public NamespacedCamelKClient inNamespace(String namespace) { - Config updated = new ConfigBuilder(getConfiguration()) - .withNamespace(namespace) - .build(); - - return new DefaultCamelKClient(newState(updated)); - } - -@Override public FunctionCallable withRequestConfig(RequestConfig requestConfig) { return new WithRequestCallable<>(this, requestConfig); } diff --git a/extensions/camel-k/client/src/main/java/io/fabric8/camelk/client/V1APIGroupClient.java b/extensions/camel-k/client/src/main/java/io/fabric8/camelk/client/V1APIGroupClient.java index 23e2ed19a12..eb6738d28cc 100644 --- a/extensions/camel-k/client/src/main/java/io/fabric8/camelk/client/V1APIGroupClient.java +++ b/extensions/camel-k/client/src/main/java/io/fabric8/camelk/client/V1APIGroupClient.java @@ -26,44 +26,49 @@ import io.fabric8.camelk.v1.IntegrationList; import io.fabric8.camelk.v1.IntegrationPlatform; import io.fabric8.camelk.v1.IntegrationPlatformList; -import io.fabric8.kubernetes.client.BaseClient; -import io.fabric8.kubernetes.client.ClientContext; -import io.fabric8.kubernetes.client.Handlers; +import io.fabric8.kubernetes.client.Client; import io.fabric8.kubernetes.client.dsl.MixedOperation; import io.fabric8.kubernetes.client.dsl.Resource; +import io.fabric8.kubernetes.client.extension.ClientAdapter; -public class V1APIGroupClient extends BaseClient implements V1APIGroupDSL { - public V1APIGroupClient() { - super(); - } +public class V1APIGroupClient extends ClientAdapter implements V1APIGroupDSL { - public V1APIGroupClient(ClientContext clientContext) { - super(clientContext); - } + public V1APIGroupClient() { + super(); + } -@Override -public MixedOperation> builds() { - return Handlers.getOperation(Build.class, BuildList.class, this); -} + public V1APIGroupClient(Client client) { + super(client); + } -@Override -public MixedOperation> camelCatalogs() { - return Handlers.getOperation(CamelCatalog.class, CamelCatalogList.class, this); -} + @Override + protected V1APIGroupClient newInstance(Client client) { + return new V1APIGroupClient(client); + } -@Override -public MixedOperation> integrations() { - return Handlers.getOperation(Integration.class, IntegrationList.class, this); -} + @Override + public MixedOperation> builds() { + return resources(Build.class, BuildList.class); + } -@Override -public MixedOperation> integrationKits() { - return Handlers.getOperation(IntegrationKit.class, IntegrationKitList.class, this); -} + @Override + public MixedOperation> camelCatalogs() { + return resources(CamelCatalog.class, CamelCatalogList.class); + } -@Override -public MixedOperation> integrationPlatforms() { - return Handlers.getOperation(IntegrationPlatform.class, IntegrationPlatformList.class, this); -} + @Override + public MixedOperation> integrations() { + return resources(Integration.class, IntegrationList.class); + } + + @Override + public MixedOperation> integrationKits() { + return resources(IntegrationKit.class, IntegrationKitList.class); + } + + @Override + public MixedOperation> integrationPlatforms() { + return resources(IntegrationPlatform.class, IntegrationPlatformList.class); + } } diff --git a/extensions/camel-k/client/src/main/java/io/fabric8/camelk/client/V1alpha1APIGroupClient.java b/extensions/camel-k/client/src/main/java/io/fabric8/camelk/client/V1alpha1APIGroupClient.java index 1524aeb75ca..b3ab576cf36 100644 --- a/extensions/camel-k/client/src/main/java/io/fabric8/camelk/client/V1alpha1APIGroupClient.java +++ b/extensions/camel-k/client/src/main/java/io/fabric8/camelk/client/V1alpha1APIGroupClient.java @@ -18,24 +18,28 @@ import io.fabric8.camelk.client.dsl.V1alpha1APIGroupDSL; import io.fabric8.camelk.v1alpha1.Kamelet; import io.fabric8.camelk.v1alpha1.KameletList; -import io.fabric8.kubernetes.client.BaseClient; -import io.fabric8.kubernetes.client.ClientContext; -import io.fabric8.kubernetes.client.Handlers; +import io.fabric8.kubernetes.client.Client; import io.fabric8.kubernetes.client.dsl.MixedOperation; import io.fabric8.kubernetes.client.dsl.Resource; +import io.fabric8.kubernetes.client.extension.ClientAdapter; -public class V1alpha1APIGroupClient extends BaseClient implements V1alpha1APIGroupDSL { +public class V1alpha1APIGroupClient extends ClientAdapter implements V1alpha1APIGroupDSL { public V1alpha1APIGroupClient() { super(); } - public V1alpha1APIGroupClient(ClientContext clientContext) { - super(clientContext); + public V1alpha1APIGroupClient(Client client) { + super(client); + } + + @Override + protected V1alpha1APIGroupClient newInstance(Client client) { + return new V1alpha1APIGroupClient(client); } @Override public MixedOperation> kamelets() { - return Handlers.getOperation(Kamelet.class, KameletList.class, this); + return resources(Kamelet.class, KameletList.class); } } diff --git a/extensions/camel-k/client/src/main/java/io/fabric8/camelk/client/dsl/V1APIGroupDSL.java b/extensions/camel-k/client/src/main/java/io/fabric8/camelk/client/dsl/V1APIGroupDSL.java index 0cb7e77f0a1..fd928426158 100644 --- a/extensions/camel-k/client/src/main/java/io/fabric8/camelk/client/dsl/V1APIGroupDSL.java +++ b/extensions/camel-k/client/src/main/java/io/fabric8/camelk/client/dsl/V1APIGroupDSL.java @@ -15,20 +15,19 @@ */ package io.fabric8.camelk.client.dsl; -import io.fabric8.kubernetes.client.Client; -import io.fabric8.kubernetes.client.dsl.MixedOperation; -import io.fabric8.kubernetes.client.dsl.NonNamespaceOperation; -import io.fabric8.kubernetes.client.dsl.Resource; import io.fabric8.camelk.v1.Build; import io.fabric8.camelk.v1.BuildList; import io.fabric8.camelk.v1.CamelCatalog; import io.fabric8.camelk.v1.CamelCatalogList; import io.fabric8.camelk.v1.Integration; -import io.fabric8.camelk.v1.IntegrationList; import io.fabric8.camelk.v1.IntegrationKit; import io.fabric8.camelk.v1.IntegrationKitList; +import io.fabric8.camelk.v1.IntegrationList; import io.fabric8.camelk.v1.IntegrationPlatform; import io.fabric8.camelk.v1.IntegrationPlatformList; +import io.fabric8.kubernetes.client.Client; +import io.fabric8.kubernetes.client.dsl.MixedOperation; +import io.fabric8.kubernetes.client.dsl.Resource; public interface V1APIGroupDSL extends Client { diff --git a/extensions/camel-k/client/src/main/java/io/fabric8/camelk/client/util/ApiVersionUtil.java b/extensions/camel-k/client/src/main/java/io/fabric8/camelk/client/util/ApiVersionUtil.java index 53e12c004f4..1eb1a7dee14 100644 --- a/extensions/camel-k/client/src/main/java/io/fabric8/camelk/client/util/ApiVersionUtil.java +++ b/extensions/camel-k/client/src/main/java/io/fabric8/camelk/client/util/ApiVersionUtil.java @@ -18,13 +18,17 @@ import io.fabric8.kubernetes.api.model.HasMetadata; import io.fabric8.kubernetes.client.utils.Utils; -/** Borrowed from the client. */ +/** + * @deprecated + * @see io.fabric8.kubernetes.client.utils.ApiVersionUtil + */ +@Deprecated public class ApiVersionUtil { - + private ApiVersionUtil() { throw new IllegalStateException("Utility class"); } - + /** * Extracts apiGroupName from apiGroupVersion when in resource for apiGroupName/acpiGroupVersion * combination @@ -34,7 +38,7 @@ private ApiVersionUtil() { * @param apiGroup apiGroupName present if any * @return Just the apiGroupName part without apiGroupVersion */ - + public static String apiGroup(T item, String apiGroup) { if (item instanceof HasMetadata && Utils.isNotNullOrEmpty(((HasMetadata) item).getApiVersion())) { diff --git a/extensions/knative/client/src/main/java/io/fabric8/knative/client/util/ApiVersionUtil.java b/extensions/knative/client/src/main/java/io/fabric8/knative/client/util/ApiVersionUtil.java index fb1f45c87dd..f021ae1f660 100644 --- a/extensions/knative/client/src/main/java/io/fabric8/knative/client/util/ApiVersionUtil.java +++ b/extensions/knative/client/src/main/java/io/fabric8/knative/client/util/ApiVersionUtil.java @@ -19,21 +19,23 @@ import io.fabric8.kubernetes.client.utils.Utils; /** - * Borrowed from the client. + * @deprecated + * @see io.fabric8.kubernetes.client.utils.ApiVersionUtil */ +@Deprecated public class ApiVersionUtil { - + private ApiVersionUtil() { throw new IllegalStateException("Utility class"); } - + /** * Extracts apiGroupName from apiGroupVersion when in resource for apiGroupName/apiGroupVersion combination * @param item resource which is being used * @param apiGroup apiGroupName present if any * @return Just the apiGroupName part without apiGroupVersion */ - + public static String apiGroup(T item, String apiGroup) { if (item instanceof HasMetadata && Utils.isNotNullOrEmpty(((HasMetadata) item).getApiVersion())) { return trimGroupOrNull(((HasMetadata) item).getApiVersion()); diff --git a/extensions/service-catalog/client/src/main/java/io/fabric8/servicecatalog/client/DefaultServiceCatalogClient.java b/extensions/service-catalog/client/src/main/java/io/fabric8/servicecatalog/client/DefaultServiceCatalogClient.java index e817c50fd1d..b496a6a60d1 100644 --- a/extensions/service-catalog/client/src/main/java/io/fabric8/servicecatalog/client/DefaultServiceCatalogClient.java +++ b/extensions/service-catalog/client/src/main/java/io/fabric8/servicecatalog/client/DefaultServiceCatalogClient.java @@ -17,7 +17,6 @@ import io.fabric8.kubernetes.client.Client; import io.fabric8.kubernetes.client.Config; -import io.fabric8.kubernetes.client.KubernetesClientBuilder; import io.fabric8.kubernetes.client.RequestConfig; import io.fabric8.kubernetes.client.WithRequestCallable; import io.fabric8.kubernetes.client.dsl.FunctionCallable; @@ -41,24 +40,29 @@ import io.fabric8.servicecatalog.api.model.ServiceInstanceList; import io.fabric8.servicecatalog.api.model.ServicePlan; import io.fabric8.servicecatalog.api.model.ServicePlanList; -import io.fabric8.servicecatalog.client.internal.ClusterServiceBrokerResource; -import io.fabric8.servicecatalog.client.internal.ClusterServiceClassResource; -import io.fabric8.servicecatalog.client.internal.ClusterServicePlanResource; -import io.fabric8.servicecatalog.client.internal.ServiceBindingResource; -import io.fabric8.servicecatalog.client.internal.ServiceInstanceResource; +import io.fabric8.servicecatalog.client.dsl.ClusterServiceBrokerResource; +import io.fabric8.servicecatalog.client.dsl.ClusterServiceClassResource; +import io.fabric8.servicecatalog.client.dsl.ClusterServicePlanResource; +import io.fabric8.servicecatalog.client.dsl.ServiceBindingResource; +import io.fabric8.servicecatalog.client.dsl.ServiceInstanceResource; public class DefaultServiceCatalogClient extends ClientAdapter implements NamespacedServiceCatalogClient { public DefaultServiceCatalogClient() { - this(new KubernetesClientBuilder().build()); + super(); } public DefaultServiceCatalogClient(Config configuration) { - this(new KubernetesClientBuilder().withConfig(configuration).build()); + super(configuration); } public DefaultServiceCatalogClient(Client client) { - super(client, DefaultServiceCatalogClient::new); + super(client); + } + + @Override + protected DefaultServiceCatalogClient newInstance(Client client) { + return new DefaultServiceCatalogClient(client); } @Override diff --git a/extensions/service-catalog/client/src/main/java/io/fabric8/servicecatalog/client/ServiceCatalogClient.java b/extensions/service-catalog/client/src/main/java/io/fabric8/servicecatalog/client/ServiceCatalogClient.java index 83c4c7deffa..94c3e934320 100644 --- a/extensions/service-catalog/client/src/main/java/io/fabric8/servicecatalog/client/ServiceCatalogClient.java +++ b/extensions/service-catalog/client/src/main/java/io/fabric8/servicecatalog/client/ServiceCatalogClient.java @@ -36,11 +36,11 @@ import io.fabric8.servicecatalog.api.model.ServiceInstanceList; import io.fabric8.servicecatalog.api.model.ServicePlan; import io.fabric8.servicecatalog.api.model.ServicePlanList; -import io.fabric8.servicecatalog.client.internal.ClusterServiceBrokerResource; -import io.fabric8.servicecatalog.client.internal.ClusterServiceClassResource; -import io.fabric8.servicecatalog.client.internal.ClusterServicePlanResource; -import io.fabric8.servicecatalog.client.internal.ServiceBindingResource; -import io.fabric8.servicecatalog.client.internal.ServiceInstanceResource; +import io.fabric8.servicecatalog.client.dsl.ClusterServiceBrokerResource; +import io.fabric8.servicecatalog.client.dsl.ClusterServiceClassResource; +import io.fabric8.servicecatalog.client.dsl.ClusterServicePlanResource; +import io.fabric8.servicecatalog.client.dsl.ServiceBindingResource; +import io.fabric8.servicecatalog.client.dsl.ServiceInstanceResource; /** * Main interface for Service Catalog Client. diff --git a/extensions/service-catalog/client/src/main/java/io/fabric8/servicecatalog/client/internal/ClusterServiceBrokerResource.java b/extensions/service-catalog/client/src/main/java/io/fabric8/servicecatalog/client/dsl/ClusterServiceBrokerResource.java similarity index 97% rename from extensions/service-catalog/client/src/main/java/io/fabric8/servicecatalog/client/internal/ClusterServiceBrokerResource.java rename to extensions/service-catalog/client/src/main/java/io/fabric8/servicecatalog/client/dsl/ClusterServiceBrokerResource.java index d4cece21ed5..3a7f675f7d6 100644 --- a/extensions/service-catalog/client/src/main/java/io/fabric8/servicecatalog/client/internal/ClusterServiceBrokerResource.java +++ b/extensions/service-catalog/client/src/main/java/io/fabric8/servicecatalog/client/dsl/ClusterServiceBrokerResource.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.fabric8.servicecatalog.client.internal; +package io.fabric8.servicecatalog.client.dsl; import io.fabric8.kubernetes.client.dsl.Resource; import io.fabric8.servicecatalog.api.model.ClusterServiceBroker; diff --git a/extensions/service-catalog/client/src/main/java/io/fabric8/servicecatalog/client/internal/ClusterServiceClassResource.java b/extensions/service-catalog/client/src/main/java/io/fabric8/servicecatalog/client/dsl/ClusterServiceClassResource.java similarity index 95% rename from extensions/service-catalog/client/src/main/java/io/fabric8/servicecatalog/client/internal/ClusterServiceClassResource.java rename to extensions/service-catalog/client/src/main/java/io/fabric8/servicecatalog/client/dsl/ClusterServiceClassResource.java index 28886542637..cfe0064f7b1 100644 --- a/extensions/service-catalog/client/src/main/java/io/fabric8/servicecatalog/client/internal/ClusterServiceClassResource.java +++ b/extensions/service-catalog/client/src/main/java/io/fabric8/servicecatalog/client/dsl/ClusterServiceClassResource.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.fabric8.servicecatalog.client.internal; +package io.fabric8.servicecatalog.client.dsl; import io.fabric8.kubernetes.client.dsl.Resource; import io.fabric8.servicecatalog.api.model.*; diff --git a/extensions/service-catalog/client/src/main/java/io/fabric8/servicecatalog/client/internal/ClusterServicePlanResource.java b/extensions/service-catalog/client/src/main/java/io/fabric8/servicecatalog/client/dsl/ClusterServicePlanResource.java similarity index 96% rename from extensions/service-catalog/client/src/main/java/io/fabric8/servicecatalog/client/internal/ClusterServicePlanResource.java rename to extensions/service-catalog/client/src/main/java/io/fabric8/servicecatalog/client/dsl/ClusterServicePlanResource.java index f24e1edf33e..3bde3190697 100644 --- a/extensions/service-catalog/client/src/main/java/io/fabric8/servicecatalog/client/internal/ClusterServicePlanResource.java +++ b/extensions/service-catalog/client/src/main/java/io/fabric8/servicecatalog/client/dsl/ClusterServicePlanResource.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.fabric8.servicecatalog.client.internal; +package io.fabric8.servicecatalog.client.dsl; import io.fabric8.kubernetes.client.dsl.Resource; import io.fabric8.servicecatalog.api.model.*; diff --git a/extensions/service-catalog/client/src/main/java/io/fabric8/servicecatalog/client/internal/ServiceBindingResource.java b/extensions/service-catalog/client/src/main/java/io/fabric8/servicecatalog/client/dsl/ServiceBindingResource.java similarity index 94% rename from extensions/service-catalog/client/src/main/java/io/fabric8/servicecatalog/client/internal/ServiceBindingResource.java rename to extensions/service-catalog/client/src/main/java/io/fabric8/servicecatalog/client/dsl/ServiceBindingResource.java index ec3984337f0..986329fea42 100644 --- a/extensions/service-catalog/client/src/main/java/io/fabric8/servicecatalog/client/internal/ServiceBindingResource.java +++ b/extensions/service-catalog/client/src/main/java/io/fabric8/servicecatalog/client/dsl/ServiceBindingResource.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.fabric8.servicecatalog.client.internal; +package io.fabric8.servicecatalog.client.dsl; import io.fabric8.kubernetes.api.model.Secret; import io.fabric8.kubernetes.client.dsl.Resource; diff --git a/extensions/service-catalog/client/src/main/java/io/fabric8/servicecatalog/client/internal/ServiceInstanceResource.java b/extensions/service-catalog/client/src/main/java/io/fabric8/servicecatalog/client/dsl/ServiceInstanceResource.java similarity index 94% rename from extensions/service-catalog/client/src/main/java/io/fabric8/servicecatalog/client/internal/ServiceInstanceResource.java rename to extensions/service-catalog/client/src/main/java/io/fabric8/servicecatalog/client/dsl/ServiceInstanceResource.java index 65ce21a1a00..75a2f266898 100644 --- a/extensions/service-catalog/client/src/main/java/io/fabric8/servicecatalog/client/internal/ServiceInstanceResource.java +++ b/extensions/service-catalog/client/src/main/java/io/fabric8/servicecatalog/client/dsl/ServiceInstanceResource.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.fabric8.servicecatalog.client.internal; +package io.fabric8.servicecatalog.client.dsl; import io.fabric8.kubernetes.client.dsl.Resource; import io.fabric8.servicecatalog.api.model.*; diff --git a/extensions/service-catalog/client/src/main/java/io/fabric8/servicecatalog/client/internal/ClusterServiceBrokerOperationsImpl.java b/extensions/service-catalog/client/src/main/java/io/fabric8/servicecatalog/client/internal/ClusterServiceBrokerOperationsImpl.java index 2f507d23436..6955f419167 100644 --- a/extensions/service-catalog/client/src/main/java/io/fabric8/servicecatalog/client/internal/ClusterServiceBrokerOperationsImpl.java +++ b/extensions/service-catalog/client/src/main/java/io/fabric8/servicecatalog/client/internal/ClusterServiceBrokerOperationsImpl.java @@ -16,13 +16,15 @@ package io.fabric8.servicecatalog.client.internal; import io.fabric8.kubernetes.client.Client; -import io.fabric8.kubernetes.client.dsl.Resource; +import io.fabric8.kubernetes.client.extension.ExtensibleResource; import io.fabric8.kubernetes.client.extension.ResourceAdapter; import io.fabric8.servicecatalog.api.model.ClusterServiceBroker; import io.fabric8.servicecatalog.api.model.ClusterServiceClass; import io.fabric8.servicecatalog.api.model.ClusterServiceClassList; import io.fabric8.servicecatalog.api.model.ClusterServicePlanList; import io.fabric8.servicecatalog.client.ServiceCatalogClient; +import io.fabric8.servicecatalog.client.dsl.ClusterServiceBrokerResource; +import io.fabric8.servicecatalog.client.dsl.ClusterServiceClassResource; import java.util.HashMap; import java.util.List; @@ -31,7 +33,7 @@ public class ClusterServiceBrokerOperationsImpl extends ResourceAdapter implements ClusterServiceBrokerResource { - public ClusterServiceBrokerOperationsImpl(Resource resource, Client client) { + public ClusterServiceBrokerOperationsImpl(ExtensibleResource resource, Client client) { super(resource, client); } diff --git a/extensions/service-catalog/client/src/main/java/io/fabric8/servicecatalog/client/internal/ClusterServiceClassOperationsImpl.java b/extensions/service-catalog/client/src/main/java/io/fabric8/servicecatalog/client/internal/ClusterServiceClassOperationsImpl.java index bf3e602362e..6126ba49100 100644 --- a/extensions/service-catalog/client/src/main/java/io/fabric8/servicecatalog/client/internal/ClusterServiceClassOperationsImpl.java +++ b/extensions/service-catalog/client/src/main/java/io/fabric8/servicecatalog/client/internal/ClusterServiceClassOperationsImpl.java @@ -16,7 +16,7 @@ package io.fabric8.servicecatalog.client.internal; import io.fabric8.kubernetes.client.Client; -import io.fabric8.kubernetes.client.dsl.Resource; +import io.fabric8.kubernetes.client.extension.ExtensibleResource; import io.fabric8.kubernetes.client.extension.ResourceAdapter; import io.fabric8.servicecatalog.api.model.ClusterServiceClass; import io.fabric8.servicecatalog.api.model.ClusterServicePlan; @@ -24,6 +24,8 @@ import io.fabric8.servicecatalog.api.model.ServiceInstance; import io.fabric8.servicecatalog.api.model.ServiceInstanceBuilder; import io.fabric8.servicecatalog.client.ServiceCatalogClient; +import io.fabric8.servicecatalog.client.dsl.ClusterServiceClassResource; +import io.fabric8.servicecatalog.client.dsl.ClusterServicePlanResource; import java.util.HashMap; import java.util.List; @@ -32,7 +34,7 @@ public class ClusterServiceClassOperationsImpl extends ResourceAdapter implements ClusterServiceClassResource { - public ClusterServiceClassOperationsImpl(Resource resource, Client client) { + public ClusterServiceClassOperationsImpl(ExtensibleResource resource, Client client) { super(resource, client); } diff --git a/extensions/service-catalog/client/src/main/java/io/fabric8/servicecatalog/client/internal/ClusterServicePlanOperationsImpl.java b/extensions/service-catalog/client/src/main/java/io/fabric8/servicecatalog/client/internal/ClusterServicePlanOperationsImpl.java index 49c15701c7d..e259ebe5596 100644 --- a/extensions/service-catalog/client/src/main/java/io/fabric8/servicecatalog/client/internal/ClusterServicePlanOperationsImpl.java +++ b/extensions/service-catalog/client/src/main/java/io/fabric8/servicecatalog/client/internal/ClusterServicePlanOperationsImpl.java @@ -16,16 +16,19 @@ package io.fabric8.servicecatalog.client.internal; import io.fabric8.kubernetes.client.Client; -import io.fabric8.kubernetes.client.dsl.Resource; +import io.fabric8.kubernetes.client.extension.ExtensibleResource; import io.fabric8.kubernetes.client.extension.ResourceAdapter; import io.fabric8.servicecatalog.api.model.ClusterServicePlan; import io.fabric8.servicecatalog.api.model.ServiceInstance; import io.fabric8.servicecatalog.api.model.ServiceInstanceBuilder; +import io.fabric8.servicecatalog.client.ServiceCatalogClient; +import io.fabric8.servicecatalog.client.dsl.ClusterServicePlanResource; +import io.fabric8.servicecatalog.client.dsl.ServiceInstanceResource; public class ClusterServicePlanOperationsImpl extends ResourceAdapter implements ClusterServicePlanResource { - public ClusterServicePlanOperationsImpl(Resource resource, Client client) { + public ClusterServicePlanOperationsImpl(ExtensibleResource resource, Client client) { super(resource, client); } @@ -36,7 +39,7 @@ public ServiceInstance instantiate(String... args) { if (args.length == 1) { instanceName = args[0]; - instanceNamespace = config.getNamespace(); + instanceNamespace = client.getConfiguration().getNamespace(); } else if (args.length == 2) { instanceNamespace = args[0]; instanceName = args[1]; @@ -45,8 +48,8 @@ public ServiceInstance instantiate(String... args) { } ClusterServicePlan item = get(); - return new ServiceInstanceOperationsImpl(context.withItem(null)) - .create(new ServiceInstanceBuilder() + return client.adapt(ServiceCatalogClient.class).serviceInstances() + .inNamespace(instanceNamespace).create(new ServiceInstanceBuilder() .withNewMetadata() .withName(instanceName) .withNamespace(instanceNamespace) @@ -61,7 +64,7 @@ public ServiceInstance instantiate(String... args) { @Override public ServiceInstanceResource instantiateAnd(String... args) { ServiceInstance item = instantiate(args); - return new ServiceInstanceOperationsImpl(context.withItem(item)); + return client.adapt(ServiceCatalogClient.class).serviceInstances().withItem(item); } } diff --git a/extensions/service-catalog/client/src/main/java/io/fabric8/servicecatalog/client/internal/ServiceBindingOperationsImpl.java b/extensions/service-catalog/client/src/main/java/io/fabric8/servicecatalog/client/internal/ServiceBindingOperationsImpl.java index a011897dae8..0e6e6ce94b5 100644 --- a/extensions/service-catalog/client/src/main/java/io/fabric8/servicecatalog/client/internal/ServiceBindingOperationsImpl.java +++ b/extensions/service-catalog/client/src/main/java/io/fabric8/servicecatalog/client/internal/ServiceBindingOperationsImpl.java @@ -16,23 +16,22 @@ package io.fabric8.servicecatalog.client.internal; import io.fabric8.kubernetes.api.model.Secret; -import io.fabric8.kubernetes.api.model.SecretList; import io.fabric8.kubernetes.client.Client; -import io.fabric8.kubernetes.client.dsl.Resource; +import io.fabric8.kubernetes.client.KubernetesClient; +import io.fabric8.kubernetes.client.extension.ExtensibleResource; import io.fabric8.kubernetes.client.extension.ResourceAdapter; import io.fabric8.servicecatalog.api.model.ServiceBinding; +import io.fabric8.servicecatalog.client.dsl.ServiceBindingResource; public class ServiceBindingOperationsImpl extends ResourceAdapter implements ServiceBindingResource { - public ServiceBindingOperationsImpl(Resource resource, Client client) { + public ServiceBindingOperationsImpl(ExtensibleResource resource, Client client) { super(resource, client); } @Override public Secret getSecret() { ServiceBinding instance = get(); - return Handlers.getOperation(Secret.class, SecretList.class, context) - .newInstance(context.withItem(null).withName(instance.getSpec().getSecretName())) - .get(); + return client.adapt(KubernetesClient.class).secrets().withName(instance.getSpec().getSecretName()).get(); } } diff --git a/extensions/service-catalog/client/src/main/java/io/fabric8/servicecatalog/client/internal/ServiceInstanceOperationsImpl.java b/extensions/service-catalog/client/src/main/java/io/fabric8/servicecatalog/client/internal/ServiceInstanceOperationsImpl.java index f94eb3755ef..86757a7cd08 100644 --- a/extensions/service-catalog/client/src/main/java/io/fabric8/servicecatalog/client/internal/ServiceInstanceOperationsImpl.java +++ b/extensions/service-catalog/client/src/main/java/io/fabric8/servicecatalog/client/internal/ServiceInstanceOperationsImpl.java @@ -16,25 +16,28 @@ package io.fabric8.servicecatalog.client.internal; import io.fabric8.kubernetes.client.Client; -import io.fabric8.kubernetes.client.dsl.Resource; +import io.fabric8.kubernetes.client.extension.ExtensibleResource; import io.fabric8.kubernetes.client.extension.ResourceAdapter; import io.fabric8.servicecatalog.api.model.ServiceBinding; import io.fabric8.servicecatalog.api.model.ServiceBindingBuilder; import io.fabric8.servicecatalog.api.model.ServiceInstance; +import io.fabric8.servicecatalog.client.ServiceCatalogClient; +import io.fabric8.servicecatalog.client.dsl.ServiceInstanceResource; public class ServiceInstanceOperationsImpl extends ResourceAdapter implements ServiceInstanceResource { - public ServiceInstanceOperationsImpl(Resource resource, Client client) { + public ServiceInstanceOperationsImpl(ExtensibleResource resource, Client client) { super(resource, client); } @Override public ServiceBinding bind(String secretName) { ServiceInstance item = get(); - return new ServiceBindingOperationsImpl(context.withItem(null)) - .create(new ServiceBindingBuilder() + return client.adapt(ServiceCatalogClient.class) + .serviceBindings().create(new ServiceBindingBuilder() .withNewMetadata() .withName(item.getMetadata().getName()) + .withNamespace(item.getMetadata().getNamespace()) .endMetadata() .withNewSpec() .withSecretName(secretName) diff --git a/extensions/service-catalog/client/src/main/java/io/fabric8/servicecatalog/client/util/ApiVersionUtil.java b/extensions/service-catalog/client/src/main/java/io/fabric8/servicecatalog/client/util/ApiVersionUtil.java index 59bdc5b5a2f..e06b2bba8e0 100644 --- a/extensions/service-catalog/client/src/main/java/io/fabric8/servicecatalog/client/util/ApiVersionUtil.java +++ b/extensions/service-catalog/client/src/main/java/io/fabric8/servicecatalog/client/util/ApiVersionUtil.java @@ -19,14 +19,16 @@ import io.fabric8.kubernetes.client.utils.Utils; /** - * Borrowed from the client. + * @deprecated + * @see io.fabric8.kubernetes.client.utils.ApiVersionUtil */ +@Deprecated public class ApiVersionUtil { private ApiVersionUtil() { throw new IllegalStateException("Utility class"); } - + /** * Extracts apiGroupName from apiGroupVersion when in resource for apiGroupName/apiGroupVersion combination * @param item resource which is being used diff --git a/extensions/tekton/client/src/main/java/io/fabric8/tekton/client/util/ApiVersionUtil.java b/extensions/tekton/client/src/main/java/io/fabric8/tekton/client/util/ApiVersionUtil.java index bd1c03d063c..fed9b3527ab 100644 --- a/extensions/tekton/client/src/main/java/io/fabric8/tekton/client/util/ApiVersionUtil.java +++ b/extensions/tekton/client/src/main/java/io/fabric8/tekton/client/util/ApiVersionUtil.java @@ -19,10 +19,12 @@ import io.fabric8.kubernetes.client.utils.Utils; /** - * Borrowed from the client. + * @deprecated + * @see io.fabric8.kubernetes.client.utils.ApiVersionUtil */ +@Deprecated public class ApiVersionUtil { - + private ApiVersionUtil() { throw new IllegalStateException("Utility class"); } @@ -32,7 +34,7 @@ private ApiVersionUtil() { * @param apiGroup apiGroupName present if any * @return Just the apiGroupName part without apiGroupVersion */ - + public static String apiGroup(T item, String apiGroup) { if (item instanceof HasMetadata && Utils.isNotNullOrEmpty(((HasMetadata) item).getApiVersion())) { return trimGroupOrNull(((HasMetadata) item).getApiVersion()); diff --git a/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/Client.java b/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/Client.java index 0551e7d5dbb..514fe1e36d1 100644 --- a/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/Client.java +++ b/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/Client.java @@ -19,7 +19,11 @@ import io.fabric8.kubernetes.api.model.APIGroup; import io.fabric8.kubernetes.api.model.APIGroupList; import io.fabric8.kubernetes.api.model.APIResourceList; +import io.fabric8.kubernetes.api.model.HasMetadata; +import io.fabric8.kubernetes.api.model.KubernetesResourceList; import io.fabric8.kubernetes.api.model.RootPaths; +import io.fabric8.kubernetes.client.dsl.MixedOperation; +import io.fabric8.kubernetes.client.dsl.Resource; import java.io.Closeable; import java.net.URL; @@ -73,4 +77,41 @@ public interface Client extends ClientContext, Closeable { * @return the {@link APIResourceList} for the groupVersion */ APIResourceList getApiResources(String groupVersion); + + /** + * Typed API for managing resources. Any properly annotated POJO can be utilized as a 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. + *

+ * + * @param resourceType Class for resource + * @param represents resource type. If it's a namespaced resource, it must implement + * {@link io.fabric8.kubernetes.api.model.Namespaced} + * @param represents resource list type + * @param represents the Resource operation type + * @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. + */ + , R extends Resource> MixedOperation resources( + Class resourceType, Class listClass, Class resourceClass); + + /** + * Typed API for managing resources. Any properly annotated POJO can be utilized as a 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. + *

+ * + * @param resourceType Class for resource + * @param represents resource type. If it's a namespaced resource, it must implement + * {@link io.fabric8.kubernetes.api.model.Namespaced} + * @param represents resource list type + * @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 > MixedOperation> resources( + Class resourceType, Class listClass) { + return resources(resourceType, listClass, Resource.class); + } } diff --git a/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/ExtensionAdapter.java b/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/ExtensionAdapter.java index 4252336ace7..e1f32f056d5 100644 --- a/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/ExtensionAdapter.java +++ b/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/ExtensionAdapter.java @@ -18,6 +18,7 @@ import io.fabric8.kubernetes.api.model.HasMetadata; import io.fabric8.kubernetes.client.dsl.Resource; +import io.fabric8.kubernetes.client.extension.ExtensibleResource; import java.util.function.BiFunction; @@ -29,7 +30,7 @@ public interface ExtensionAdapter { public interface HandlerFactory { - > void register(Class type, BiFunction, Client, R> target); + > void register(Class type, BiFunction, Client, R> target); } /** diff --git a/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/ExtensionAdapterSupport.java b/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/ExtensionAdapterSupport.java index 707e14f7d98..493e453ef0a 100644 --- a/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/ExtensionAdapterSupport.java +++ b/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/ExtensionAdapterSupport.java @@ -22,6 +22,7 @@ import java.util.concurrent.ConcurrentMap; public abstract class ExtensionAdapterSupport { + protected Boolean isAdaptable(Client client, ConcurrentMap isApi, ConcurrentMap usesApiGroups, String apiGroup) { URL masterUrl = client.getMasterUrl(); if (isApi.containsKey(masterUrl)) { diff --git a/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/dsl/NonNamespaceOperation.java b/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/dsl/NonNamespaceOperation.java index 5277e9ea2c4..a27592cff5a 100644 --- a/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/dsl/NonNamespaceOperation.java +++ b/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/dsl/NonNamespaceOperation.java @@ -31,5 +31,7 @@ public interface NonNamespaceOperation extends Replaceable, StatusReplaceable, Loadable { + + R withItem(T item); } diff --git a/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/dsl/Operation.java b/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/dsl/Operation.java index 07410c0a446..8a20679f415 100644 --- a/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/dsl/Operation.java +++ b/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/dsl/Operation.java @@ -27,4 +27,6 @@ public interface Operation Namespaceable>, FilterWatchListMultiDeletable, Loadable { + + R withItem(T item); } diff --git a/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/extension/ClientAdapter.java b/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/extension/ClientAdapter.java index c98df948e48..baa18547d86 100644 --- a/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/extension/ClientAdapter.java +++ b/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/extension/ClientAdapter.java @@ -1,3 +1,19 @@ +/** + * Copyright (C) 2015 Red Hat, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package io.fabric8.kubernetes.client.extension; import io.fabric8.kubernetes.api.model.APIGroup; @@ -8,22 +24,31 @@ import io.fabric8.kubernetes.api.model.RootPaths; import io.fabric8.kubernetes.client.Client; import io.fabric8.kubernetes.client.Config; +import io.fabric8.kubernetes.client.KubernetesClientBuilder; import io.fabric8.kubernetes.client.NamespacedKubernetesClient; import io.fabric8.kubernetes.client.dsl.MixedOperation; import io.fabric8.kubernetes.client.dsl.Resource; import io.fabric8.kubernetes.client.http.HttpClient; import java.net.URL; -import java.util.function.Function; -public abstract class ClientAdapter implements Client { +/** + * To be used as the base class for creating extension clients + */ +public abstract class ClientAdapter implements Client { protected Client client; - private Function newInstance; - public ClientAdapter(Client client, Function newInstance) { + public ClientAdapter() { + this(new KubernetesClientBuilder().build()); + } + + public ClientAdapter(Config configuration) { + this(new KubernetesClientBuilder().withConfig(configuration).build()); + } + + public ClientAdapter(Client client) { this.client = client; - this.newInstance = newInstance; } @Override @@ -37,12 +62,12 @@ public Config getConfiguration() { } @Override - public Boolean isAdaptable(Class type) { + public Boolean isAdaptable(Class type) { return client.isAdaptable(type); } @Override - public C adapt(Class type) { + public A adapt(Class type) { return client.adapt(type); } @@ -91,20 +116,20 @@ public APIResourceList getApiResources(String groupVersion) { return client.getApiResources(groupVersion); } + @Override public , R extends Resource> MixedOperation resources( Class resourceType, Class listClass, Class resourceClass) { + return client.resources(resourceType, listClass, resourceClass); } - public > MixedOperation> resources( - Class resourceType, Class listClass) { - } - - public T inAnyNamespace() { + public C inAnyNamespace() { return inNamespace(null); } - public T inNamespace(String namespace) { - return newInstance.apply(client.adapt(NamespacedKubernetesClient.class).inNamespace(namespace)); + public C inNamespace(String namespace) { + return newInstance(client.adapt(NamespacedKubernetesClient.class).inNamespace(namespace)); } + protected abstract C newInstance(Client client); + } diff --git a/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/extension/ExtensibleResource.java b/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/extension/ExtensibleResource.java new file mode 100644 index 00000000000..5b1a3705399 --- /dev/null +++ b/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/extension/ExtensibleResource.java @@ -0,0 +1,63 @@ +/** + * Copyright (C) 2015 Red Hat, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.fabric8.kubernetes.client.extension; + +import io.fabric8.kubernetes.api.model.DeletionPropagation; +import io.fabric8.kubernetes.client.dsl.Resource; + +import java.util.List; +import java.util.Map; +import java.util.concurrent.TimeUnit; +import java.util.function.Function; + +/** + * Provides an interface that is usable by the {@link ResourceAdapter} that returns + * a non-specialized value + */ +public interface ExtensibleResource extends Resource { + + @Override + ExtensibleResource lockResourceVersion(String resourceVersion); + + @Override + ExtensibleResource cascading(boolean enabled); + + @Override + ExtensibleResource dryRun(boolean isDryRun); + + @Override + ExtensibleResource withResourceVersion(String resourceVersion); + + @Override + ExtensibleResource fromServer(); + + @Override + ExtensibleResource withGracePeriod(long gracePeriodSeconds); + + @Override + ExtensibleResource withPropagationPolicy(DeletionPropagation propagationPolicy); + + @Override + ExtensibleResource withWaitRetryBackoff(long initialBackoff, TimeUnit backoffUnit, double backoffMultiplier); + + @Override + ExtensibleResource withIndexers(Map>> indexers); + + @Override + ExtensibleResource withLimit(Long limit); + +} diff --git a/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/extension/ResourceAdapter.java b/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/extension/ResourceAdapter.java index 2a5cf3f50a6..8aa37c3d499 100644 --- a/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/extension/ResourceAdapter.java +++ b/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/extension/ResourceAdapter.java @@ -1,3 +1,19 @@ +/** + * Copyright (C) 2015 Red Hat, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package io.fabric8.kubernetes.client.extension; import io.fabric8.kubernetes.api.builder.Visitor; @@ -31,10 +47,10 @@ public class ResourceAdapter implements Resource { - protected Resource resource; + protected ExtensibleResource resource; protected Client client; - public ResourceAdapter(Resource resource, Client client) { + public ResourceAdapter(ExtensibleResource resource, Client client) { this.resource = resource; this.client = client; } @@ -56,17 +72,12 @@ public T get() { @Override public ReplaceDeletable lockResourceVersion(String resourceVersion) { - return resource.lockResourceVersion(resourceVersion); + return new ResourceAdapter<>(resource.lockResourceVersion(resourceVersion), client); } @Override public EditReplacePatchDeletable cascading(boolean enabled) { - return resource.cascading(enabled); - } - - @Override - public WritableOperation dryRun() { - return resource.dryRun(); + return new ResourceAdapter<>(resource.cascading(enabled), client); } @Override @@ -81,12 +92,12 @@ public T updateStatus(T item) { @Override public WatchAndWaitable withResourceVersion(String resourceVersion) { - return resource.withResourceVersion(resourceVersion); + return new ResourceAdapter<>(resource.withResourceVersion(resourceVersion), client); } @Override public Gettable fromServer() { - return resource.fromServer(); + return new ResourceAdapter<>(resource.fromServer(), client); } @Override @@ -101,7 +112,7 @@ public T create(T... item) { @Override public Deletable withGracePeriod(long gracePeriodSeconds) { - return resource.withGracePeriod(gracePeriodSeconds); + return new ResourceAdapter<>(resource.withGracePeriod(gracePeriodSeconds), client); } @Override @@ -126,7 +137,7 @@ public T require() throws ResourceNotFoundException { @Override public EditReplacePatchDeletable withPropagationPolicy(DeletionPropagation propagationPolicy) { - return resource.withPropagationPolicy(propagationPolicy); + return new ResourceAdapter<>(resource.withPropagationPolicy(propagationPolicy), client); } @Override @@ -166,17 +177,17 @@ public T waitUntilCondition(Predicate condition, long amount, TimeUnit timeUn @Override public Waitable withWaitRetryBackoff(long initialBackoff, TimeUnit backoffUnit, double backoffMultiplier) { - return resource.withWaitRetryBackoff(initialBackoff, backoffUnit, backoffMultiplier); + return new ResourceAdapter<>(resource.withWaitRetryBackoff(initialBackoff, backoffUnit, backoffMultiplier), client); } @Override public Informable withIndexers(Map>> indexers) { - return resource.withIndexers(indexers); + return new ResourceAdapter<>(resource.withIndexers(indexers), client); } @Override public WritableOperation dryRun(boolean isDryRun) { - return resource.dryRun(isDryRun); + return new ResourceAdapter<>(resource.dryRun(isDryRun), client); } @Override @@ -191,7 +202,7 @@ public T patch(PatchContext patchContext, T item) { @Override public Informable withLimit(Long limit) { - return resource.withLimit(limit); + return new ResourceAdapter<>(resource.withLimit(limit), client); } @Override diff --git a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/BaseClient.java b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/BaseClient.java index 6d4dd7391db..c616734976c 100644 --- a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/BaseClient.java +++ b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/BaseClient.java @@ -16,11 +16,15 @@ package io.fabric8.kubernetes.client; +import io.fabric8.kubernetes.client.dsl.MixedOperation; +import io.fabric8.kubernetes.client.dsl.Resource; import io.fabric8.kubernetes.client.dsl.base.OperationSupport; import io.fabric8.kubernetes.client.http.HttpClient; import io.fabric8.kubernetes.api.model.APIGroup; import io.fabric8.kubernetes.api.model.APIGroupList; import io.fabric8.kubernetes.api.model.APIResourceList; +import io.fabric8.kubernetes.api.model.HasMetadata; +import io.fabric8.kubernetes.api.model.KubernetesResourceList; import io.fabric8.kubernetes.api.model.RootPaths; import io.fabric8.kubernetes.client.utils.HttpClientUtils; import io.fabric8.kubernetes.client.utils.Utils; @@ -159,4 +163,12 @@ protected void adaptState() { protected SimpleClientContext newState(Config updated) { return new SimpleClientContext(updated, httpClient); } + + @Override + public , R extends Resource> MixedOperation resources( + Class resourceType, Class listClass, Class resourceClass) { + // TODO: make this more robust + return Handlers.getOperation(resourceType, listClass, this); + } + } diff --git a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/ResourcedHasMetadataOperation.java b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/ResourcedHasMetadataOperation.java index a8e66f9a9fe..08e65ff2a42 100644 --- a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/ResourcedHasMetadataOperation.java +++ b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/ResourcedHasMetadataOperation.java @@ -1,23 +1,39 @@ +/** + * Copyright (C) 2015 Red Hat, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package io.fabric8.kubernetes.client; import io.fabric8.kubernetes.api.model.HasMetadata; import io.fabric8.kubernetes.api.model.KubernetesResourceList; import io.fabric8.kubernetes.client.dsl.Resource; -import io.fabric8.kubernetes.client.dsl.base.BaseOperation; -import io.fabric8.kubernetes.client.dsl.base.HasMetadataOperation; import io.fabric8.kubernetes.client.dsl.base.OperationContext; +import io.fabric8.kubernetes.client.dsl.base.ResourceDefinitionContext; import io.fabric8.kubernetes.client.dsl.internal.HasMetadataOperationsImpl; +import io.fabric8.kubernetes.client.extension.ExtensibleResource; import io.fabric8.kubernetes.client.utils.KubernetesResourceUtil; import java.util.function.BiFunction; class ResourcedHasMetadataOperation, R extends Resource> - extends HasMetadataOperation { + extends HasMetadataOperationsImpl { - private BiFunction, Client, R> adapter; + private BiFunction, Client, R> adapter; - public ResourcedHasMetadataOperation(OperationContext ctx, Class type, Class listType, BiFunction, Client, R> adapter) { - super(ctx, type, listType); + public ResourcedHasMetadataOperation(OperationContext ctx, ResourceDefinitionContext resourceDefinitionContext, Class type, Class listType, BiFunction, Client, R> adapter) { + super(ctx, resourceDefinitionContext, type, listType); this.adapter = adapter; } @@ -25,16 +41,16 @@ public ResourcedHasMetadataOperation(OperationContext ctx, Class type, Class< protected R newResource(OperationContext context) { return adapter.apply(super.newInstance(context), new BaseClient(context)); } - + @Override - public BaseOperation newInstance(OperationContext context) { - return new ResourcedHasMetadataOperation<>(context, type, listType, adapter); + public HasMetadataOperationsImpl newInstance(OperationContext context) { + return new ResourcedHasMetadataOperation<>(context, this.rdc, type, listType, adapter); } public static , R extends Resource> void register( - Class type, BiFunction, Client, R> target) { + Class type, BiFunction, Client, R> target) { Handlers.register(type, (c) -> { - return new ResourcedHasMetadataOperation<>(HasMetadataOperationsImpl.defaultContext(c), type, + return new ResourcedHasMetadataOperation<>(HasMetadataOperationsImpl.defaultContext(c), ResourceDefinitionContext.fromResourceType(type), type, KubernetesResourceUtil.inferListType(type), target); }); } diff --git a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/base/BaseOperation.java b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/base/BaseOperation.java index b67d51c2eb4..ba5dfaea6cc 100755 --- a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/base/BaseOperation.java +++ b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/base/BaseOperation.java @@ -15,10 +15,6 @@ */ package io.fabric8.kubernetes.client.dsl.base; -import io.fabric8.kubernetes.api.model.ObjectReference; -import io.fabric8.kubernetes.client.dsl.WritableOperation; -import io.fabric8.kubernetes.client.utils.CreateOrReplaceHelper; -import io.fabric8.kubernetes.client.utils.Serialization; import io.fabric8.kubernetes.api.builder.TypedVisitor; import io.fabric8.kubernetes.api.builder.Visitor; import io.fabric8.kubernetes.api.model.DeletionPropagation; @@ -27,6 +23,7 @@ import io.fabric8.kubernetes.api.model.LabelSelector; import io.fabric8.kubernetes.api.model.ListOptions; import io.fabric8.kubernetes.api.model.ListOptionsBuilder; +import io.fabric8.kubernetes.api.model.ObjectReference; import io.fabric8.kubernetes.api.model.Status; import io.fabric8.kubernetes.api.model.autoscaling.v1.Scale; import io.fabric8.kubernetes.api.model.extensions.DeploymentRollback; @@ -38,24 +35,23 @@ import io.fabric8.kubernetes.client.ResourceNotFoundException; import io.fabric8.kubernetes.client.Watch; import io.fabric8.kubernetes.client.Watcher; -import io.fabric8.kubernetes.client.dsl.EditReplacePatchDeletable; import io.fabric8.kubernetes.client.dsl.FilterNested; import io.fabric8.kubernetes.client.dsl.FilterWatchListDeletable; -import io.fabric8.kubernetes.client.dsl.Gettable; -import io.fabric8.kubernetes.client.dsl.Informable; import io.fabric8.kubernetes.client.dsl.MixedOperation; import io.fabric8.kubernetes.client.dsl.NonNamespaceOperation; -import io.fabric8.kubernetes.client.dsl.ReplaceDeletable; import io.fabric8.kubernetes.client.dsl.Resource; import io.fabric8.kubernetes.client.dsl.internal.DefaultOperationInfo; import io.fabric8.kubernetes.client.dsl.internal.WatchConnectionManager; import io.fabric8.kubernetes.client.dsl.internal.WatchHTTPManager; +import io.fabric8.kubernetes.client.extension.ExtensibleResource; import io.fabric8.kubernetes.client.http.HttpRequest; import io.fabric8.kubernetes.client.informers.ListerWatcher; import io.fabric8.kubernetes.client.informers.ResourceEventHandler; import io.fabric8.kubernetes.client.informers.SharedIndexInformer; import io.fabric8.kubernetes.client.informers.impl.DefaultSharedIndexInformer; import io.fabric8.kubernetes.client.readiness.Readiness; +import io.fabric8.kubernetes.client.utils.CreateOrReplaceHelper; +import io.fabric8.kubernetes.client.utils.Serialization; import io.fabric8.kubernetes.client.utils.URLUtils; import io.fabric8.kubernetes.client.utils.URLUtils.URLBuilder; import io.fabric8.kubernetes.client.utils.Utils; @@ -85,7 +81,7 @@ public class BaseOperation, - Resource, + ExtensibleResource, ListerWatcher { private static final String WATCH = "watch"; @@ -239,7 +235,7 @@ public R withName(String name) { } @Override - public ReplaceDeletable lockResourceVersion(String resourceVersion) { + public ExtensibleResource lockResourceVersion(String resourceVersion) { return newInstance(context.withResourceVersion(resourceVersion)); } @@ -256,7 +252,7 @@ public NonNamespaceOperation inAnyNamespace() { @Override - public EditReplacePatchDeletable cascading(boolean cascading) { + public ExtensibleResource cascading(boolean cascading) { return newInstance(context.withCascading(cascading).withPropagationPolicy(null)); } @@ -289,7 +285,7 @@ public R load(String path) { } @Override - public Gettable fromServer() { + public ExtensibleResource fromServer() { return newInstance(context.withReloadingFromServer(true)); } @@ -520,8 +516,9 @@ public T patchStatus(T item) { throw new KubernetesClientException(READ_ONLY_UPDATE_EXCEPTION_MESSAGE); } - public BaseOperation withItem(T item) { - return newInstance(context.withItem(item)); + @Override + public R withItem(T item) { + return newResource(context.withItem(item)); } void deleteThis() { @@ -778,12 +775,12 @@ public OperationInfo forOperationType(String type) { } @Override - public FilterWatchListDeletable withGracePeriod(long gracePeriodSeconds) { + public ExtensibleResource withGracePeriod(long gracePeriodSeconds) { return newInstance(context.withGracePeriodSeconds(gracePeriodSeconds)); } @Override - public EditReplacePatchDeletable withPropagationPolicy(DeletionPropagation propagationPolicy) { + public ExtensibleResource withPropagationPolicy(DeletionPropagation propagationPolicy) { return newInstance(context.withPropagationPolicy(propagationPolicy)); } @@ -928,12 +925,12 @@ public void setNamespace(String namespace) { } @Override - public WritableOperation dryRun(boolean isDryRun) { + public ExtensibleResource dryRun(boolean isDryRun) { return newInstance(context.withDryRun(isDryRun)); } @Override - public Informable withIndexers(Map>> indexers) { + public ExtensibleResource withIndexers(Map>> indexers) { BaseOperation result = newInstance(context); result.indexers = indexers; result.limit = this.limit; diff --git a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/base/HasMetadataOperation.java b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/base/HasMetadataOperation.java index 36cb1eae1a2..e269bf625de 100644 --- a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/base/HasMetadataOperation.java +++ b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/base/HasMetadataOperation.java @@ -117,16 +117,16 @@ protected T requireFromServer() { protected T requireFromServer(ObjectMeta metadata) { try { if (Utils.isNotNullOrEmpty(getName())) { - return withItem(null).require(); + return newInstance(context.withItem(null)).require(); } if (getItem() != null) { String name = KubernetesResourceUtil.getName(getItem()); if (Utils.isNotNullOrEmpty(name)) { - return withItem(null).withName(name).require(); + return newInstance(context.withItem(null)).withName(name).require(); } } if (metadata != null && Utils.isNotNullOrEmpty(metadata.getName())) { - return withItem(null).withName(metadata.getName()).require(); + return newInstance(context.withItem(null)).withName(metadata.getName()).require(); } } catch (ResourceNotFoundException e) { if (e.getCause() instanceof KubernetesClientException) { diff --git a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/HasMetadataOperationsImpl.java b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/HasMetadataOperationsImpl.java index 7db57dd9973..5cdcab09523 100644 --- a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/HasMetadataOperationsImpl.java +++ b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/HasMetadataOperationsImpl.java @@ -32,7 +32,7 @@ public class HasMetadataOperationsImpl> extends HasMetadataOperation> implements MixedOperation> { - private final ResourceDefinitionContext rdc; + protected final ResourceDefinitionContext rdc; public HasMetadataOperationsImpl(ClientContext clientContext, ResourceDefinitionContext rdc, Class type, Class listType) { this(defaultContext(clientContext), rdc, type, listType); diff --git a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/batch/v1/JobOperationsImpl.java b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/batch/v1/JobOperationsImpl.java index 67e63daf427..9d48bd31c70 100644 --- a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/batch/v1/JobOperationsImpl.java +++ b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/batch/v1/JobOperationsImpl.java @@ -80,11 +80,6 @@ public ScalableResource load(InputStream is) { } } - @Override - public ScalableResource fromServer() { - return newInstance(context.withReloadingFromServer(true)); - } - @Override public Job scale(int count) { return scale(count, false); diff --git a/kubernetes-client/src/test/java/io/fabric8/kubernetes/client/utils/PodOperationUtilTest.java b/kubernetes-client/src/test/java/io/fabric8/kubernetes/client/utils/PodOperationUtilTest.java index 861651edf4e..1f9f2022d89 100644 --- a/kubernetes-client/src/test/java/io/fabric8/kubernetes/client/utils/PodOperationUtilTest.java +++ b/kubernetes-client/src/test/java/io/fabric8/kubernetes/client/utils/PodOperationUtilTest.java @@ -20,11 +20,11 @@ import io.fabric8.kubernetes.api.model.PodList; import io.fabric8.kubernetes.api.model.PodListBuilder; import io.fabric8.kubernetes.client.dsl.FilterWatchListDeletable; -import io.fabric8.kubernetes.client.dsl.Gettable; import io.fabric8.kubernetes.client.dsl.LogWatch; import io.fabric8.kubernetes.client.dsl.PodResource; import io.fabric8.kubernetes.client.dsl.base.OperationContext; import io.fabric8.kubernetes.client.dsl.internal.core.v1.PodOperationsImpl; +import io.fabric8.kubernetes.client.extension.ExtensibleResource; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.Mockito; @@ -91,7 +91,8 @@ void testWaitUntilReadyBeforeFetchingLogs() throws InterruptedException { .withNewMetadata().withName("foo").endMetadata() .withNewStatus().withPhase("Pending").endStatus() .build(); - Gettable gettablePod = () -> pod; + ExtensibleResource gettablePod = Mockito.mock(ExtensibleResource.class); + when(gettablePod.get()).thenReturn(pod); when(podOperations.fromServer()).thenReturn(gettablePod); when(podOperations.waitUntilReady(5, TimeUnit.SECONDS)).thenReturn(pod);