feat: add label intersection mode for precise pod targeting#777
feat: add label intersection mode for precise pod targeting#777XploY04 wants to merge 6 commits intolitmuschaos:masterfrom
Conversation
|
HI @XploY04 , We need to first add the below pre-requisites changes in chaos-operator: The First we need to update the workload schema to include a new field named Based on this field, we should modify the logic to append the value after the colon ( Finally, regenerate the CRDs to reflect these schema changes by running |
|
Hey @ispeakc0de, I've created the prerequisite PR in chaos-operator as requested: litmuschaos/chaos-operator#510 This adds the I initially thought users could simply override TARGETS via env vars (which does work), but I understand now that a schema-based approach provides better UX, validation, and maintainability. Please let me know if any changes are needed! |
| data := AppDetails{ | ||
| Kind: val[0], | ||
| Namespace: val[1], | ||
| Kind: val[0], |
There was a problem hiding this comment.
Can we check for array length to avoid array index out of bound?
There was a problem hiding this comment.
raise an error if len(val) < 3
…el matching for pod selection Signed-off-by: XploY04 <2004agarwalyash@gmail.com>
… modes Signed-off-by: XploY04 <2004agarwalyash@gmail.com>
…l selector for intersection matching Signed-off-by: XploY04 <2004agarwalyash@gmail.com>
… format Signed-off-by: XploY04 <2004agarwalyash@gmail.com>
|
Hey @ispeakc0de @neelanjan00 , please review and merge. |
What this PR does / why we need it:
This PR adds support for label intersection mode when selecting target pods for chaos experiments, enabling precise pod targeting by matching ALL specified labels (AND logic) instead of the default union behavior that matches ANY label (OR logic).
Problem: Currently, multiple labels use UNION (OR) logic - selecting pods that match ANY label. This causes unintended pod selection when precise targeting is needed (e.g., "primary role AND specific cluster"). As noted in issue #774, when working with CloudNativePG clusters that have multiple instances with different roles, the union behavior selects too many pods.
Solution: Adds optional 4th parameter to TARGETS env variable:
Where mode can be
union(default) orintersectionExample:
Changes:
LabelMatchModefield toAppDetailsstructgetPodsWithIntersectionLabels()functionGetTargets()to parse optional mode parameterBackward Compatibility: Fully compatible - defaults to union mode
Which issue this PR fixes : fixes #774
Use Cases:
Checklist:
breaking-changestag - Not applicable (backward compatible)requires-upgradetag - Not applicablepkg/types/types_test.go)