Skip to content

memory savings#298

Merged
matthyx merged 3 commits intomainfrom
server-side-apply
Mar 19, 2026
Merged

memory savings#298
matthyx merged 3 commits intomainfrom
server-side-apply

Conversation

@matthyx
Copy link
Contributor

@matthyx matthyx commented Mar 16, 2026

Summary by CodeRabbit

  • Chores
    • Server-side apply is now explicitly disabled during server initialization; startup will report errors if registry initialization or the flag adjustment fails.

@coderabbitai
Copy link

coderabbitai bot commented Mar 16, 2026

📝 Walkthrough

Walkthrough

PersistentPreRunE in NewCommandStartWardleServer now receives the active *cobra.Command, checks and returns errors from defaults.ComponentGlobalsRegistry.Set(), and explicitly sets the feature-gates flag to ServerSideApply=false via cmd.Flags().Set(...), error-checking that operation as well.

Changes

Cohort / File(s) Summary
Server startup pre-run hook
pkg/cmd/server/start.go
PersistentPreRunE now accepts the active *cobra.Command, returns any error from defaults.ComponentGlobalsRegistry.Set(), and sets feature-gates to ServerSideApply=false using cmd.Flags().Set(...), with error checks for the flag mutation. (+9/-2 lines)

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 I hopped into startup, flag in paw,
I set ServerSideApply to "no" with awe,
Checked every step, returned what I'd found,
Quieted a feature without making a sound,
Tiny rabbit fixes, tidy and neat — hurrah! 🥕

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Title check ❓ Inconclusive The title 'memory savings' is vague and does not clearly convey the specific technical change of disabling ServerSideApply feature gate in the Wardle server startup hook. Consider a more descriptive title that reflects the actual change, such as 'Disable ServerSideApply feature gate in server startup' or 'Set ServerSideApply=false during server initialization'.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch server-side-apply
📝 Coding Plan
  • Generate coding plan for human review comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@matthyx matthyx changed the title disable server-side apply feature gate memory savings Mar 16, 2026
Copy link

@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: 1

🧹 Nitpick comments (1)
pkg/cmd/server/start.go (1)

217-221: watch-cache memory-saving comment appears misleading for this codebase.

Line 217 says this reduces memory, but pkg/apiserver/apiserver.go (Lines 83-150) wires custom file-based storage with WatchDispatcher, not the generic cacher path. This flag likely has little/no effect here; suggest updating/removing this comment (or the flag write) to avoid operational confusion.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@pkg/cmd/server/start.go` around lines 217 - 221, The comment claiming
"disable watch cache to reduce memory usage" is misleading because the apiserver
uses a custom file-based storage and WatchDispatcher (see
pkg/apiserver/apiserver.go) so setting flags.Set("watch-cache","false") has
little or no effect; either remove the comment and the flags.Set("watch-cache",
"false") call in start.go, or replace the comment with a clear note that the
watch-cache flag is ineffective here due to the custom WatchDispatcher wiring,
keeping the code only if backward compatibility is desired; update the logger
usage (logger.L().Warning) accordingly if you remove the flag so there is no
misleading warning about failing to set an unused behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@pkg/cmd/server/start.go`:
- Around line 211-227: The flag enforcement for disabling ServerSideApply,
watch-cache, and enable-swagger-ui is currently done via flags.Set during
command construction (using flags.Set) so users can override them and failures
only warn; move these checks into the existing PersistentPreRunE hook so they
run after CLI parsing, call flags.Set for "feature-gates"
("ServerSideApply=false"), "watch-cache" ("false") and "enable-swagger-ui"
("false") there, and on any error return a non-nil error from PersistentPreRunE
(do not use logger.L().Warning) to fail closed; finally remove the duplicate
flags.Set block from the earlier command setup to avoid redundant pre-parse
defaults.

---

