From 6f76c2205f768838b18f5c73ad4b3cdb0c705b90 Mon Sep 17 00:00:00 2001 From: Mario Constanti Date: Tue, 3 Jan 2023 13:28:09 +0100 Subject: [PATCH] prefix GVK labels in CustomResourceMonitoring This will prefix the auto-generated GVK labels for CustomResources with cr_ to make it a bit more clear that these labels got generated. Signed-off-by: Mario Constanti --- docs/customresourcestate-metrics.md | 2 +- pkg/customresourcestate/registry_factory.go | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/docs/customresourcestate-metrics.md b/docs/customresourcestate-metrics.md index 5296091ebc..ec5418d970 100644 --- a/docs/customresourcestate-metrics.md +++ b/docs/customresourcestate-metrics.md @@ -49,7 +49,7 @@ spec: - --resources=certificatesigningrequests,configmaps,cronjobs,daemonsets,deployments,endpoints,foos,horizontalpodautoscalers,ingresses,jobs,limitranges,mutatingwebhookconfigurations,namespaces,networkpolicies,nodes,persistentvolumeclaims,persistentvolumes,poddisruptionbudgets,pods,replicasets,replicationcontrollers,resourcequotas,secrets,services,statefulsets,storageclasses,validatingwebhookconfigurations,volumeattachments,verticalpodautoscalers ``` -NOTE: The `group`, `version`, and `kind` common labels are reserved, and will be overwritten by the values from the `groupVersionKind` field. +NOTE: The `cr_group`, `cr_version`, and `cr_kind` common labels are reserved, and will be overwritten by the values from the `groupVersionKind` field. ### Examples diff --git a/pkg/customresourcestate/registry_factory.go b/pkg/customresourcestate/registry_factory.go index e027cae8e7..3c49a16842 100644 --- a/pkg/customresourcestate/registry_factory.go +++ b/pkg/customresourcestate/registry_factory.go @@ -32,15 +32,17 @@ import ( generator "k8s.io/kube-state-metrics/v2/pkg/metric_generator" ) +const gvkLabelPrefix string = "cr_" + func compile(resource Resource) ([]compiledFamily, error) { var families []compiledFamily // Explicitly add GVK labels to all CR metrics. if resource.CommonLabels == nil { resource.CommonLabels = map[string]string{} } - resource.CommonLabels["group"] = resource.GroupVersionKind.Group - resource.CommonLabels["version"] = resource.GroupVersionKind.Version - resource.CommonLabels["kind"] = resource.GroupVersionKind.Kind + resource.CommonLabels[gvkLabelPrefix+"group"] = resource.GroupVersionKind.Group + resource.CommonLabels[gvkLabelPrefix+"version"] = resource.GroupVersionKind.Version + resource.CommonLabels[gvkLabelPrefix+"kind"] = resource.GroupVersionKind.Kind for _, f := range resource.Metrics { family, err := compileFamily(f, resource) if err != nil {