Skip to content

Commit

Permalink
prefix GVK labels in CustomResourceMonitoring
Browse files Browse the repository at this point in the history
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 <mario@constanti.de>
  • Loading branch information
bavarianbidi committed Jan 3, 2023
1 parent f1288f9 commit 6f76c22
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion docs/customresourcestate-metrics.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 5 additions & 3 deletions pkg/customresourcestate/registry_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 6f76c22

Please sign in to comment.