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

fix: duplicate custom resources #2066

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
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
13 changes: 7 additions & 6 deletions pkg/app/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (
_ "k8s.io/client-go/plugin/pkg/client/auth" // Initialize common client auth plugins.
"k8s.io/client-go/tools/clientcmd"
"k8s.io/klog/v2"
"k8s.io/apimachinery/pkg/util/sets"

"github.com/oklog/run"
"github.com/prometheus/client_golang/prometheus"
Expand Down Expand Up @@ -184,25 +185,25 @@ func RunKubeStateMetrics(ctx context.Context, opts *options.Options) error {

}

resources := make([]string, len(factories))
resources := sets.New[string]()

for i, factory := range factories {
resources[i] = factory.Name()
for _, factory := range factories {
resources.Insert(factory.Name())
}

switch {
case len(opts.Resources) == 0 && !opts.CustomResourcesOnly:
resources = append(resources, options.DefaultResources.AsSlice()...)
resources.Insert(options.DefaultResources.AsSlice()...)
klog.InfoS("Used default resources")
case opts.CustomResourcesOnly:
// enable custom resource only, these resources will be populated later on
klog.InfoS("Used CRD resources only")
default:
resources = append(resources, opts.Resources.AsSlice()...)
resources.Insert(opts.Resources.AsSlice()...)
klog.InfoS("Used resources", "resources", resources)
}

if err := storeBuilder.WithEnabledResources(resources); err != nil {
if err := storeBuilder.WithEnabledResources(resources.UnsortedList()); err != nil {
return fmt.Errorf("failed to set up resources: %v", err)
}

Expand Down
Loading