kubernetes / kube-state-metrics

Add-on agent to generate and expose cluster-level metrics.
https://kubernetes.io/docs/concepts/cluster-administration/kube-state-metrics/
Apache License 2.0
5.2k stars 1.92k forks source link

Custom resource state metrics wildcard not working #2384

Open akselleirv opened 1 month ago

akselleirv commented 1 month ago

What happened:

Metrics from custom resource is not produced when wildcard is used in kind field.

What you expected to happen:

The wildcard should produce metrics for all kinds.

How to reproduce it (as minimally and precisely as possible):

I have the following helm chart values file

rbac:
  extraRules:
    - apiGroups: ["azure.tnnova.io"]
      resources: ["*"]
      verbs: ["get", "list", "watch"]
    - apiGroups: ["apiextensions.k8s.io"]
      resources: ["customresourcedefinitions"]
      verbs: ["get", "list", "watch"]
customResourceState:
  enabled: true
  config:
    kind: CustomResourceStateMetrics
    spec:
      resources:
        - groupVersionKind:
            group: "azure.tnnova.io"
            version: "v1alpha1"
            kind: "UserAssignedIdentity"
          labelsFromPath:
            namespace: [metadata, namespace]
          metrics:
              - name: status_conditions
                help: "The condition of the resource"
                each:
                  type: StateSet
                  stateSet:
                    path: [status, conditions, "0"]
                    labelName: status
                    valueFrom: [status]
                    list: ["True", "False", "Unknown"]
                    labelsFromPath:
                      type: [type]

It produces the following metrics:

# HELP kube_customresource_status_conditions The condition of the resource
# TYPE kube_customresource_status_conditions stateset
kube_customresource_status_conditions{customresource_group="azure.tnnova.io",customresource_kind="UserAssignedIdentity",customresource_version="v1alpha1",namespace="s01234-example-system",status="False",type="Ready"} 0
kube_customresource_status_conditions{customresource_group="azure.tnnova.io",customresource_kind="UserAssignedIdentity",customresource_version="v1alpha1",namespace="s01234-example-system",status="True",type="Ready"} 1
kube_customresource_status_conditions{customresource_group="azure.tnnova.io",customresource_kind="UserAssignedIdentity",customresource_version="v1alpha1",namespace="s01234-example-system",status="Unknown",type="Ready"} 0

However, when I replace kind="UserAssignedIdentity" to kind="*" , like:

...
        - groupVersionKind:
            group: "azure.tnnova.io"
            version: "v1alpha1"
            kind: "*"
...

Then it no longer produces any metrics. I have verified that the kube-state-metrics service account has list,watch,get on customresourcedefintions.

Anything else we need to know?:

Environment:

logicalhan commented 1 month ago

/triage accepted /assign @rexagod