Nitpick comments:
In `@pkg/cmd/server/start.go`:
- Around line 217-221: The comment claiming "disable watch cache to reduce
memory usage" is misleading because the apiserver uses a custom file-based
storage and WatchDispatcher (see pkg/apiserver/apiserver.go) so setting
flags.Set("watch-cache","false") has little or no effect; either remove the
comment and the flags.Set("watch-cache", "false") call in start.go, or replace
the comment with a clear note that the watch-cache flag is ineffective here due
to the custom WatchDispatcher wiring, keeping the code only if backward
compatibility is desired; update the logger usage (logger.L().Warning)
accordingly if you remove the flag so there is no misleading warning about
failing to set an unused behavior.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: b01ce61e-d9a7-4109-a450-684b9ee1aa66

📥 Commits

Reviewing files that changed from the base of the PR and between 9008e6d and b9f92f1.

📒 Files selected for processing (1)
  • pkg/cmd/server/start.go

@github-actions
Copy link

Summary:

  • License scan: failure
  • Credentials scan: failure
  • Vulnerabilities scan: success
  • Unit test: success
  • Go linting: failure

1 similar comment
@github-actions
Copy link

Summary:

  • License scan: failure
  • Credentials scan: failure
  • Vulnerabilities scan: success
  • Unit test: success
  • Go linting: failure

@matthyx matthyx moved this to Needs Reviewer in KS PRs tracking Mar 17, 2026
matthyx added 3 commits March 19, 2026 14:00
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
Signed-off-by: Matthias Bertschy <matthias.bertschy@gmail.com>
@matthyx matthyx force-pushed the server-side-apply branch from 18c2220 to 677a774 Compare March 19, 2026 13:10
Copy link

@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: 1

♻️ Duplicate comments (1)
pkg/cmd/server/start.go (1)

136-138: ⚠️ Potential issue | 🟠 Major

Do not bypass ServerSideApply=false enforcement when skipDefaultComponentGlobalsRegistrySet is true.

Line 136 returns before Line 143 runs, so this path skips the forced feature-gate entirely. If this flag is meant to be always enforced, the early return should only skip registry setup, not the enforcement block.

Suggested fix
 PersistentPreRunE: func(cmd *cobra.Command, _ []string) error {
-    if skipDefaultComponentGlobalsRegistrySet {
-        return nil
-    }
-    if err := defaults.ComponentGlobalsRegistry.Set(); err != nil {
-        return err
-    }
+    if !skipDefaultComponentGlobalsRegistrySet {
+        if err := defaults.ComponentGlobalsRegistry.Set(); err != nil {
+            return err
+        }
+    }
     flags := cmd.Flags()
     if err := flags.Set("feature-gates", "ServerSideApply=false"); err != nil {
         return err
     }
     return nil
 },

Also applies to: 143-145

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@pkg/cmd/server/start.go` around lines 136 - 138, The early return when
skipDefaultComponentGlobalsRegistrySet is true currently prevents the
ServerSideApply=false enforcement from running; change the control flow in
start.go so the return only skips the registry setup and not the enforcement
block: remove or move the return that uses
skipDefaultComponentGlobalsRegistrySet so that the feature-gate enforcement (the
ServerSideApply=false check around the code at/near lines referencing
ServerSideApply) always executes, while still bypassing calls that set up the
default component globals registry; reference the
skipDefaultComponentGlobalsRegistrySet variable and the enforcement code around
ServerSideApply to ensure enforcement always runs even when registry setup is
skipped.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@pkg/cmd/server/start.go`:
- Around line 142-145: The code currently replaces the entire "feature-gates"
flag via flags.Set("feature-gates", "ServerSideApply=false"); change this to
read the existing feature-gates value, parse/merge in the entry
ServerSideApply=false (overriding any existing ServerSideApply setting), and
write back the combined comma-separated value using flags.Set; update the logic
around flags.Set/flags.Get (the same flags variable and the "feature-gates" key)
so user-provided gates are preserved while ensuring ServerSideApply is set to
false.

---

