Skip to content

WINC-1859: Implement log file rotation for WICD#4177

Draft
jrvaldes wants to merge 2 commits into
openshift:masterfrom
jrvaldes:WINC-1859-wicd-logFileMaxSizeMB
Draft

WINC-1859: Implement log file rotation for WICD#4177
jrvaldes wants to merge 2 commits into
openshift:masterfrom
jrvaldes:WINC-1859-wicd-logFileMaxSizeMB

Conversation

@jrvaldes
Copy link
Copy Markdown
Contributor

@jrvaldes jrvaldes commented Jun 2, 2026

This pull request introduces a new CLI flag for maximum log file size and ensures log file size is consistently set for WICD service configuration, also refactors and centralizes the log configuration logic moving environment variable parsing and log runner command construction into a new dedicated logconfig package.

Summary by CodeRabbit

  • New Features

    • Added --log-file-max-size flag to controller daemon.
    • Added environment variable support for log file size, age, and flush interval configuration.
    • Windows daemon now supports log file size limits.
  • Refactor

    • Consolidated log configuration into dedicated module.
  • Tests

    • Added comprehensive test coverage for log configuration functionality.

jrvaldes added 2 commits June 2, 2026 14:48
this commit introduces a new package to load the configuration
for log files from environment and generalizes the previous implementation.
this commit introduces the logFileMaxSizeMb param in the
WICD controller to allow configuration for log file rotation
@openshift-ci-robot openshift-ci-robot added the jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. label Jun 2, 2026
@openshift-ci-robot
Copy link
Copy Markdown

openshift-ci-robot commented Jun 2, 2026

@jrvaldes: This pull request references WINC-1859 which is a valid jira issue.

Details

In response to this:

This pull request introduces a new CLI flag for maximum log file size and ensures log file size is consistently set for WICD service configuration, also refactors and centralizes the log configuration logic moving environment variable parsing and log runner command construction into a new dedicated logconfig package.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository.

@openshift-ci
Copy link
Copy Markdown
Contributor

openshift-ci Bot commented Jun 2, 2026

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@openshift-ci openshift-ci Bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jun 2, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jun 2, 2026

📝 Walkthrough

Walkthrough

This PR consolidates log file configuration management across the Windows Machine Config Operator by extracting a duplicated initialization pattern from pkg/services into a new shared pkg/logconfig package. The logconfig package parses log configuration from environment variables (file size, age, flush interval), provides a size converter for megabyte scaling, and generates kube-log-runner command strings with conditional rotation and flush parameters. The controller daemon gains a new --log-file-max-size CLI flag that wires into klog configuration. Services and WICD components are refactored to use the centralized helpers, eliminating duplication and enabling consistent log configuration across service boundaries.

