diff --git a/internal/controller/managedcluster_controller.go b/internal/controller/managedcluster_controller.go index 4e247c7a1..a2882da49 100644 --- a/internal/controller/managedcluster_controller.go +++ b/internal/controller/managedcluster_controller.go @@ -132,7 +132,7 @@ func (r *ManagedClusterReconciler) setStatusFromClusterStatus( ) (bool, error) { l := ctrl.LoggerFrom(ctx) - resourceConditions, err := status.ConditionsFromResource(ctx, r.DynamicClient, schema.GroupVersionResource{ + resourceConditions, err := status.GetResourceConditions(ctx, managedCluster.Namespace, r.DynamicClient, schema.GroupVersionResource{ Group: "cluster.x-k8s.io", Version: "v1beta1", Resource: "clusters", diff --git a/internal/controller/management_controller.go b/internal/controller/management_controller.go index 840146865..091dfcc7c 100644 --- a/internal/controller/management_controller.go +++ b/internal/controller/management_controller.go @@ -237,7 +237,7 @@ func (r *ManagementReconciler) checkProviderStatus(ctx context.Context, provider Resource: resourceType, } - resourceConditions, err := status.GetResourceConditions(ctx, r.DynamicClient, gvr, + resourceConditions, err := status.GetResourceConditions(ctx, r.SystemNamespace, r.DynamicClient, gvr, labels.SelectorFromSet(map[string]string{hmc.FluxHelmChartNameKey: providerTemplateName}).String(), ) if err != nil { diff --git a/internal/utils/status/status.go b/internal/utils/status/status.go index aea4dfe05..8e6c07d75 100644 --- a/internal/utils/status/status.go +++ b/internal/utils/status/status.go @@ -85,10 +85,12 @@ type ResourceConditions struct { // If the resource is not found, returns a ResourceNotFoundError which can be // checked by the caller to prevent reconciliation loops. func GetResourceConditions( - ctx context.Context, dynamicClient dynamic.Interface, + ctx context.Context, namespace string, dynamicClient dynamic.Interface, gvr schema.GroupVersionResource, labelSelector string, ) (resourceConditions *ResourceConditions, err error) { - list, err := dynamicClient.Resource(gvr).List(ctx, metav1.ListOptions{LabelSelector: labelSelector, Limit: 2}) + list, err := dynamicClient.Resource(gvr).Namespace(namespace).List(ctx, metav1.ListOptions{ + LabelSelector: labelSelector, Limit: 2, + }) if err != nil { if apierrors.IsNotFound(err) { return nil, ResourceNotFoundError{Resource: gvr.Resource}