Skip to content

Commit 66a6cae

Browse files
committed
Merge remote-tracking branch 'upstream/main'
2 parents 6bf2df6 + 535085e commit 66a6cae

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+436
-231
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ env:
2121
E2E_SETUP_KUBECTL: yes
2222
SUDO: sudo
2323
GO_VERSION: "^1.20"
24-
GOLANGCI_LINT_VERSION: "v1.53.3"
24+
GOLANGCI_LINT_VERSION: "v1.54.2"
2525

2626
jobs:
2727
ci-go-lint:

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ GIT_COMMIT ?= $(shell git rev-parse --short HEAD)
1515
OS ?= $(shell uname -s | tr A-Z a-z)
1616
ALL_ARCH = amd64 arm arm64 ppc64le s390x
1717
PKG = github.com/prometheus/common
18-
PROMETHEUS_VERSION = 2.45.0
19-
GO_VERSION = 1.20.6
18+
PROMETHEUS_VERSION = 2.46.0
19+
GO_VERSION = 1.20.7
2020
IMAGE = $(REGISTRY)/kube-state-metrics
2121
MULTI_ARCH_IMG = $(IMAGE)-$(ARCH)
2222
USER ?= $(shell id -u -n)

docs/cli-arguments.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ Flags:
5353
--log_file_max_size uint Defines the maximum size a log file can grow to (no effect when -logtostderr=true). Unit is megabytes. If the value is 0, the maximum file size is unlimited. (default 1800)
5454
--logtostderr log to standard error instead of files (default true)
5555
--metric-allowlist string Comma-separated list of metrics to be exposed. This list comprises of exact metric names and/or regex patterns. The allowlist and denylist are mutually exclusive.
56-
--metric-annotations-allowlist string Comma-separated list of Kubernetes annotations keys that will be used in the resource' labels metric. By default the metric contains only name and namespace labels. To include additional annotations provide a list of resource names in their plural form and Kubernetes annotation keys you would like to allow for them (Example: '=namespaces=[kubernetes.io/team,...],pods=[kubernetes.io/team],...)'. A single '*' can be provided per resource instead to allow any annotations, but that has severe performance implications (Example: '=pods=[*]').
56+
--metric-annotations-allowlist string Comma-separated list of Kubernetes annotations keys that will be used in the resource' labels metric. By default the annotations metrics are not exposed. To include them, provide a list of resource names in their plural form and Kubernetes annotation keys you would like to allow for them (Example: '=namespaces=[kubernetes.io/team,...],pods=[kubernetes.io/team],...)'. A single '*' can be provided per resource instead to allow any annotations, but that has severe performance implications (Example: '=pods=[*]').
5757
--metric-denylist string Comma-separated list of metrics not to be enabled. This list comprises of exact metric names and/or regex patterns. The allowlist and denylist are mutually exclusive.
58-
--metric-labels-allowlist string Comma-separated list of additional Kubernetes label keys that will be used in the resource' labels metric. By default the metric contains only name and namespace labels. To include additional labels provide a list of resource names in their plural form and Kubernetes label keys you would like to allow for them (Example: '=namespaces=[k8s-label-1,k8s-label-n,...],pods=[app],...)'. A single '*' can be provided per resource instead to allow any labels, but that has severe performance implications (Example: '=pods=[*]'). Additionally, an asterisk (*) can be provided as a key, which will resolve to all resources, i.e., assuming '--resources=deployments,pods', '=*=[*]' will resolve to '=deployments=[*],pods=[*]'.
58+
--metric-labels-allowlist string Comma-separated list of additional Kubernetes label keys that will be used in the resource' labels metric. By default the labels metrics are not exposed. To include them, provide a list of resource names in their plural form and Kubernetes label keys you would like to allow for them (Example: '=namespaces=[k8s-label-1,k8s-label-n,...],pods=[app],...)'. A single '*' can be provided per resource instead to allow any labels, but that has severe performance implications (Example: '=pods=[*]'). Additionally, an asterisk (*) can be provided as a key, which will resolve to all resources, i.e., assuming '--resources=deployments,pods', '=*=[*]' will resolve to '=deployments=[*],pods=[*]'.
5959
--metric-opt-in-list string Comma-separated list of metrics which are opt-in and not enabled by default. This is in addition to the metric allow- and denylists
6060
--namespaces string Comma-separated list of namespaces to be enabled. Defaults to ""
6161
--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.

