From b06d352d050f25e4f65c050face2b77c18b923df Mon Sep 17 00:00:00 2001 From: Cedric Lamoriniere Date: Wed, 15 Feb 2023 13:00:05 +0100 Subject: [PATCH 1/5] fix: public Builder compatibility with the BuilderInterface --- pkg/builder/builder.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/pkg/builder/builder.go b/pkg/builder/builder.go index ba1f10bac1..828e956f14 100644 --- a/pkg/builder/builder.go +++ b/pkg/builder/builder.go @@ -32,6 +32,10 @@ import ( "k8s.io/kube-state-metrics/v2/pkg/options" ) +// Make sure the public Builder implements the public BuilderInterface. +// New internal Builder methods should be added to the public BuilderInterface. +var _ ksmtypes.BuilderInterface = &Builder{} + // Builder helps to build store. It follows the builder pattern // (https://en.wikipedia.org/wiki/Builder_pattern). type Builder struct { @@ -61,6 +65,11 @@ func (b *Builder) WithNamespaces(n options.NamespaceList) { b.internal.WithNamespaces(n) } +// WithFieldSelectorFilter sets the fieldSelector property of a Builder. +func (b *Builder) WithFieldSelectorFilter(fieldSelectorFilter string) { + b.internal.WithFieldSelectorFilter(fieldSelectorFilter) +} + // WithSharding sets the shard and totalShards property of a Builder. func (b *Builder) WithSharding(shard int32, totalShards int) { b.internal.WithSharding(shard, totalShards) @@ -103,8 +112,8 @@ func (b *Builder) WithAllowAnnotations(annotations map[string][]string) { } // WithAllowLabels configures which labels can be returned for metrics -func (b *Builder) WithAllowLabels(l map[string][]string) { - b.internal.WithAllowLabels(l) +func (b *Builder) WithAllowLabels(l map[string][]string) error { + return b.internal.WithAllowLabels(l) } // WithGenerateStoresFunc configures a custom generate store function From 63d2138ee49fb36d4b912a17c9243e90e5e3696d Mon Sep 17 00:00:00 2001 From: Pranshu Srivastava Date: Fri, 17 Feb 2023 00:07:02 +0530 Subject: [PATCH 2/5] Don't crash on non-existent path values Don't crash on non-existent path values in CRS. Signed-off-by: Pranshu Srivastava --- pkg/customresourcestate/registry_factory.go | 4 ++++ pkg/customresourcestate/registry_factory_test.go | 12 ++++++++++++ 2 files changed, 16 insertions(+) diff --git a/pkg/customresourcestate/registry_factory.go b/pkg/customresourcestate/registry_factory.go index 91bbde4735..ca825f26d6 100644 --- a/pkg/customresourcestate/registry_factory.go +++ b/pkg/customresourcestate/registry_factory.go @@ -430,6 +430,10 @@ func (c compiledGauge) value(it interface{}) (*eachValue, error) { Value: 0, }, nil } + // no it means no iterables were passed down, meaning that the path resolution never happened + if it == nil { + return nil, fmt.Errorf("got nil while resolving path") + } // Don't error if there was not a type-casting issue (`toFloat64`), but rather a failed lookup. return nil, nil } diff --git a/pkg/customresourcestate/registry_factory_test.go b/pkg/customresourcestate/registry_factory_test.go index bce47c1c4e..c1d6f1621c 100644 --- a/pkg/customresourcestate/registry_factory_test.go +++ b/pkg/customresourcestate/registry_factory_test.go @@ -18,6 +18,7 @@ package customresourcestate import ( "encoding/json" + "errors" "reflect" "testing" @@ -194,6 +195,17 @@ func Test_values(t *testing.T) { }, wantResult: []eachValue{ newEachValue(t, 1.6563744e+09), }}, + {name: "non-existent path", each: &compiledGauge{ + compiledCommon: compiledCommon{ + path: mustCompilePath(t, "foo"), + labelFromPath: map[string]valuePath{ + "name": mustCompilePath(t, "name"), + }, + }, + ValueFrom: mustCompilePath(t, "creationTimestamp"), + }, wantResult: nil, wantErrors: []error{ + errors.New("[foo]: got nil while resolving path"), + }}, {name: "array", each: &compiledGauge{ compiledCommon: compiledCommon{ path: mustCompilePath(t, "status", "condition_values"), From 08c4765d5fdeddca2bdb70a136b46eeaf800e208 Mon Sep 17 00:00:00 2001 From: Pranshu Srivastava Date: Fri, 17 Feb 2023 18:12:22 +0530 Subject: [PATCH 3/5] fixup! Don't crash on non-existent path values --- pkg/customresourcestate/registry_factory.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/customresourcestate/registry_factory.go b/pkg/customresourcestate/registry_factory.go index ca825f26d6..9b4674d9de 100644 --- a/pkg/customresourcestate/registry_factory.go +++ b/pkg/customresourcestate/registry_factory.go @@ -434,7 +434,7 @@ func (c compiledGauge) value(it interface{}) (*eachValue, error) { if it == nil { return nil, fmt.Errorf("got nil while resolving path") } - // Don't error if there was not a type-casting issue (`toFloat64`), but rather a failed lookup. + // Don't error if there was not a type-casting issue (`toFloat64`). return nil, nil } value, err := toFloat64(got, c.NilIsZero) From 2d4579e31df7c0251fabfd152a30347d62a844b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20R=C3=BCger?= Date: Fri, 17 Feb 2023 15:32:35 +0100 Subject: [PATCH 4/5] build: Bump to go 1.19.6 --- Makefile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 1622a01552..0ebf7d25fc 100644 --- a/Makefile +++ b/Makefile @@ -16,7 +16,7 @@ OS ?= $(shell uname -s | tr A-Z a-z) ALL_ARCH = amd64 arm arm64 ppc64le s390x PKG = github.com/prometheus/common PROMETHEUS_VERSION = 2.40.6 -GO_VERSION = 1.19.4 +GO_VERSION = 1.19.6 IMAGE = $(REGISTRY)/kube-state-metrics MULTI_ARCH_IMG = $(IMAGE)-$(ARCH) USER ?= $(shell id -u -n) @@ -66,7 +66,8 @@ build-local: build: kube-state-metrics kube-state-metrics: - ${DOCKER_CLI} run --rm -v "${PWD}:/go/src/k8s.io/kube-state-metrics" -w /go/src/k8s.io/kube-state-metrics -e GOOS=$(OS) -e GOARCH=$(ARCH) golang:${GO_VERSION} make build-local + # Need to update git setting to prevent failing builds due to https://github.com/docker-library/golang/issues/452 + ${DOCKER_CLI} run --rm -v "${PWD}:/go/src/k8s.io/kube-state-metrics" -w /go/src/k8s.io/kube-state-metrics -e GOOS=$(OS) -e GOARCH=$(ARCH) golang:${GO_VERSION} git config --global --add safe.directory "*" && make build-local test-unit: GOOS=$(shell uname -s | tr A-Z a-z) GOARCH=$(ARCH) $(TESTENVVAR) go test --race $(FLAGS) $(PKGS) From f6f119c1bffb7dc9bdf00a579f45f89fddd13a0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20R=C3=BCger?= Date: Mon, 20 Feb 2023 12:12:49 +0100 Subject: [PATCH 5/5] *: Cut v2.8.1 --- CHANGELOG.md | 5 +++++ README.md | 4 ++-- VERSION | 2 +- examples/autosharding/cluster-role-binding.yaml | 2 +- examples/autosharding/cluster-role.yaml | 2 +- examples/autosharding/role-binding.yaml | 2 +- examples/autosharding/role.yaml | 2 +- examples/autosharding/service-account.yaml | 2 +- examples/autosharding/service.yaml | 2 +- examples/autosharding/statefulset.yaml | 6 +++--- examples/standard/cluster-role-binding.yaml | 2 +- examples/standard/cluster-role.yaml | 2 +- examples/standard/deployment.yaml | 6 +++--- examples/standard/service-account.yaml | 2 +- examples/standard/service.yaml | 2 +- 15 files changed, 24 insertions(+), 19 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 60ed126642..39dd53d3a6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## v2.8.1 / 2023-02-22 + +* [BUGFIX] Don't crash on non-existent paths @rexagod #1998 +* [BUGFIX] Fix public Builder compatibility with BuilderInterface @clamoriniere #1994 + ## v2.8.0 / 2023-02-10 Note: The `--version` flag was removed as `kube-state-metrics version` also provides the same information. See #1956 diff --git a/README.md b/README.md index 0712cc1cac..85a1a41b3d 100644 --- a/README.md +++ b/README.md @@ -78,7 +78,7 @@ Generally, it is recommended to use the latest release of kube-state-metrics. If | **v2.5.0** | v1.24 | | **v2.6.0** | v1.24 | | **v2.7.0** | v1.25 | -| **v2.8.0** | v1.26 | +| **v2.8.1** | v1.26 | | **main** | v1.26 | @@ -91,7 +91,7 @@ release. #### Container Image The latest container image can be found at: -* `registry.k8s.io/kube-state-metrics/kube-state-metrics:v2.8.0` (arch: `amd64`, `arm`, `arm64`, `ppc64le` and `s390x`) +* `registry.k8s.io/kube-state-metrics/kube-state-metrics:v2.8.1` (arch: `amd64`, `arm`, `arm64`, `ppc64le` and `s390x`) ### Metrics Documentation diff --git a/VERSION b/VERSION index 834f262953..dbe5900654 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -2.8.0 +2.8.1 diff --git a/examples/autosharding/cluster-role-binding.yaml b/examples/autosharding/cluster-role-binding.yaml index 27a4cb32d4..fb3c5925a9 100644 --- a/examples/autosharding/cluster-role-binding.yaml +++ b/examples/autosharding/cluster-role-binding.yaml @@ -4,7 +4,7 @@ metadata: labels: app.kubernetes.io/component: exporter app.kubernetes.io/name: kube-state-metrics - app.kubernetes.io/version: 2.8.0 + app.kubernetes.io/version: 2.8.1 name: kube-state-metrics roleRef: apiGroup: rbac.authorization.k8s.io diff --git a/examples/autosharding/cluster-role.yaml b/examples/autosharding/cluster-role.yaml index 2772ca33d4..a22c1844f0 100644 --- a/examples/autosharding/cluster-role.yaml +++ b/examples/autosharding/cluster-role.yaml @@ -4,7 +4,7 @@ metadata: labels: app.kubernetes.io/component: exporter app.kubernetes.io/name: kube-state-metrics - app.kubernetes.io/version: 2.8.0 + app.kubernetes.io/version: 2.8.1 name: kube-state-metrics rules: - apiGroups: diff --git a/examples/autosharding/role-binding.yaml b/examples/autosharding/role-binding.yaml index 2a5a949cf4..507b97d378 100644 --- a/examples/autosharding/role-binding.yaml +++ b/examples/autosharding/role-binding.yaml @@ -4,7 +4,7 @@ metadata: labels: app.kubernetes.io/component: exporter app.kubernetes.io/name: kube-state-metrics - app.kubernetes.io/version: 2.8.0 + app.kubernetes.io/version: 2.8.1 name: kube-state-metrics namespace: kube-system roleRef: diff --git a/examples/autosharding/role.yaml b/examples/autosharding/role.yaml index 89388d87a7..bf0f46d173 100644 --- a/examples/autosharding/role.yaml +++ b/examples/autosharding/role.yaml @@ -4,7 +4,7 @@ metadata: labels: app.kubernetes.io/component: exporter app.kubernetes.io/name: kube-state-metrics - app.kubernetes.io/version: 2.8.0 + app.kubernetes.io/version: 2.8.1 name: kube-state-metrics namespace: kube-system rules: diff --git a/examples/autosharding/service-account.yaml b/examples/autosharding/service-account.yaml index 5ea655e3cc..ca291f8251 100644 --- a/examples/autosharding/service-account.yaml +++ b/examples/autosharding/service-account.yaml @@ -5,6 +5,6 @@ metadata: labels: app.kubernetes.io/component: exporter app.kubernetes.io/name: kube-state-metrics - app.kubernetes.io/version: 2.8.0 + app.kubernetes.io/version: 2.8.1 name: kube-state-metrics namespace: kube-system diff --git a/examples/autosharding/service.yaml b/examples/autosharding/service.yaml index 7457658c4c..d78ab8bc6a 100644 --- a/examples/autosharding/service.yaml +++ b/examples/autosharding/service.yaml @@ -4,7 +4,7 @@ metadata: labels: app.kubernetes.io/component: exporter app.kubernetes.io/name: kube-state-metrics - app.kubernetes.io/version: 2.8.0 + app.kubernetes.io/version: 2.8.1 name: kube-state-metrics namespace: kube-system spec: diff --git a/examples/autosharding/statefulset.yaml b/examples/autosharding/statefulset.yaml index 8865c4866f..a6a33687b2 100644 --- a/examples/autosharding/statefulset.yaml +++ b/examples/autosharding/statefulset.yaml @@ -4,7 +4,7 @@ metadata: labels: app.kubernetes.io/component: exporter app.kubernetes.io/name: kube-state-metrics - app.kubernetes.io/version: 2.8.0 + app.kubernetes.io/version: 2.8.1 name: kube-state-metrics namespace: kube-system spec: @@ -18,7 +18,7 @@ spec: labels: app.kubernetes.io/component: exporter app.kubernetes.io/name: kube-state-metrics - app.kubernetes.io/version: 2.8.0 + app.kubernetes.io/version: 2.8.1 spec: automountServiceAccountToken: true containers: @@ -34,7 +34,7 @@ spec: valueFrom: fieldRef: fieldPath: metadata.namespace - image: registry.k8s.io/kube-state-metrics/kube-state-metrics:v2.8.0 + image: registry.k8s.io/kube-state-metrics/kube-state-metrics:v2.8.1 livenessProbe: httpGet: path: /healthz diff --git a/examples/standard/cluster-role-binding.yaml b/examples/standard/cluster-role-binding.yaml index 27a4cb32d4..fb3c5925a9 100644 --- a/examples/standard/cluster-role-binding.yaml +++ b/examples/standard/cluster-role-binding.yaml @@ -4,7 +4,7 @@ metadata: labels: app.kubernetes.io/component: exporter app.kubernetes.io/name: kube-state-metrics - app.kubernetes.io/version: 2.8.0 + app.kubernetes.io/version: 2.8.1 name: kube-state-metrics roleRef: apiGroup: rbac.authorization.k8s.io diff --git a/examples/standard/cluster-role.yaml b/examples/standard/cluster-role.yaml index 2772ca33d4..a22c1844f0 100644 --- a/examples/standard/cluster-role.yaml +++ b/examples/standard/cluster-role.yaml @@ -4,7 +4,7 @@ metadata: labels: app.kubernetes.io/component: exporter app.kubernetes.io/name: kube-state-metrics - app.kubernetes.io/version: 2.8.0 + app.kubernetes.io/version: 2.8.1 name: kube-state-metrics rules: - apiGroups: diff --git a/examples/standard/deployment.yaml b/examples/standard/deployment.yaml index c62236e5bf..ecc14a3f88 100644 --- a/examples/standard/deployment.yaml +++ b/examples/standard/deployment.yaml @@ -4,7 +4,7 @@ metadata: labels: app.kubernetes.io/component: exporter app.kubernetes.io/name: kube-state-metrics - app.kubernetes.io/version: 2.8.0 + app.kubernetes.io/version: 2.8.1 name: kube-state-metrics namespace: kube-system spec: @@ -17,11 +17,11 @@ spec: labels: app.kubernetes.io/component: exporter app.kubernetes.io/name: kube-state-metrics - app.kubernetes.io/version: 2.8.0 + app.kubernetes.io/version: 2.8.1 spec: automountServiceAccountToken: true containers: - - image: registry.k8s.io/kube-state-metrics/kube-state-metrics:v2.8.0 + - image: registry.k8s.io/kube-state-metrics/kube-state-metrics:v2.8.1 livenessProbe: httpGet: path: /healthz diff --git a/examples/standard/service-account.yaml b/examples/standard/service-account.yaml index 5ea655e3cc..ca291f8251 100644 --- a/examples/standard/service-account.yaml +++ b/examples/standard/service-account.yaml @@ -5,6 +5,6 @@ metadata: labels: app.kubernetes.io/component: exporter app.kubernetes.io/name: kube-state-metrics - app.kubernetes.io/version: 2.8.0 + app.kubernetes.io/version: 2.8.1 name: kube-state-metrics namespace: kube-system diff --git a/examples/standard/service.yaml b/examples/standard/service.yaml index 7457658c4c..d78ab8bc6a 100644 --- a/examples/standard/service.yaml +++ b/examples/standard/service.yaml @@ -4,7 +4,7 @@ metadata: labels: app.kubernetes.io/component: exporter app.kubernetes.io/name: kube-state-metrics - app.kubernetes.io/version: 2.8.0 + app.kubernetes.io/version: 2.8.1 name: kube-state-metrics namespace: kube-system spec: