Skip to content

Commit

Permalink
fixed missing error handling for pod usage
Browse files Browse the repository at this point in the history
  • Loading branch information
SOF3 committed Apr 18, 2023
1 parent 5aad843 commit c803016
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
18 changes: 15 additions & 3 deletions pkg/controllers/federatedcluster/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
)
}
}

Expand All @@ -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),
)
}
}
})
Expand Down
16 changes: 14 additions & 2 deletions pkg/controllers/scheduler/schedulingunit.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit c803016

Please sign in to comment.