Skip to content

Commit

Permalink
fix fabric8io#3845: adding an api only framework for extensions
Browse files Browse the repository at this point in the history
also deprecating extra ApiVersionUtil classes
moving resource interfaces in service-catalog client from internal to
dsl
  • Loading branch information
shawkins committed Feb 16, 2022
1 parent c438ddf commit f31e881
Show file tree
Hide file tree
Showing 36 changed files with 376 additions and 183 deletions.
5 changes: 5 additions & 0 deletions extensions/camel-k/client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,14 @@
<groupId>io.fabric8</groupId>
<artifactId>camel-k-model-v1</artifactId>
</dependency>
<dependency>
<groupId>io.fabric8</groupId>
<artifactId>kubernetes-client-api</artifactId>
</dependency>
<dependency>
<groupId>io.fabric8</groupId>
<artifactId>kubernetes-client</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<DefaultCamelKClient> implements NamespacedCamelKClient {

public DefaultCamelKClient() {
super();
Expand All @@ -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<NamespacedCamelKClient> withRequestConfig(RequestConfig requestConfig) {
return new WithRequestCallable<>(this, requestConfig);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<V1APIGroupClient> implements V1APIGroupDSL {

public V1APIGroupClient(ClientContext clientContext) {
super(clientContext);
}
public V1APIGroupClient() {
super();
}

@Override
public MixedOperation<Build, BuildList, Resource<Build>> builds() {
return Handlers.getOperation(Build.class, BuildList.class, this);
}
public V1APIGroupClient(Client client) {
super(client);
}

@Override
public MixedOperation<CamelCatalog, CamelCatalogList, Resource<CamelCatalog>> camelCatalogs() {
return Handlers.getOperation(CamelCatalog.class, CamelCatalogList.class, this);
}
@Override
protected V1APIGroupClient newInstance(Client client) {
return new V1APIGroupClient(client);
}

@Override
public MixedOperation<Integration, IntegrationList, Resource<Integration>> integrations() {
return Handlers.getOperation(Integration.class, IntegrationList.class, this);
}
@Override
public MixedOperation<Build, BuildList, Resource<Build>> builds() {
return resources(Build.class, BuildList.class);
}

@Override
public MixedOperation<IntegrationKit, IntegrationKitList, Resource<IntegrationKit>> integrationKits() {
return Handlers.getOperation(IntegrationKit.class, IntegrationKitList.class, this);
}
@Override
public MixedOperation<CamelCatalog, CamelCatalogList, Resource<CamelCatalog>> camelCatalogs() {
return resources(CamelCatalog.class, CamelCatalogList.class);
}

@Override
public MixedOperation<IntegrationPlatform, IntegrationPlatformList, Resource<IntegrationPlatform>> integrationPlatforms() {
return Handlers.getOperation(IntegrationPlatform.class, IntegrationPlatformList.class, this);
}
@Override
public MixedOperation<Integration, IntegrationList, Resource<Integration>> integrations() {
return resources(Integration.class, IntegrationList.class);
}

@Override
public MixedOperation<IntegrationKit, IntegrationKitList, Resource<IntegrationKit>> integrationKits() {
return resources(IntegrationKit.class, IntegrationKitList.class);
}

@Override
public MixedOperation<IntegrationPlatform, IntegrationPlatformList, Resource<IntegrationPlatform>> integrationPlatforms() {
return resources(IntegrationPlatform.class, IntegrationPlatformList.class);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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<V1alpha1APIGroupClient> 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<Kamelet, KameletList, Resource<Kamelet>> kamelets() {
return Handlers.getOperation(Kamelet.class, KameletList.class, this);
return resources(Kamelet.class, KameletList.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -34,7 +38,7 @@ private ApiVersionUtil() {
* @param apiGroup apiGroupName present if any
* @return Just the apiGroupName part without apiGroupVersion
*/

public static <T> String apiGroup(T item, String apiGroup) {
if (item instanceof HasMetadata
&& Utils.isNotNullOrEmpty(((HasMetadata) item).getApiVersion())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <T> String apiGroup(T item, String apiGroup) {
if (item instanceof HasMetadata && Utils.isNotNullOrEmpty(((HasMetadata) item).getApiVersion())) {
return trimGroupOrNull(((HasMetadata) item).getApiVersion());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<DefaultServiceCatalogClient> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -31,7 +33,7 @@

public class ClusterServiceBrokerOperationsImpl extends ResourceAdapter<ClusterServiceBroker> implements ClusterServiceBrokerResource {

public ClusterServiceBrokerOperationsImpl(Resource<ClusterServiceBroker> resource, Client client) {
public ClusterServiceBrokerOperationsImpl(ExtensibleResource<ClusterServiceBroker> resource, Client client) {
super(resource, client);
}

Expand Down
Loading

0 comments on commit f31e881

Please sign in to comment.