Skip to content

Commit d5a8e1a

Browse files
committed
fix: cover also the deprecated value from annotation for triggerReconcilerOnAllEvent
Signed-off-by: Attila Mészáros <a_meszaros@apple.com>
1 parent 748f3a3 commit d5a8e1a

2 files changed

Lines changed: 87 additions & 1 deletion

File tree

operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/BaseConfigurationService.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,8 +318,13 @@ private <P extends HasMetadata> ResolvedControllerConfiguration<P> controllerCon
318318
final var dependentFieldManager =
319319
fieldManager.equals(CONTROLLER_NAME_AS_FIELD_MANAGER) ? name : fieldManager;
320320

321+
// the deprecated triggerReconcilerOnAllEvent is still honored, otherwise enabling all-event
322+
// mode under its former name would be silently ignored
323+
@SuppressWarnings("removal")
321324
var triggerReconcilerOnAllEvents =
322-
annotation != null && annotation.triggerReconcilerOnAllEvents();
325+
annotation != null
326+
&& (annotation.triggerReconcilerOnAllEvents()
327+
|| annotation.triggerReconcilerOnAllEvent());
323328

324329
var defaultFilters = annotation == null || annotation.defaultFilters();
325330

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/*
2+
* Copyright Java Operator SDK Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package io.javaoperatorsdk.operator.api.config;
17+
18+
import org.junit.jupiter.api.Test;
19+
20+
import io.fabric8.kubernetes.api.model.ConfigMap;
21+
import io.javaoperatorsdk.operator.api.reconciler.Context;
22+
import io.javaoperatorsdk.operator.api.reconciler.ControllerConfiguration;
23+
import io.javaoperatorsdk.operator.api.reconciler.Reconciler;
24+
import io.javaoperatorsdk.operator.api.reconciler.UpdateControl;
25+
26+
import static org.assertj.core.api.Assertions.assertThat;
27+
28+
class BaseConfigurationServiceTest {
29+
30+
private final BaseConfigurationService configurationService = new BaseConfigurationService();
31+
32+
@Test
33+
void readsTriggerReconcilerOnAllEvents() {
34+
assertThat(
35+
configurationService
36+
.configFor(new AllEventsReconciler())
37+
.triggerReconcilerOnAllEvents())
38+
.isTrue();
39+
}
40+
41+
@Test
42+
void readsDeprecatedTriggerReconcilerOnAllEventAttribute() {
43+
assertThat(
44+
configurationService
45+
.configFor(new DeprecatedAllEventsReconciler())
46+
.triggerReconcilerOnAllEvents())
47+
.isTrue();
48+
}
49+
50+
@Test
51+
void triggerReconcilerOnAllEventsDefaultsToFalse() {
52+
assertThat(
53+
configurationService.configFor(new DefaultReconciler()).triggerReconcilerOnAllEvents())
54+
.isFalse();
55+
}
56+
57+
@ControllerConfiguration(triggerReconcilerOnAllEvents = true)
58+
private static class AllEventsReconciler implements Reconciler<ConfigMap> {
59+
@Override
60+
public UpdateControl<ConfigMap> reconcile(ConfigMap resource, Context<ConfigMap> context) {
61+
return UpdateControl.noUpdate();
62+
}
63+
}
64+
65+
@SuppressWarnings("removal")
66+
@ControllerConfiguration(triggerReconcilerOnAllEvent = true)
67+
private static class DeprecatedAllEventsReconciler implements Reconciler<ConfigMap> {
68+
@Override
69+
public UpdateControl<ConfigMap> reconcile(ConfigMap resource, Context<ConfigMap> context) {
70+
return UpdateControl.noUpdate();
71+
}
72+
}
73+
74+
@ControllerConfiguration
75+
private static class DefaultReconciler implements Reconciler<ConfigMap> {
76+
@Override
77+
public UpdateControl<ConfigMap> reconcile(ConfigMap resource, Context<ConfigMap> context) {
78+
return UpdateControl.noUpdate();
79+
}
80+
}
81+
}

0 commit comments

Comments
 (0)