Skip to content

fix: add listMapKey to VMRule rules for structured server-side apply merge#2258

Merged
vrutkovs merged 2 commits into
VictoriaMetrics:masterfrom
mvanhorn:fix/657-vmrule-rules-listmapkey
Jun 17, 2026
Merged

fix: add listMapKey to VMRule rules for structured server-side apply merge#2258
vrutkovs merged 2 commits into
VictoriaMetrics:masterfrom
mvanhorn:fix/657-vmrule-rules-listmapkey

Conversation

@mvanhorn

@mvanhorn mvanhorn commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds a +listMapKey=alert marker to the VMRule rules array so Kubernetes server-side apply merges rule entries by key instead of replacing the whole list, preventing rules from clobbering each other on partial applies.

Why this matters

VMRule.spec.groups[].rules was a plain list with no listMapKey, so a server-side apply that touched one rule replaced the entire rules array, dropping rules managed by other appliers (#657). Marking the list with its identifying key lets the API server do a structured merge. The change is in api/operator/v1beta1/vmrule_types.go with the regenerated CRD in config/crd/overlay/crd.yaml, plus a unit test and docs/api.md / docs/CHANGELOG.md updates.

Testing

  • Added a unit test asserting the merge-key marker is present on the rules field.
  • go build and go vet pass on the api module; the CRD overlay regenerates cleanly.

Closes #657


Summary by cubic

Make VMRule.spec.groups[].rules a map-style list keyed by record and alert so server-side apply merges rules by key instead of replacing the list. Adds XOR validation and defaults for record/alert to prevent invalid specs and rule clobbering (fixes #657).

  • Bug Fixes
    • Marked RuleGroup.rules with +listType=map, +listMapKey=record, +listMapKey=alert; set Rule.record/Rule.alert defaults to ""; regenerated CRDs with x-kubernetes-list-type, x-kubernetes-list-map-keys, and defaults; updated docs/api.md and docs/CHANGELOG.md.
    • Enforced validation: error if both record and alert are set, or neither.
    • Added tests for CRD schema markers and JSON field names, JSON round-trip/validation, composite-key SSA merges for rules, and traditional SMP merge-by-name behavior for groups.

Written for commit 7d0ebe1. Summary will update on new commits.

Review in cubic

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No issues found across 5 files

Re-trigger cubic

@AndrewChubatiuk

Copy link
Copy Markdown
Contributor

hey @mvanhorn
thanks for PR
could you clarify a purpose of added tests cases? they seem to be irrelevant

Comment thread api/operator/v1beta1/vmrule_types.go
Comment thread api/operator/v1beta1/vmrule_types_test.go
@AndrewChubatiuk AndrewChubatiuk force-pushed the fix/657-vmrule-rules-listmapkey branch from 0e4384d to 5edbd61 Compare June 15, 2026 19:17
@AndrewChubatiuk AndrewChubatiuk enabled auto-merge (squash) June 15, 2026 19:18
@AndrewChubatiuk AndrewChubatiuk requested a review from vrutkovs June 15, 2026 19:21
@AndrewChubatiuk AndrewChubatiuk force-pushed the fix/657-vmrule-rules-listmapkey branch from 5edbd61 to 8e7c3b5 Compare June 15, 2026 19:39
@AndrewChubatiuk AndrewChubatiuk force-pushed the fix/657-vmrule-rules-listmapkey branch 2 times, most recently from 89d983b to b91107c Compare June 16, 2026 11:21
@vrutkovs vrutkovs disabled auto-merge June 17, 2026 09:47
@vrutkovs vrutkovs enabled auto-merge (squash) June 17, 2026 09:47
@vrutkovs vrutkovs force-pushed the fix/657-vmrule-rules-listmapkey branch from 0bdf36b to 0897f6c Compare June 17, 2026 09:47
@vrutkovs vrutkovs force-pushed the fix/657-vmrule-rules-listmapkey branch from 0897f6c to 7d0ebe1 Compare June 17, 2026 10:24
@vrutkovs vrutkovs merged commit 6f7b2f1 into VictoriaMetrics:master Jun 17, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add patchMergeKey to VMRule CRDs

3 participants