-
Notifications
You must be signed in to change notification settings - Fork 236
docs: operations section #3282
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
Merged
Merged
docs: operations section #3282
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
docs/content/en/docs/documentation/dependent-resource-and-workflows/_index.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| --- | ||
| title: Operations | ||
| weight: 70 | ||
| --- | ||
|
|
||
| This section covers operations-related features for running and managing operators in production. |
2 changes: 1 addition & 1 deletion
2
...nt/en/docs/documentation/configuration.md → ...documentation/operations/configuration.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
116 changes: 116 additions & 0 deletions
116
docs/content/en/docs/documentation/operations/helm-chart.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,116 @@ | ||
| --- | ||
| title: Generic Helm Chart | ||
| weight: 76 | ||
| --- | ||
|
|
||
| A generic, reusable Helm chart for deploying Java operators built with JOSDK is available at | ||
| [`helm/generic-helm-chart`](https://github.com/java-operator-sdk/java-operator-sdk/tree/main/helm/generic-helm-chart). | ||
|
|
||
| It is intended as a **template for operator developers** — a starting point that covers common deployment | ||
| patterns so you don't have to write a chart from scratch. The chart is maintained on a **best-effort basis**. | ||
| Contributions are more than welcome. | ||
|
|
||
| The chart is used in the | ||
| [`metrics-processing` sample operator E2E test](https://github.com/java-operator-sdk/java-operator-sdk/blob/main/sample-operators/metrics-processing/src/test/java/io/javaoperatorsdk/operator/sample/metrics/MetricsHandlingE2E.java) | ||
| to deploy the operator to a cluster via Helm. | ||
|
|
||
| ## What the Chart Provides | ||
|
|
||
| - **Deployment** with security defaults (non-root user, read-only filesystem, no privilege escalation) | ||
| - **Dynamic RBAC** (ClusterRole, ClusterRoleBinding, ServiceAccount) — permissions are generated automatically | ||
| from the primary and secondary resources you declare in `values.yaml` | ||
| - **ConfigMap** for operator configuration (`config.yaml`) and logging (`log4j2.xml`), mounted at `/config` | ||
| - **Leader election** support (opt-in) | ||
| - **Extensibility** via extra containers, init containers, volumes, and environment variables | ||
|
|
||
| ## Key Configuration | ||
|
|
||
| The most important values to set when adapting the chart for your operator: | ||
|
|
||
| ```yaml | ||
| image: | ||
| repository: my-operator-image # required | ||
| tag: "latest" | ||
|
|
||
| # Custom resources your operator reconciles | ||
| primaryResources: | ||
| - apiGroup: "sample.javaoperatorsdk" | ||
| resources: | ||
| - myresources | ||
|
|
||
| # Kubernetes resources your operator manages | ||
| secondaryResources: | ||
| - apiGroup: "" | ||
| resources: | ||
| - configmaps | ||
| - services | ||
| ``` | ||
|
|
||
| Primary resources get read/watch/patch permissions and status sub-resource access. | ||
| Secondary resources get full CRUD permissions. Default verbs can be overridden per resource entry. | ||
|
|
||
| ### Operator Environment | ||
|
|
||
| The chart injects `OPERATOR_NAMESPACE` automatically. You can optionally set `WATCH_NAMESPACE` to | ||
| restrict the operator to a single namespace, and add arbitrary environment variables: | ||
|
|
||
| ```yaml | ||
| operator: | ||
| watchNamespace: "" # empty = all namespaces | ||
| env: | ||
| - name: MY_CUSTOM_VAR | ||
| value: "some-value" | ||
| ``` | ||
|
|
||
| ### Resource Defaults | ||
|
|
||
| ```yaml | ||
| resources: | ||
| limits: | ||
| cpu: 500m | ||
| memory: 512Mi | ||
| requests: | ||
| cpu: 100m | ||
| memory: 128Mi | ||
| ``` | ||
|
|
||
| See the full | ||
| [`values.yaml`](https://github.com/java-operator-sdk/java-operator-sdk/blob/main/helm/generic-helm-chart/values.yaml) | ||
| for all available options. | ||
|
|
||
| ## Usage Example | ||
|
|
||
| A working example of how to use the chart can be found in the metrics-processing sample operator's | ||
| [`helm-values.yaml`](https://github.com/java-operator-sdk/java-operator-sdk/blob/main/sample-operators/metrics-processing/src/test/resources/helm-values.yaml): | ||
|
|
||
| ```yaml | ||
| image: | ||
| repository: metrics-processing-operator | ||
| pullPolicy: Never | ||
| tag: "latest" | ||
|
|
||
| nameOverride: "metrics-processing-operator" | ||
|
|
||
| resources: {} | ||
|
|
||
| primaryResources: | ||
| - apiGroup: "sample.javaoperatorsdk" | ||
| resources: | ||
| - metricshandlingcustomresource1s | ||
| - metricshandlingcustomresource2s | ||
| ``` | ||
|
|
||
| Install with: | ||
|
|
||
| ```shell | ||
| helm install my-operator ./helm/generic-helm-chart -f my-values.yaml --namespace my-ns | ||
| ``` | ||
|
|
||
| ## Testing the Chart | ||
|
|
||
| The chart includes unit tests using the [helm-unittest](https://github.com/helm-unittest/helm-unittest) plugin. | ||
| Run them with: | ||
|
|
||
| ```shell | ||
| ./helm/run-tests.sh | ||
| ``` |
72 changes: 72 additions & 0 deletions
72
docs/content/en/docs/documentation/operations/leader-election.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| --- | ||
| title: Leader Election | ||
| weight: 74 | ||
| --- | ||
|
|
||
| When running multiple replicas of an operator for high availability, leader election ensures that | ||
| only one instance actively reconciles resources at a time. JOSDK uses Kubernetes | ||
| [Lease](https://kubernetes.io/docs/concepts/architecture/leases/) objects for leader election. | ||
|
|
||
| ## Enabling Leader Election | ||
|
|
||
| ### Programmatic Configuration | ||
|
|
||
| ```java | ||
| var operator = new Operator(o -> o.withLeaderElectionConfiguration( | ||
| new LeaderElectionConfiguration("my-operator-lease", "operator-namespace"))); | ||
| ``` | ||
|
|
||
| Or using the builder for full control: | ||
|
|
||
| ```java | ||
| import static io.javaoperatorsdk.operator.api.config.LeaderElectionConfigurationBuilder.aLeaderElectionConfiguration; | ||
|
|
||
| var config = aLeaderElectionConfiguration("my-operator-lease") | ||
| .withLeaseNamespace("operator-namespace") | ||
| .withIdentity(System.getenv("POD_NAME")) | ||
| .withLeaseDuration(Duration.ofSeconds(15)) | ||
| .withRenewDeadline(Duration.ofSeconds(10)) | ||
| .withRetryPeriod(Duration.ofSeconds(2)) | ||
| .build(); | ||
|
|
||
| var operator = new Operator(o -> o.withLeaderElectionConfiguration(config)); | ||
| ``` | ||
|
|
||
| ### External Configuration | ||
|
|
||
| Leader election can also be configured via properties (e.g. environment variables or a config file). | ||
|
|
||
| See details under [configurations](configuration.md) page. | ||
|
|
||
| ## How It Works | ||
|
|
||
| 1. When leader election is enabled, the operator starts but **does not process events** until it acquires | ||
| the lease. | ||
| 2. Once leadership is acquired, event processing begins normally. | ||
| 3. If leadership is lost (e.g. the leader pod becomes unresponsive), another instance acquires the lease | ||
| and takes over reconciliation. The instance that lost the lead is terminated (`System.exit()`) | ||
|
|
||
| ### Identity and Namespace Inference | ||
|
|
||
| If not explicitly set: | ||
| - **Identity** is resolved from the `HOSTNAME` environment variable, then the pod name, falling back to a | ||
| random UUID. | ||
| - **Lease namespace** defaults to the namespace the operator pod is running in. | ||
|
|
||
| ## RBAC Requirements | ||
|
|
||
| The operator's service account needs permissions to manage Lease objects: | ||
|
|
||
| ```yaml | ||
| - apiGroups: ["coordination.k8s.io"] | ||
| resources: ["leases"] | ||
| verbs: ["create", "update", "get"] | ||
| ``` | ||
|
|
||
| JOSDK checks for these permissions at startup and throws a clear error if they are missing. | ||
|
|
||
| ## Sample E2E Test | ||
|
|
||
| A complete working example is available in the | ||
| [`leader-election` sample operator](https://github.com/java-operator-sdk/java-operator-sdk/tree/main/sample-operators/leader-election), | ||
| including multi-replica deployment manifests and an E2E test that verifies failover behavior. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| --- | ||
| title: Logging | ||
| weight: 72 | ||
| --- | ||
|
|
||
| ## Contextual Info for Logging with MDC | ||
|
|
||
| Logging is enhanced with additional contextual information using | ||
| [MDC](http://www.slf4j.org/manual.html#mdc). The following attributes are available in most | ||
| parts of reconciliation logic and during the execution of the controller: | ||
|
|
||
| | MDC Key | Value added from primary resource | | ||
| |:---------------------------|:----------------------------------| | ||
| | `resource.apiVersion` | `.apiVersion` | | ||
| | `resource.kind` | `.kind` | | ||
| | `resource.name` | `.metadata.name` | | ||
| | `resource.namespace` | `.metadata.namespace` | | ||
| | `resource.resourceVersion` | `.metadata.resourceVersion` | | ||
| | `resource.generation` | `.metadata.generation` | | ||
| | `resource.uid` | `.metadata.uid` | | ||
|
|
||
| For more information about MDC see this [link](https://www.baeldung.com/mdc-in-log4j-2-logback). | ||
|
|
||
| ### MDC entries during event handling | ||
|
|
||
| Although, usually users might not require it in their day-to-day workflow, it is worth mentioning that | ||
| there are additional MDC entries managed for event handling. Typically, you might be interested in it | ||
| in your `SecondaryToPrimaryMapper` related logs. | ||
| For `InformerEventSource` and `ControllerEventSource` the following information is present: | ||
|
|
||
| | MDC Key | Value from Resource from the Event | | ||
| |:-----------------------------------------------|:-------------------------------------------------| | ||
| | `eventsource.event.resource.name` | `.metadata.name` | | ||
| | `eventsource.event.resource.uid` | `.metadata.uid` | | ||
| | `eventsource.event.resource.namespace` | `.metadata.namespace` | | ||
| | `eventsource.event.resource.kind` | resource kind | | ||
| | `eventsource.event.resource.resourceVersion` | `.metadata.resourceVersion` | | ||
| | `eventsource.event.action` | action name (e.g. `ADDED`, `UPDATED`, `DELETED`) | | ||
| | `eventsource.name` | name of the event source | | ||
|
Comment on lines
+31
to
+39
|
||
|
|
||
| ### Note on null values | ||
|
|
||
| If a resource doesn't provide values for one of the specified keys, the key will be omitted and not added to the MDC | ||
| context. There is, however, one notable exception: the resource's namespace, where, instead of omitting the key, we emit | ||
| the `MDCUtils.NO_NAMESPACE` value instead. This allows searching for resources without namespace (notably, clustered | ||
| resources) in the logs more easily. | ||
|
|
||
| ### Disabling MDC support | ||
|
|
||
| MDC support is enabled by default. If you want to disable it, you can set the `JAVA_OPERATOR_SDK_USE_MDC` environment | ||
| variable to `false` when you start your operator. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| --- | ||
| title: FAQ | ||
| weight: 90 | ||
| weight: 100 | ||
| --- | ||
|
|
||
| ## Events and Reconciliation | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The table rows start with
||instead of a single|. Many Markdown renderers (and Hugo Markdown configurations) expect| ... | ... |and may not render this as a table. Use a single leading pipe per row (e.g.,| MDC Key | ... |) for consistent rendering.