docs/pod-metrics.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
| kube_pod_container_status_last_terminated_reason | Gauge | Describes the last reason the container was in terminated state | | `container`=&lt;container-name&gt; <br> `pod`=&lt;pod-name&gt; <br> `namespace`=&lt;pod-namespace&gt; <br> `reason`=&lt;last-terminated-reason&gt; <br> `uid`=&lt;pod-uid&gt; | EXPERIMENTAL | - |
2525
| kube_pod_container_status_last_terminated_exitcode | Gauge | Describes the exit code for the last container in terminated state. | | `container`=&lt;container-name&gt; <br> `pod`=&lt;pod-name&gt; <br> `namespace`=&lt;pod-namespace&gt; <br> `uid`=&lt;pod-uid&gt; | EXPERIMENTAL | - |
2626
| kube_pod_container_status_ready | Gauge | Describes whether the containers readiness check succeeded | | `container`=&lt;container-name&gt; <br> `pod`=&lt;pod-name&gt; <br> `namespace`=&lt;pod-namespace&gt; <br> `uid`=&lt;pod-uid&gt; | STABLE | - |
27+
| kube_pod_status_initialized_time | Gauge | Time when the pod is initialized. | seconds | `pod`=&lt;pod-name&gt; <br> `namespace`=&lt;pod-namespace&gt; <br> `uid`=&lt;pod-uid&gt; | EXPERIMENTAL |
2728
| kube_pod_status_ready_time | Gauge | Time when pod passed readiness probes. | seconds | `pod`=&lt;pod-name&gt; <br> `namespace`=&lt;pod-namespace&gt; <br> `uid`=&lt;pod-uid&gt; | EXPERIMENTAL |
2829
| kube_pod_status_container_ready_time | Gauge | Time when the container of the pod entered Ready state. | seconds | `pod`=&lt;pod-name&gt; <br> `namespace`=&lt;pod-namespace&gt; <br> `uid`=&lt;pod-uid&gt; | EXPERIMENTAL |
2930
| kube_pod_container_status_restarts_total | Counter | The number of container restarts per container | | `container`=&lt;container-name&gt; <br> `namespace`=&lt;pod-namespace&gt; <br> `pod`=&lt;pod-name&gt; <br> `uid`=&lt;pod-uid&gt; | STABLE | - |

docs/resourcequota-metrics.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# ResourceQuota Metrics
22

3-
| Metric name | Metric type | Labels/tags | Status |
4-
| -------------------------- | ----------- | ----------------------------------------------------------------------------------------------------------------------------------------- | ------ |
5-
| kube_resourcequota | Gauge | `resourcequota`=&lt;quota-name&gt; <br> `namespace`=&lt;namespace&gt; <br> `resource`=&lt;ResourceName&gt; <br> `type`=&lt;quota-type&gt; | STABLE |
6-
| kube_resourcequota_created | Gauge | `resourcequota`=&lt;quota-name&gt; <br> `namespace`=&lt;namespace&gt; | STABLE |
3+
| Metric name | Metric type | Labels/tags | Status |
4+
| ------------------------------ | ----------- | --------------------------------------------------------------------------------------------------------------------------------------------------- | ------------ |
5+
| kube_resourcequota | Gauge | `resourcequota`=&lt;quota-name&gt; <br> `namespace`=&lt;namespace&gt; <br> `resource`=&lt;ResourceName&gt; <br> `type`=&lt;quota-type&gt; | STABLE |
6+
| kube_resourcequota_created | Gauge | `resourcequota`=&lt;quota-name&gt; <br> `namespace`=&lt;namespace&gt; | STABLE |
7+
| kube_resourcequota_annotations | Gauge | `resourcequota`=&lt;quota-name&gt; <br> `namespace`=&lt;namespace&gt; <br> `annotation_RESOURCE_QUOTA_ANNOTATION`=&lt;RESOURCE_QUOTA_ANNOTATION&gt; | EXPERIMENTAL |
8+
| kube_resourcequota_labels | Gauge | `resourcequota`=&lt;quota-name&gt; <br> `namespace`=&lt;namespace&gt; <br> `label_RESOURCE_QUOTA_LABEL`=&lt;RESOURCE_QUOTA_LABEL&gt; | EXPERIMENTAL |