🚥 Pre-merge checks | ✅ 19 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Go Best Practices & Build Tags ⚠️ Warning fs.Set() errors ignored without justification in cmd/daemon/controller.go. pkg/logconfig/init() logs errors silently, disabling log rotation on invalid env vars. Check fs.Set() errors or document why ignored. Validate logconfig env vars after logger setup or fail startup to surface misconfiguration.
✅ Passed checks (19 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: implementing log file rotation for WICD by adding configuration flags and centralizing log setup.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Security: Secrets, Ssh & Csr ✅ Passed PR implements log file rotation configuration with no secrets, SSH connections, or CSR approval logic. Error messages only log env var names, never values, preventing credential leakage.
Kubernetes Controller Patterns ✅ Passed PR modifies only log configuration, not controller reconciliation patterns. No changes to Reconcile logic, requeue, status conditions, watch predicates, finalizers, or owner references.
Windows Service Management ✅ Passed Service ordering, dependencies, descriptions, cleanup, recovery actions, and SCM interactions all properly maintained in windows.go. PR changes only add log file size to WICD args.
Platform-Specific Requirements ✅ Passed PR is narrowly scoped to Windows log rotation configuration; does not introduce platform-specific requirements for vSphere, AWS, Azure, or GCP per the custom check instructions.
Stable And Deterministic Test Names ✅ Passed No Ginkgo tests in PR. Uses Go stdlib testing with stable table-driven test names. All 43 test names are static, deterministic strings with no dynamic values.
Test Structure And Quality ✅ Passed Codebase uses standard Go testing, not Ginkgo. Tests follow repository patterns: table-driven tests, t.Cleanup for cleanup, meaningful assertion messages, no cluster operations.
Microshift Test Compatibility ✅ Passed PR adds only standard Go unit tests (TestGetEnvDuration, TestGetEnvQuantity, TestGetLogFileSizeMegabytes, TestGetLogRunnerForCmd), not Ginkgo e2e tests. Check is not applicable.
Single Node Openshift (Sno) Test Compatibility ✅ Passed This PR adds no Ginkgo e2e tests (It(), Describe(), Context(), When()). The SNO check only applies when Ginkgo e2e tests are added. The test files contain only standard Go unit tests.
Topology-Aware Scheduling Compatibility ✅ Passed PR modifies only log configuration (CLI flags, logconfig package). No Kubernetes manifests, scheduling constraints, or topology assumptions introduced.
Ote Binary Stdout Contract ✅ Passed No stdout contract violations found. pkg/logconfig/init() uses ctrl.Log (proper logger), cmd/daemon/controller.go klog output directed to log files or stderr, no fmt.Print calls in process-level code.
Ipv6 And Disconnected Network Test Compatibility ✅ Passed This PR adds only standard Go unit tests, not Ginkgo e2e tests. No IPv4 assumptions or external connectivity requirements detected.
No-Weak-Crypto ✅ Passed PR introduces no weak crypto (MD5, SHA1, DES, RC4, 3DES, Blowfish, ECB), custom implementations, or non-constant-time secret comparisons. New logconfig package handles log configuration only.
Container-Privileges ✅ Passed PR modifies only Go source files for log rotation configuration; no Kubernetes manifests or container privilege escalation configurations are introduced.
No-Sensitive-Data-In-Logs ✅ Passed No sensitive data exposed in logs. Only operational parameters (numeric log sizes, directory paths, env var names) are logged; values are never logged.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands and usage tips.

@jrvaldes
Copy link
Copy Markdown
Contributor Author

jrvaldes commented Jun 2, 2026

@coderabbitai full review

@openshift-ci
Copy link
Copy Markdown
Contributor

openshift-ci Bot commented Jun 2, 2026

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: jrvaldes

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci openshift-ci Bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jun 2, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jun 2, 2026

✅ Actions performed

Full review triggered.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (3)
pkg/logconfig/logconfig_test.go (1)

282-421: 💤 Low value

Solid coverage — minor: test name drifted from the function under test.

TestGetLogRunnerForCmd exercises GenerateKubeLogRunnerCmd (the old getLogRunnerForCmd is gone). Renaming to TestGenerateKubeLogRunnerCmd keeps go test -run and grep aligned with the actual symbol. The ordering/contains assertions themselves are well done.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkg/logconfig/logconfig_test.go` around lines 282 - 421, The test function
name no longer matches the symbol under test; rename the test from
TestGetLogRunnerForCmd to TestGenerateKubeLogRunnerCmd so it reflects and maps
to GenerateKubeLogRunnerCmd; update the function declaration only (leave all
test body assertions and references to GenerateKubeLogRunnerCmd unchanged) to
keep go test filtering and grep consistent.
pkg/logconfig/logconfig.go (1)

25-40: 💤 Low value

Harden the overflow/rounding guard for ScaledValue in GetLogFileSizeMegabytes.
resource.Quantity.ScaledValue drops the internal exact/ok signal from the scaling path; as a result, if mb < 0 can miss cases where the scaled conversion doesn’t cleanly fit into an int64 (and then uint64(mb) would proceed). Prefer using mb, ok := q.AsScaledInt64(resource.Mega) (or q.Value() with explicit bounds checks) and return 0 when ok is false.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkg/logconfig/logconfig.go` around lines 25 - 40, GetLogFileSizeMegabytes
currently uses q.ScaledValue(resource.Mega) which can drop the exact/ok signal
and let an out-of-range value slip through; update GetLogFileSizeMegabytes to
use q.AsScaledInt64(resource.Mega) (or q.Value() with explicit bounds checks) so
you get (mb, ok) and return 0 when ok is false or mb is negative, then safely
convert mb to uint64; reference the GetLogFileSizeMegabytes function and the
resource.Quantity methods AsScaledInt64 / Value when making this change.
pkg/services/services.go (1)

314-351: ⚡ Quick win

Remove dead env parsing helpers from pkg/services/services.go
pkg/logconfig now defines and uses its own getEnvQuantityString/getEnvDurationString (pkg/logconfig/init.go), while the versions in pkg/services/services.go appear to have no remaining call sites (only the function definitions). Drop the dead helpers from pkg/services/services.go or reuse the pkg/logconfig implementations to avoid duplication.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkg/services/services.go` around lines 314 - 351, The two dead helper
functions getEnvQuantityString and getEnvDurationString in services.go are
duplicated and unused; remove these definitions from services.go, and if any
remaining code later needs them, replace references to those functions with the
implementations in pkg/logconfig (importing that package and calling
logconfig.GetEnvQuantityString/GetEnvDurationString or the exact exported names
used there); otherwise simply delete the getEnvQuantityString and
getEnvDurationString functions to eliminate the dead code.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@cmd/daemon/controller.go`:
- Around line 76-82: fs.Set("log_file_max_size", logFileMaxSizeString) currently
ignores the returned error; update the controller initialization (around the
block that sets log_file_max_size in controller.go) to capture the error from
fs.Set and handle it (e.g., log via klog.Errorf/klog.Fatalf or return the error
from the enclosing function) so a typo or invalid value doesn't silently leave
logging misconfigured; preserve the existing special-case message that converts
"0" to "unlimited" when composing the klog.Infof message.

In `@pkg/logconfig/init.go`:
- Around line 7-25: The init() currently swallows env parse errors (overwriting
logFileSize/logFileAge/flushInterval with empty strings), which can silently
disable log rotation and prevents GenerateKubeLogRunnerCmd from emitting flags;
instead move the parsing out of package init into a validation function (e.g.,
ValidateLogConfig) that uses getEnvQuantityString/getEnvDurationString to set
the globals and returns an error on parse failure, then call ValidateLogConfig
after ctrl.SetLogger in cmd/operator/main.go so failures can be logged by the
real logger (or cause process exit); ensure you do not overwrite the globals on
error—return/exit with a non-zero status or log.Fatalf so invalid env values are
surfaced and rotation flags are not silently omitted.

---

Nitpick comments:
In `@pkg/logconfig/logconfig_test.go`:
- Around line 282-421: The test function name no longer matches the symbol under
test; rename the test from TestGetLogRunnerForCmd to
TestGenerateKubeLogRunnerCmd so it reflects and maps to
GenerateKubeLogRunnerCmd; update the function declaration only (leave all test
body assertions and references to GenerateKubeLogRunnerCmd unchanged) to keep go
test filtering and grep consistent.

In `@pkg/logconfig/logconfig.go`:
- Around line 25-40: GetLogFileSizeMegabytes currently uses
q.ScaledValue(resource.Mega) which can drop the exact/ok signal and let an
out-of-range value slip through; update GetLogFileSizeMegabytes to use
q.AsScaledInt64(resource.Mega) (or q.Value() with explicit bounds checks) so you
get (mb, ok) and return 0 when ok is false or mb is negative, then safely
convert mb to uint64; reference the GetLogFileSizeMegabytes function and the
resource.Quantity methods AsScaledInt64 / Value when making this change.

In `@pkg/services/services.go`:
- Around line 314-351: The two dead helper functions getEnvQuantityString and
getEnvDurationString in services.go are duplicated and unused; remove these
definitions from services.go, and if any remaining code later needs them,
replace references to those functions with the implementations in pkg/logconfig
(importing that package and calling
logconfig.GetEnvQuantityString/GetEnvDurationString or the exact exported names
used there); otherwise simply delete the getEnvQuantityString and
getEnvDurationString functions to eliminate the dead code.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Central YAML (inherited)

Review profile: CHILL

Plan: Enterprise

Run ID: bb45bcec-f745-439d-b25f-c93f7ec9a90e

📥 Commits

Reviewing files that changed from the base of the PR and between bcb0701 and 9f47b11.

📒 Files selected for processing (8)
  • cmd/daemon/controller.go
  • pkg/logconfig/init.go
  • pkg/logconfig/logconfig.go
  • pkg/logconfig/logconfig_test.go
  • pkg/services/init.go
  • pkg/services/services.go
  • pkg/services/services_test.go
  • pkg/windows/windows.go
💤 Files with no reviewable changes (2)
  • pkg/services/init.go
  • pkg/services/services_test.go

Comment thread cmd/daemon/controller.go
Comment thread pkg/logconfig/init.go
@jrvaldes
Copy link
Copy Markdown
Contributor Author

jrvaldes commented Jun 2, 2026

/test ?

@jrvaldes
Copy link
Copy Markdown
Contributor Author

jrvaldes commented Jun 2, 2026

/test lint

@jrvaldes
Copy link
Copy Markdown
Contributor Author

jrvaldes commented Jun 2, 2026

/test unit

@jrvaldes
Copy link
Copy Markdown
Contributor Author

jrvaldes commented Jun 2, 2026

/test vsphere-e2e-operator

@jrvaldes
Copy link
Copy Markdown
Contributor Author

jrvaldes commented Jun 3, 2026

/test lint

@jrvaldes
Copy link
Copy Markdown
Contributor Author

jrvaldes commented Jun 3, 2026

/test vsphere-e2e-operator

@openshift-ci
Copy link
Copy Markdown
Contributor

openshift-ci Bot commented Jun 3, 2026

@jrvaldes: The following tests failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
ci/prow/vsphere-e2e-operator 9f47b11 link true /test vsphere-e2e-operator
ci/prow/lint 9f47b11 link true /test lint

Full PR test history. Your PR dashboard.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

Comment thread pkg/services/services.go
// kubeProxyConfiguration returns the Service definition for kube-proxy
func kubeProxyConfiguration(debug bool) servicescm.Service {
cmd := getLogRunnerForCmd(windows.KubeProxyPath, windows.KubeProxyLog)
cmd := logconfig.GenerateKubeLogRunnerCmd(windows.KubeLogRunnerPath, windows.KubeProxyPath, windows.KubeProxyLog)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since this is generating and returning the logrunnercmd, it can be GetKubeLogRunnerCmd?

Comment thread cmd/daemon/controller.go
fs.Set("log_file_max_size", logFileMaxSizeString)

if logFileMaxSizeString == "0" {
logFileMaxSizeString = "unlimited"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't this be default unlimited and then if set to a value other than 0, then set to that value?

func GetLogFileSize() string {
return logFileSize
// GetLogFileSizeMegabytes returns the configured log file size resource value in megabytes
func GetLogFileSizeMegabytes() uint64 {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can still keep this as GetLogFileSize if there isn't going to be another function that will need to return size not in megabytes. Function doc can state that the value will be in megabytes.

Comment thread pkg/windows/windows.go
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. jira/valid-reference Indicates that this PR references a valid Jira ticket of any type.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants