Skip to content

Commit ebc3539

Browse files
authored
docs: finalizers and best braticies page (#647)
1 parent 767858d commit ebc3539

File tree

3 files changed

+89
-5
lines changed

3 files changed

+89
-5
lines changed

Diff for: docs/_data/sidebar.yml

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
url: /docs/using-samples
88
- title: Features
99
url: /docs/features
10+
- title: Patterns and Best Practices
11+
url: /docs/patterns-best-practices
1012
- title: FAQ
1113
url: /docs/faq
1214
- title: Contributing

Diff for: docs/documentation/features.md

+59-5
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,69 @@ layout: docs
55
permalink: /docs/features
66
---
77

8-
# Features
8+
# Features
99

10-
## Controller Registration
10+
Java Operator SDK is a high level framework and related tooling in order to facilitate implementation of Kubernetes
11+
operators. The features are by default following the best practices in an opinionated way. However, feature flags and
12+
other configuration options are provided to fine tune or turn off these features.
1113

12-
## Configurations
14+
## Controller Execution in a Nutshell
1315

14-
## Finalizers
16+
Controller execution is always triggered by an event. Events typically come from the custom resource
17+
(i.e. custom resource is created, updated or deleted) that the controller is watching, but also from different sources
18+
(see event sources). When an event is received reconciliation is executed, unless there is already a reconciliation
19+
happening for a particular custom resource. In other words it is guaranteed by the framework that no concurrent
20+
reconciliation happens for a custom resource.
1521

16-
### When not to Use Finalizers
22+
After a reconciliation (
23+
i.e. [ResourceController](https://github.com/java-operator-sdk/java-operator-sdk/blob/master/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/ResourceController.java)
24+
called), a post-processing phase follows, where typically framework checks if:
25+
26+
- an exception was thrown during execution, if yes schedules a retry.
27+
- there are new events received during the controller execution, if yes schedule the execution again.
28+
- there is an instruction to re-schedule the execution for the future, if yes schedule a timer event with the specified
29+
delay.
30+
- if none above, the reconciliation is finished.
31+
32+
Briefly, in the hearth of the execution is an eventing system, where events are the triggers of the reconciliation
33+
execution.
34+
35+
## Finalizer Support
36+
37+
[Kubernetes finalizers](https://kubernetes.io/docs/concepts/overview/working-with-objects/finalizers/)
38+
make sure that a reconciliation happens when a custom resource is instructed to be deleted. Typical case when it's
39+
useful, when an operator is down (pod not running). Without a finalizer the reconciliation - thus the cleanup
40+
i.e. [`ResourceController.deleteResource(...)`](https://github.com/java-operator-sdk/java-operator-sdk/blob/master/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/ResourceController.java)
41+
42+
- would not happen if a custom resource is deleted.
43+
44+
Finalizers are automatically added by the framework as the first step, thus when a custom resource is created, but
45+
before the first reconciliation, the custom resource is updated via a Kubernetes API call. As a result of this update, the
46+
finalizer will be present. The subsequent event will be received, which will trigger the first reconciliation.
47+
48+
The finalizer that is automatically added will be also removed after the `deleteResource` is executed on the controller.
49+
However, the removal behavior can be further customized, and can be instructed to "not remove yet" - this is useful just
50+
in some specific corner cases, when there would be a long waiting period for some dependent resource cleanup.
51+
52+
The name of the finalizers can be specified, in case it is not, a name will be generated.
53+
54+
This behavior can be turned off, so when configured no finalizer will be added or removed.
55+
See [`@Controller`](https://github.com/java-operator-sdk/java-operator-sdk/blob/master/operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/Controller.java)
56+
annotation for more details.
57+
58+
### When not to Use Finalizers?
59+
60+
Typically, automated finalizer handling should be turned off, when **all** the cleanup of the dependent resources is
61+
handled by Kubernetes itself. This is handled by
62+
Kubernetes [garbage collection](https://kubernetes.io/docs/concepts/architecture/garbage-collection/#owners-dependents).
63+
Setting the owner reference and related fields are not in the scope of the SDK for now, it's up to the user to have them
64+
configured properly when creating the objects.
65+
66+
When automatic finalizer handling is turned off, the `ResourceController.deleteResource(...)` method is not called, in
67+
case of a delete event received. So it does not make sense to implement this method and turn off finalizer at the same
68+
time.
69+
70+
## Separating `createOrUpdate` from `delete`
1771

1872
## Automatic Retries on Error
1973

Diff for: docs/documentation/patterns-best-practices.md

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
---
2+
title: Patterns and Best Practices
3+
description: Patterns and Best Practices Implementing a Controller
4+
layout: docs
5+
permalink: /docs/patterns-best-practices
6+
---
7+
8+
# Patterns and Best Practices
9+
10+
This document describes patters and best practices, to build and run operators, and how to implement them in terms
11+
of Java Operator SDK.
12+
13+
## Implementing a Controller
14+
15+
### Sync of Async Way of Resource Handling
16+
17+
### Idempotency
18+
19+
## Why to Have Automated Retries?
20+
21+
## Managing State
22+
23+
## Dependent Resources
24+
25+
### EventSources and Caching
26+
27+
### Why are Events Irrelevant?
28+

0 commit comments

Comments
 (0)