go.mod

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ require (
1717
github.com/spf13/viper v1.16.0
1818
github.com/stretchr/testify v1.8.4
1919
gopkg.in/yaml.v3 v3.0.1
20-
k8s.io/api v0.27.4
21-
k8s.io/apimachinery v0.27.4
22-
k8s.io/client-go v0.27.4
23-
k8s.io/component-base v0.27.4
20+
k8s.io/api v0.27.5
21+
k8s.io/apimachinery v0.27.5
22+
k8s.io/client-go v0.27.5
23+
k8s.io/component-base v0.27.5
2424
k8s.io/klog/v2 v2.100.1
25-
k8s.io/sample-controller v0.27.4
26-
k8s.io/utils v0.0.0-20230711102312-30195339c3c7
25+
k8s.io/sample-controller v0.27.5
26+
k8s.io/utils v0.0.0-20230726121419-3b25d923346b
2727
)
2828

2929
require (

go.sum

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -606,22 +606,22 @@ honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWh
606606
honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg=
607607
honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
608608
honnef.co/go/tools v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
609-
k8s.io/api v0.27.4 h1:0pCo/AN9hONazBKlNUdhQymmnfLRbSZjd5H5H3f0bSs=
610-
k8s.io/api v0.27.4/go.mod h1:O3smaaX15NfxjzILfiln1D8Z3+gEYpjEpiNA/1EVK1Y=
611-
k8s.io/apimachinery v0.27.4 h1:CdxflD4AF61yewuid0fLl6bM4a3q04jWel0IlP+aYjs=
612-
k8s.io/apimachinery v0.27.4/go.mod h1:XNfZ6xklnMCOGGFNqXG7bUrQCoR04dh/E7FprV6pb+E=
613-
k8s.io/client-go v0.27.4 h1:vj2YTtSJ6J4KxaC88P4pMPEQECWMY8gqPqsTgUKzvjk=
614-
k8s.io/client-go v0.27.4/go.mod h1:ragcly7lUlN0SRPk5/ZkGnDjPknzb37TICq07WhI6Xc=
615-
k8s.io/component-base v0.27.4 h1:Wqc0jMKEDGjKXdae8hBXeskRP//vu1m6ypC+gwErj4c=
616-
k8s.io/component-base v0.27.4/go.mod h1:hoiEETnLc0ioLv6WPeDt8vD34DDeB35MfQnxCARq3kY=
609+
k8s.io/api v0.27.5 h1:49hIzqJNSuOQpA53MMihgAS4YDcQitTy58B9PMFthLc=
610+
k8s.io/api v0.27.5/go.mod h1:zjBZB+c0KDU55Wxb9Bob9WZGxu9zdKHitzHxBtaIVoA=
611+
k8s.io/apimachinery v0.27.5 h1:6Q5HBXYJJPisd6yDVAprLe6FQsmw7a7Cu69dcrpQET8=
612+
k8s.io/apimachinery v0.27.5/go.mod h1:XNfZ6xklnMCOGGFNqXG7bUrQCoR04dh/E7FprV6pb+E=
613+
k8s.io/client-go v0.27.5 h1:sH/fkqzk35kuf0GPx+dZuN7fhEswBSAVCrWFq3E1km0=
614+
k8s.io/client-go v0.27.5/go.mod h1:u+IKnqPZSPw51snIMKiIAV8LQQ+hya5bvxpOOPTUXPI=
615+
k8s.io/component-base v0.27.5 h1:IXo80yOVx7qXG2g1loPpo2g1HUK3CnxNpq9LtGmXAmM=
616+
k8s.io/component-base v0.27.5/go.mod h1:AGJyFHmaxplY4C4lu18UrJBNHcxdv0o6jOL/+HcC0S0=
617617
k8s.io/klog/v2 v2.100.1 h1:7WCHKK6K8fNhTqfBhISHQ97KrnJNFZMcQvKp7gP/tmg=
618618
k8s.io/klog/v2 v2.100.1/go.mod h1:y1WjHnz7Dj687irZUWR/WLkLc5N1YHtjLdmgWjndZn0=
619619
k8s.io/kube-openapi v0.0.0-20230501164219-8b0f38b5fd1f h1:2kWPakN3i/k81b0gvD5C5FJ2kxm1WrQFanWchyKuqGg=
620620
k8s.io/kube-openapi v0.0.0-20230501164219-8b0f38b5fd1f/go.mod h1:byini6yhqGC14c3ebc/QwanvYwhuMWF6yz2F8uwW8eg=
621-
k8s.io/sample-controller v0.27.4 h1:oeKVVOWw+fVaZVWCw3l9myrAoNUqR8A4BcA91fyyZaU=
622-
k8s.io/sample-controller v0.27.4/go.mod h1:bfGT2cEyzWjfCqVSrWPbNsym9MkgKz7Z7Bwl0tjysOo=
623-
k8s.io/utils v0.0.0-20230711102312-30195339c3c7 h1:ZgnF1KZsYxWIifwSNZFZgNtWE89WI5yiP5WwlfDoIyc=
624-
k8s.io/utils v0.0.0-20230711102312-30195339c3c7/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0=
621+
k8s.io/sample-controller v0.27.5 h1:N3mMPdEFJ8gdn7HMCIecnTU7h6YVfVJjSDt72nxAocc=
622+
k8s.io/sample-controller v0.27.5/go.mod h1:KtTxV9H5DpvbU5WpM2o/Cpv/fuZykJhqBqCJdNfFRpg=
623+
k8s.io/utils v0.0.0-20230726121419-3b25d923346b h1:sgn3ZU783SCgtaSJjpcVVlRqd6GSnlTLKgpAAttJvpI=
624+
k8s.io/utils v0.0.0-20230726121419-3b25d923346b/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0=
625625
rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8=
626626
rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0=
627627
rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA=

internal/store/builder.go

Lines changed: 2 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,6 @@ import (
3838
policyv1 "k8s.io/api/policy/v1"
3939
rbacv1 "k8s.io/api/rbac/v1"
4040
storagev1 "k8s.io/api/storage/v1"
41-
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
42-
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
43-
"k8s.io/apimachinery/pkg/runtime/schema"
44-
"k8s.io/client-go/discovery"
4541
clientset "k8s.io/client-go/kubernetes"
4642
"k8s.io/client-go/tools/cache"
4743
"k8s.io/klog/v2"
@@ -431,7 +427,7 @@ func (b *Builder) buildReplicationControllerStores() []cache.Store {
431427
}
432428

433429
func (b *Builder) buildResourceQuotaStores() []cache.Store {
434-
return b.buildStoresFunc(resourceQuotaMetricFamilies, &v1.ResourceQuota{}, createResourceQuotaListWatch, b.useAPIServerCache)
430+
return b.buildStoresFunc(resourceQuotaMetricFamilies(b.allowAnnotationsList["resourcequotas"], b.allowLabelsList["resourcequotas"]), &v1.ResourceQuota{}, createResourceQuotaListWatch, b.useAPIServerCache)
435431
}
436432

437433
func (b *Builder) buildSecretStores() []cache.Store {
@@ -544,10 +540,7 @@ func (b *Builder) buildCustomResourceStores(resourceName string,
544540
metricFamilies = generator.FilterFamilyGenerators(b.familyGeneratorFilter, metricFamilies)
545541
composedMetricGenFuncs := generator.ComposeMetricGenFuncs(metricFamilies)
546542

547-
var familyHeaders []string
548-
if b.hasResources(resourceName, expectedType) {
549-
familyHeaders = generator.ExtractMetricFamilyHeaders(metricFamilies)
550-
}
543+
familyHeaders := generator.ExtractMetricFamilyHeaders(metricFamilies)
551544

552545
gvr := util.GVRFromType(resourceName, expectedType)
553546
var gvrString string
@@ -590,65 +583,6 @@ func (b *Builder) buildCustomResourceStores(resourceName string,
590583
return stores
591584
}
592585

593-
func (b *Builder) hasResources(resourceName string, expectedType interface{}) bool {
594-
gvr := util.GVRFromType(resourceName, expectedType)
595-
if gvr == nil {
596-
return true
597-
}
598-
discoveryClient, err := util.CreateDiscoveryClient(b.utilOptions.Apiserver, b.utilOptions.Kubeconfig)
599-
if err != nil {
600-
klog.ErrorS(err, "Failed to create discovery client")
601-
return false
602-
}
603-
g := gvr.Group
604-
v := gvr.Version
605-
r := gvr.Resource
606-
isCRDInstalled, err := discovery.IsResourceEnabled(discoveryClient, schema.GroupVersionResource{
607-
Group: g,
608-
Version: v,
609-
Resource: r,
610-
})
611-
if err != nil {
612-
klog.ErrorS(err, "Failed to check if CRD is enabled", "group", g, "version", v, "resource", r)
613-
return false
614-
}
615-
if !isCRDInstalled {
616-
klog.InfoS("CRD is not installed", "group", g, "version", v, "resource", r)
617-
return false
618-
}
619-
// Wait for the resource to come up.
620-
timer := time.NewTimer(ResourceDiscoveryTimeout)
621-
ticker := time.NewTicker(ResourceDiscoveryInterval)
622-
dynamicClient, err := util.CreateDynamicClient(b.utilOptions.Apiserver, b.utilOptions.Kubeconfig)
623-
if err != nil {
624-
klog.ErrorS(err, "Failed to create dynamic client")
625-
return false
626-
}
627-
var list *unstructured.UnstructuredList
628-
for range ticker.C {
629-
select {
630-
case <-timer.C:
631-
klog.InfoS("No CRs found for GVR", "group", g, "version", v, "resource", r)
632-
return false
633-
default:
634-
list, err = dynamicClient.Resource(schema.GroupVersionResource{
635-
Group: g,
636-
Version: v,
637-
Resource: r,
638-
}).List(b.ctx, metav1.ListOptions{})
639-
if err != nil {
640-
klog.ErrorS(err, "Failed to list objects", "group", g, "version", v, "resource", r)
641-
return false
642-
}
643-
}
644-
if len(list.Items) > 0 {
645-
break
646-
}
647-
}
648-
649-
return true
650-
}
651-
652586
// startReflector starts a Kubernetes client-go reflector with the given
653587
// listWatcher and registers it with the given store.
654588
func (b *Builder) startReflector(

internal/store/certificatesigningrequest.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ func csrMetricFamilies(allowAnnotationsList, allowLabelsList []string) []generat
4949
basemetrics.ALPHA,
5050
"",
5151
wrapCSRFunc(func(j *certv1.CertificateSigningRequest) *metric.Family {
52+
if len(allowAnnotationsList) == 0 {
53+
return &metric.Family{}
54+
}
5255
annotationKeys, annotationValues := createPrometheusLabelKeysValues("annotation", j.Annotations, allowAnnotationsList)
5356
return &metric.Family{
5457
Metrics: []*metric.Metric{
@@ -68,6 +71,9 @@ func csrMetricFamilies(allowAnnotationsList, allowLabelsList []string) []generat
6871
basemetrics.STABLE,
6972
"",
7073
wrapCSRFunc(func(j *certv1.CertificateSigningRequest) *metric.Family {
74+
if len(allowLabelsList) == 0 {
75+
return &metric.Family{}
76+
}
7177
labelKeys, labelValues := createPrometheusLabelKeysValues("label", j.Labels, allowLabelsList)
7278
return &metric.Family{
7379
Metrics: []*metric.Metric{

0 commit comments

Comments
 (0)