Skip to content

Commit 8b45826

Browse files
author
Kate Osborn
committed
Change predicate name
1 parent 32bc60d commit 8b45826

File tree

3 files changed

+11
-24
lines changed

3 files changed

+11
-24
lines changed

internal/mode/static/state/change_processor.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ func NewChangeProcessorImpl(cfg ChangeProcessorConfig) *ChangeProcessorImpl {
161161
{
162162
gvk: extractGVK(&apiv1.Secret{}),
163163
store: newObjectStoreMapAdapter(clusterStore.Secrets),
164-
predicate: newStateChangedPredicateFuncs(isReferenced),
164+
predicate: funcPredicate{stateChanged: isReferenced},
165165
},
166166
{
167167
gvk: extractGVK(&apiext.CustomResourceDefinition{}),

internal/mode/static/state/changed_predicate.go

+8-21
Original file line numberDiff line numberDiff line change
@@ -10,31 +10,18 @@ type stateChangedPredicate interface {
1010
delete(object client.Object) bool
1111
}
1212

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

19-
func (f funcs) upsert(oldObject, newObject client.Object) bool {
20-
return f.upsertStateChangeFunc(oldObject, newObject)
19+
func (f funcPredicate) upsert(_, newObject client.Object) bool {
20+
return f.stateChanged(newObject)
2121
}
2222

23-
func (f funcs) delete(object client.Object) bool {
24-
return f.deleteStateChangeFunc(object)
25-
}
26-
27-
// newStateChangedPredicateFuncs returns a predicate funcs that applies the given function on calls to upsert and
28-
// delete.
29-
func newStateChangedPredicateFuncs(stateChangedFunc func(object client.Object) bool) funcs {
30-
return funcs{
31-
upsertStateChangeFunc: func(oldObject, newObject client.Object) bool {
32-
return stateChangedFunc(newObject)
33-
},
34-
deleteStateChangeFunc: func(object client.Object) bool {
35-
return stateChangedFunc(object)
36-
},
37-
}
23+
func (f funcPredicate) delete(object client.Object) bool {
24+
return f.stateChanged(object)
3825
}
3926

4027
// generationChangedPredicate implements stateChangedPredicate based on the generation of the object.

internal/mode/static/state/changed_predicate_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ import (
99
"sigs.k8s.io/controller-runtime/pkg/client"
1010
)
1111

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

15-
p := newStateChangedPredicateFuncs(alwaysTrueFunc)
15+
p := funcPredicate{stateChanged: alwaysTrueFunc}
1616

1717
g := NewWithT(t)
1818

0 commit comments

Comments
 (0)