Skip to content

Commit

Permalink
storagegroup controller will not reconcile on drive delete event
Browse files Browse the repository at this point in the history
Signed-off-by: Shi, Crane <[email protected]>
  • Loading branch information
CraneShiEMC committed Jul 30, 2023
1 parent fec5cfa commit 5b33d51
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
8 changes: 8 additions & 0 deletions pkg/crcontrollers/storagegroup/storagegroupcontroller.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,21 @@ func (c *Controller) SetupWithManager(mgr ctrl.Manager) error {
WithOptions(controller.Options{}).
Watches(&source.Kind{Type: &drivecrd.Drive{}}, &handler.EnqueueRequestForObject{}).
WithEventFilter(predicate.Funcs{
DeleteFunc: func(e event.DeleteEvent) bool {
return c.filterDeleteEvent(e.Object)
},

Check warning on line 70 in pkg/crcontrollers/storagegroup/storagegroupcontroller.go

View check run for this annotation

Codecov / codecov/patch

pkg/crcontrollers/storagegroup/storagegroupcontroller.go#L68-L70

Added lines #L68 - L70 were not covered by tests
UpdateFunc: func(e event.UpdateEvent) bool {
return c.filterUpdateEvent(e.ObjectOld, e.ObjectNew)
},
}).
Complete(c)
}

func (c *Controller) filterDeleteEvent(obj runtime.Object) bool {
_, isStorageGroup := obj.(*sgcrd.StorageGroup)
return isStorageGroup
}

func (c *Controller) filterUpdateEvent(old runtime.Object, new runtime.Object) bool {
if newDrive, ok := new.(*drivecrd.Drive); ok {
if oldDrive, ok := old.(*drivecrd.Drive); ok {
Expand Down
10 changes: 10 additions & 0 deletions pkg/crcontrollers/storagegroup/storagegroupcontroller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,16 @@ var (
}
)

func TestStorageGroupController_filterDeleteEvent(t *testing.T) {
kubeClient, err := k8s.GetFakeKubeClient(testNs, testLogger)
assert.Nil(t, err)

c := NewController(kubeClient, kubeClient, testLogger)

testDrive1 := drive1.DeepCopy()
assert.False(t, c.filterDeleteEvent(testDrive1))
}

func TestStorageGroupController_filterDriveUpdateEvent(t *testing.T) {
testDrive1 := drive1.DeepCopy()
testDrive2 := drive2.DeepCopy()
Expand Down

0 comments on commit 5b33d51

Please sign in to comment.