Skip to content

Commit

Permalink
Fix fabric8io#2694: Remove deprecated methods from KubernetesClient DSL
Browse files Browse the repository at this point in the history
Removing the following deprecated methods from KubernetesClient DSL:
- `client.customResourceDefinitions()`
- `client.events()`
- `client.customResources(CustomResourceDefinition crd, Class<T>
  resourceType, Class<L> listClass)`
- `client.customResource(CustomResourceDefinition crd, Class<T>
  resourceType, Class<L> listClass)`
  • Loading branch information
rohanKanojia committed Feb 2, 2021
1 parent 3e5cb2f commit 1971f57
Show file tree
Hide file tree
Showing 20 changed files with 41 additions and 301 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#### Improvements
* Fix #2717: Remove edit() methods from RawCustomResourceOperationsImpl taking InputStream arguments
* Fix #2694: Remove deprecated methods from KubernetesClient DSL

#### Dependency Upgrade
* update Tekton Triggers model to v0.11.1
Expand All @@ -16,7 +17,13 @@
* Fix #2702 : Add support for discovery.k8s.io/v1beta1 EndpointSlice in KubernetesClient DSL

_**Note**_: Breaking changes in the API
##### DSL Changes:
- `client.settings()` DSL has been removed since PodPreset v1alpha1 API is no longer present in Kubernetes 1.20.x
- `client.customResourceDefinitions()` has been removed. Use `client.apiextensions().v1beta1().customResourceDefinitions()` instead
- `client.events()` has been removed. Use `client.v1().events()` instead
- `client.customResources(...)` methods having `CustomResourceDefinitionContext`/`CustomResourceDefinition` as argument for typed CustomResource API have been removed. Use the new annotations `@Version`, `@Group` introduced in 5.x versions of client.

##### Model Changes:
- Classes in `io.fabric8.kubernetes.api.model.scheduling` have been moved to `io.fabric8.kubernetes.api.model.scheduling.v1` and `io.fabric8.kubernetes.api.model.scheduling.v1beta1`
- Classes in `io.fabric8.kubernetes.api.model.admission` have been moved to `io.fabric8.kubernetes.api.model.admission.v1` and `io.fabric8.kubernetes.api.model.admission.v1beta1`
- Classes in `io.fabric8.kubernetes.api.model.certificates` have been moved to `io.fabric8.kubernetes.api.model.certificates.v1` and `io.fabric8.kubernetes.api.model.certificates.v1beta1`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
import io.fabric8.kubernetes.api.model.ConfigMapList;
import io.fabric8.kubernetes.api.model.Endpoints;
import io.fabric8.kubernetes.api.model.EndpointsList;
import io.fabric8.kubernetes.api.model.Event;
import io.fabric8.kubernetes.api.model.EventList;
import io.fabric8.kubernetes.api.model.HasMetadata;
import io.fabric8.kubernetes.api.model.KubernetesResourceList;
import io.fabric8.kubernetes.api.model.LimitRange;
Expand Down Expand Up @@ -182,11 +180,6 @@ public MixedOperation<Endpoints, EndpointsList, Resource<Endpoints>> endpoints()
return delegate.endpoints();
}

@Override
public MixedOperation<Event, EventList, Resource<Event>> events() {
return delegate.events();
}

@Override
public NonNamespaceOperation<Namespace, NamespaceList, Resource<Namespace>> namespaces() {
return delegate.namespaces();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,12 @@
import io.fabric8.kubernetes.api.model.HasMetadata;
import io.fabric8.kubernetes.api.model.KubernetesListBuilder;
import io.fabric8.kubernetes.api.model.KubernetesResourceList;
import io.fabric8.kubernetes.api.model.apiextensions.v1beta1.CustomResourceDefinition;
import io.fabric8.kubernetes.api.model.apiextensions.v1beta1.CustomResourceDefinitionList;
import io.fabric8.kubernetes.api.model.ConfigMap;
import io.fabric8.kubernetes.api.model.ConfigMapList;
import io.fabric8.kubernetes.api.model.ComponentStatus;
import io.fabric8.kubernetes.api.model.ComponentStatusList;
import io.fabric8.kubernetes.api.model.Endpoints;
import io.fabric8.kubernetes.api.model.EndpointsList;
import io.fabric8.kubernetes.api.model.Event;
import io.fabric8.kubernetes.api.model.EventList;
import io.fabric8.kubernetes.api.model.LimitRange;
import io.fabric8.kubernetes.api.model.LimitRangeList;
import io.fabric8.kubernetes.api.model.Namespace;
Expand Down Expand Up @@ -65,7 +61,6 @@
import io.fabric8.kubernetes.client.dsl.base.CustomResourceDefinitionContext;
import io.fabric8.kubernetes.client.dsl.internal.ClusterOperationsImpl;
import io.fabric8.kubernetes.client.dsl.internal.CreateOnlyResourceOperationsImpl;
import io.fabric8.kubernetes.client.dsl.internal.apiextensions.v1beta1.CustomResourceDefinitionOperationsImpl;
import io.fabric8.kubernetes.client.dsl.internal.CustomResourceOperationContext;
import io.fabric8.kubernetes.client.dsl.internal.CustomResourceOperationsImpl;
import io.fabric8.kubernetes.client.dsl.internal.KubernetesListOperationsImpl;
Expand Down Expand Up @@ -222,14 +217,6 @@ public MixedOperation<Endpoints, EndpointsList, Resource<Endpoints>> endpoints()
return new EndpointsOperationsImpl(httpClient, getConfiguration());
}

