5
5
/**
6
6
* Convenience implementations of, and utility methods for, {@link ResourceEventFilter}.
7
7
*/
8
+ @ Deprecated
8
9
public final class ResourceEventFilters {
9
10
10
- private static final ResourceEventFilter <HasMetadata > USE_FINALIZER =
11
- (controller , oldResource , newResource ) -> {
12
- if (controller .useFinalizer ()) {
13
- final var finalizer = controller .getConfiguration ().getFinalizerName ();
14
- boolean oldFinalizer = oldResource == null || oldResource .hasFinalizer (finalizer );
15
- boolean newFinalizer = newResource .hasFinalizer (finalizer );
16
-
17
- return !newFinalizer || !oldFinalizer ;
18
- } else {
19
- return false ;
20
- }
21
- };
22
-
23
- private static final ResourceEventFilter <HasMetadata > GENERATION_AWARE =
24
- (controller , oldResource , newResource ) -> {
25
- final var generationAware = controller .getConfiguration ().isGenerationAware ();
26
- return oldResource == null || !generationAware ||
27
- oldResource .getMetadata ().getGeneration () < newResource .getMetadata ().getGeneration ();
28
- };
29
-
30
11
private static final ResourceEventFilter <HasMetadata > PASSTHROUGH =
31
12
(configuration , oldResource , newResource ) -> true ;
32
13
33
- private static final ResourceEventFilter <HasMetadata > NONE =
34
- (configuration , oldResource , newResource ) -> false ;
35
-
36
- private static final ResourceEventFilter <HasMetadata > MARKED_FOR_DELETION =
37
- (configuration , oldResource , newResource ) -> newResource .isMarkedForDeletion ();
38
-
39
14
private ResourceEventFilters () {}
40
15
41
16
/**
@@ -49,117 +24,4 @@ public static <T extends HasMetadata> ResourceEventFilter<T> passthrough() {
49
24
return (ResourceEventFilter <T >) PASSTHROUGH ;
50
25
}
51
26
52
- /**
53
- * Retrieves a filter that reject all events.
54
- *
55
- * @param <T> the type of custom resource the filter should handle
56
- * @return a filter that reject all events
57
- */
58
- @ SuppressWarnings ("unchecked" )
59
- public static <T extends HasMetadata > ResourceEventFilter <T > none () {
60
- return (ResourceEventFilter <T >) NONE ;
61
- }
62
-
63
- /**
64
- * Retrieves a filter that accepts all events if generation-aware processing is not activated but
65
- * only changes that represent a generation increase otherwise.
66
- *
67
- * @param <T> the type of custom resource the filter should handle
68
- * @return a filter accepting changes based on generation information
69
- */
70
- @ SuppressWarnings ("unchecked" )
71
- public static <T extends HasMetadata > ResourceEventFilter <T > generationAware () {
72
- return (ResourceEventFilter <T >) GENERATION_AWARE ;
73
- }
74
-
75
- /**
76
- * Retrieves a filter that accepts changes if the target controller uses a finalizer and that
77
- * finalizer hasn't already been applied, rejecting them otherwise.
78
- *
79
- * @param <T> the type of custom resource the filter should handle
80
- * @return a filter accepting changes based on whether the finalizer is needed and has been
81
- * applied
82
- */
83
- @ SuppressWarnings ("unchecked" )
84
- public static <T extends HasMetadata > ResourceEventFilter <T > finalizerNeededAndApplied () {
85
- return (ResourceEventFilter <T >) USE_FINALIZER ;
86
- }
87
-
88
- /**
89
- * Retrieves a filter that accepts changes if the custom resource is marked for deletion.
90
- *
91
- * @param <T> the type of custom resource the filter should handle
92
- * @return a filter accepting changes based on whether the Custom Resource is marked for deletion.
93
- */
94
- @ SuppressWarnings ("unchecked" )
95
- public static <T extends HasMetadata > ResourceEventFilter <T > markedForDeletion () {
96
- return (ResourceEventFilter <T >) MARKED_FOR_DELETION ;
97
- }
98
-
99
- /**
100
- * Combines the provided, potentially {@code null} filters with an AND logic, i.e. the resulting
101
- * filter will only accept the change if all filters accept it, reject it otherwise.
102
- * <p>
103
- * Note that the evaluation of filters is lazy: the result is returned as soon as possible without
104
- * evaluating all filters if possible.
105
- *
106
- * @param items the filters to combine
107
- * @param <T> the type of custom resources the filters are supposed to handle
108
- * @return a combined filter implementing the AND logic combination of the provided filters
109
- */
110
- @ SafeVarargs
111
- public static <T extends HasMetadata > ResourceEventFilter <T > and (
112
- ResourceEventFilter <T >... items ) {
113
- if (items == null ) {
114
- return none ();
115
- }
116
-
117
- return (configuration , oldResource , newResource ) -> {
118
- for (ResourceEventFilter <T > item : items ) {
119
- if (item == null ) {
120
- continue ;
121
- }
122
-
123
- if (!item .acceptChange (configuration , oldResource , newResource )) {
124
- return false ;
125
- }
126
- }
127
-
128
- return true ;
129
- };
130
- }
131
-
132
- /**
133
- * Combines the provided, potentially {@code null} filters with an OR logic, i.e. the resulting
134
- * filter will accept the change if any of the filters accepts it, rejecting it only if all reject
135
- * it.
136
- * <p>
137
- * Note that the evaluation of filters is lazy: the result is returned as soon as possible without
138
- * evaluating all filters if possible.
139
- *
140
- * @param items the filters to combine
141
- * @param <T> the type of custom resources the filters are supposed to handle
142
- * @return a combined filter implementing the OR logic combination of both provided filters
143
- */
144
- @ SafeVarargs
145
- public static <T extends HasMetadata > ResourceEventFilter <T > or (
146
- ResourceEventFilter <T >... items ) {
147
- if (items == null ) {
148
- return none ();
149
- }
150
-
151
- return (configuration , oldResource , newResource ) -> {
152
- for (ResourceEventFilter <T > item : items ) {
153
- if (item == null ) {
154
- continue ;
155
- }
156
-
157
- if (item .acceptChange (configuration , oldResource , newResource )) {
158
- return true ;
159
- }
160
- }
161
-
162
- return false ;
163
- };
164
- }
165
27
}
0 commit comments