-
Notifications
You must be signed in to change notification settings - Fork 2
Description
What would you like to be added
The spec.target field for Metric and FederatedMetric should be enhanced to interpret partial GVK specifications as filters. The handler should discover all matching resources based on the provided fields.
The desired filtering behaviour should be as follows:
- If only
groupis set: Monitor all resources across all versions and kinds within that API group. - If only
versionis set: Monitor all resources across all groups and kinds that exist in that version. - If only
kindis set: Monitor all resources with that kind, regardless of their group or version. - Any combination (e.g.,
groupandversion): Monitor all resources that match the specified combination.
Why is this needed
The spec.target fields for Metric and FederatedMetric (group, version, and kind) are defined as optional in the API schema. This implies that users should be able to omit any of these fields, and the controller should handle it gracefully by treating them as filters.
However, the current implementation requires a full Group-Version-Kind (GVK) to be specified. If any part of the GVK is omitted, the metric controller either fails to reconcile or returns an incorrect value.
For example, it is not possible to create a single Metric that counts all resources within a specific API group (e.g., account.btp.sap.crossplane.io or toolkit.fluxcd.io).
The ManagedMetric resource already supports this filtering behaviour.
Analysis of Current Behaviour
I tested the current behaviour of Metric with various partial GVK combinations. The results show that the current implementation cannot handle these cases correctly.
The group a.b.c is a placeholder for account.btp.sap.crossplane.io and MyKind for Subaccount from the original test data.
| Target Configuration | Result |
|---|---|
Full GVK (Working Baseline) target:
group: "a.b.c"
version: "v1alpha1"
kind: "MyKind" |
✅ Success: Correctly records a value of 1, as only one resource existed. |
Group Only target:
group: "a.b.c" |
❌ Error: failed to retrieve target resource(s): converting (v1.APIGroup) to (v1.APIResourceList): unknown conversion |
Version Only target:
version: "v1alpha1" |
❌ Error: failed to retrieve target resource(s): the server could not find the requested resource |
Kind Only target:
kind: "MyKind" |
❌ Error: failed to retrieve target resource(s): groupVersion shouldn't be empty |
Group and Kind target:
group: "a.b.c"
kind: "MyKind" |
❌ Error: failed to retrieve target resource(s): converting (v1.APIGroup) to (v1.APIResourceList): unknown conversion |
Group and Version target:
group: "a.b.c"
version: "v1alpha1" |
0, even when matching resources exist. |
Version and Kind target:
version: "v1alpha1"
kind: "MyKind" |
❌ Error: failed to retrieve target resource(s): the server could not find the requested resource |