@@ -38,6 +38,7 @@ public abstract class AbstractOperatorExtension
38
38
public static final int DEFAULT_NAMESPACE_DELETE_TIMEOUT = 90 ;
39
39
40
40
private final KubernetesClient kubernetesClient ;
41
+ private final KubernetesClient infrastructureKubernetesClient ;
41
42
protected final List <HasMetadata > infrastructure ;
42
43
protected Duration infrastructureTimeout ;
43
44
protected final boolean oneNamespacePerClass ;
@@ -56,10 +57,15 @@ protected AbstractOperatorExtension(
56
57
boolean preserveNamespaceOnError ,
57
58
boolean waitForNamespaceDeletion ,
58
59
KubernetesClient kubernetesClient ,
60
+ KubernetesClient infrastructureKubernetesClient ,
59
61
Function <ExtensionContext , String > namespaceNameSupplier ,
60
62
Function <ExtensionContext , String > perClassNamespaceNameSupplier ) {
61
63
this .kubernetesClient =
62
64
kubernetesClient != null ? kubernetesClient : new KubernetesClientBuilder ().build ();
65
+ this .infrastructureKubernetesClient =
66
+ infrastructureKubernetesClient != null
67
+ ? infrastructureKubernetesClient
68
+ : new KubernetesClientBuilder ().build ();
63
69
this .infrastructure = infrastructure ;
64
70
this .infrastructureTimeout = infrastructureTimeout ;
65
71
this .oneNamespacePerClass = oneNamespacePerClass ;
@@ -94,6 +100,11 @@ public KubernetesClient getKubernetesClient() {
94
100
return kubernetesClient ;
95
101
}
96
102
103
+ @ Override
104
+ public KubernetesClient getInfrastructureKubernetesClient () {
105
+ return infrastructureKubernetesClient ;
106
+ }
107
+
97
108
public String getNamespace () {
98
109
return namespace ;
99
110
}
@@ -141,16 +152,16 @@ protected void beforeEachImpl(ExtensionContext context) {
141
152
protected void before (ExtensionContext context ) {
142
153
LOGGER .info ("Initializing integration test in namespace {}" , namespace );
143
154
144
- kubernetesClient
155
+ infrastructureKubernetesClient
145
156
.namespaces ()
146
157
.resource (
147
158
new NamespaceBuilder ()
148
159
.withMetadata (new ObjectMetaBuilder ().withName (namespace ).build ())
149
160
.build ())
150
161
.serverSideApply ();
151
162
152
- kubernetesClient .resourceList (infrastructure ).serverSideApply ();
153
- kubernetesClient
163
+ infrastructureKubernetesClient .resourceList (infrastructure ).serverSideApply ();
164
+ infrastructureKubernetesClient
154
165
.resourceList (infrastructure )
155
166
.waitUntilReady (infrastructureTimeout .toMillis (), TimeUnit .MILLISECONDS );
156
167
}
@@ -172,16 +183,19 @@ protected void after(ExtensionContext context) {
172
183
if (preserveNamespaceOnError && context .getExecutionException ().isPresent ()) {
173
184
LOGGER .info ("Preserving namespace {}" , namespace );
174
185
} else {
175
- kubernetesClient .resourceList (infrastructure ).delete ();
186
+ infrastructureKubernetesClient .resourceList (infrastructure ).delete ();
176
187
deleteOperator ();
177
188
LOGGER .info ("Deleting namespace {} and stopping operator" , namespace );
178
- kubernetesClient .namespaces ().withName (namespace ).delete ();
189
+ infrastructureKubernetesClient .namespaces ().withName (namespace ).delete ();
179
190
if (waitForNamespaceDeletion ) {
180
191
LOGGER .info ("Waiting for namespace {} to be deleted" , namespace );
181
192
Awaitility .await ("namespace deleted" )
182
193
.pollInterval (50 , TimeUnit .MILLISECONDS )
183
194
.atMost (namespaceDeleteTimeout , TimeUnit .SECONDS )
184
- .until (() -> kubernetesClient .namespaces ().withName (namespace ).get () == null );
195
+ .until (
196
+ () ->
197
+ infrastructureKubernetesClient .namespaces ().withName (namespace ).get ()
198
+ == null );
185
199
}
186
200
}
187
201
}
0 commit comments