14
14
import io .fabric8 .kubernetes .client .KubernetesClient ;
15
15
import io .fabric8 .kubernetes .client .KubernetesClientBuilder ;
16
16
import io .fabric8 .kubernetes .client .utils .KubernetesResourceUtil ;
17
+ import io .javaoperatorsdk .jenvtest .junit .EnableKubeAPIServer ;
17
18
import io .javaoperatorsdk .operator .api .config .ConfigurationServiceProvider ;
18
19
import io .javaoperatorsdk .operator .health .InformerHealthIndicator ;
19
20
import io .javaoperatorsdk .operator .junit .LocallyRunOperatorExtension ;
30
31
31
32
/**
32
33
* The test relies on a special api server configuration: "min-request-timeout" to have a very low
33
- * value, use: "minikube start --extra-config=apiserver.min-request-timeout=3"
34
+ * value (in case want to try with minikube use: "minikube start
35
+ * --extra-config=apiserver.min-request-timeout=3")
34
36
*
35
37
* <p>
36
38
* This is important when tests are affected by permission changes, since the watch permissions are
41
43
* The test ends with "ITS" (Special) since it needs to run separately from other ITs
42
44
* </p>
43
45
*/
46
+ @ EnableKubeAPIServer (apiServerFlags = {"--min-request-timeout" , "3" })
44
47
class InformerRelatedBehaviorITS {
45
48
46
49
public static final String TEST_RESOURCE_NAME = "test1" ;
47
- public static final String ADDITIONAL_NAMESPACE_NAME = "additionalns " ;
50
+ public static final String ADDITIONAL_NAMESPACE_SUFFIX = "-additional " ;
48
51
49
52
KubernetesClient adminClient = new KubernetesClientBuilder ().build ();
50
53
InformerRelatedBehaviorTestReconciler reconciler ;
51
54
String actualNamespace ;
55
+ String additionalNamespace ;
52
56
volatile boolean replacementStopHandlerCalled = false ;
53
57
54
58
@ BeforeEach
@@ -57,6 +61,7 @@ void beforeEach(TestInfo testInfo) {
57
61
adminClient );
58
62
testInfo .getTestMethod ().ifPresent (method -> {
59
63
actualNamespace = KubernetesResourceUtil .sanitizeName (method .getName ());
64
+ additionalNamespace = actualNamespace + ADDITIONAL_NAMESPACE_SUFFIX ;
60
65
adminClient .resource (namespace ()).createOrReplace ();
61
66
});
62
67
// cleans up binding before test, not all test cases use cluster role
@@ -66,7 +71,6 @@ void beforeEach(TestInfo testInfo) {
66
71
@ AfterEach
67
72
void cleanup () {
68
73
adminClient .resource (testCustomResource ()).delete ();
69
- adminClient .resource (namespace ()).delete ();
70
74
}
71
75
72
76
@ Test
@@ -110,24 +114,15 @@ void startsUpWhenNoPermissionToSecondaryResource() {
110
114
111
115
@ Test
112
116
void startsUpIfNoPermissionToOneOfTwoNamespaces () {
113
- var otherNamespace =
114
- adminClient .resource (namespace (ADDITIONAL_NAMESPACE_NAME )).createOrReplace ();
115
- try {
116
- addRoleBindingsToTestNamespaces ();
117
- var operator = startOperator (false , false , actualNamespace , ADDITIONAL_NAMESPACE_NAME );
118
- assertInformerNotWatchingForAdditionalNamespace (operator );
119
-
120
- adminClient .resource (testCustomResource ()).createOrReplace ();
121
- waitForWatchReconnect ();
122
- assertReconciled ();
123
-
124
- } finally {
125
- adminClient .resource (otherNamespace ).delete ();
126
- await ().untilAsserted (() -> {
127
- var ns = adminClient .namespaces ().resource (otherNamespace ).fromServer ().get ();
128
- assertThat (ns ).isNull ();
129
- });
130
- }
117
+ adminClient .resource (namespace (additionalNamespace )).createOrReplace ();
118
+
119
+ addRoleBindingsToTestNamespaces ();
120
+ var operator = startOperator (false , false , actualNamespace , additionalNamespace );
121
+ assertInformerNotWatchingForAdditionalNamespace (operator );
122
+
123
+ adminClient .resource (testCustomResource ()).createOrReplace ();
124
+ waitForWatchReconnect ();
125
+ assertReconciled ();
131
126
}
132
127
133
128
private void assertInformerNotWatchingForAdditionalNamespace (Operator operator ) {
@@ -139,17 +134,17 @@ private void assertInformerNotWatchingForAdditionalNamespace(Operator operator)
139
134
InformerHealthIndicator controllerHealthIndicator =
140
135
(InformerHealthIndicator ) unhealthyEventSources
141
136
.get (ControllerResourceEventSource .class .getSimpleName ())
142
- .informerHealthIndicators ().get (ADDITIONAL_NAMESPACE_NAME );
137
+ .informerHealthIndicators ().get (additionalNamespace );
143
138
assertThat (controllerHealthIndicator ).isNotNull ();
144
- assertThat (controllerHealthIndicator .getTargetNamespace ()).isEqualTo (ADDITIONAL_NAMESPACE_NAME );
139
+ assertThat (controllerHealthIndicator .getTargetNamespace ()).isEqualTo (additionalNamespace );
145
140
assertThat (controllerHealthIndicator .isWatching ()).isFalse ();
146
141
147
142
InformerHealthIndicator configMapHealthIndicator =
148
143
(InformerHealthIndicator ) unhealthyEventSources
149
144
.get (ConfigMapDependentResource .class .getSimpleName ())
150
- .informerHealthIndicators ().get (ADDITIONAL_NAMESPACE_NAME );
145
+ .informerHealthIndicators ().get (additionalNamespace );
151
146
assertThat (configMapHealthIndicator ).isNotNull ();
152
- assertThat (configMapHealthIndicator .getTargetNamespace ()).isEqualTo (ADDITIONAL_NAMESPACE_NAME );
147
+ assertThat (configMapHealthIndicator .getTargetNamespace ()).isEqualTo (additionalNamespace );
153
148
assertThat (configMapHealthIndicator .isWatching ()).isFalse ();
154
149
}
155
150
0 commit comments