Skip to content

fix: AND multiple filters in the pod and cluster data sources - #338

Open
nagaboinaramgopal wants to merge 1 commit into
apache:mainfrom
nagaboinaramgopal:fix/pod-cluster-datasource-and-filters
Open

fix: AND multiple filters in the pod and cluster data sources#338
nagaboinaramgopal wants to merge 1 commit into
apache:mainfrom
nagaboinaramgopal:fix/pod-cluster-datasource-and-filters

Conversation

@nagaboinaramgopal

Copy link
Copy Markdown

Description

applyPodFilters (data_source_cloudstack_pod.go) and applyClusterFilters (data_source_cloudstack_cluster.go) returned true as 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:

data "cloudstack_pod" "p" {
  filter { name = "name"             value = "pod-a" }
  filter { name = "allocation_state" value = "Disabled" }
}

selects a pod named pod-a even when it is actually Enabled, 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 false the moment a filter does not match and true only after all match. This aligns pod and cluster with that established behaviour.

Testing

Added unit tests TestApplyPodFiltersAreAndedNotOred and TestApplyClusterFiltersAreAndedNotOred asserting 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:

go test ./cloudstack/ -run 'TestApply(Pod|Cluster)FiltersAreAndedNotOred'

The tests fail against the current code and pass with the fix.

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>
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.

1 participant