Skip to content

Commit

Permalink
Minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelawyu committed Aug 31, 2023
1 parent 581c690 commit 3cd8b62
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 14 deletions.
32 changes: 18 additions & 14 deletions pkg/controllers/hub/endpointsliceexport/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,24 @@ const (
endpointSliceExportRetryInterval = time.Second * 5
)

var (
endpointSliceImportIndexerFunc = func(o client.Object) []string {
endpointSliceImport, ok := o.(*fleetnetv1alpha1.EndpointSliceImport)
if !ok {
return []string{}
}

Check warning on line 46 in pkg/controllers/hub/endpointsliceexport/controller.go

View check run for this annotation

Codecov / codecov/patch

pkg/controllers/hub/endpointsliceexport/controller.go#L45-L46

Added lines #L45 - L46 were not covered by tests
return []string{endpointSliceImport.ObjectMeta.Name}
}

endpointSliceExportIndexerFunc = func(o client.Object) []string {
endpointSliceExport, ok := o.(*fleetnetv1alpha1.EndpointSliceExport)
if !ok {
return []string{}
}

Check warning on line 54 in pkg/controllers/hub/endpointsliceexport/controller.go

View check run for this annotation

Codecov / codecov/patch

pkg/controllers/hub/endpointsliceexport/controller.go#L53-L54

Added lines #L53 - L54 were not covered by tests
return []string{endpointSliceExport.Spec.OwnerServiceReference.NamespacedName}
}
)

// Reconciler reconciles the distribution of EndpointSlices across the fleet.
type Reconciler struct {
HubClient client.Client
Expand Down Expand Up @@ -231,13 +249,6 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu
// SetupWithManager sets up the EndpointSliceExport controller with a controller manager.
func (r *Reconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager) error {
// Set up an index for efficient EndpointSliceImport lookup.
endpointSliceImportIndexerFunc := func(o client.Object) []string {
endpointSliceImport, ok := o.(*fleetnetv1alpha1.EndpointSliceImport)
if !ok {
return []string{}
}
return []string{endpointSliceImport.ObjectMeta.Name}
}
if err := mgr.GetFieldIndexer().IndexField(ctx,
&fleetnetv1alpha1.EndpointSliceImport{},
endpointSliceImportNameFieldKey,
Expand All @@ -248,13 +259,6 @@ func (r *Reconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager) err
}

// Set up an index for efficient EndpointSliceExport lookup.
endpointSliceExportIndexerFunc := func(o client.Object) []string {
endpointSliceExport, ok := o.(*fleetnetv1alpha1.EndpointSliceExport)
if !ok {
return []string{}
}
return []string{endpointSliceExport.Spec.OwnerServiceReference.NamespacedName}
}
if err := mgr.GetFieldIndexer().IndexField(ctx,
&fleetnetv1alpha1.EndpointSliceExport{},
endpointSliceExportOwnerSvcNamespacedNameFieldKey,
Expand Down
5 changes: 5 additions & 0 deletions pkg/controllers/hub/endpointsliceexport/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,9 @@ func TestWithdrawAllEndpointSliceImports(t *testing.T) {
t.Run(tc.name, func(t *testing.T) {
fakeHubClientBuilder := fake.NewClientBuilder().
WithScheme(scheme.Scheme).
// Set up indexes on the fake client.
WithIndex(&fleetnetv1alpha1.EndpointSliceExport{}, endpointSliceExportOwnerSvcNamespacedNameFieldKey, endpointSliceExportIndexerFunc).
WithIndex(&fleetnetv1alpha1.EndpointSliceImport{}, endpointSliceImportNameFieldKey, endpointSliceImportIndexerFunc).
WithObjects(tc.endpointSliceExport)
for idx := range tc.endpointSliceImports {
fakeHubClientBuilder = fakeHubClientBuilder.WithObjects(tc.endpointSliceImports[idx])
Expand Down Expand Up @@ -408,6 +411,8 @@ func TestScanForEndpointSliceImports(t *testing.T) {
t.Run(tc.name, func(t *testing.T) {
fakeHubClientBuilder := fake.NewClientBuilder().
WithScheme(scheme.Scheme).
WithIndex(&fleetnetv1alpha1.EndpointSliceExport{}, endpointSliceExportOwnerSvcNamespacedNameFieldKey, endpointSliceExportIndexerFunc).
WithIndex(&fleetnetv1alpha1.EndpointSliceImport{}, endpointSliceImportNameFieldKey, endpointSliceImportIndexerFunc).
WithObjects(tc.endpointSliceExport)
for idx := range tc.endpointSliceImports {
fakeHubClientBuilder = fakeHubClientBuilder.WithObjects(tc.endpointSliceImports[idx])
Expand Down

0 comments on commit 3cd8b62

Please sign in to comment.