Skip to content

Commit 1f5061f

Browse files
shawkinsmanusa
authored andcommitted
changing the generic resource method name
also allowing inform to work off of withName
1 parent 23b25dd commit 1f5061f

File tree

4 files changed

+22
-17
lines changed

4 files changed

+22
-17
lines changed

kubernetes-client/src/main/java/io/fabric8/kubernetes/client/KubernetesClient.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,12 +161,12 @@ public interface KubernetesClient extends Client {
161161
<T extends HasMetadata, L extends KubernetesResourceList<T>> MixedOperation<T, L, Resource<T>> customResources(CustomResourceDefinitionContext crdContext, Class<T> resourceType, Class<L> listClass);
162162

163163
/**
164-
* Semi-Typed API for managing CustomResources.
164+
* Semi-Typed API for managing {@link GenericKubernetesResource}s which can represent any resource.
165165
*
166-
* @param crdContext CustomResourceDefinitionContext describes the core fields used to search for CustomResources
167-
* @return returns a MixedOperation object with which you can do basic CustomResource operations
166+
* @param crdContext CustomResourceDefinitionContext describes the core fields
167+
* @return returns a MixedOperation object with which you can do basic operations
168168
*/
169-
default MixedOperation<GenericKubernetesResource, GenericKubernetesResourceList, Resource<GenericKubernetesResource>> genericCustomResources(
169+
default MixedOperation<GenericKubernetesResource, GenericKubernetesResourceList, Resource<GenericKubernetesResource>> genericKubernetesResources(
170170
CustomResourceDefinitionContext crdContext) {
171171
return customResources(crdContext, GenericKubernetesResource.class, GenericKubernetesResourceList.class);
172172
}

kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/Resource.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,5 @@ public interface Resource<T> extends CreateOrReplaceable<T>,
2525
CascadingEditReplacePatchDeletable<T>,
2626
VersionWatchAndWaitable<T>,
2727
DryRunable<WritableOperation<T>>,
28-
Requirable<T>, Readiable {
28+
Requirable<T>, Readiable, Informable<T> {
2929
}

kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/base/BaseOperation.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
import java.net.MalformedURLException;
7373
import java.net.URL;
7474
import java.util.Arrays;
75+
import java.util.Collections;
7576
import java.util.Iterator;
7677
import java.util.List;
7778
import java.util.Map;
@@ -1206,16 +1207,20 @@ public Informable<T> withIndexers(Map<String, Function<T, List<String>>> indexer
12061207

12071208
@Override
12081209
public SharedIndexInformer<T> inform(ResourceEventHandler<T> handler, long resync) {
1209-
// create an informer that will consume no additional threads beyond the underlying Watch
1210+
// convert the name into something listable
1211+
FilterWatchListDeletable<T, L> baseOperation =
1212+
getName() == null ? this : withFields(Collections.singletonMap("metadata.name", getName()));
1213+
1214+
// use the local context / namespace
12101215
DefaultSharedIndexInformer<T, L> informer = new DefaultSharedIndexInformer<>(getType(), new ListerWatcher<T, L>() {
12111216
@Override
12121217
public L list(ListOptions params, String namespace, OperationContext context) {
1213-
return BaseOperation.this.list();
1218+
return baseOperation.list(params);
12141219
}
12151220

12161221
@Override
12171222
public Watch watch(ListOptions params, String namespace, OperationContext context, Watcher<T> watcher) {
1218-
return BaseOperation.this.watch(params, watcher);
1223+
return baseOperation.watch(params, watcher);
12191224
}
12201225
}, resync, context, Runnable::run); // just run the event notification in the websocket thread
12211226
if (handler != null) {
@@ -1224,6 +1229,7 @@ public Watch watch(ListOptions params, String namespace, OperationContext contex
12241229
if (indexers != null) {
12251230
informer.addIndexers(indexers);
12261231
}
1232+
// synchronous start list/watch must succeed in the calling thread
12271233
informer.run();
12281234
return informer;
12291235
}

kubernetes-tests/src/test/java/io/fabric8/kubernetes/client/mock/InformTest.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ void testInformPodWithLabel() throws InterruptedException {
5454
.withResourceVersion("1").endMetadata().build();
5555

5656
server.expect()
57-
.withPath("/api/v1/namespaces/test/pods?labelSelector=my-label")
57+
.withPath("/api/v1/namespaces/test/pods?watch=false&labelSelector=my-label")
5858
.andReturn(HttpURLConnection.HTTP_OK,
5959
new PodListBuilder().withNewMetadata().withResourceVersion("1").endMetadata().withItems(pod1).build())
6060
.once();
@@ -108,7 +108,7 @@ void testInformGeneric() throws InterruptedException {
108108
list.setItems(Arrays.asList(dummy));
109109

110110
server.expect()
111-
.withPath("/apis/demos.fabric8.io/v1/namespaces/test/dummies?labelSelector=my-label")
111+
.withPath("/apis/demos.fabric8.io/v1/namespaces/test/dummies?watch=false&labelSelector=my-label")
112112
.andReturn(HttpURLConnection.HTTP_OK, list)
113113
.once();
114114

@@ -151,7 +151,7 @@ public void onUpdate(GenericKubernetesResource oldObj, GenericKubernetesResource
151151
.build();
152152

153153
SharedIndexInformer<GenericKubernetesResource> informer =
154-
client.genericCustomResources(context).withLabel("my-label").inform(handler);
154+
client.genericKubernetesResources(context).withLabel("my-label").inform(handler);
155155

156156
assertTrue(deleteLatch.await(10, TimeUnit.SECONDS));
157157
assertTrue(addLatch.await(10, TimeUnit.SECONDS));
@@ -169,13 +169,13 @@ void testGenericWithKnownType() throws InterruptedException {
169169
.withResourceVersion("1").endMetadata().build();
170170

171171
server.expect()
172-
.withPath("/apis/demos.fabric8.io/v1/namespaces/test/dummies?labelSelector=my-label")
172+
.withPath("/api/v1/namespaces/test/pods?watch=false&fieldSelector=metadata.name%3Dpod1")
173173
.andReturn(HttpURLConnection.HTTP_OK,
174174
new PodListBuilder().withNewMetadata().withResourceVersion("1").endMetadata().withItems(pod1).build())
175175
.once();
176176

177177
server.expect()
178-
.withPath("/apis/demos.fabric8.io/v1/namespaces/test/dummies?labelSelector=my-label&resourceVersion=1&watch=true")
178+
.withPath("/api/v1/namespaces/test/pods?fieldSelector=metadata.name%3Dpod1%2Cmetadata.name%3Dpod1&resourceVersion=1&watch=true")
179179
.andUpgradeToWebSocket()
180180
.open()
181181
.waitFor(EVENT_WAIT_PERIOD_MS)
@@ -206,15 +206,14 @@ public void onUpdate(GenericKubernetesResource oldObj, GenericKubernetesResource
206206

207207
// When
208208
CustomResourceDefinitionContext context = new CustomResourceDefinitionContext.Builder()
209-
.withKind("Dummy")
209+
.withKind("Pod")
210210
.withScope("Namespaced")
211211
.withVersion("v1")
212-
.withGroup("demos.fabric8.io")
213-
.withPlural("dummies")
212+
.withPlural("pods")
214213
.build();
215214

216215
SharedIndexInformer<GenericKubernetesResource> informer =
217-
client.genericCustomResources(context).withLabel("my-label").inform(handler);
216+
client.genericKubernetesResources(context).withName("pod1").inform(handler);
218217

219218
assertTrue(deleteLatch.await(1000, TimeUnit.SECONDS));
220219
assertTrue(addLatch.await(1000, TimeUnit.SECONDS));

0 commit comments

Comments
 (0)