33import java .time .Duration ;
44
55import org .junit .jupiter .api .*;
6+ import org .slf4j .Logger ;
7+ import org .slf4j .LoggerFactory ;
68
79import io .fabric8 .kubernetes .api .model .ConfigMap ;
810import io .fabric8 .kubernetes .api .model .ConfigMapBuilder ;
3436/**
3537 * The test relies on a special api server configuration: "min-request-timeout" to have a very low
3638 * value (in case want to try with minikube use: "minikube start
37- * --extra-config=apiserver.min-request-timeout=3 ")
39+ * --extra-config=apiserver.min-request-timeout=1 ")
3840 *
3941 * <p>
4042 * This is important when tests are affected by permission changes, since the watch permissions are
4547 * The test ends with "ITS" (Special) since it needs to run separately from other ITs
4648 * </p>
4749 */
48- @ EnableKubeAPIServer (apiServerFlags = {"--min-request-timeout" , "3 " })
50+ @ EnableKubeAPIServer (apiServerFlags = {"--min-request-timeout" , "1 " })
4951class InformerRelatedBehaviorITS {
5052
53+ private static final Logger log = LoggerFactory .getLogger (InformerRelatedBehaviorITS .class );
54+
5155 public static final String TEST_RESOURCE_NAME = "test1" ;
5256 public static final String ADDITIONAL_NAMESPACE_SUFFIX = "-additional" ;
5357
5458 KubernetesClient adminClient = new KubernetesClientBuilder ().build ();
5559 InformerRelatedBehaviorTestReconciler reconciler ;
5660 String actualNamespace ;
5761 String additionalNamespace ;
62+ Operator operator ;
5863 volatile boolean replacementStopHandlerCalled = false ;
5964
6065 @ BeforeEach
@@ -72,8 +77,11 @@ void beforeEach(TestInfo testInfo) {
7277
7378 @ AfterEach
7479 void cleanup () {
75- adminClient .resource (testCustomResource ()).delete ();
80+ if (operator != null ) {
81+ operator .stop (Duration .ofSeconds (1 ));
82+ }
7683 adminClient .resource (dependentConfigMap ()).delete ();
84+ adminClient .resource (testCustomResource ()).delete ();
7785 }
7886
7987 @ Test
@@ -90,7 +98,7 @@ void startsUpWhenNoPermissionToCustomResource() {
9098 adminClient .resource (testCustomResource ()).createOrReplace ();
9199 setNoCustomResourceAccess ();
92100
93- var operator = startOperator (false );
101+ operator = startOperator (false );
94102 assertNotReconciled ();
95103 assertRuntimeInfoNoCRPermission (operator );
96104
@@ -106,7 +114,7 @@ void startsUpWhenNoPermissionToSecondaryResource() {
106114 adminClient .resource (testCustomResource ()).createOrReplace ();
107115 setNoConfigMapAccess ();
108116
109- var operator = startOperator (false );
117+ operator = startOperator (false );
110118 assertNotReconciled ();
111119 assertRuntimeInfoForSecondaryPermission (operator );
112120
@@ -120,7 +128,7 @@ void startsUpIfNoPermissionToOneOfTwoNamespaces() {
120128 adminClient .resource (namespace (additionalNamespace )).createOrReplace ();
121129
122130 addRoleBindingsToTestNamespaces ();
123- var operator = startOperator (false , false , actualNamespace , additionalNamespace );
131+ operator = startOperator (false , false , actualNamespace , additionalNamespace );
124132 assertInformerNotWatchingForAdditionalNamespace (operator );
125133
126134 adminClient .resource (testCustomResource ()).createOrReplace ();
@@ -151,17 +159,18 @@ private void assertInformerNotWatchingForAdditionalNamespace(Operator operator)
151159 assertThat (configMapHealthIndicator .isWatching ()).isFalse ();
152160 }
153161
162+
154163 @ Test
155164 void resilientForLoosingPermissionForCustomResource () {
156165 setFullResourcesAccess ();
157- startOperator (true );
166+ operator = startOperator (true );
158167 setNoCustomResourceAccess ();
159168
160169 waitForWatchReconnect ();
170+
161171 adminClient .resource (testCustomResource ()).createOrReplace ();
162172
163173 assertNotReconciled ();
164-
165174 setFullResourcesAccess ();
166175 assertReconciled ();
167176 }
@@ -210,7 +219,7 @@ void notExitingWithDefaultStopHandlerIfErrorHappensOnStartup() {
210219
211220 private static void waitForWatchReconnect () {
212221 try {
213- Thread .sleep (6000 );
222+ Thread .sleep (5000 );
214223 } catch (InterruptedException e ) {
215224 throw new IllegalStateException (e );
216225 }
0 commit comments