Skip to content

Commit

Permalink
Change predicate name
Browse files Browse the repository at this point in the history
  • Loading branch information
kate-osborn committed Dec 5, 2023
1 parent 32bc60d commit 8b45826
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 24 deletions.
2 changes: 1 addition & 1 deletion internal/mode/static/state/change_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ func NewChangeProcessorImpl(cfg ChangeProcessorConfig) *ChangeProcessorImpl {
{
gvk: extractGVK(&apiv1.Secret{}),
store: newObjectStoreMapAdapter(clusterStore.Secrets),
predicate: newStateChangedPredicateFuncs(isReferenced),
predicate: funcPredicate{stateChanged: isReferenced},
},
{
gvk: extractGVK(&apiext.CustomResourceDefinition{}),
Expand Down
29 changes: 8 additions & 21 deletions internal/mode/static/state/changed_predicate.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,18 @@ type stateChangedPredicate interface {
delete(object client.Object) bool
}

// funcs is a function that implements stateChangedPredicate.
type funcs struct {
upsertStateChangeFunc func(oldObject, newObject client.Object) bool
deleteStateChangeFunc func(object client.Object) bool
// funcPredicate applies the stateChanged function on upsert and delete. On upsert, the newObject is passed.
// Implements stateChangedPredicate.
type funcPredicate struct {
stateChanged func(object client.Object) bool
}

func (f funcs) upsert(oldObject, newObject client.Object) bool {
return f.upsertStateChangeFunc(oldObject, newObject)
func (f funcPredicate) upsert(_, newObject client.Object) bool {
return f.stateChanged(newObject)
}

func (f funcs) delete(object client.Object) bool {
return f.deleteStateChangeFunc(object)
}

// newStateChangedPredicateFuncs returns a predicate funcs that applies the given function on calls to upsert and
// delete.
func newStateChangedPredicateFuncs(stateChangedFunc func(object client.Object) bool) funcs {
return funcs{
upsertStateChangeFunc: func(oldObject, newObject client.Object) bool {
return stateChangedFunc(newObject)
},
deleteStateChangeFunc: func(object client.Object) bool {
return stateChangedFunc(object)
},
}
func (f funcPredicate) delete(object client.Object) bool {
return f.stateChanged(object)
}

// generationChangedPredicate implements stateChangedPredicate based on the generation of the object.
Expand Down
4 changes: 2 additions & 2 deletions internal/mode/static/state/changed_predicate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"
)

func TestFuncsPredicate(t *testing.T) {
func TestFuncPredicate(t *testing.T) {
alwaysTrueFunc := func(object client.Object) bool { return true }

p := newStateChangedPredicateFuncs(alwaysTrueFunc)
p := funcPredicate{stateChanged: alwaysTrueFunc}

g := NewWithT(t)

Expand Down

0 comments on commit 8b45826

Please sign in to comment.