-
Notifications
You must be signed in to change notification settings - Fork 3
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
Changes from 4 commits
09ae2e0
1ebc998
a78f53e
588dd07
a573d71
f6e3f51
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -303,8 +303,9 @@ func (csl *ConfigurationSettingLoader) CheckAndRefreshSentinels( | |
return sentinelChanged, eTags, NewArgumentError("spec.configuration.refresh", fmt.Errorf("refresh is not specified")) | ||
} | ||
refreshedETags := make(map[acpv1.Sentinel]*azcore.ETag) | ||
sentinels := getSentinels(provider.Spec.Configuration.Refresh.Monitoring.Sentinels) | ||
|
||
for _, sentinel := range provider.Spec.Configuration.Refresh.Monitoring.Sentinels { | ||
for _, sentinel := range sentinels { | ||
if eTag, ok := eTags[sentinel]; ok { | ||
// Initialize the updatedETags with the current eTags | ||
refreshedETags[sentinel] = eTag | ||
|
@@ -624,14 +625,14 @@ func GetSecret(ctx context.Context, | |
} | ||
|
||
func GetKeyValueFilters(acpSpec acpv1.AzureAppConfigurationProviderSpec) []acpv1.Selector { | ||
return deduplicateFilters(acpSpec.Configuration.Selectors) | ||
return deduplicateFilters(processEmptyLabelFilter(acpSpec.Configuration.Selectors)) | ||
} | ||
|
||
func GetFeatureFlagFilters(acpSpec acpv1.AzureAppConfigurationProviderSpec) []acpv1.Selector { | ||
featureFlagFilters := make([]acpv1.Selector, 0) | ||
|
||
if acpSpec.FeatureFlag != nil { | ||
featureFlagFilters = deduplicateFilters(acpSpec.FeatureFlag.Selectors) | ||
featureFlagFilters = deduplicateFilters(processEmptyLabelFilter(acpSpec.FeatureFlag.Selectors)) | ||
for i := 0; i < len(featureFlagFilters); i++ { | ||
if featureFlagFilters[i].KeyFilter != nil { | ||
prefixedFeatureFlagFilter := FeatureFlagKeyPrefix + *featureFlagFilters[i].KeyFilter | ||
|
@@ -643,6 +644,40 @@ func GetFeatureFlagFilters(acpSpec acpv1.AzureAppConfigurationProviderSpec) []ac | |
return featureFlagFilters | ||
} | ||
|
||
func getSentinels(sentinels []acpv1.Sentinel) []acpv1.Sentinel { | ||
var results []acpv1.Sentinel | ||
for _, sentinel := range sentinels { | ||
label := sentinel.Label | ||
if sentinel.Label != nil && len(*sentinel.Label) == 0 { | ||
label = nil | ||
} | ||
|
||
results = append(results, acpv1.Sentinel{ | ||
Key: sentinel.Key, | ||
Label: label, | ||
}) | ||
|
||
} | ||
return results | ||
} | ||
|
||
func processEmptyLabelFilter(filters []acpv1.Selector) []acpv1.Selector { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about rename to "normalizeLableFilter"? |
||
var result []acpv1.Selector | ||
for i := 0; i < len(filters); i++ { | ||
labelFilter := filters[i].LabelFilter | ||
if filters[i].LabelFilter != nil && len(*filters[i].LabelFilter) == 0 { | ||
labelFilter = nil | ||
} | ||
|
||
result = append(result, acpv1.Selector{ | ||
KeyFilter: filters[i].KeyFilter, | ||
LabelFilter: labelFilter, | ||
}) | ||
} | ||
|
||
return result | ||
} | ||
|
||
func deduplicateFilters(filters []acpv1.Selector) []acpv1.Selector { | ||
var result []acpv1.Selector | ||
findDuplicate := false | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -88,15 +88,15 @@ func (s *EtagSettingsClient) GetSettings(ctx context.Context, client *azappconfi | |
} | ||
|
||
func (s *SentinelSettingsClient) GetSettings(ctx context.Context, client *azappconfig.Client) (*SettingsResponse, error) { | ||
sentinelSetting, err := client.GetSetting(ctx, s.sentinel.Key, &azappconfig.GetSettingOptions{Label: &s.sentinel.Label, OnlyIfChanged: s.etag}) | ||
sentinelSetting, err := client.GetSetting(ctx, s.sentinel.Key, &azappconfig.GetSettingOptions{Label: s.sentinel.Label, OnlyIfChanged: s.etag}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need to do the same as |
||
if err != nil { | ||
var respErr *azcore.ResponseError | ||
if errors.As(err, &respErr) { | ||
var label string | ||
if s.sentinel.Label == "\x00" { // NUL is escaped to \x00 in golang | ||
if s.sentinel.Label == nil { // NUL is escaped to \x00 in golang | ||
label = "no" | ||
} else { | ||
label = fmt.Sprintf("'%s'", s.sentinel.Label) | ||
label = fmt.Sprintf("'%s'", *s.sentinel.Label) | ||
} | ||
switch respErr.StatusCode { | ||
case 404: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about rename to "normalizeSentinels" ?