@@ -67,6 +67,11 @@ private OperatorExtension(
67
67
this .waitForNamespaceDeletion = waitForNamespaceDeletion ;
68
68
}
69
69
70
+ /**
71
+ * Creates a {@link Builder} to set up an {@link OperatorExtension} instance.
72
+ *
73
+ * @return the builder.
74
+ */
70
75
public static Builder builder () {
71
76
return new Builder ();
72
77
}
@@ -96,17 +101,32 @@ public KubernetesClient getKubernetesClient() {
96
101
return kubernetesClient ;
97
102
}
98
103
104
+ /**
105
+ * Returns the test namespace.
106
+ *
107
+ * @return the namespace name.
108
+ */
99
109
public String getNamespace () {
100
110
return namespace ;
101
111
}
102
112
113
+ /**
114
+ * The list of controllers known by the operator.
115
+ *
116
+ * @return the list of {@link ResourceController}.
117
+ */
103
118
@ SuppressWarnings ({"rawtypes" })
104
119
public List <ResourceController > getControllers () {
105
120
return operator .getControllers ().stream ()
106
121
.map (ConfiguredController ::getController )
107
122
.collect (Collectors .toUnmodifiableList ());
108
123
}
109
124
125
+ /**
126
+ * The list of controllers of the give {@code type} known by the operator.
127
+ *
128
+ * @return the list of {@link ResourceController} matching the required type.
129
+ */
110
130
@ SuppressWarnings ({"rawtypes" })
111
131
public <T extends ResourceController > T getControllerOfType (Class <T > type ) {
112
132
return operator .getControllers ().stream ()
@@ -123,22 +143,42 @@ public <T extends HasMetadata> NonNamespaceOperation<T, KubernetesResourceList<T
123
143
return kubernetesClient .resources (type ).inNamespace (namespace );
124
144
}
125
145
126
- public <T extends HasMetadata > T getNamedResource (Class <T > type , String name ) {
146
+ /**
147
+ * Lookup a resource given its {@code type} and {@code name} in the current test namespace.
148
+ *
149
+ * @param type Class for resource
150
+ * @param name the name of the resource
151
+ * @param <T> T type represents resource type
152
+ * @return The resource or null if it does not exist
153
+ */
154
+ public <T extends HasMetadata > T get (Class <T > type , String name ) {
127
155
return kubernetesClient .resources (type ).inNamespace (namespace ).withName (name ).get ();
128
156
}
129
157
158
+ /**
159
+ * Creates a resource in the current test namespace.
160
+ *
161
+ * @param type Class for resource
162
+ * @param resource the resource to create
163
+ * @param <T> T type represents resource type
164
+ * @return The resource or null if it does not exist
165
+ */
130
166
public <T extends HasMetadata > T create (Class <T > type , T resource ) {
131
167
return kubernetesClient .resources (type ).inNamespace (namespace ).create (resource );
132
168
}
133
169
170
+ /**
171
+ * Replaces a resource in the current test namespace.
172
+ *
173
+ * @param type Class for resource
174
+ * @param resource the resource to create
175
+ * @param <T> T type represents resource type
176
+ * @return The resource or null if it does not exist
177
+ */
134
178
public <T extends HasMetadata > T replace (Class <T > type , T resource ) {
135
179
return kubernetesClient .resources (type ).inNamespace (namespace ).replace (resource );
136
180
}
137
181
138
- public <T extends HasMetadata > T get (Class <T > type , String name ) {
139
- return kubernetesClient .resources (type ).inNamespace (namespace ).withName (name ).get ();
140
- }
141
-
142
182
143
183
@ SuppressWarnings ("unchecked" )
144
184
protected void before (ExtensionContext context ) {
@@ -225,33 +265,71 @@ protected Builder() {
225
265
true );
226
266
}
227
267
268
+ /**
269
+ * Configures if the test namespace should be preserved in case of error for troubleshooting.
270
+ *
271
+ * @param value true if the namespace should be preserved.
272
+ * @return this builder
273
+ */
228
274
public Builder preserveNamespaceOnError (boolean value ) {
229
275
this .preserveNamespaceOnError = value ;
230
276
return this ;
231
277
}
232
278
279
+ /**
280
+ * Configures if the extension should wait for the test namespace deletion.
281
+ *
282
+ * @param value true if the waiting for namespace deletion is required.
283
+ * @return this builder
284
+ */
233
285
public Builder waitForNamespaceDeletion (boolean value ) {
234
286
this .waitForNamespaceDeletion = value ;
235
287
return this ;
236
288
}
237
289
290
+ /**
291
+ * Defines the {@link ConfigurationService} the operator should use.
292
+ *
293
+ * @param value the {@link ConfigurationService}.
294
+ * @return this builder
295
+ */
238
296
public Builder withConfigurationService (ConfigurationService value ) {
239
297
configurationService = value ;
240
298
return this ;
241
299
}
242
300
301
+ /**
302
+ * Add a {@link ResourceController} to the operator.
303
+ *
304
+ * @param value the {@link ResourceController}
305
+ * @return this builder
306
+ */
243
307
@ SuppressWarnings ("rawtypes" )
244
308
public Builder withController (ResourceController value ) {
245
309
controllers .add (new ControllerSpec (value , null ));
246
310
return this ;
247
311
}
248
312
313
+ /**
314
+ * Add a {@link ResourceController} to the operator with a {@link Retry} policy.
315
+ *
316
+ * @param value the {@link ResourceController}
317
+ * @param retry the {@link Retry} policy.
318
+ * @return this builder
319
+ */
249
320
@ SuppressWarnings ("rawtypes" )
250
321
public Builder withController (ResourceController value , Retry retry ) {
251
322
controllers .add (new ControllerSpec (value , retry ));
252
323
return this ;
253
324
}
254
325
326
+ /**
327
+ * Add a {@link ResourceController} to the operator by providing its class name. The controller
328
+ * is instantiated using the default empty constructor.
329
+ *
330
+ * @param value the {@link ResourceController} type.
331
+ * @return this builder
332
+ */
255
333
@ SuppressWarnings ("rawtypes" )
256
334
public Builder withController (Class <? extends ResourceController > value ) {
257
335
try {
@@ -262,6 +340,11 @@ public Builder withController(Class<? extends ResourceController> value) {
262
340
return this ;
263
341
}
264
342
343
+ /**
344
+ * Build a new {@link OperatorExtension} instance.
345
+ *
346
+ * @return a new {@link OperatorExtension} instance.
347
+ */
265
348
public OperatorExtension build () {
266
349
return new OperatorExtension (
267
350
configurationService ,
0 commit comments