feat: implement prefix-based metadata filtering for StatefulSet and P…#1720
Conversation
|
CLA Assistant Lite bot CLA Assistant Lite bot All contributors have signed the COC ✍️ ✅ |
|
I have read the CLA Document and I hereby sign the CLA |
|
I have read the Code of Conduct and I hereby accept the Terms |
There was a problem hiding this comment.
Pull request overview
This pull request implements prefix-based metadata filtering to give users control over how labels and annotations propagate from Custom Resources (CR) to StatefulSets and Pods, addressing issue #1652 where CR metadata changes triggered unnecessary pod rolling restarts.
Purpose: The PR solves a significant operational problem where adding simple organizational labels (e.g., team: platform) to a CR would cause disruptive rolling restarts of all pods. The new filtering mechanism allows users to selectively control metadata propagation.
Changes:
- Implements
sts-only.*andpod-only.*prefix-based filtering with automatic prefix stripping during propagation - Adds full sync semantics for metadata (including removal of keys no longer in CR) via new
SyncParentMetaToPodTemplateandSyncParentMetaToStatefulSetfunctions - Fixes a critical memory-sharing bug where StatefulSet and Pod Template label maps shared the same underlying memory reference
- Adds metadata-only change detection in
ApplyStatefulSetviaMergeStatefulSetMetaUpdatesto avoid unnecessary pod updates
Reviewed changes
Copilot reviewed 18 out of 18 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| pkg/splunk/common/util.go | Core filtering logic with prefix constants, exclusion rules, managed key tracking (Get/Set functions), and sync functions for both Pod Template and StatefulSet |
| pkg/splunk/common/util_test.go | Comprehensive unit tests (1800+ lines) covering all filtering scenarios, prefix stripping, managed key tracking, and sync behavior |
| pkg/splunk/common/statefulset_util.go | New MergeStatefulSetMetaUpdates function to detect StatefulSet metadata-only changes without triggering pod restarts |
| pkg/splunk/common/statefulset_util_test.go | Unit tests for metadata merge logic covering various edge cases including nil handling |
| pkg/splunk/enterprise/configuration.go | Creates separate label maps for StatefulSet and Pod Template (bug fix), replaces AppendParentMeta with new SyncParentMeta* functions |
| pkg/splunk/enterprise/configuration_test.go | Test verifying label maps don't share memory (regression test for bug fix) |
| pkg/splunk/splkcontroller/statefulset.go | Integrates MergeStatefulSetMetaUpdates into ApplyStatefulSet to detect metadata-only changes |
| pkg/splunk/splkcontroller/statefulset_metadata_test.go | Tests for annotation persistence and metadata-only change detection |
| pkg/splunk/test/controller.go | Adds DeepCopy() calls to prevent annotation pollution between test cases |
| pkg/splunk/enterprise/testdata/fixtures/*.json | Updates test fixtures with new managed-cr tracking annotations |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
3ba72d7 to
e647fb3
Compare
|
Hi @vivekr-splunk |
Description
This PR implements prefix-based metadata filtering to give users control over how labels and annotations propagate from the Custom Resource (CR) to the underlying StatefulSet and Pods.
Note: This is a part of #1644.
It contains the first commit + a bug fix which we discovered after a long validation.
Previously, almost all metadata was copied everywhere. Now you can use specific prefixes to target where you want your labels to go:
sts-only.*: Keys starting with this are added only to the StatefulSet metadata (and the prefix is stripped!). They won't appear on the Pod Template, so adding them won't trigger a pod rollout.pod-only.*: Keys are added only to the Pod Template (and excluded from the StatefulSet metadata).kubectl.kubernetes.io/*andoperator.splunk.com/*prefixes to prevent clutter and conflicts.Regular labels without these prefixes work exactly as before—propagatating to both.
Key Changes
sts-only.andpod-only.prefixes.SyncParentMetaToStatefulSetwhich handles the transformation (strippingsts-only.) and syncing logic.Testing and Verification
Many unit tests are implemented.
For E2E validation:
sts-only.my-tag: true.my-tag: true.my-tag(and thus no rollout if added later).pod-only.scrapper: true.pod-only.scrapper: true.environment: prod.environment: prod.Related Issues
#1652
PR Checklist