ROX-33022: refactor admission controller config map persister#19707
ROX-33022: refactor admission controller config map persister#19707
Conversation
|
Skipping CI for Draft Pull Request. |
📝 WalkthroughSummary by CodeRabbitRelease Notes
WalkthroughAdds a ConfigMap stream to AdmissionController settings, serializes settings into gzipped Kubernetes ConfigMaps, introduces a shared ConfigMap persister component, removes the legacy admissioncontroller-specific persister, and wires the sensor to use the new shared persister. Changes
Sequence DiagramsequenceDiagram
participant SettingsMgr as SettingsManager
participant ConfigStream as ConfigMapStream
participant ConfigPersister as ConfigMapPersister
participant K8sAPI as Kubernetes API
SettingsMgr->>SettingsMgr: UpdatePolicies/Config/FlushCache
SettingsMgr->>SettingsMgr: pushSettings(settings)
SettingsMgr->>SettingsMgr: settingsToConfigMap(settings)
SettingsMgr->>ConfigStream: Push(*v1.ConfigMap)
ConfigPersister->>ConfigStream: Iterator.Next()
ConfigStream-->>ConfigPersister: *v1.ConfigMap
ConfigPersister->>K8sAPI: Create(ConfigMap)
alt ConfigMap exists
K8sAPI-->>ConfigPersister: AlreadyExists
ConfigPersister->>K8sAPI: Get(ConfigMap)
K8sAPI-->>ConfigPersister: Existing ConfigMap
ConfigPersister->>K8sAPI: Update(ConfigMap)
else Created
K8sAPI-->>ConfigPersister: Created
end
K8sAPI-->>ConfigPersister: Result
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~22 minutes 🚥 Pre-merge checks | ✅ 1 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (1 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@sensor/common/admissioncontroller/settings_manager_impl.go`:
- Around line 137-144: The current pushSettings function pushes to
settingsStream before converting to a ConfigMap, causing silent divergence if
settingsToConfigMap fails; update pushSettings so it first calls
settingsToConfigMap(newSettings) and if that succeeds push both
p.settingsStream.Push(newSettings) and p.configStream.Push(config) atomically,
and if conversion fails avoid pushing settings (or explicitly revert/notify) and
improve the error log to include the conversion error and note that configStream
was not updated (include the error and identifying context from newSettings);
reference pushSettings, settingsToConfigMap, settingsStream.Push, and
configStream.Push when making the change.
In `@sensor/common/configmap/persister.go`:
- Around line 56-63: The Start() logic is inverted because ErrorSignal.Reset()
returns false when unsignaled, causing configMapPersister.Start to error on
first call; change the check in Start() to treat a true Reset() as the "already
started" case (i.e., if p.stopSig.Reset() { return errors.New("config persister
was already started") }) or alternatively initialize p.stopSig to a triggered
state before Start so Reset() returns true only when already started; update the
Start() method of configMapPersister (referencing stopSig.Reset and Start)
accordingly so the component can actually start on first invocation.
🪄 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: Central YAML (base), Organization UI (inherited)
Review profile: CHILL
Plan: Pro
Run ID: 1587e1c5-8db6-4bfd-a51a-b7ecadb30b83
📒 Files selected for processing (7)
sensor/common/admissioncontroller/mocks/settings_manager.gosensor/common/admissioncontroller/settings_manager.gosensor/common/admissioncontroller/settings_manager_impl.gosensor/common/admissioncontroller/settings_manager_impl_test.gosensor/common/configmap/persister.gosensor/kubernetes/admissioncontroller/config_map_persister.gosensor/kubernetes/sensor/sensor.go
💤 Files with no reviewable changes (1)
- sensor/kubernetes/admissioncontroller/config_map_persister.go
|
Images are ready for the commit at 6d74b69. To use with deploy scripts, first |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #19707 +/- ##
=======================================
Coverage 49.59% 49.59%
=======================================
Files 2756 2755 -1
Lines 207961 207919 -42
=======================================
- Hits 103129 103123 -6
+ Misses 97172 97133 -39
- Partials 7660 7663 +3
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
/test gke-nongroovy-e2e-tests |
The admission controller's config_map_persister was tightly coupled to admission control settings. This refactors it into two parts: - A generic ConfigMap persister (sensor/common/configmap) that watches a ValueStream of ConfigMaps and applies them to Kubernetes - The settings-to-ConfigMap conversion logic moved into the admission controller's settings manager, which now exposes a ConfigMapStream() This enables reuse of the ConfigMap persistence mechanism for other components (e.g. FACT file activity configuration). The old sensor/kubernetes/admissioncontroller/config_map_persister.go is removed and its test relocated to the settings manager package.
50c286e to
6d74b69
Compare
|
PR needs rebase. DetailsInstructions 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. |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
sensor/common/configmap/persister.go (1)
108-132: Consider cloning the ConfigMap before mutation.Line 124 mutates
configMap.ResourceVersiondirectly on the object obtained from the stream. While the current usage insettingsToConfigMapcreates a fresh ConfigMap per push (so this is safe in practice), directly mutating stream-provided values is fragile if future code reuses objects.Optional defensive copy
func (p *configMapPersister) applyCurrentConfigMap(ctx context.Context) error { configMap := p.settingsStreamIt.Value() if configMap == nil { return nil } + // Clone to avoid mutating the stream's value + configMap = configMap.DeepCopy() _, err := p.client.Create(ctx, configMap, metav1.CreateOptions{})🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@sensor/common/configmap/persister.go` around lines 108 - 132, The code in configMapPersister.applyCurrentConfigMap mutates the stream-provided object from p.settingsStreamIt.Value() by setting configMap.ResourceVersion; make a defensive deep copy of the ConfigMap before any mutation (e.g. clone the returned object into a new variable) so you never modify the stream's original; update subsequent calls to use the cloned ConfigMap when calling p.client.Create, p.client.Update and when copying ResourceVersion from existing, ensuring the original stream value remains unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@sensor/common/configmap/persister.go`:
- Around line 108-132: The code in configMapPersister.applyCurrentConfigMap
mutates the stream-provided object from p.settingsStreamIt.Value() by setting
configMap.ResourceVersion; make a defensive deep copy of the ConfigMap before
any mutation (e.g. clone the returned object into a new variable) so you never
modify the stream's original; update subsequent calls to use the cloned
ConfigMap when calling p.client.Create, p.client.Update and when copying
ResourceVersion from existing, ensuring the original stream value remains
unchanged.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Central YAML (base), Organization UI (inherited)
Review profile: CHILL
Plan: Pro
Run ID: 54292650-ea16-4e35-8d25-d13b82dc99ba
📒 Files selected for processing (8)
sensor/common/admissioncontroller/mocks/settings_manager.gosensor/common/admissioncontroller/settings_manager.gosensor/common/admissioncontroller/settings_manager_impl.gosensor/common/admissioncontroller/settings_manager_impl_test.gosensor/common/configmap/persister.gosensor/kubernetes/admissioncontroller/config_map_persister.gosensor/kubernetes/admissioncontroller/config_map_persister_test.gosensor/kubernetes/sensor/sensor.go
💤 Files with no reviewable changes (2)
- sensor/kubernetes/admissioncontroller/config_map_persister_test.go
- sensor/kubernetes/admissioncontroller/config_map_persister.go
🚧 Files skipped from review as they are similar to previous changes (2)
- sensor/common/admissioncontroller/settings_manager.go
- sensor/common/admissioncontroller/mocks/settings_manager.go
Description
The admission controller's config_map_persister was tightly coupled to admission control settings. This refactors it into two parts:
This enables reuse of the ConfigMap persistence mechanism for other components (e.g. FACT file activity configuration).
The old sensor/kubernetes/admissioncontroller/config_map_persister.go is removed and its test relocated to the settings manager package.
User-facing documentation
Testing and quality
Automated testing
How I validated my change
change me!