29
29
30
30
import java .util .concurrent .TimeUnit ;
31
31
32
+ import java .util .function .Function ;
33
+
32
34
import hapi .services .tiller .ReleaseServiceGrpc ;
33
35
import hapi .services .tiller .ReleaseServiceGrpc .ReleaseServiceBlockingStub ;
34
36
import hapi .services .tiller .ReleaseServiceGrpc .ReleaseServiceFutureStub ;
@@ -85,7 +87,7 @@ public class Tiller implements ConfigAware<Config>, Closeable {
85
87
*
86
88
* <p>This field is never {@code null}.</p>
87
89
*/
88
- public static final String VERSION = "2.8.2 " ;
90
+ public static final String VERSION = "2.12.3 " ;
89
91
90
92
/**
91
93
* The Kubernetes namespace into which Tiller server instances are
@@ -207,13 +209,43 @@ public Tiller(final ManagedChannel channel) {
207
209
*
208
210
* @exception NullPointerException if {@code portForward} is {@code
209
211
* null}
212
+ *
213
+ * @see #Tiller(LocalPortForward, Function)
210
214
*/
211
215
public Tiller (final LocalPortForward portForward ) {
216
+ this (portForward , null );
217
+ }
218
+
219
+ /**
220
+ * Creates a new {@link Tiller} that will use information from the
221
+ * supplied {@link LocalPortForward} to establish a communications
222
+ * channel with the Tiller server.
223
+ *
224
+ * @param portForward the {@link LocalPortForward} to use; must not
225
+ * be {@code null}
226
+ *
227
+ * @param channelBuilder a {@link Function} capable of accepting a
228
+ * {@link LocalPortForward} and returning a new {@link
229
+ * ManagedChannel}; if {@code null} the {@link
230
+ * #buildChannel(LocalPortForward)} method will be used instead; if
231
+ * non-{@code null} then the {@link #buildChannel(LocalPortForward)}
232
+ * method will never be called
233
+ *
234
+ * @exception NullPointerException if {@code portForward} is {@code
235
+ * null}
236
+ *
237
+ * @see #Tiller(LocalPortForward, Function)
238
+ */
239
+ public Tiller (final LocalPortForward portForward , final Function <? super LocalPortForward , ? extends ManagedChannel > channelBuilder ) {
212
240
super ();
213
241
Objects .requireNonNull (portForward );
214
242
this .config = null ;
215
243
this .portForward = null ; // yes, null
216
- this .channel = this .buildChannel (portForward );
244
+ if (channelBuilder == null ) {
245
+ this .channel = this .buildChannel (portForward );
246
+ } else {
247
+ this .channel = channelBuilder .apply (portForward );
248
+ }
217
249
}
218
250
219
251
/**
@@ -242,9 +274,11 @@ public Tiller(final LocalPortForward portForward) {
242
274
* identifying a Pod within the cluster that houses a Tiller instance
243
275
*
244
276
* @exception NullPointerException if {@code client} is {@code null}
277
+ *
278
+ * @see #Tiller(HttpClientAware, String, int, Map, Function)
245
279
*/
246
280
public <T extends HttpClientAware & KubernetesClient > Tiller (final T client ) throws MalformedURLException {
247
- this (client , DEFAULT_NAMESPACE , DEFAULT_PORT , DEFAULT_LABELS );
281
+ this (client , DEFAULT_NAMESPACE , DEFAULT_PORT , DEFAULT_LABELS , null );
248
282
}
249
283
250
284
/**
@@ -283,9 +317,11 @@ public <T extends HttpClientAware & KubernetesClient> Tiller(final T client) thr
283
317
*
284
318
* @exception TillerException if a ready Tiller pod could not be
285
319
* found and consequently a connection could not be established
320
+ *
321
+ * @see #Tiller(HttpClientAware, String, int, Map, Function)
286
322
*/
287
323
public <T extends HttpClientAware & KubernetesClient > Tiller (final T client , final String namespaceHousingTiller ) throws MalformedURLException {
288
- this (client , namespaceHousingTiller , DEFAULT_PORT , DEFAULT_LABELS );
324
+ this (client , namespaceHousingTiller , DEFAULT_PORT , DEFAULT_LABELS , null );
289
325
}
290
326
291
327
/**
@@ -330,11 +366,72 @@ public <T extends HttpClientAware & KubernetesClient> Tiller(final T client, fin
330
366
*
331
367
* @exception TillerException if a ready Tiller pod could not be
332
368
* found and consequently a connection could not be established
369
+ *
370
+ * @see #Tiller(HttpClientAware, String, int, Map, Function)
333
371
*/
334
372
public <T extends HttpClientAware & KubernetesClient > Tiller (final T client ,
335
373
String namespaceHousingTiller ,
336
374
int tillerPort ,
337
- Map <String , String > tillerLabels ) throws MalformedURLException {
375
+ Map <String , String > tillerLabels )
376
+ throws MalformedURLException {
377
+ this (client , namespaceHousingTiller , tillerPort , tillerLabels , null );
378
+ }
379
+
380
+ /**
381
+ * Creates a new {@link Tiller} that will forward a local port to
382
+ * the supplied (remote) port on a Pod housing Tiller in the supplied
383
+ * namespace running in the Kubernetes cluster with which the
384
+ * supplied {@link KubernetesClient} is capable of communicating.
385
+ *
386
+ * <p>The {@linkplain Pods#getFirstReadyPod(Listable) first ready
387
+ * Pod} with labels matching the supplied {@code tillerLabels} is
388
+ * deemed to be the pod housing the Tiller instance to connect
389
+ * to.</p>
390
+ *
391
+ * @param <T> a {@link KubernetesClient} implementation that is also
392
+ * an {@link HttpClientAware} implementation, such as {@link
393
+ * DefaultKubernetesClient}
394
+ *
395
+ * @param client the {@link KubernetesClient}-and-{@link
396
+ * HttpClientAware} implementation that can communicate with a
397
+ * Kubernetes cluster; must not be {@code null}; no reference to
398
+ * this object is retained by this {@link Tiller} instance
399
+ *
400
+ * @param namespaceHousingTiller the namespace within which a Tiller
401
+ * instance is hopefully running; if {@code null}, then the value of
402
+ * {@link #DEFAULT_NAMESPACE} will be used instead
403
+ *
404
+ * @param tillerPort the remote port to attempt to forward a local
405
+ * port to; normally {@code 44134}
406
+ *
407
+ * @param tillerLabels a {@link Map} representing the Kubernetes
408
+ * labels (and their values) identifying a Pod housing a Tiller
409
+ * instance; if {@code null} then the value of {@link
410
+ * #DEFAULT_LABELS} will be used instead
411
+ *
412
+ * @param channelBuilder a {@link Function} capable of accepting a
413
+ * {@link LocalPortForward} and returning a new {@link
414
+ * ManagedChannel}; if {@code null} the {@link
415
+ * #buildChannel(LocalPortForward)} method will be used instead; if
416
+ * non-{@code null} then the {@link #buildChannel(LocalPortForward)}
417
+ * method will never be called
418
+ *
419
+ * @exception MalformedURLException if there was a problem
420
+ * identifying a Pod within the cluster that houses a Tiller instance
421
+ *
422
+ * @exception NullPointerException if {@code client} is {@code null}
423
+ *
424
+ * @exception KubernetesClientException if there was a problem
425
+ * connecting to Kubernetes
426
+ *
427
+ * @exception TillerException if a ready Tiller pod could not be
428
+ * found and consequently a connection could not be established
429
+ */
430
+ public <T extends HttpClientAware & KubernetesClient > Tiller (final T client ,
431
+ String namespaceHousingTiller ,
432
+ int tillerPort ,
433
+ Map <String , String > tillerLabels ,
434
+ Function <? super LocalPortForward , ? extends ManagedChannel > channelBuilder ) throws MalformedURLException {
338
435
super ();
339
436
Objects .requireNonNull (client );
340
437
this .config = client .getConfiguration ();
@@ -357,7 +454,11 @@ public <T extends HttpClientAware & KubernetesClient> Tiller(final T client,
357
454
if (this .portForward == null ) {
358
455
throw new TillerException ("Could not forward port to a Ready Tiller pod's port " + tillerPort + " in namespace " + namespaceHousingTiller + " with labels " + tillerLabels );
359
456
}
360
- this .channel = this .buildChannel (this .portForward );
457
+ if (channelBuilder == null ) {
458
+ this .channel = this .buildChannel (this .portForward );
459
+ } else {
460
+ this .channel = channelBuilder .apply (this .portForward );
461
+ }
361
462
}
362
463
363
464
0 commit comments