Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set label filter to nil when it's empty string #70

Merged
merged 6 commits into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions internal/loader/configuraiton_setting_loader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1216,6 +1216,7 @@ func TestGetFilters(t *testing.T) {
two := "two"
three := "three"
labelString := "test"
emptyLabel := ""
testSpec := acpv1.AzureAppConfigurationProviderSpec{
Configuration: acpv1.AzureAppConfigurationKeyValueOptions{
Selectors: []acpv1.Selector{
Expand Down Expand Up @@ -1324,6 +1325,19 @@ func TestGetFilters(t *testing.T) {
assert.Equal(t, "test", *filters6[0].LabelFilter)
assert.Equal(t, "one", *filters6[1].KeyFilter)
assert.Nil(t, filters6[1].LabelFilter)

testSpec7 := acpv1.AzureAppConfigurationProviderSpec{
Configuration: acpv1.AzureAppConfigurationKeyValueOptions{
Selectors: []acpv1.Selector{
{KeyFilter: &one, LabelFilter: &emptyLabel},
},
},
}

filters7 := GetKeyValueFilters(testSpec7)
assert.Len(t, filters7, 1)
assert.Equal(t, "one", *filters7[0].KeyFilter)
assert.Nil(t, filters7[0].LabelFilter)
}

func TestCompare(t *testing.T) {
Expand Down
10 changes: 9 additions & 1 deletion internal/loader/configuration_setting_loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,15 @@ func deduplicateFilters(filters []acpv1.Selector) []acpv1.Selector {
}
}
if !findDuplicate {
result = append(result, filters[i])
labelFilter := filters[i].LabelFilter
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we should do the conversion while deduplicating the selectors, we need to do it more straightforwardly.

Copy link
Contributor

Choose a reason for hiding this comment

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

And what about the label for the sentinel?

// need to check if labelFilter is empty, if so, set it to nil
if labelFilter != nil && len(*labelFilter) == 0 {
labelFilter = nil
}
result = append(result, acpv1.Selector{
KeyFilter: filters[i].KeyFilter,
LabelFilter: labelFilter,
})
}
}
reverse(result)
Expand Down
Loading