Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fromCustomResourceType is of type CustomResource #2700

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -3,6 +3,7 @@
### 5.0-SNAPSHOT

#### Bugs
* Fix #2695: fromCustomResourceType should be of type `CustomResource`

#### Improvements

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

Expand All @@ -400,7 +400,7 @@ public <T extends HasMetadata> MixedOperation<T, KubernetesResourceList<T>, Reso
* {@inheritDoc}
*/
@Override
public <T extends HasMetadata, L extends KubernetesResourceList<T>> MixedOperation<T, L, Resource<T>> customResources(Class<T> resourceType, Class<L> listClass) {
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);
}

Expand Down
Expand Up @@ -118,7 +118,7 @@ public interface KubernetesClient extends Client {
* {@link io.fabric8.kubernetes.api.model.Namespaced}
* @return returns a MixedOperation object with which you can do basic CustomResource operations
*/
<T extends HasMetadata> MixedOperation<T, KubernetesResourceList<T>, Resource<T>> customResources(Class<T> resourceType);
<T extends CustomResource> MixedOperation<T, KubernetesResourceList<T>, Resource<T>> customResources(Class<T> resourceType);


/**
Expand All @@ -138,7 +138,7 @@ public interface KubernetesClient extends Client {
* @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(Class<T> resourceType, Class<L> listClass);
<T extends CustomResource, L extends KubernetesResourceList<T>> MixedOperation<T, L, Resource<T>> customResources(Class<T> resourceType, Class<L> listClass);


/**
Expand Down
Expand Up @@ -15,13 +15,12 @@
*/
package io.fabric8.kubernetes.client.dsl.base;

import io.fabric8.kubernetes.api.model.HasMetadata;
import io.fabric8.kubernetes.api.model.apiextensions.v1beta1.CustomResourceDefinition;
import io.fabric8.kubernetes.api.model.apiextensions.v1beta1.CustomResourceDefinitionBuilder;
import io.fabric8.kubernetes.api.model.apiextensions.v1beta1.CustomResourceDefinitionSpec;
import io.fabric8.kubernetes.api.model.apiextensions.v1beta1.CustomResourceDefinitionVersion;
import io.fabric8.kubernetes.client.CustomResource;
import io.fabric8.kubernetes.client.KubernetesClientException;
import io.fabric8.kubernetes.api.model.apiextensions.v1beta1.CustomResourceDefinitionSpec;
import io.fabric8.kubernetes.client.utils.KubernetesVersionPriority;

import java.lang.reflect.InvocationTargetException;
Expand Down Expand Up @@ -59,6 +58,7 @@ public String getKind() {
return kind;
}

@SuppressWarnings("rawtypes")
public static CustomResourceDefinitionBuilder v1beta1CRDFromCustomResourceType(Class<? extends CustomResource> customResource) {
try {
final CustomResource instance = customResource.getDeclaredConstructor().newInstance();
Expand All @@ -85,7 +85,10 @@ public static CustomResourceDefinitionBuilder v1beta1CRDFromCustomResourceType(C
}
}

public static io.fabric8.kubernetes.api.model.apiextensions.v1.CustomResourceDefinitionBuilder v1CRDFromCustomResourceType(Class<? extends CustomResource> customResource) {
@SuppressWarnings("rawtypes")
public static io.fabric8.kubernetes.api.model.apiextensions.v1.CustomResourceDefinitionBuilder v1CRDFromCustomResourceType(
Class<? extends CustomResource> customResource
) {
try {
final CustomResource instance = customResource.getDeclaredConstructor().newInstance();
return new io.fabric8.kubernetes.api.model.apiextensions.v1.CustomResourceDefinitionBuilder()
Expand All @@ -107,9 +110,10 @@ public static io.fabric8.kubernetes.api.model.apiextensions.v1.CustomResourceDef
}
}

public static CustomResourceDefinitionContext fromCustomResourceType(Class<? extends HasMetadata> customResource) {
@SuppressWarnings("rawtypes")
public static CustomResourceDefinitionContext fromCustomResourceType(Class<? extends CustomResource> customResource) {
try {
final CustomResource instance = (CustomResource) customResource.getDeclaredConstructor().newInstance();
final CustomResource instance = customResource.getDeclaredConstructor().newInstance();
return new Builder()
.withGroup(instance.getGroup())
.withVersion(instance.getVersion())
Expand All @@ -136,7 +140,8 @@ public static CustomResourceDefinitionContext fromCrd(CustomResourceDefinition c
}

public static CustomResourceDefinitionContext fromCrd(
io.fabric8.kubernetes.api.model.apiextensions.v1.CustomResourceDefinition crd) {
io.fabric8.kubernetes.api.model.apiextensions.v1.CustomResourceDefinition crd
) {
return new CustomResourceDefinitionContext.Builder()
.withGroup(crd.getSpec().getGroup())
.withVersion(getVersion(crd.getSpec()))
Expand All @@ -163,7 +168,8 @@ private static String getVersion(CustomResourceDefinitionSpec spec) {
}

private static String getVersion(
io.fabric8.kubernetes.api.model.apiextensions.v1.CustomResourceDefinitionSpec spec) {
io.fabric8.kubernetes.api.model.apiextensions.v1.CustomResourceDefinitionSpec spec
) {
return getVersion(
spec.getVersions().stream()
.map(io.fabric8.kubernetes.api.model.apiextensions.v1.CustomResourceDefinitionVersion::getName)
Expand Down
Expand Up @@ -64,6 +64,7 @@
import io.fabric8.kubernetes.client.AdmissionRegistrationAPIGroupDSL;
import io.fabric8.kubernetes.client.Config;
import io.fabric8.kubernetes.client.ConfigBuilder;
import io.fabric8.kubernetes.client.CustomResource;
import io.fabric8.kubernetes.client.KubernetesClient;
import io.fabric8.kubernetes.client.NamespacedKubernetesClient;
import io.fabric8.kubernetes.client.OAuthTokenProvider;
Expand Down Expand Up @@ -430,12 +431,12 @@ public Createable<TokenReview> tokenReviews() {
}

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

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

Expand Down