Skip to content

Commit

Permalink
Filter by namespace within GetResourceConditions
Browse files Browse the repository at this point in the history
Signed-off-by: Kyle Squizzato <[email protected]>
  • Loading branch information
squizzi committed Oct 22, 2024
1 parent 2905c9a commit acc8d45
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion internal/controller/managedcluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion internal/controller/management_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 4 additions & 2 deletions internal/utils/status/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down

0 comments on commit acc8d45

Please sign in to comment.