diff --git a/docs/cli-arguments.md b/docs/cli-arguments.md index 7f7ee451ab..5d6881c37f 100644 --- a/docs/cli-arguments.md +++ b/docs/cli-arguments.md @@ -47,6 +47,7 @@ Usage of ./kube-state-metrics: --namespaces string Comma-separated list of namespaces to be enabled. Defaults to "" --namespaces-denylist string Comma-separated list of namespaces not to be enabled. If namespaces and namespaces-denylist are both set, only namespaces that are excluded in namespaces-denylist will be used. --one_output If true, only write logs to their native severity level (vs also writing to each lower severity level; no effect when -logtostderr=true) + --options-config-file string Path to the kube-state-metrics options config file --pod string Name of the pod that contains the kube-state-metrics container. When set, it is expected that --pod and --pod-namespace are both set. Most likely this should be passed via the downward API. This is used for auto-detecting sharding. If set, this has preference over statically configured sharding. This is experimental, it may be removed without notice. --pod-namespace string Name of the namespace of the pod specified by --pod. When set, it is expected that --pod and --pod-namespace are both set. Most likely this should be passed via the downward API. This is used for auto-detecting sharding. If set, this has preference over statically configured sharding. This is experimental, it may be removed without notice. --port int Port to expose metrics on. (default 8080) diff --git a/pkg/app/server.go b/pkg/app/server.go index b076e8472b..b632b564e3 100644 --- a/pkg/app/server.go +++ b/pkg/app/server.go @@ -19,10 +19,11 @@ package app import ( "context" "fmt" - "io/ioutil" "net" "net/http" "net/http/pprof" + "os" + "path/filepath" "strconv" "time" @@ -69,6 +70,7 @@ func (pl promLogger) Log(v ...interface{}) error { return nil } +// RunKubeStateMetricsWrapper runs KSM with context cancellation. func RunKubeStateMetricsWrapper(ctx context.Context, opts *options.Options, factories ...customresource.RegistryFactory) error { err := runKubeStateMetrics(ctx, opts, factories...) if <-ctx.Done() == struct{}{} && ctx.Err() == context.Canceled { @@ -102,7 +104,7 @@ func runKubeStateMetrics(ctx context.Context, opts *options.Options, factories . // TODO: Should the options config file override flags? got := options.GetOptsConfigFile(*opts) if got != "" { - optsConfigFile, err := ioutil.ReadFile(got) + optsConfigFile, err := os.ReadFile(filepath.Clean(got)) if err != nil { return fmt.Errorf("failed to read opts config file: %v", err) } diff --git a/pkg/options/options.go b/pkg/options/options.go index ce26dbb7cf..6702c4333f 100644 --- a/pkg/options/options.go +++ b/pkg/options/options.go @@ -43,8 +43,8 @@ type Options struct { TotalShards int Pod string Namespace string - MetricDenylist MetricSet `yaml:"metric_denylist"` - MetricAllowlist MetricSet `yaml:"metric_allowlist"` + MetricDenylist MetricSet + MetricAllowlist MetricSet MetricOptInList MetricSet Version bool AnnotationsAllowList LabelsAllowList @@ -62,6 +62,7 @@ type Options struct { flags *pflag.FlagSet } +// GetOptsConfigFile is the getter for --options-config-file value. func GetOptsConfigFile(opt Options) string { return opt.optsConfigFile }