Description
What happened:
I was tring to use CRS to collect my CR metrics and was looking into the codes, and found something that might be a bug.
IIUC everytime there's a new Add/Delete event in CRDiscoverer, it will re-build the CR stores and restart all available stores. factoryGenerator
is where it recreates CR store builders using CRS config and discovery cache, which points to here. For every Custom Resource that is defined in CRS config, ResolveGVKToGVKPs
function is used for finding the matching CR in the discovery cache, and only those having matched entries in the cache map will be returned. However, for the case where both version and kind is specified, it will always return GVK no matter whether it exists in the cache or not. This is causing the following issue:
For example, in CRS config I define my resource with GVK all specified:
kind: CustomResourceStateMetrics
spec:
resources:
- groupVersionKind:
group: jobset.x-k8s.io
kind: "JobSet"
version: "v1alpha2"
Even if JobSet CRD is not registered, KSM will still bring up a store to list and watch my JobSet resource which causes spamming list/watch error logs failed to list
.
Is this intended?
What you expected to happen:
From what I understand, for the above case, it shouldn't create a list/watch store for JobSet when it's not registered in API server.
Basically in ResolveGVKToGVKPs
, the logic should be:
if hasVersion && hasKind {
for _, el := range r.Map[g][v] {
if el.Kind == k {
return []groupVersionKindPlural{
{
GroupVersionKind: schema.GroupVersionKind{
Group: g,
Version: v,
Kind: k,
},
Plural: el.Plural,
},
}, nil
}
}
}
How to reproduce it (as minimally and precisely as possible):
# An example: https://github.com/kubernetes/kube-state-metrics/issues/2223#issuecomment-1792850276
minikube start
...
go run main.go --custom-resource-state-only --custom-resource-state-config-file ksm-2223/custom-resource-config-file.yaml --kubeconfig ~/.kube/config
Anything else we need to know?:
Environment:
- kube-state-metrics version:
- Kubernetes version (use
kubectl version
): - Cloud provider or hardware configuration:
- Other info: