fix: AND multiple filters in the pod and cluster data sources - #338
Open
nagaboinaramgopal wants to merge 1 commit into
Open
fix: AND multiple filters in the pod and cluster data sources#338nagaboinaramgopal wants to merge 1 commit into
nagaboinaramgopal wants to merge 1 commit into
Conversation
applyPodFilters and applyClusterFilters returned true as soon as any single filter matched, so a data source with two or more filter blocks selected a resource that matched only one of them (for example a pod matching the name filter but not the allocation_state filter). Every other data source in the provider (instance, volume, template, and others) requires all filters to match. Return false as soon as a filter does not match, and true only after all filters have matched. Adds unit tests for both. Signed-off-by: Ramgopal Nagaboina <ramgopal.nagaboina.dev@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
applyPodFilters(data_source_cloudstack_pod.go) andapplyClusterFilters(data_source_cloudstack_cluster.go) returnedtrueas soon as any single filter block matched, so a data source with two or more filters selected a resource that matched only one of them. For example:selects a pod named
pod-aeven when it is actuallyEnabled, because the name filter alone short-circuits to a match. The result is silent selection of the wrong pod or cluster.Every other data source in the provider (instance, volume, template, and others) ANDs its filters: it returns
falsethe moment a filter does not match andtrueonly after all match. This aligns pod and cluster with that established behaviour.Testing
Added unit tests
TestApplyPodFiltersAreAndedNotOredandTestApplyClusterFiltersAreAndedNotOredasserting that a resource matching only one of two filters is not selected, and that a resource matching all filters is. They need no live CloudStack:The tests fail against the current code and pass with the fix.