2929
3030import java .util .concurrent .TimeUnit ;
3131
32+ import java .util .function .Function ;
33+
3234import hapi .services .tiller .ReleaseServiceGrpc ;
3335import hapi .services .tiller .ReleaseServiceGrpc .ReleaseServiceBlockingStub ;
3436import hapi .services .tiller .ReleaseServiceGrpc .ReleaseServiceFutureStub ;
@@ -85,7 +87,7 @@ public class Tiller implements ConfigAware<Config>, Closeable {
8587 *
8688 * <p>This field is never {@code null}.</p>
8789 */
88- public static final String VERSION = "2.8.2 " ;
90+ public static final String VERSION = "2.12.3 " ;
8991
9092 /**
9193 * The Kubernetes namespace into which Tiller server instances are
@@ -207,13 +209,43 @@ public Tiller(final ManagedChannel channel) {
207209 *
208210 * @exception NullPointerException if {@code portForward} is {@code
209211 * null}
212+ *
213+ * @see #Tiller(LocalPortForward, Function)
210214 */
211215 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 ) {
212240 super ();
213241 Objects .requireNonNull (portForward );
214242 this .config = null ;
215243 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+ }
217249 }
218250
219251 /**
@@ -242,9 +274,11 @@ public Tiller(final LocalPortForward portForward) {
242274 * identifying a Pod within the cluster that houses a Tiller instance
243275 *
244276 * @exception NullPointerException if {@code client} is {@code null}
277+ *
278+ * @see #Tiller(HttpClientAware, String, int, Map, Function)
245279 */
246280 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 );
248282 }
249283
250284 /**
@@ -283,9 +317,11 @@ public <T extends HttpClientAware & KubernetesClient> Tiller(final T client) thr
283317 *
284318 * @exception TillerException if a ready Tiller pod could not be
285319 * found and consequently a connection could not be established
320+ *
321+ * @see #Tiller(HttpClientAware, String, int, Map, Function)
286322 */
287323 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 );
289325 }
290326
291327 /**
@@ -330,11 +366,72 @@ public <T extends HttpClientAware & KubernetesClient> Tiller(final T client, fin
330366 *
331367 * @exception TillerException if a ready Tiller pod could not be
332368 * found and consequently a connection could not be established
369+ *
370+ * @see #Tiller(HttpClientAware, String, int, Map, Function)
333371 */
334372 public <T extends HttpClientAware & KubernetesClient > Tiller (final T client ,
335373 String namespaceHousingTiller ,
336374 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 {
338435 super ();
339436 Objects .requireNonNull (client );
340437 this .config = client .getConfiguration ();
@@ -357,7 +454,11 @@ public <T extends HttpClientAware & KubernetesClient> Tiller(final T client,
357454 if (this .portForward == null ) {
358455 throw new TillerException ("Could not forward port to a Ready Tiller pod's port " + tillerPort + " in namespace " + namespaceHousingTiller + " with labels " + tillerLabels );
359456 }
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+ }
361462 }
362463
363464
0 commit comments