Handle singular labels in allowlist
Handle singular labels in allowlist failing when such a label is supplied, in order to keep the behaviour in sync with --resources. Signed-off-by: Pranshu Srivastava <rexagod@gmail.com>
This commit is contained in:
parent
734389481a
commit
052f572ae7
|
|
@ -200,10 +200,16 @@ func (b *Builder) WithAllowAnnotations(annotations map[string][]string) {
|
|||
}
|
||||
|
||||
// WithAllowLabels configures which labels can be returned for metrics
|
||||
func (b *Builder) WithAllowLabels(labels map[string][]string) {
|
||||
func (b *Builder) WithAllowLabels(labels map[string][]string) error {
|
||||
if len(labels) > 0 {
|
||||
for label := range labels {
|
||||
if !resourceExists(label) {
|
||||
return fmt.Errorf("resource %s does not exist. Available resources: %s", label, strings.Join(availableResources(), ","))
|
||||
}
|
||||
}
|
||||
b.allowLabelsList = labels
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Build initializes and registers all enabled stores.
|
||||
|
|
|
|||
|
|
@ -149,7 +149,9 @@ func RunKubeStateMetrics(ctx context.Context, opts *options.Options, factories .
|
|||
storeBuilder.WithCustomResourceClients(customResourceClients)
|
||||
storeBuilder.WithSharding(opts.Shard, opts.TotalShards)
|
||||
storeBuilder.WithAllowAnnotations(opts.AnnotationsAllowList)
|
||||
storeBuilder.WithAllowLabels(opts.LabelsAllowList)
|
||||
if err := storeBuilder.WithAllowLabels(opts.LabelsAllowList); err != nil {
|
||||
return fmt.Errorf("failed to set up labels allowlist: %v", err)
|
||||
}
|
||||
|
||||
ksmMetricsRegistry.MustRegister(
|
||||
collectors.NewProcessCollector(collectors.ProcessCollectorOpts{}),
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ type BuilderInterface interface {
|
|||
WithUsingAPIServerCache(u bool)
|
||||
WithFamilyGeneratorFilter(l generator.FamilyGeneratorFilter)
|
||||
WithAllowAnnotations(a map[string][]string)
|
||||
WithAllowLabels(l map[string][]string)
|
||||
WithAllowLabels(l map[string][]string) error
|
||||
WithGenerateStoresFunc(f BuildStoresFunc)
|
||||
WithGenerateCustomResourceStoresFunc(f BuildCustomResourceStoresFunc)
|
||||
DefaultGenerateStoresFunc() BuildStoresFunc
|
||||
|
|
|
|||
Loading…
Reference in New Issue