Skip to content

Commit c0a03ad

Browse files
authored
Merge pull request #1813 from bavarianbidi/crd_only_mode
introduce custom-resources-only flag ...
2 parents d5bd2c8 + 53af116 commit c0a03ad

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

docs/cli-arguments.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ Usage of ./kube-state-metrics:
3030
--apiserver string The URL of the apiserver to use as a master
3131
--custom-resource-state-config string Inline Custom Resource State Metrics config YAML (experimental)
3232
--custom-resource-state-config-file string Path to a Custom Resource State Metrics config file (experimental)
33+
--custom-resource-state-only Only provide Custom Resource State metrics (experimental)
3334
--enable-gzip-encoding Gzip responses when requested by clients via 'Accept-Encoding: gzip' header.
3435
-h, --help Print Help text
3536
--host string Host to expose metrics on. (default "::")

pkg/app/server.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,21 @@ func RunKubeStateMetrics(ctx context.Context, opts *options.Options, factories .
8888
storeBuilder.WithMetrics(ksmMetricsRegistry)
8989

9090
var resources []string
91-
if len(opts.Resources) == 0 {
91+
switch {
92+
case len(opts.Resources) == 0 && !opts.CustomResourcesOnly:
9293
klog.InfoS("Used default resources")
9394
resources = options.DefaultResources.AsSlice()
9495
// enable custom resource
9596
for _, factory := range factories {
9697
resources = append(resources, factory.Name())
9798
}
98-
} else {
99+
case opts.CustomResourcesOnly:
100+
// enable custom resource only
101+
for _, factory := range factories {
102+
resources = append(resources, factory.Name())
103+
}
104+
klog.InfoS("Used CRD resources only", "resources", resources)
105+
default:
99106
klog.InfoS("Used resources", "resources", opts.Resources.String())
100107
resources = opts.Resources.AsSlice()
101108
}

pkg/options/options.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ type Options struct {
5757

5858
CustomResourceConfig string
5959
CustomResourceConfigFile string
60+
CustomResourcesOnly bool
6061

6162
flags *pflag.FlagSet
6263
}
@@ -123,6 +124,7 @@ func (o *Options) AddFlags() {
123124

124125
o.flags.StringVar(&o.CustomResourceConfig, "custom-resource-state-config", "", "Inline Custom Resource State Metrics config YAML (experimental)")
125126
o.flags.StringVar(&o.CustomResourceConfigFile, "custom-resource-state-config-file", "", "Path to a Custom Resource State Metrics config file (experimental)")
127+
o.flags.BoolVar(&o.CustomResourcesOnly, "custom-resource-state-only", false, "Only provide Custom Resource State metrics (experimental)")
126128
}
127129

128130
// Parse parses the flag definitions from the argument list.

0 commit comments

Comments
 (0)