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

Doc: Update docs in places where POJOs are required. #2369

Merged
merged 1 commit into from Jul 29, 2020
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
6 changes: 4 additions & 2 deletions CHANGELOG.md
Expand Up @@ -5,10 +5,12 @@
* Fix #2316: Cannot load resource from stream without apiVersion

#### Improvements
* Fix #2331: Fixed documentation for namespaced informer for all custom types implementing `Namespaced` interface

#### Dependency Upgrade
* Fix #2355: bump jandex from 2.1.3.Final to 2.2.0.Final
* Fix #2353: bump workflow action-setup- versions + kubernetes to 1.18.6
* Fix #2360: bump mockito-core from 3.4.0 to 3.4.2
* Fix #2355: bump jandex from 2.1.3.Final to 2.2.0.Final
* Fix #2353: chore: bump workflow action-setup versions + kubernetes to 1.18.6

#### New Features
* Fix #2287: Add support for V1 and V1Beta1 CustomResourceDefinition
Expand Down
56 changes: 47 additions & 9 deletions doc/CHEATSHEET.md
Expand Up @@ -1706,6 +1706,8 @@ spec:
image: my-awesome-cron-image
```
For a CustomResource like this one, we should have a `CronTab` java class like this:

**Note:** Please make sure that your CustomResource POJO is implementing `Namespaced` interface if it's a namespaced resource. Otherwise it would be considered a Cluster scoped resource.
```
/**
* Copyright (C) 2015 Red Hat, Inc.
Expand Down Expand Up @@ -1907,7 +1909,7 @@ Kubernetes Client also provides `SharedInformer` support in order to stay update
```
SharedInformerFactory sharedInformerFactory = client.informers();
```
- Create `SharedIndexInformer` for some Kubernetes Resource(requires resource's class, resource's list class, and resync period(when to check with server again while watching something):
- Create `SharedIndexInformer` for some Kubernetes Resource(requires resource's class, resource's list class, and resync period(when to check with server again while watching something). By default it watches in all namespaces.:
```
SharedIndexInformer<Pod> podInformer = sharedInformerFactory.sharedIndexInformerFor(Pod.class, PodList.class, 30 * 1000L);
podInformer.addEventHandler(new ResourceEventHandler<Pod>() {
Expand All @@ -1927,26 +1929,31 @@ podInformer.addEventHandler(new ResourceEventHandler<Pod>() {
}
});
```
- Create `SharedIndexInformer` for some Custom Resource(in our case, `Dummy` resource provided in our [examples](https://github.com/fabric8io/kubernetes-client/tree/master/kubernetes-examples/src/main/java/io/fabric8/kubernetes/examples/crds):
- Create `SharedIndexInformer` for some Custom Resource(in our case, `Dummy` resource provided in our [examples](https://github.com/fabric8io/kubernetes-client/tree/master/kubernetes-examples/src/main/java/io/fabric8/kubernetes/examples/crds) . By default it watches in all namespaces.
```
CustomResourceDefinitionContext crdContext = new CustomResourceDefinitionContext.Builder()
.withVersion("v1")
.withScope("Namespaced")
.withGroup("demo.fabric8.io")
.withPlural("dummies")
.build();
SharedIndexInformer<Dummy> dummyInformer = sharedInformerFactory.sharedIndexInformerForCustomResource(crdContext, Dummy.class, DummyList.class, 1 * 60 * 1000);
dummyInformer.addEventHandler(new ResourceEventHandler<Dummy>() {
@Override
public void onAdd(Dummy pod) {
System.out.printf("%s dummy added\n", pod.getMetadata().getName());
public void onAdd(Dummy dummy) {
System.out.printf("%s dummy added\n", dummy.getMetadata().getName());
}

@Override
public void onUpdate(Dummy oldPod, Dummy newPod) {
System.out.printf("%s dummy updated\n", oldPod.getMetadata().getName());
public void onUpdate(Dummy oldDummy, Dummy newDummy) {
System.out.printf("%s dummy updated\n", oldDummy.getMetadata().getName());
}

@Override
public void onDelete(Dummy pod, boolean deletedFinalStateUnknown) {
System.out.printf("%s dummy deleted \n", pod.getMetadata().getName());
public void onDelete(Dummy dummy, boolean deletedFinalStateUnknown) {
System.out.printf("%s dummy deleted \n", dummy.getMetadata().getName());
}
});

```
- Create namespaced `SharedIndexInformer` (informers specific to a particular `Namespace`):
```
Expand Down Expand Up @@ -1975,6 +1982,37 @@ podInformer.addEventHandler(new ResourceEventHandler<Pod>() {
}
});
```
- Create Namespaced Informer for a Custom Resource(**Note:** Your CustomResource POJO must implement `Namespaced` interface like the one used in this example: [Dummy.java](https://github.com/fabric8io/kubernetes-client/blob/master/kubernetes-examples/src/main/java/io/fabric8/kubernetes/examples/crds/Dummy.java))
```
CustomResourceDefinitionContext crdContext = new CustomResourceDefinitionContext.Builder()
.withVersion("v1")
.withScope("Namespaced")
.withGroup("demo.fabric8.io")
.withPlural("dummies")
.build();
SharedIndexInformer<Dummy> dummyInformer = sharedInformerFactory.sharedIndexInformerForCustomResource(crdContext,
Dummy.class,
DummyList.class,
new OperationContext().withNamespace("default"), // Namespace to watch
1 * 60 * 1000);
dummyInformer.addEventHandler(new ResourceEventHandler<Dummy>() {
@Override
public void onAdd(Dummy dummy) {
System.out.printf("%s dummy added\n", dummy.getMetadata().getName());
}

@Override
public void onUpdate(Dummy oldDummy, Dummy newDummy) {
System.out.printf("%s dummy updated\n", oldDummy.getMetadata().getName());
}

@Override
public void onDelete(Dummy dummy, boolean deletedFinalStateUnknown) {
System.out.printf("%s dummy deleted \n", dummy.getMetadata().getName());
}
});
```

- Start all registered informers:
```
sharedInformerFactory.startAllRegisteredInformers();
Expand Down
Expand Up @@ -81,8 +81,8 @@ public SharedInformerFactory(ExecutorService threadPool, OkHttpClient okHttpClie
* @param apiTypeClass apiType class
* @param apiListTypeClass api list type class
* @param resyncPeriodInMillis resync period in milliseconds
* @param <T> the type parameter
* @param <L> the type's list parameter
* @param <T> the type parameter (should extend {@link io.fabric8.kubernetes.api.model.HasMetadata} and implement {@link io.fabric8.kubernetes.api.model.Namespaced})
* @param <L> the type's list parameter (should extend {@link io.fabric8.kubernetes.api.model.KubernetesResourceList}
* @return the shared index informer
*/
public synchronized <T extends HasMetadata, L extends KubernetesResourceList<T>> SharedIndexInformer<T> sharedIndexInformerFor(Class<T> apiTypeClass, Class<L> apiListTypeClass, long resyncPeriodInMillis) {
Expand All @@ -98,8 +98,8 @@ public synchronized <T extends HasMetadata, L extends KubernetesResourceList<T>>
* @param apiTypeClass apiType class
* @param apiListTypeClass api list type class
* @param resyncPeriodInMillis resync period in milliseconds
* @param <T> the type parameter
* @param <L> the type's list parameter
* @param <T> the type parameter (should extend {@link io.fabric8.kubernetes.api.model.HasMetadata} and implement {@link io.fabric8.kubernetes.api.model.Namespaced})
* @param <L> the type's list parameter (should extend {@link io.fabric8.kubernetes.api.model.KubernetesResourceList}
* @return the shared index informer
*/
public synchronized <T extends HasMetadata, L extends KubernetesResourceList<T>> SharedIndexInformer<T> sharedIndexInformerForCustomResource(CustomResourceDefinitionContext customResourceContext, Class<T> apiTypeClass, Class<L> apiListTypeClass, long resyncPeriodInMillis) {
Expand All @@ -116,8 +116,8 @@ public synchronized <T extends HasMetadata, L extends KubernetesResourceList<T>>
* @param apiListTypeClass api list type class
* @param operationContext operation context
* @param resyncPeriodInMillis resync period in milliseconds
* @param <T> the type parameter
* @param <L> the type's list parameter
* @param <T> the type parameter (should extend {@link io.fabric8.kubernetes.api.model.HasMetadata} and implement {@link io.fabric8.kubernetes.api.model.Namespaced})
* @param <L> the type's list parameter (should extend {@link io.fabric8.kubernetes.api.model.KubernetesResourceList}
* @return the shared index informer
*/
public synchronized <T extends HasMetadata, L extends KubernetesResourceList<T>> SharedIndexInformer<T> sharedIndexInformerForCustomResource(CustomResourceDefinitionContext customResourceContext, Class<T> apiTypeClass, Class<L> apiListTypeClass, OperationContext operationContext, long resyncPeriodInMillis) {
Expand All @@ -135,8 +135,8 @@ public synchronized <T extends HasMetadata, L extends KubernetesResourceList<T>>
* @param apiListTypeClass api list type class
* @param operationContext operation context
* @param resyncPeriodInMillis resync period in milliseconds
* @param <T> the type parameter
* @param <L> the type's list parameter
* @param <T> the type parameter (should extend {@link io.fabric8.kubernetes.api.model.HasMetadata} and implement {@link io.fabric8.kubernetes.api.model.Namespaced})
* @param <L> the type's list parameter (should extend {@link io.fabric8.kubernetes.api.model.KubernetesResourceList}
* @return the shared index informer
*/
public synchronized <T extends HasMetadata, L extends KubernetesResourceList<T>> SharedIndexInformer<T> sharedIndexInformerFor(Class<T> apiTypeClass, Class<L> apiListTypeClass, OperationContext operationContext, long resyncPeriodInMillis) {
Expand Down