- 
                Notifications
    You must be signed in to change notification settings 
- Fork 2
Description
Problem
After successfully installing the metrics-operator, I wanted to create my first very basic metric, see
The metric is setup to look at the pods in the same cluster where the metrics-operator runs.
After that, nothing happened - no status change.
When looking at the logs, I can see the following error message:
...
2025-06-02T11:24:42Z    INFO    controllers.Metric    Reconciling Metric    {"namespace": {"name":"basic-pods","namespace":"default"}, "name": "basic-pods"}
2025-06-02T11:24:42Z    INFO    Warning: Reconciler returned both a non-zero result and a non-nil error. The result will always be ignored if the error is non-nil and the non-nil error causes requeuing with exponential backoff. For more details, see: https://pkg.go.dev/sigs.k8s.io/controller-runtime/pkg/reconcile#Reconciler    {"controller": "metric", "controllerGroup": "metrics.cloud.sap", "controllerKind": "Metric", "Metric": {"name":"basic-pods","namespace":"default"}, "namespace": "default", "name": "basic-pods", "reconcileID": "7feb6bc5-411d-432a-9124-8756682d29e5"}
2025-06-02T11:24:42Z    ERROR    Reconciler error    {"controller": "metric", "controllerGroup": "metrics.cloud.sap", "controllerKind": "Metric", "Metric": {"name":"basic-pods","namespace":"default"}, "namespace": "default", "name": "basic-pods", "reconcileID": "7feb6bc5-411d-432a-9124-8756682d29e5", "error": "failed to retrieve Remote Cluster Acces Ref with name  in namespace : RemoteClusterAccess.metrics.cloud.sap \"\" not found"}
sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller[...]).reconcileHandler
    /home/runner/go/pkg/mod/sigs.k8s.io/[email protected]/pkg/internal/controller/controller.go:341
sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller[...]).processNextWorkItem
    /home/runner/go/pkg/mod/sigs.k8s.io/[email protected]/pkg/internal/controller/controller.go:288
sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller[...]).Start.func2.2
    /home/runner/go/pkg/mod/sigs.k8s.io/[email protected]/pkg/internal/controller/controller.go:249
So the controller is complaining about: failed to retrieve Remote Cluster Acces Ref with name  in namespace. But it should not look up any RemoteClusterAccess CR because the Metric CR is not specifying any reference to it and the Pods should be observed in the same cluster.
Important links
It looks like this code below gets called, even if we are not specifying any RemoteClusterAccessRef:
Could it be possible that the reference gets defaulted somehow?
Solution
The issue could come from
https://github.com/SAP/metrics-operator/blob/3cc44c348d545da3b76a74bfb5ecbf3312866e5f/api/v1alpha1/metric_types.go#L59
This is just a pointer struct reference without having its own field.
We should change that in ALL metric resources where this pointer struct will get used.