Duplicate comments:
In `@pkg/cmd/server/start.go`:
- Around line 136-138: The early return when
skipDefaultComponentGlobalsRegistrySet is true currently prevents the
ServerSideApply=false enforcement from running; change the control flow in
start.go so the return only skips the registry setup and not the enforcement
block: remove or move the return that uses
skipDefaultComponentGlobalsRegistrySet so that the feature-gate enforcement (the
ServerSideApply=false check around the code at/near lines referencing
ServerSideApply) always executes, while still bypassing calls that set up the
default component globals registry; reference the
skipDefaultComponentGlobalsRegistrySet variable and the enforcement code around
ServerSideApply to ensure enforcement always runs even when registry setup is
skipped.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 4ae774be-9875-4fb1-be17-1db051b3a0b2

📥 Commits

Reviewing files that changed from the base of the PR and between b9f92f1 and 677a774.

📒 Files selected for processing (1)
  • pkg/cmd/server/start.go

Comment on lines +142 to +145
flags := cmd.Flags()
if err := flags.Set("feature-gates", "ServerSideApply=false"); err != nil {
return err
}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🌐 Web query:

In Kubernetes/Cobra CLI flag handling, when calling cmd.Flags().Set("feature-gates", "ServerSideApply=false"), does this replace the entire feature-gates value or merge with existing entries (e.g. --feature-gates=Foo=true)?

💡 Result:

In Kubernetes/Cobra CLI flag handling, calling cmd.Flags.Set("feature-gates", "ServerSideApply=false") replaces the entire feature-gates value rather than merging with existing entries. The --feature-gates flag uses a custom pflag.Value implementation from k8s.io/component-base/cli/flag, specifically ColonSeparatedMultimapStringString. Its Set(string) method is designed such that "The first call to Set will clear the map before adding entries; subsequent calls will simply append to the map." When cmd.Flags.Set(name, value) is called, it invokes flag.Value.Set(value) on the flag's Value. For this custom type, the first Set clears any existing map contents (e.g., from prior CLI flags like --feature-gates=Foo=true or defaults) and parses the new string into the map. Thus, it fully replaces the value. This behavior enables overriding defaults or prior settings with a single new comma-separated list, without preserving previous entries.

Citations:


🏁 Script executed:

# Examine the code context around lines 142-145 in pkg/cmd/server/start.go
head -160 pkg/cmd/server/start.go | tail -40 | cat -n

Repository: kubescape/storage

Length of output: 1898


🏁 Script executed:

# Search for any feature-gates handling or merging logic in the codebase
rg "feature-gates|FeatureGates" --type go -A 3 -B 3 | head -100

Repository: kubescape/storage

Length of output: 385


🏁 Script executed:

# Check where feature-gates flag is defined/registered
rg "feature-gates|featureGates|FeatureGates" --type go | head -50

Repository: kubescape/storage

Length of output: 163


Merge feature-gates instead of replacing the entire value.

Line 143 calls flags.Set("feature-gates", "ServerSideApply=false"), which replaces the entire feature-gates value and drops any entries passed by users (e.g., --feature-gates=Foo=true). Retrieve the current value, merge in ServerSideApply=false, and set the combined result to preserve user-provided gates.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@pkg/cmd/server/start.go` around lines 142 - 145, The code currently replaces
the entire "feature-gates" flag via flags.Set("feature-gates",
"ServerSideApply=false"); change this to read the existing feature-gates value,
parse/merge in the entry ServerSideApply=false (overriding any existing
ServerSideApply setting), and write back the combined comma-separated value
using flags.Set; update the logic around flags.Set/flags.Get (the same flags
variable and the "feature-gates" key) so user-provided gates are preserved while
ensuring ServerSideApply is set to false.

@github-actions
Copy link

Summary:

  • License scan: failure
  • Credentials scan: failure
  • Vulnerabilities scan: failure
  • Unit test: success
  • Go linting: failure

@matthyx matthyx merged commit 27dc7b7 into main Mar 19, 2026
7 checks passed
@matthyx matthyx deleted the server-side-apply branch March 19, 2026 13:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Needs Reviewer

Development

Successfully merging this pull request may close these issues.

1 participant