Skip to content

Commit cc3d0cc

Browse files
authored
docs: new structure of docs (#2737)
1 parent 0dc0f6a commit cc3d0cc

File tree

27 files changed

+974
-1203
lines changed

27 files changed

+974
-1203
lines changed

Diff for: docs/content/en/blog/_index.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: Blog
3-
menu: {main: {weight: 30}}
3+
menu: {main: {weight: 2}}
44
---
55

66
This is the **blog** section. It has two categories: News and Releases.

Diff for: docs/content/en/blog/news/_index.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
---
22
title: Posts
3-
weight: 20
3+
weight: 220
44
---

Diff for: docs/content/en/blog/releases/_index.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
---
22
title: Releases
3-
weight: 20
3+
weight: 230
44
---

Diff for: docs/content/en/community/_index.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: Community
3-
menu: {main: {weight: 40}}
3+
menu: {main: {weight: 3}}
44
---
55

66
<!--add blocks of content here to add more sections to the community page -->

Diff for: docs/content/en/docs/_index.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
---
22
title: Documentation
33
linkTitle: Docs
4-
menu: {main: {weight: 20}}
5-
weight: 20
4+
menu: {main: {weight: 1}}
5+
weight: 1
66
---
77

88

Diff for: docs/content/en/docs/contributing/_index.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: Contributing To Java Operator SDK
3-
weight: 100
3+
weight: 110
44
---
55

66
First of all, we'd like to thank you for considering contributing to the project! We really

Diff for: docs/content/en/docs/documentation/_index.md

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
title: Documentation
3+
weight: 40
4+
---

Diff for: docs/content/en/docs/architecture/_index.md renamed to docs/content/en/docs/documentation/architecture.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
---
22
title: Architecture and Internals
3-
weight: 90
3+
weight: 85
44
---
55

6-
76
This document gives an overview of the internal structure and components of Java Operator SDK core,
87
in order to make it easier for developers to understand and contribute to it. This document is
98
not intended to be a comprehensive reference, rather an introduction to the core concepts and we

Diff for: docs/content/en/docs/configuration/_index.md renamed to docs/content/en/docs/documentation/configuration.md

+65-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
---
2-
title: Configuring JOSDK
3-
layout: docs
4-
permalink: /docs/configuration
2+
title: Configurations
3+
weight: 55
54
---
65

7-
# Configuration options
8-
96
The Java Operator SDK (JOSDK) provides several abstractions that work great out of the
107
box. However, while we strive to cover the most common cases with the default behavior, we also
118
recognize that that default behavior is not always what any given user might want for their
@@ -52,6 +49,68 @@ operator.register(reconciler, configOverrider ->
5249
configOverrider.withFinalizer("my-nifty-operator/finalizer").withLabelSelector("foo=bar"));
5350
```
5451

52+
## Dynamically Changing Target Namespaces
53+
54+
A controller can be configured to watch a specific set of namespaces in addition of the
55+
namespace in which it is currently deployed or the whole cluster. The framework supports
56+
dynamically changing the list of these namespaces while the operator is running.
57+
When a reconciler is registered, an instance of
58+
[`RegisteredController`](https://github.com/java-operator-sdk/java-operator-sdk/blob/ec37025a15046d8f409c77616110024bf32c3416/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/RegisteredController.java#L5)
59+
is returned, providing access to the methods allowing users to change watched namespaces as the
60+
operator is running.
61+
62+
A typical scenario would probably involve extracting the list of target namespaces from a
63+
`ConfigMap` or some other input but this part is out of the scope of the framework since this is
64+
use-case specific. For example, reacting to changes to a `ConfigMap` would probably involve
65+
registering an associated `Informer` and then calling the `changeNamespaces` method on
66+
`RegisteredController`.
67+
68+
```java
69+
70+
public static void main(String[] args) {
71+
KubernetesClient client = new DefaultKubernetesClient();
72+
Operator operator = new Operator(client);
73+
RegisteredController registeredController = operator.register(new WebPageReconciler(client));
74+
operator.installShutdownHook();
75+
operator.start();
76+
77+
// call registeredController further while operator is running
78+
}
79+
80+
```
81+
82+
If watched namespaces change for a controller, it might be desirable to propagate these changes to
83+
`InformerEventSources` associated with the controller. In order to express this,
84+
`InformerEventSource` implementations interested in following such changes need to be
85+
configured appropriately so that the `followControllerNamespaceChanges` method returns `true`:
86+
87+
```java
88+
89+
@ControllerConfiguration
90+
public class MyReconciler implements Reconciler<TestCustomResource> {
91+
92+
@Override
93+
public Map<String, EventSource> prepareEventSources(
94+
EventSourceContext<ChangeNamespaceTestCustomResource> context) {
95+
96+
InformerEventSource<ConfigMap, TestCustomResource> configMapES =
97+
new InformerEventSource<>(InformerEventSourceConfiguration.from(ConfigMap.class, TestCustomResource.class)
98+
.withNamespacesInheritedFromController(context)
99+
.build(), context);
100+
101+
return EventSourceUtils.nameEventSources(configMapES);
102+
}
103+
104+
}
105+
```
106+
107+
As seen in the above code snippet, the informer will have the initial namespaces inherited from
108+
controller, but also will adjust the target namespaces if it changes for the controller.
109+
110+
See also
111+
the [integration test](https://github.com/operator-framework/java-operator-sdk/tree/main/operator-framework/src/test/java/io/javaoperatorsdk/operator/baseapi/changenamespace)
112+
for this feature.
113+
55114
## DependentResource-level configuration
56115

57116
`DependentResource` implementations can implement the `DependentResourceConfigurator` interface
@@ -61,7 +120,7 @@ provides specific support for the `KubernetesDependentResource`, which can be co
61120
`KubernetesDependentResourceConfig` instance, which is then passed to the `configureWith` method
62121
implementation.
63122

64-
TODO: still subject to change / uniformization
123+
TODO
65124

66125
## EventSource-level configuration
67126

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
title: Dependent resources and workflows
3+
weight: 70
4+
---
5+
6+
Dependent resources and workflows are features sometimes referenced as higher
7+
level abstractions. These two related concepts provides an abstraction
8+
over reconciliation of a single resource (Dependent resource) and the
9+
orchestration of such resources (Workflows).

Diff for: docs/content/en/docs/dependent-resources/_index.md renamed to docs/content/en/docs/documentation/dependent-resource-and-workflows/dependent-resources.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
2-
title: Dependent Resources
3-
weight: 60
2+
title: Dependent resources
3+
weight: 75
44
---
55

66
## Motivations and Goals

Diff for: docs/content/en/docs/workflows/_index.md renamed to docs/content/en/docs/documentation/dependent-resource-and-workflows/workflows.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: Workflows
3-
weight: 70
3+
weight: 80
44
---
55

66
## Overview
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
---
2+
title: Error handling and retries
3+
weight: 46
4+
---
5+
6+
## Automatic Retries on Error
7+
8+
JOSDK will schedule an automatic retry of the reconciliation whenever an exception is thrown by
9+
your `Reconciler`. The retry is behavior is configurable but a default implementation is provided
10+
covering most of the typical use-cases, see
11+
[GenericRetry](https://github.com/java-operator-sdk/java-operator-sdk/blob/master/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/retry/GenericRetry.java)
12+
.
13+
14+
```java
15+
GenericRetry.defaultLimitedExponentialRetry()
16+
.setInitialInterval(5000)
17+
.setIntervalMultiplier(1.5D)
18+
.setMaxAttempts(5);
19+
```
20+
21+
You can also configure the default retry behavior using the `@GradualRetry` annotation.
22+
23+
It is possible to provide a custom implementation using the `retry` field of the
24+
`@ControllerConfiguration` annotation and specifying the class of your custom implementation.
25+
Note that this class will need to provide an accessible no-arg constructor for automated
26+
instantiation. Additionally, your implementation can be automatically configured from an
27+
annotation that you can provide by having your `Retry` implementation implement the
28+
`AnnotationConfigurable` interface, parameterized with your annotation type. See the
29+
`GenericRetry` implementation for more details.
30+
31+
Information about the current retry state is accessible from
32+
the [Context](https://github.com/java-operator-sdk/java-operator-sdk/blob/master/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/Context.java)
33+
object. Of note, particularly interesting is the `isLastAttempt` method, which could allow your
34+
`Reconciler` to implement a different behavior based on this status, by setting an error message
35+
in your resource' status, for example, when attempting a last retry.
36+
37+
Note, though, that reaching the retry limit won't prevent new events to be processed. New
38+
reconciliations will happen for new events as usual. However, if an error also occurs that
39+
would normally trigger a retry, the SDK won't schedule one at this point since the retry limit
40+
is already reached.
41+
42+
A successful execution resets the retry state.
43+
44+
### Setting Error Status After Last Retry Attempt
45+
46+
In order to facilitate error reporting, `Reconciler` can implement the
47+
[ErrorStatusHandler](https://github.com/java-operator-sdk/java-operator-sdk/blob/main/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/ErrorStatusHandler.java)
48+
interface:
49+
50+
```java
51+
public interface ErrorStatusHandler<P extends HasMetadata> {
52+
53+
ErrorStatusUpdateControl<P> updateErrorStatus(P resource, Context<P> context, Exception e);
54+
55+
}
56+
```
57+
58+
The `updateErrorStatus` method is called in case an exception is thrown from the `Reconciler`. It is
59+
also called even if no retry policy is configured, just after the reconciler execution.
60+
`RetryInfo.getAttemptCount()` is zero after the first reconciliation attempt, since it is not a
61+
result of a retry (regardless of whether a retry policy is configured or not).
62+
63+
`ErrorStatusUpdateControl` is used to tell the SDK what to do and how to perform the status
64+
update on the primary resource, always performed as a status sub-resource request. Note that
65+
this update request will also produce an event, and will result in a reconciliation if the
66+
controller is not generation aware.
67+
68+
This feature is only available for the `reconcile` method of the `Reconciler` interface, since
69+
there should not be updates to resource that have been marked for deletion.
70+
71+
Retry can be skipped in cases of unrecoverable errors:
72+
73+
```java
74+
ErrorStatusUpdateControl.patchStatus(customResource).withNoRetry();
75+
```
76+
77+
### Correctness and Automatic Retries
78+
79+
While it is possible to deactivate automatic retries, this is not desirable, unless for very
80+
specific reasons. Errors naturally occur, whether it be transient network errors or conflicts
81+
when a given resource is handled by a `Reconciler` but is modified at the same time by a user in
82+
a different process. Automatic retries handle these cases nicely and will usually result in a
83+
successful reconciliation.
84+
85+
## Retry and Rescheduling and Event Handling Common Behavior
86+
87+
Retry, reschedule and standard event processing form a relatively complex system, each of these
88+
functionalities interacting with the others. In the following, we describe the interplay of
89+
these features:
90+
91+
1. A successful execution resets a retry and the rescheduled executions which were present before
92+
the reconciliation. However, a new rescheduling can be instructed from the reconciliation
93+
outcome (`UpdateControl` or `DeleteControl`).
94+
95+
For example, if a reconciliation had previously been re-scheduled after some amount of time, but an event triggered
96+
the reconciliation (or cleanup) in the mean time, the scheduled execution would be automatically cancelled, i.e.
97+
re-scheduling a reconciliation does not guarantee that one will occur exactly at that time, it simply guarantees that
98+
one reconciliation will occur at that time at the latest, triggering one if no event from the cluster triggered one.
99+
Of course, it's always possible to re-schedule a new reconciliation at the end of that "automatic" reconciliation.
100+
101+
Similarly, if a retry was scheduled, any event from the cluster triggering a successful execution in the mean time
102+
would cancel the scheduled retry (because there's now no point in retrying something that already succeeded)
103+
104+
2. In case an exception happened, a retry is initiated. However, if an event is received
105+
meanwhile, it will be reconciled instantly, and this execution won't count as a retry attempt.
106+
3. If the retry limit is reached (so no more automatic retry would happen), but a new event
107+
received, the reconciliation will still happen, but won't reset the retry, and will still be
108+
marked as the last attempt in the retry info. The point (1) still holds, but in case of an
109+
error, no retry will happen.
110+
111+
The thing to keep in mind when it comes to retrying or rescheduling is that JOSDK tries to avoid unnecessary work. When
112+
you reschedule an operation, you instruct JOSDK to perform that operation at the latest by the end of the rescheduling
113+
delay. If something occurred on the cluster that triggers that particular operation (reconciliation or cleanup), then
114+
JOSDK considers that there's no point in attempting that operation again at the end of the specified delay since there
115+
is now no point to do so anymore. The same idea also applies to retries.

0 commit comments

Comments
 (0)