Description
What would you like to be added:
KSM default configuration generation should be moved into a more generic solution.
Currently it's indirectly done defining and parsing the cli flags in https://github.com/kubernetes/kube-state-metrics/blob/main/pkg/options/options.go#L102
Why is this needed:
Assume you are a provider of an own controller with own CRDs.
With that you want to ship a very opinionated monitoring-binary which is in fact a re-packaged ksm
.
example code:
package main
import (
"context"
ksm "k8s.io/kube-state-metrics/v2/pkg/app"
"k8s.io/kube-state-metrics/v2/pkg/options"
)
var (
//go:embed resource_config.yaml
resourceConfig string
)
func main() {
ctx := context.Background()
opts := options.NewOptions()
opts.Kubeconfig = "/tmp/my-kubeconfig"
opts.CustomResourcesOnly = true
opts.CustomResourceConfig = resourceConfig
opts.Port = 8080
// opts.ServerReadTimeout = 60 * time.Second
// opts.ServerWriteTimeout = 60 * time.Second
// opts.ServerIdleTimeout = 5 * time.Minute
// opts.ServerReadHeaderTimeout = 5 * time.Second
opts.TotalShards = 1
ksm.RunKubeStateMetricsWrapper(ctx, opts)
}
You have to know all the values from the Options
struct, otherwise your self-build KSM won't start (e.g. opts.TotalShards
is an int
and without setting it explicitly to 1
, the default value will be 0
... and with that you will never get any metrics if you try to scrape them.
Describe the solution you'd like
options.NewOptions()
is doing the default-value generation.
Additional context
This is some kind of a theoretical problem. I've stumbled over that once I've supported a User in KSM slack
with his very custom deployment method. (xref: slack thread in kube-state-metrics
)
If this seems to be a valid use-case, I'm happy to take over the necessary implementation steps.