-
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
docs: operations section #3282
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| --- | ||
| title: Operations | ||
| weight: 85 | ||
| --- | ||
|
|
||
| This section covers operations-related features for running and managing operators in production. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,116 @@ | ||
| --- | ||
| title: Generic Helm Chart | ||
| weight: 86 | ||
| --- | ||
|
|
||
| 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 | ||
csviri marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 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 | ||
| ``` | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| --- | ||
| title: Logging | ||
| weight: 88 | ||
| --- | ||
|
|
||
| ## 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` | | ||
|
Comment on lines
+12
to
+20
|
||
|
|
||
| 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 | ||
csviri marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 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. | ||
Uh oh!
There was an error while loading. Please reload this page.