@@ -41,7 +41,7 @@ class InformerRelatedBehaviorITS {
41
41
KubernetesClient adminClient = new KubernetesClientBuilder ().build ();
42
42
InformerRelatedBehaviorTestReconciler reconciler ;
43
43
String actualNamespace ;
44
- volatile boolean stopHandlerCalled = false ;
44
+ volatile boolean replacementStopHandlerCalled = false ;
45
45
46
46
@ BeforeEach
47
47
void beforeEach (TestInfo testInfo ) {
@@ -136,7 +136,19 @@ void callsStopHandlerOnStartupFail() {
136
136
137
137
assertThrows (OperatorException .class , () -> startOperator (true ));
138
138
139
- await ().untilAsserted (() -> assertThat (stopHandlerCalled ).isTrue ());
139
+ await ().untilAsserted (() -> assertThat (replacementStopHandlerCalled ).isTrue ());
140
+ }
141
+
142
+ @ Test
143
+ void notExitingWithDefaultStopHandlerIfErrorHappensOnStartup () {
144
+ setNoCustomResourceAccess ();
145
+ adminClient .resource (testCustomResource ()).createOrReplace ();
146
+
147
+ assertThrows (OperatorException .class , () -> startOperator (true , false ));
148
+
149
+ // note that we just basically check here that the default handler does not call system exit.
150
+ // Thus, the test does not terminate before to assert.
151
+ await ().untilAsserted (() -> assertThat (replacementStopHandlerCalled ).isFalse ());
140
152
}
141
153
142
154
private static void waitForWatchReconnect () {
@@ -183,16 +195,20 @@ KubernetesClient clientUsingServiceAccount() {
183
195
}
184
196
185
197
Operator startOperator (boolean stopOnInformerErrorDuringStartup ) {
198
+ return startOperator (stopOnInformerErrorDuringStartup , true );
199
+ }
200
+
201
+ Operator startOperator (boolean stopOnInformerErrorDuringStartup , boolean addStopHandler ) {
186
202
ConfigurationServiceProvider .reset ();
187
203
reconciler = new InformerRelatedBehaviorTestReconciler ();
188
204
189
205
Operator operator = new Operator (clientUsingServiceAccount (),
190
206
co -> {
191
207
co .withStopOnInformerErrorDuringStartup (stopOnInformerErrorDuringStartup );
192
208
co .withCacheSyncTimeout (Duration .ofMillis (3000 ));
193
- co . withInformerStoppedHandler (( informer , ex ) -> {
194
- stopHandlerCalled = true ;
195
- });
209
+ if ( addStopHandler ) {
210
+ co . withInformerStoppedHandler (( informer , ex ) -> replacementStopHandlerCalled = true ) ;
211
+ }
196
212
});
197
213
operator .register (reconciler );
198
214
operator .installShutdownHook ();
0 commit comments