|
| 1 | +# Log rotation for managed Windows services |
| 2 | + |
| 3 | +Log rotation for managed Windows services is available for WMCO 10.22+. This feature rotates log files based |
| 4 | +on configurable size and age thresholds and is configured via environment variables in the operator. |
| 5 | + |
| 6 | +## Enabling log rotation for managed Windows services |
| 7 | + |
| 8 | +To enable and customize the log rotation behavior, add the following environment variables to the subscription (OLMv0). |
| 9 | +The operator will restart to load the newly added environment variables and apply log rotation to the |
| 10 | +managed services. This will result in a reconfiguration of the existing Windows nodes, one at a time, until all |
| 11 | +nodes have been handled, to minimize disruption. |
| 12 | + |
| 13 | +### Setting environment variables in the subscription: |
| 14 | +```yaml |
| 15 | +kind: Subscription |
| 16 | +spec: |
| 17 | + config: |
| 18 | + env: |
| 19 | + - name: SERVICES_LOG_FILE_SIZE |
| 20 | + value: "100M" # Rotate when log reaches this size (suggested: 100M) |
| 21 | + - name: SERVICES_LOG_FILE_AGE |
| 22 | + value: "168h" # Keep rotated logs for this duration (e.g: 168h/7 days) |
| 23 | + - name: SERVICES_LOG_FLUSH_INTERVAL |
| 24 | + value: "5s" # Flush logs to disk at this interval (suggested: 5s) |
| 25 | +``` |
| 26 | +
|
| 27 | +### Patching the subscription using the CLI: |
| 28 | +```shell script |
| 29 | +oc patch subscription <subscription_name> -n <namespace_name> \ |
| 30 | + --type=merge \ |
| 31 | + -p '{"spec":{"config":{"env":[{"name":"SERVICES_LOG_FILE_SIZE","value":"100M"},{"name":"SERVICES_LOG_FILE_AGE","value":"168h"},{"name":"SERVICES_LOG_FLUSH_INTERVAL","value":"5s"}]}}}' |
| 32 | +``` |
| 33 | + |
| 34 | +### Patching the operator deployment using the CLI (OLMv1 or manual installs): |
| 35 | + |
| 36 | +```shell script |
| 37 | + oc set env deployment/windows-machine-config-operator -n <namespace_name> -c manager \ |
| 38 | + SERVICES_LOG_FILE_SIZE="100M" \ |
| 39 | + SERVICES_LOG_FILE_AGE="168h" \ |
| 40 | + SERVICES_LOG_FLUSH_INTERVAL="5s" |
| 41 | +``` |
| 42 | +where: |
| 43 | +- `<namespace_name>`: The namespace where the operator is installed (e.g., `openshift-windows-machine-config-operator`) |
| 44 | +- `<subscription_name>`: The name of the subscription used to install the operator (e.g., `windows-machine-config-operator-subscription`) |
| 45 | + |
| 46 | +## Disabling log rotation for managed Windows services |
| 47 | + |
| 48 | +To disable log rotation, remove the `SERVICES_LOG_FILE_SIZE`, `SERVICES_LOG_FILE_AGE`, and `SERVICES_LOG_FLUSH_INTERVAL` |
| 49 | +environment variables from the subscription or operator deployment. |
| 50 | + |
| 51 | +## Behavior when log rotation settings change |
| 52 | + |
| 53 | +**Effect on existing log files:** When rotation settings are changed (enabled, disabled, or updated), any previously |
| 54 | +rotated log files are retained according to the `SERVICES_LOG_FILE_AGE` value that was in effect when they were |
| 55 | +created. Once that retention period expires, the files are cleaned up automatically. New log files and any future |
| 56 | +rotated files will follow the updated rotation rules going forward. |
| 57 | + |
| 58 | +**Operator and node behavior:** Any change to the `SERVICES_LOG_FILE_SIZE`, `SERVICES_LOG_FILE_AGE`, or |
| 59 | +`SERVICES_LOG_FLUSH_INTERVAL` environment variables—whether in the subscription (OLMv0) or the operator deployment |
| 60 | +(OLMv1 / manual installs)—will cause the operator to restart in order to load the updated configuration. After |
| 61 | +restarting, the operator will reconfigure each Windows node one at a time to apply the new log rotation settings, |
| 62 | +minimizing disruption. Note that service continuity during reconfiguration is not guaranteed; brief interruptions |
| 63 | +to managed services (such as kubelet or kube-proxy) may occur on each node as it is reconfigured. |
0 commit comments