diff --git a/pkg/controllers/federatedcluster/util_test.go b/pkg/controllers/federatedcluster/util_test.go index 346cee16..8acddbd9 100644 --- a/pkg/controllers/federatedcluster/util_test.go +++ b/pkg/controllers/federatedcluster/util_test.go @@ -262,11 +262,19 @@ func Test_aggregateResources(t *testing.T) { t.Run(tc.name, func(t *testing.T) { allocatable, available := AggregateResources(tc.nodes, tc.pods) if len(allocatable) != len(tc.expectedAllocatable) { - t.Fatalf("expected allocatable %s differs from actual allocatable %s", spew.Sdump(tc.expectedAllocatable), spew.Sdump(allocatable)) + t.Fatalf( + "expected allocatable %s differs from actual allocatable %s", + spew.Sdump(tc.expectedAllocatable), + spew.Sdump(allocatable), + ) } for name, actualQuantity := range allocatable { if expectedQuantity, ok := tc.expectedAllocatable[name]; !ok || !actualQuantity.Equal(expectedQuantity) { - t.Fatalf("expected allocatable %s differs from actual allocatable %s", spew.Sdump(tc.expectedAllocatable), spew.Sdump(allocatable)) + t.Fatalf( + "expected allocatable %s differs from actual allocatable %s", + spew.Sdump(tc.expectedAllocatable), + spew.Sdump(allocatable), + ) } } @@ -275,7 +283,11 @@ func Test_aggregateResources(t *testing.T) { } for name, actualQuantity := range available { if expectedQuantity, ok := tc.expectedAvailable[name]; !ok || !actualQuantity.Equal(expectedQuantity) { - t.Fatalf("expected available %s differs from actual available %s", spew.Sdump(tc.expectedAvailable), spew.Sdump(available)) + t.Fatalf( + "expected available %s differs from actual available %s", + spew.Sdump(tc.expectedAvailable), + spew.Sdump(available), + ) } } }) diff --git a/pkg/controllers/scheduler/schedulingunit.go b/pkg/controllers/scheduler/schedulingunit.go index 7edba14c..b3a50ea9 100644 --- a/pkg/controllers/scheduler/schedulingunit.go +++ b/pkg/controllers/scheduler/schedulingunit.go @@ -83,6 +83,9 @@ func (s *Scheduler) schedulingUnitForFedObject( selectorPath := s.typeConfig.Spec.PathDefinition.LabelSelector if selectorPath != "" { currentUsage, err = s.getPodUsage(ctx, fedObject, selectorPath) + if err != nil { + return nil, fmt.Errorf("get pod resource usage: %w", err) + } } schedulingUnit := &framework.SchedulingUnit{ @@ -173,7 +176,11 @@ func (s *Scheduler) schedulingUnitForFedObject( return schedulingUnit, nil } -func (s *Scheduler) getPodUsage(ctx context.Context, fedObject *unstructured.Unstructured, selectorPath string) (map[string]framework.Resource, error) { +func (s *Scheduler) getPodUsage( + ctx context.Context, + fedObject *unstructured.Unstructured, + selectorPath string, +) (map[string]framework.Resource, error) { clusters, err := s.clusterLister.List(labels.Everything()) if err != nil { return nil, fmt.Errorf("failed to get clusters from store: %w", err) @@ -201,7 +208,12 @@ func (s *Scheduler) getPodUsage(ctx context.Context, fedObject *unstructured.Uns return currentUsage, nil } -func (s *Scheduler) getClusterPodUsage(ctx context.Context, cluster *fedcorev1a1.FederatedCluster, fedObject *unstructured.Unstructured, selector *metav1.LabelSelector) (res framework.Resource, err error) { +func (s *Scheduler) getClusterPodUsage( + ctx context.Context, + cluster *fedcorev1a1.FederatedCluster, + fedObject *unstructured.Unstructured, + selector *metav1.LabelSelector, +) (res framework.Resource, err error) { client, exists, err := s.federatedClient.KubeClientsetForCluster(cluster.Name) if err != nil { return res, fmt.Errorf("get clientset: %w", err)