/**
* {@inheritDoc}
*/
@Override
public MixedOperation<Event, EventList, Resource<Event>> events() {
return new EventOperationsImpl(httpClient, getConfiguration());
}

/**
* {@inheritDoc}
*/
Expand Down Expand Up @@ -347,14 +334,6 @@ public MixedOperation<LimitRange, LimitRangeList, Resource<LimitRange>> limitRan
return new LimitRangeOperationsImpl(httpClient, getConfiguration());
}

/**
* {@inheritDoc}
*/
@Override
public NonNamespaceOperation<CustomResourceDefinition, CustomResourceDefinitionList, Resource<CustomResourceDefinition>> customResourceDefinitions() {
return new CustomResourceDefinitionOperationsImpl(httpClient, getConfiguration());
}

/**
* {@inheritDoc}
*/
Expand Down Expand Up @@ -392,7 +371,7 @@ public Createable<TokenReview> tokenReviews() {
*/
@Override
public <T extends CustomResource> MixedOperation<T, KubernetesResourceList<T>, Resource<T>> customResources(Class<T> resourceType) {
return customResources(CustomResourceDefinitionContext.fromCustomResourceType(resourceType), resourceType, null);
return customResources(resourceType, null);
}


Expand All @@ -401,29 +380,8 @@ public <T extends CustomResource> MixedOperation<T, KubernetesResourceList<T>, R
*/
@Override
public <T extends CustomResource, L extends KubernetesResourceList<T>> MixedOperation<T, L, Resource<T>> customResources(Class<T> resourceType, Class<L> listClass) {
return customResources(CustomResourceDefinitionContext.fromCustomResourceType(resourceType), resourceType, listClass);
}


/**
* {@inheritDoc}
*/
@Override
public <T extends HasMetadata, L extends KubernetesResourceList<T>> MixedOperation<T, L, Resource<T>> customResources(CustomResourceDefinitionContext crdContext, Class<T> resourceType, Class<L> listClass) {
return new CustomResourceOperationsImpl<>(new CustomResourceOperationContext().withOkhttpClient(httpClient).withConfig(getConfiguration())
.withCrdContext(crdContext)
.withType(resourceType)
.withListType(listClass)
.withPropagationPolicy(DEFAULT_PROPAGATION_POLICY));
}

/**
* {@inheritDoc}
*/
@Override
public <T extends HasMetadata, L extends KubernetesResourceList<T>> MixedOperation<T, L, Resource<T>> customResources(CustomResourceDefinition crd, Class<T> resourceType, Class<L> listClass) {
return new CustomResourceOperationsImpl<>(new CustomResourceOperationContext().withOkhttpClient(httpClient).withConfig(getConfiguration())
.withCrd(crd)
.withCrdContext(CustomResourceDefinitionContext.fromCustomResourceType(resourceType))
.withType(resourceType)
.withListType(listClass)
.withPropagationPolicy(DEFAULT_PROPAGATION_POLICY));
Expand All @@ -437,15 +395,6 @@ public RawCustomResourceOperationsImpl customResource(CustomResourceDefinitionCo
return new RawCustomResourceOperationsImpl(httpClient, getConfiguration(), customResourceDefinition);
}


/**
* {@inheritDoc}
*/
@Override
public <T extends HasMetadata, L extends KubernetesResourceList<T>> MixedOperation<T, L, Resource<T>> customResource(CustomResourceDefinition crd, Class<T> resourceType, Class<L> listClass) {
return customResources(crd, resourceType, listClass);
}

@Override
public DiscoveryAPIGroupDSL discovery() {
return adapt(DiscoveryAPIGroupClient.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
import io.fabric8.kubernetes.api.model.ComponentStatusList;
import io.fabric8.kubernetes.api.model.Endpoints;
import io.fabric8.kubernetes.api.model.EndpointsList;
import io.fabric8.kubernetes.api.model.Event;
import io.fabric8.kubernetes.api.model.EventList;
import io.fabric8.kubernetes.api.model.LimitRange;
import io.fabric8.kubernetes.api.model.LimitRangeList;
import io.fabric8.kubernetes.api.model.Namespace;
Expand Down Expand Up @@ -59,8 +57,6 @@
import io.fabric8.kubernetes.api.model.node.v1beta1.RuntimeClass;
import io.fabric8.kubernetes.api.model.node.v1beta1.RuntimeClassList;
import io.fabric8.kubernetes.client.dsl.*;
import io.fabric8.kubernetes.api.model.apiextensions.v1beta1.CustomResourceDefinition;
import io.fabric8.kubernetes.api.model.apiextensions.v1beta1.CustomResourceDefinitionList;
import io.fabric8.kubernetes.client.dsl.base.CustomResourceDefinitionContext;
import io.fabric8.kubernetes.client.dsl.internal.RawCustomResourceOperationsImpl;
import io.fabric8.kubernetes.client.extended.leaderelection.LeaderElectorBuilder;
Expand All @@ -76,18 +72,6 @@
*/
public interface KubernetesClient extends Client {

/**
* API entrypoint for CustomResourcedefinition(CRDs). This offers basic operations like
* load, get, create, update, delete and watch for APIGroup apiextensions/v1beta1
*
* @deprecated Use {@link #apiextensions()}: {@link ApiextensionsAPIGroupDSL#v1beta1()}
* or {@link ApiextensionsAPIGroupDSL#v1()} to access Custom Resource Definition DSL for specific API versions.
*
* @return NonNamespaceOperation object for CustomResourceDefinition
*/
@Deprecated
NonNamespaceOperation<CustomResourceDefinition, CustomResourceDefinitionList, Resource<CustomResourceDefinition>> customResourceDefinitions();

/**
* API entrypoint for apiextensions resources. Currently support both
* v1 and v1beta1
Expand Down Expand Up @@ -120,7 +104,6 @@ public interface KubernetesClient extends Client {
*/
<T extends CustomResource> MixedOperation<T, KubernetesResourceList<T>, Resource<T>> customResources(Class<T> resourceType);


/**
* 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
Expand All @@ -140,78 +123,6 @@ public interface KubernetesClient extends Client {
*/
<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.
* </p>
*
* @param crdContext CustomResourceDefinitionContext describes the core fields used to search for CustomResources
* @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
* @param <L> L type represents CustomResourceList type
* @return returns a MixedOperation object with which you can do basic CustomResource operations
*/
<T extends HasMetadata, L extends KubernetesResourceList<T>> MixedOperation<T, L, Resource<T>> customResources(CustomResourceDefinitionContext crdContext, 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.
* </p>
*
* @deprecated use {@link #customResources(CustomResourceDefinitionContext, Class, Class)}, which takes a {@link CustomResourceDefinitionContext}
* instead of a full {@link CustomResourceDefinition}.
*
* @param crd CustomResourceDefinition object on basic of which this CustomResource was created
* @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
* @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(CustomResourceDefinition crd, Class<T> resourceType, Class<L> listClass);

/**
* Old API for dealing with CustomResources.
*
* @deprecated use {@link #customResources(CustomResourceDefinitionContext, Class, Class)}, which takes a {@link CustomResourceDefinitionContext}
* instead of a full {@link CustomResourceDefinition}.
*
* <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.
* </p>
*
* @param crd Custom Resource Definition
* @param resourceType resource type Pojo
* @param listClass list class Pojo
* @param <T> template argument for resource. If it's Namespaced resource, it must implement
* io.fabric8.kubernetes.api.model.Namespaced
* @param <L> template argument for list
* @return Kubernetes client object for manipulating custom resource.
*/
<T extends HasMetadata, L extends KubernetesResourceList<T>> MixedOperation<T, L, Resource<T>> customResource(CustomResourceDefinition crd, Class<T> resourceType, Class<L> listClass);

/**
* Discovery API entrypoint for APIGroup discovery.k8s.io
*
Expand Down Expand Up @@ -393,14 +304,6 @@ public interface KubernetesClient extends Client {
*/
MixedOperation<Endpoints, EndpointsList, Resource<Endpoints>> endpoints();

/**
* API entrypoint for getting events in Kubernetes. Events (core/v1)
*
* @deprecated Use KubernetesClient#v1#events instead.
* @return MixedOperation object for doing operations for Events
*/
MixedOperation<Event, EventList, Resource<Event>> events();

/**
* API entrypoint for namespace related operations in Kubernetes. Namespace (core/v1)
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/**
* Copyright (C) 2015 Red Hat, Inc.
/** 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.
Expand All @@ -25,8 +24,6 @@
import io.fabric8.kubernetes.api.model.ConfigMapList;
import io.fabric8.kubernetes.api.model.Endpoints;
import io.fabric8.kubernetes.api.model.EndpointsList;
import io.fabric8.kubernetes.api.model.Event;
import io.fabric8.kubernetes.api.model.EventList;
import io.fabric8.kubernetes.api.model.HasMetadata;
import io.fabric8.kubernetes.api.model.KubernetesResourceList;
import io.fabric8.kubernetes.api.model.LimitRange;
Expand All @@ -51,8 +48,6 @@
import io.fabric8.kubernetes.api.model.ServiceAccount;
import io.fabric8.kubernetes.api.model.ServiceAccountList;
import io.fabric8.kubernetes.api.model.ServiceList;
import io.fabric8.kubernetes.api.model.apiextensions.v1beta1.CustomResourceDefinition;
import io.fabric8.kubernetes.api.model.apiextensions.v1beta1.CustomResourceDefinitionList;
import io.fabric8.kubernetes.api.model.certificates.v1beta1.CertificateSigningRequest;
import io.fabric8.kubernetes.api.model.certificates.v1beta1.CertificateSigningRequestList;
import io.fabric8.kubernetes.api.model.authentication.TokenReview;
Expand Down Expand Up @@ -333,10 +328,6 @@ public MixedOperation<PersistentVolumeClaim, PersistentVolumeClaimList, Resource
return delegate.persistentVolumeClaims();
}

public MixedOperation<Event, EventList, Resource<Event>> events() {
return delegate.events();
}

public MixedOperation<ReplicationController, ReplicationControllerList, RollableScalableResource<ReplicationController>> replicationControllers() {
return delegate.replicationControllers();
}
Expand Down Expand Up @@ -402,11 +393,6 @@ public AutoscalingAPIGroupDSL autoscaling() {
@Override
public RbacAPIGroupDSL rbac() { return delegate.rbac(); }

@Override
public NonNamespaceOperation<CustomResourceDefinition, CustomResourceDefinitionList, Resource<CustomResourceDefinition>> customResourceDefinitions() {
return delegate.customResourceDefinitions();
}

@Override
public ApiextensionsAPIGroupDSL apiextensions() {
return delegate.apiextensions();
Expand Down Expand Up @@ -437,21 +423,6 @@ public <T extends CustomResource, L extends KubernetesResourceList<T>> MixedOper
return delegate.customResources(resourceType, listClass);
}

@Override
public <T extends HasMetadata, L extends KubernetesResourceList<T>> MixedOperation<T, L, Resource<T>> customResources(CustomResourceDefinitionContext crdContext, Class<T> resourceType, Class<L> listClass) {
return delegate.customResources(crdContext, resourceType, listClass);
}

@Override
public <T extends HasMetadata, L extends KubernetesResourceList<T>> MixedOperation<T, L, Resource<T>> customResources(CustomResourceDefinition crd, Class<T> resourceType, Class<L> listClass) {
return delegate.customResources(crd, resourceType, listClass);
}

@Override
public <T extends HasMetadata, L extends KubernetesResourceList<T>> MixedOperation<T, L, Resource<T>> customResource(CustomResourceDefinition crd, Class<T> resourceType, Class<L> listClass) {
return customResources(crd, resourceType, listClass);
}

@Override
public DiscoveryAPIGroupDSL discovery() {
return delegate.discovery();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public static void main(String[] args) {
}
}

CustomResourceDefinitionList crds = client.customResourceDefinitions().list();
CustomResourceDefinitionList crds = client.apiextensions().v1beta1().customResourceDefinitions().list();
List<CustomResourceDefinition> crdsItems = crds.getItems();
System.out.println("Found " + crdsItems.size() + " CRD(s)");
CustomResourceDefinition dummyCRD = null;
Expand All @@ -119,7 +119,7 @@ public static void main(String[] args) {
KubernetesDeserializer.registerCustomKind(HasMetadata.getApiVersion(Dummy.class), dummyCRD.getKind(), Dummy.class);

// lets create a client for the CRD
NonNamespaceOperation<Dummy, DummyList, Resource<Dummy>> dummyClient = client.customResources(dummyCRD, Dummy.class, DummyList.class);
NonNamespaceOperation<Dummy, DummyList, Resource<Dummy>> dummyClient = client.customResources(Dummy.class, DummyList.class);
if (resourceNamespaced) {
dummyClient = ((MixedOperation<Dummy, DummyList, Resource<Dummy>>) dummyClient).inNamespace(namespace);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public void onDelete(Dummy pod, boolean deletedFinalStateUnknown) {
.map(HasMetadata::getMetadata).map(ObjectMeta::getNamespace).orElse("default"));
}

client.customResources(crdContext, Dummy.class, DummyList.class).createOrReplace(toCreate);
client.customResources(Dummy.class, DummyList.class).createOrReplace(toCreate);
// Wait for some time now
TimeUnit.MINUTES.sleep(5);
} catch (InterruptedException interruptedException) {
Expand Down
Loading

0 comments on commit 1971f57

Please sign in to comment.