Skip to content

Commit

Permalink
use no cache reader and address feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
chihshenghuang committed Nov 27, 2024
1 parent 94918d6 commit 2a04893
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
12 changes: 7 additions & 5 deletions internal/controllers/selfhealing/slice.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,14 @@ const (
// sliceController check if the resource slice is deleted but it is still present in the composition current synthesis status.
// If yes, it will update the composition PendingResynthesis status to trigger re-synthesis process.
type sliceController struct {
client client.Client
client client.Client
noCacheReader client.Reader
}

func NewSliceController(mgr ctrl.Manager) error {
s := &sliceController{
client: mgr.GetClient(),
client: mgr.GetClient(),
noCacheReader: mgr.GetAPIReader(),
}
return ctrl.NewControllerManagedBy(mgr).
Named("selfHealingSliceController").
Expand Down Expand Up @@ -78,7 +80,7 @@ func (s *sliceController) Reconcile(ctx context.Context, req ctrl.Request) (ctrl
slice := &apiv1.ResourceSlice{}
slice.Name = ref.Name
slice.Namespace = comp.Namespace
err := s.client.Get(ctx, client.ObjectKeyFromObject(slice), slice)
err := s.noCacheReader.Get(ctx, client.ObjectKeyFromObject(slice), slice)
if errors.IsNotFound(err) {
// The resource slice should not be deleted if it is still referenced by the composition.
// Update the composition status to trigger re-synthesis process.
Expand All @@ -91,8 +93,8 @@ func (s *sliceController) Reconcile(ctx context.Context, req ctrl.Request) (ctrl
return ctrl.Result{}, nil
}

if client.IgnoreNotFound(err) != nil {
return ctrl.Result{}, client.IgnoreNotFound(fmt.Errorf("getting resource slice: %w", err))
if err != nil {
return ctrl.Result{}, fmt.Errorf("getting resource slice: %w", err)
}
}

Expand Down
2 changes: 1 addition & 1 deletion internal/controllers/selfhealing/slice_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ func TestRequeueForPodTimeout(t *testing.T) {
slice.Status.Resources = []apiv1.ResourceState{{Ready: &readyTime, Reconciled: true}}
require.NoError(t, mgr.GetClient().Create(ctx, slice))

// check the both composition and synthesizer are existed before reconciliation
// Check the both composition and synthesizer are existed before reconciliation
testutil.Eventually(t, func() bool {
err := mgr.GetClient().Get(ctx, client.ObjectKeyFromObject(comp), comp)
if err != nil {
Expand Down

0 comments on commit 2a04893

Please sign in to comment.