rename to --enable-unscheduled-pods-fetching

This commit is contained in:
Catherine Fang 2024-06-13 12:46:48 -04:00
parent 49e1170f67
commit 85f8a2c4cc
9 changed files with 19 additions and 11 deletions

View File

@ -282,7 +282,7 @@ spec:
fieldPath: spec.nodeName
```
To track metrics for unassigned pods, you need to add an additional deployment and set `--fetch-unscheduled-pods`, as shown in the following example:
To track metrics for unassigned pods, you need to add an additional deployment and set `--enable-unscheduled-pods-fetching`, as shown in the following example:
```
apiVersion: apps/v1
@ -295,7 +295,7 @@ spec:
name: kube-state-metrics
args:
- --resources=pods
- --fetch-unscheduled-pods
- --enable-unscheduled-pods-fetching
```
Other metrics can be sharded via [Horizontal sharding](#horizontal-sharding).

View File

@ -283,7 +283,7 @@ spec:
fieldPath: spec.nodeName
```
To track metrics for unassigned pods, you need to add an additional deployment and set `--fetch-unscheduled-pods`, as shown in the following example:
To track metrics for unassigned pods, you need to add an additional deployment and set `--enable-unscheduled-pods-fetching`, as shown in the following example:
```
apiVersion: apps/v1
@ -296,7 +296,7 @@ spec:
name: kube-state-metrics
args:
- --resources=pods
- --fetch-unscheduled-pods
- --enable-unscheduled-pods-fetching
```
Other metrics can be sharded via [Horizontal sharding](#horizontal-sharding).

View File

@ -48,7 +48,7 @@ Flags:
--custom-resource-state-config-file string Path to a Custom Resource State Metrics config file (experimental)
--custom-resource-state-only Only provide Custom Resource State metrics (experimental)
--enable-gzip-encoding Gzip responses when requested by clients via 'Accept-Encoding: gzip' header.
--fetch-unscheduled-pods This configuration is used in conjunction with node configuration. When this configuration is true, node configuration is empty and the metric of no scheduled pods is scraped. This is experimental.
--enable-unscheduled-pods-fetching This configuration is used in conjunction with node configuration. When this configuration is true, node configuration is empty and the metric of no scheduled pods is scraped. This is experimental.
-h, --help Print Help text
--host string Host to expose metrics on. (default "::")
--kubeconfig string Absolute path to the kubeconfig file

View File

@ -23,7 +23,7 @@ spec:
containers:
- args:
- --resources=pods
- --fetch-unscheduled-pods
- --enable-unscheduled-pods-fetching
image: registry.k8s.io/kube-state-metrics/kube-state-metrics:v2.13.0
livenessProbe:
httpGet:

View File

@ -377,7 +377,7 @@
local c = ksm.deployment.spec.template.spec.containers[0] {
args: [
'--resources=pods',
'--fetch-unscheduled-pods',
'--enable-unscheduled-pods-fetching',
],
name: shardksmname,
};
@ -410,7 +410,7 @@
local c = ksm.deployment.spec.template.spec.containers[0] {
args: [
'--resources=pods',
'--fetch-unscheduled-pods',
'--enable-unscheduled-pods-fetching',
],
};
local shardksmname = ksm.name + "-no-node-pods";

View File

@ -224,7 +224,7 @@ func RunKubeStateMetrics(ctx context.Context, opts *options.Options) error {
namespaces := opts.Namespaces.GetNamespaces()
nsFieldSelector := namespaces.GetExcludeNSFieldSelector(opts.NamespacesDenylist)
nodeFieldSelector := opts.Node.GetNodeFieldSelector(opts.FetchUnscheduledPods)
nodeFieldSelector := opts.Node.GetNodeFieldSelector(opts.EnableUnscheduledPodsFetching)
merged, err := storeBuilder.MergeFieldSelectors([]string{nsFieldSelector, nodeFieldSelector})
if err != nil {
return err

View File

@ -59,7 +59,7 @@ type Options struct {
Namespaces NamespaceList `yaml:"namespaces"`
NamespacesDenylist NamespaceList `yaml:"namespaces_denylist"`
Node NodeType `yaml:"node"`
FetchUnscheduledPods bool `yaml:"fetch_unscheduled_pods"`
EnableUnscheduledPodsFetching bool `yaml:"enable_unscheduled_pods_fetching"`
Pod string `yaml:"pod"`
Port int `yaml:"port"`
Resources ResourceSet `yaml:"resources"`
@ -138,7 +138,7 @@ func (o *Options) AddFlags(cmd *cobra.Command) {
o.cmd.Flags().BoolVar(&o.CustomResourcesOnly, "custom-resource-state-only", false, "Only provide Custom Resource State metrics (experimental)")
o.cmd.Flags().BoolVar(&o.EnableGZIPEncoding, "enable-gzip-encoding", false, "Gzip responses when requested by clients via 'Accept-Encoding: gzip' header.")
o.cmd.Flags().BoolVar(&o.FetchUnscheduledPods, "fetch-unscheduled-pods", false, "This configuration is used in conjunction with node configuration. When this configuration is true, node configuration is empty and the metric of no scheduled pods is scraped. This is experimental.")
o.cmd.Flags().BoolVar(&o.EnableUnscheduledPodsFetching, "enable-unscheduled-pods-fetching", false, "This configuration is used in conjunction with node configuration. When this configuration is true, node configuration is empty and the metric of no scheduled pods is scraped. This is experimental.")
o.cmd.Flags().BoolVarP(&o.Help, "help", "h", false, "Print Help text")
o.cmd.Flags().BoolVarP(&o.UseAPIServerCache, "use-apiserver-cache", "", false, "Sets resourceVersion=0 for ListWatch requests, using cached resources from the apiserver instead of an etcd quorum read.")
o.cmd.Flags().Int32Var(&o.Shard, "shard", int32(0), "The instances shard nominal (zero indexed) within the total number of shards. (default 0)")

View File

@ -110,6 +110,9 @@ type NodeType string
// GetNodeFieldSelector returns a nodename field selector.
func (n *NodeType) GetNodeFieldSelector(noNodeAssigned bool) string {
if noNodeAssigned {
if string(*n) != "" {
klog.Warningf("spec.nodeName=%s will not be used, because --enable-unscheduled-pods-fetching is set", string(*n))
}
klog.InfoS("Using spec.nodeName= to select unscheduable pods without node")
return "spec.nodeName="
}

View File

@ -190,6 +190,11 @@ func TestNodeFieldSelector(t *testing.T) {
Node: "",
Wanted: "spec.nodeName=",
},
{
Desc: "have node name when --enable-unscheduled-pods-fetching is set",
Node: "",
Wanted: "spec.nodeName=",
},
}
for _, test := range tests1 {
node := test.Node