Skip to content

Commit

Permalink
fix fabric8io#3845 fabric8io#3407: refining resourceList to use commo…
Browse files Browse the repository at this point in the history
…n logic
  • Loading branch information
shawkins committed Feb 17, 2022
1 parent 0e6b058 commit 5d934c3
Show file tree
Hide file tree
Showing 15 changed files with 121 additions and 661 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,21 @@

package io.fabric8.kubernetes.client.dsl;

import java.util.List;

import io.fabric8.kubernetes.api.builder.Visitable;
import io.fabric8.kubernetes.client.FromServerGettable;

import java.util.List;

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


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

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,15 @@ public class NamespaceableResourceAdapter<T extends HasMetadata> implements Name
public NamespaceableResourceAdapter(T item, HasMetadataOperation<T, ?, ?> op) {
this.operation = op;
this.item = item;
this.resource = getResource(item, op);
}

public static <T extends HasMetadata> Resource<T> getResource(T item, HasMetadataOperation<T, ?, ?> op) {
String namespace = KubernetesResourceUtil.getNamespace(item);
if (namespace != null) {
this.resource = op.inNamespace(namespace).withItem(item);
} else {
this.resource = op.withItem(item);
return op.inNamespace(namespace).withItem(item);
}
return op.withItem(item);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ public ExtensibleResource<T> cascading(boolean cascading) {

@Override
public R load(InputStream is) {
return newResource(context.withItem(unmarshal(is, type)));
return withItem(unmarshal(is, type));
}

@Override
Expand Down Expand Up @@ -519,6 +519,8 @@ public T patchStatus(T item) {

@Override
public R withItem(T item) {
// set both the item and the name - not all operations are looking at the item for the name
// things like configMaps().load(...).watch(...) for example
return newResource(context.withItem(item).withName(KubernetesResourceUtil.getName(item)));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ public T patch(PatchContext patchContext, String patch) {
}

@Override
public BaseOperation<T, L, R> newInstance(OperationContext context) {
public HasMetadataOperation<T, L, R> newInstance(OperationContext context) {
return new HasMetadataOperation<>(context, type, listType);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import io.fabric8.kubernetes.api.model.GenericKubernetesResource;
import io.fabric8.kubernetes.api.model.GenericKubernetesResourceList;
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;

Expand All @@ -38,7 +37,7 @@ protected void validateOperation(Class<GenericKubernetesResource> type) {
}

@Override
public BaseOperation<GenericKubernetesResource, GenericKubernetesResourceList, Resource<GenericKubernetesResource>> newInstance(OperationContext context) {
public HasMetadataOperation<GenericKubernetesResource, GenericKubernetesResourceList, Resource<GenericKubernetesResource>> newInstance(OperationContext context) {
return new GenericKubernetesResourceOperationsImpl(context, resourceNamespaced);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
import io.fabric8.kubernetes.api.model.HasMetadata;
import io.fabric8.kubernetes.api.model.KubernetesList;
import io.fabric8.kubernetes.api.model.KubernetesListBuilder;
import io.fabric8.kubernetes.client.BaseClient;
import io.fabric8.kubernetes.client.ClientContext;
import io.fabric8.kubernetes.client.KubernetesClientException;
import io.fabric8.kubernetes.client.NamespaceableResourceAdapter;
import io.fabric8.kubernetes.client.ResourceHandler;
import io.fabric8.kubernetes.client.dsl.Createable;
import io.fabric8.kubernetes.client.dsl.Gettable;
Expand Down Expand Up @@ -124,9 +124,14 @@ public KubernetesList get() {
return new KubernetesListBuilder(list).withItems(list.getItems().stream().map(meta -> getResource(meta).get()).collect(Collectors.toList())).build();
}

/**
* Similar to Loadable.load - does not use the namespace from the resource
*
* see also {@link NamespaceVisitFromServerGetWatchDeleteRecreateWaitApplicableListImpl#getResource(OperationContext, HasMetadata)}
*/
private Resource<HasMetadata> getResource(HasMetadata resource) {
ResourceHandler<HasMetadata, ?> handler = NamespaceVisitFromServerGetWatchDeleteRecreateWaitApplicableImpl.handlerOf(resource, context);
return handler.operation(this.context, null).newInstance(context.withItem(resource));
ResourceHandler<HasMetadata, ?> handler = NamespaceVisitFromServerGetWatchDeleteRecreateWaitApplicableListImpl.handlerOf(resource, context);
return handler.operation(context, null).newInstance(context.withItem(null)).withItem(resource);
}

@Override
Expand Down

This file was deleted.

Loading

0 comments on commit 5d934c3

Please sign in to comment.