3
3
import java .time .Duration ;
4
4
5
5
import org .junit .jupiter .api .*;
6
+ import org .slf4j .Logger ;
7
+ import org .slf4j .LoggerFactory ;
6
8
7
9
import io .fabric8 .kubernetes .api .model .ConfigMap ;
8
10
import io .fabric8 .kubernetes .api .model .ConfigMapBuilder ;
34
36
/**
35
37
* The test relies on a special api server configuration: "min-request-timeout" to have a very low
36
38
* 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 ")
38
40
*
39
41
* <p>
40
42
* This is important when tests are affected by permission changes, since the watch permissions are
45
47
* The test ends with "ITS" (Special) since it needs to run separately from other ITs
46
48
* </p>
47
49
*/
48
- @ EnableKubeAPIServer (apiServerFlags = {"--min-request-timeout" , "3 " })
50
+ @ EnableKubeAPIServer (apiServerFlags = {"--min-request-timeout" , "1 " })
49
51
class InformerRelatedBehaviorITS {
50
52
53
+ private static final Logger log = LoggerFactory .getLogger (InformerRelatedBehaviorITS .class );
54
+
51
55
public static final String TEST_RESOURCE_NAME = "test1" ;
52
56
public static final String ADDITIONAL_NAMESPACE_SUFFIX = "-additional" ;
53
57
54
58
KubernetesClient adminClient = new KubernetesClientBuilder ().build ();
55
59
InformerRelatedBehaviorTestReconciler reconciler ;
56
60
String actualNamespace ;
57
61
String additionalNamespace ;
62
+ Operator operator ;
58
63
volatile boolean replacementStopHandlerCalled = false ;
59
64
60
65
@ BeforeEach
@@ -72,8 +77,11 @@ void beforeEach(TestInfo testInfo) {
72
77
73
78
@ AfterEach
74
79
void cleanup () {
75
- adminClient .resource (testCustomResource ()).delete ();
80
+ if (operator != null ) {
81
+ operator .stop (Duration .ofSeconds (1 ));
82
+ }
76
83
adminClient .resource (dependentConfigMap ()).delete ();
84
+ adminClient .resource (testCustomResource ()).delete ();
77
85
}
78
86
79
87
@ Test
@@ -90,7 +98,7 @@ void startsUpWhenNoPermissionToCustomResource() {
90
98
adminClient .resource (testCustomResource ()).createOrReplace ();
91
99
setNoCustomResourceAccess ();
92
100
93
- var operator = startOperator (false );
101
+ operator = startOperator (false );
94
102
assertNotReconciled ();
95
103
assertRuntimeInfoNoCRPermission (operator );
96
104
@@ -106,7 +114,7 @@ void startsUpWhenNoPermissionToSecondaryResource() {
106
114
adminClient .resource (testCustomResource ()).createOrReplace ();
107
115
setNoConfigMapAccess ();
108
116
109
- var operator = startOperator (false );
117
+ operator = startOperator (false );
110
118
assertNotReconciled ();
111
119
assertRuntimeInfoForSecondaryPermission (operator );
112
120
@@ -120,7 +128,7 @@ void startsUpIfNoPermissionToOneOfTwoNamespaces() {
120
128
adminClient .resource (namespace (additionalNamespace )).createOrReplace ();
121
129
122
130
addRoleBindingsToTestNamespaces ();
123
- var operator = startOperator (false , false , actualNamespace , additionalNamespace );
131
+ operator = startOperator (false , false , actualNamespace , additionalNamespace );
124
132
assertInformerNotWatchingForAdditionalNamespace (operator );
125
133
126
134
adminClient .resource (testCustomResource ()).createOrReplace ();
@@ -151,17 +159,18 @@ private void assertInformerNotWatchingForAdditionalNamespace(Operator operator)
151
159
assertThat (configMapHealthIndicator .isWatching ()).isFalse ();
152
160
}
153
161
162
+
154
163
@ Test
155
164
void resilientForLoosingPermissionForCustomResource () {
156
165
setFullResourcesAccess ();
157
- startOperator (true );
166
+ operator = startOperator (true );
158
167
setNoCustomResourceAccess ();
159
168
160
169
waitForWatchReconnect ();
170
+
161
171
adminClient .resource (testCustomResource ()).createOrReplace ();
162
172
163
173
assertNotReconciled ();
164
-
165
174
setFullResourcesAccess ();
166
175
assertReconciled ();
167
176
}
@@ -210,7 +219,7 @@ void notExitingWithDefaultStopHandlerIfErrorHappensOnStartup() {
210
219
211
220
private static void waitForWatchReconnect () {
212
221
try {
213
- Thread .sleep (6000 );
222
+ Thread .sleep (5000 );
214
223
} catch (InterruptedException e ) {
215
224
throw new IllegalStateException (e );
216
225
}
0 commit comments