undo changes in internal/store/builder.go

This commit is contained in:
Walther Lee 2024-09-30 09:21:42 -07:00
parent 294163d5d6
commit 7b375e9ef4
2 changed files with 7 additions and 15 deletions

View File

@ -107,26 +107,18 @@ func (b *Builder) WithMetrics(r prometheus.Registerer) {
// WithEnabledResources sets the enabledResources property of a Builder. // WithEnabledResources sets the enabledResources property of a Builder.
func (b *Builder) WithEnabledResources(r []string) error { func (b *Builder) WithEnabledResources(r []string) error {
enabledResources := map[string]bool{}
for _, er := range b.enabledResources {
enabledResources[er] = true
}
var newResources []string
for _, resource := range r { for _, resource := range r {
// validate that the resource exists and skip those that are already enabled
if !resourceExists(resource) { if !resourceExists(resource) {
return fmt.Errorf("resource %s does not exist. Available resources: %s", resource, strings.Join(availableResources(), ",")) return fmt.Errorf("resource %s does not exist. Available resources: %s", resource, strings.Join(availableResources(), ","))
} }
if _, ok := enabledResources[resource]; !ok {
newResources = append(newResources, resource)
}
}
if len(newResources) == 0 {
return nil
} }
b.enabledResources = append(b.enabledResources, newResources...) var sortedResources []string
sort.Strings(b.enabledResources) sortedResources = append(sortedResources, r...)
sort.Strings(sortedResources)
b.enabledResources = append(b.enabledResources, sortedResources...)
return nil return nil
} }

View File

@ -259,7 +259,7 @@ func TestVariableVKsDiscoveryAndResolution(t *testing.T) {
// Note: we use count to make sure that only one metrics handler is running, and we also want to validate that the // Note: we use count to make sure that only one metrics handler is running, and we also want to validate that the
// new metric is available and the old one was removed, otherwise, the response could come from the // new metric is available and the old one was removed, otherwise, the response could come from the
// previous handler before its context was cancelled, or maybe because it failed to be cancelled. // previous handler before its context was cancelled, or maybe because it failed to be cancelled.
if strings.Count(string(out), testUpdateCRDMetric) == 1 && !strings.Contains(string(out), testMetric) { if strings.Contains(string(out), testUpdateCRDMetric) && !strings.Contains(string(out), testMetric) {
klog.InfoS("metrics available", "metric", string(out)) klog.InfoS("metrics available", "metric", string(out))
// Signal the process to exit, since we know the metrics are being generated as expected. // Signal the process to exit, since we know the metrics are being generated as expected.
ch <- true ch <- true