@@ -69,7 +69,7 @@ public class Config {
69
69
private static final Logger LOGGER = LoggerFactory .getLogger (Config .class );
70
70
71
71
/**
72
- * Disables auto-configuration based on opinionated defaults in a {@link Config} object in the default constructor
72
+ * Disables auto-configuration based on opinionated defaults in a {@link Config} object in the Builder constructor
73
73
*/
74
74
public static final String KUBERNETES_DISABLE_AUTO_CONFIG_SYSTEM_PROPERTY = "kubernetes.disable.autoConfig" ;
75
75
public static final String KUBERNETES_MASTER_SYSTEM_PROPERTY = "kubernetes.master" ;
@@ -151,6 +151,9 @@ public class Config {
151
151
152
152
private static final String ACCESS_TOKEN = "access-token" ;
153
153
private static final String ID_TOKEN = "id-token" ;
154
+ private static final TlsVersion [] DEFAULT_TLS_VERSIONS_LIST = new TlsVersion [] { TlsVersion .TLS_1_3 , TlsVersion .TLS_1_2 };
155
+ private static final int DEFAULT_WATCH_RECONNECT_INTERVAL = 1000 ;
156
+ private static final int DEFAULT_CONNECTION_TIMEOUT = 10 * 1000 ;
154
157
155
158
private boolean trustCerts ;
156
159
private boolean disableHostnameVerification ;
@@ -178,7 +181,7 @@ public class Config {
178
181
private volatile String autoOAuthToken ;
179
182
private OAuthTokenProvider oauthTokenProvider ;
180
183
private long websocketPingInterval = DEFAULT_WEBSOCKET_PING_INTERVAL ;
181
- private int connectionTimeout = 10 * 1000 ;
184
+ private int connectionTimeout = DEFAULT_CONNECTION_TIMEOUT ;
182
185
private int maxConcurrentRequests = DEFAULT_MAX_CONCURRENT_REQUESTS ;
183
186
private int maxConcurrentRequestsPerHost = DEFAULT_MAX_CONCURRENT_REQUESTS_PER_HOST ;
184
187
@@ -190,7 +193,7 @@ public class Config {
190
193
/**
191
194
* fields not used but needed for builder generation.
192
195
*/
193
- private int watchReconnectInterval = 1000 ;
196
+ private int watchReconnectInterval = DEFAULT_WATCH_RECONNECT_INTERVAL ;
194
197
private int watchReconnectLimit = -1 ;
195
198
private int uploadRequestTimeout = DEFAULT_UPLOAD_REQUEST_TIMEOUT ;
196
199
private int requestRetryBackoffLimit ;
@@ -218,7 +221,7 @@ public class Config {
218
221
private String proxyPassword ;
219
222
private String [] noProxy ;
220
223
private String userAgent = "fabric8-kubernetes-client/" + Version .clientVersion ();
221
- private TlsVersion [] tlsVersions = new TlsVersion [] { TlsVersion . TLS_1_3 , TlsVersion . TLS_1_2 } ;
224
+ private TlsVersion [] tlsVersions = DEFAULT_TLS_VERSIONS_LIST ;
222
225
223
226
private boolean onlyHttpWatches ;
224
227
@@ -239,7 +242,7 @@ public class Config {
239
242
*/
240
243
@ Deprecated
241
244
public Config () {
242
- this (! disableAutoConfig ()) ;
245
+ this . autoConfigure = true ;
243
246
}
244
247
245
248
private static boolean disableAutoConfig () {
@@ -336,7 +339,7 @@ public Config(String masterUrl, String apiVersion, String namespace, boolean tru
336
339
DEFAULT_UPLOAD_REQUEST_TIMEOUT , false , null , Collections .emptyList ());
337
340
}
338
341
339
- @ Buildable ( builderPackage = "io.fabric8.kubernetes.api.builder" , editableEnabled = false )
342
+ @ Deprecated
340
343
public Config (String masterUrl , String apiVersion , String namespace , boolean trustCerts , boolean disableHostnameVerification ,
341
344
String caCertFile , String caCertData , String clientCertFile , String clientCertData , String clientKeyFile ,
342
345
String clientKeyData , String clientKeyAlgo , String clientKeyPassphrase , String username , String password ,
@@ -350,56 +353,198 @@ public Config(String masterUrl, String apiVersion, String namespace, boolean tru
350
353
OAuthTokenProvider oauthTokenProvider , Map <String , String > customHeaders , int requestRetryBackoffLimit ,
351
354
int requestRetryBackoffInterval , int uploadRequestTimeout , boolean onlyHttpWatches , NamedContext currentContext ,
352
355
List <NamedContext > contexts ) {
353
- this .apiVersion = apiVersion ;
354
- this .namespace = namespace ;
355
- this .trustCerts = trustCerts ;
356
- this .disableHostnameVerification = disableHostnameVerification ;
357
- this .caCertFile = caCertFile ;
358
- this .caCertData = caCertData ;
359
- this .clientCertFile = clientCertFile ;
360
- this .clientCertData = clientCertData ;
361
- this .clientKeyFile = clientKeyFile ;
362
- this .clientKeyData = clientKeyData ;
363
- this .clientKeyAlgo = clientKeyAlgo ;
364
- this .clientKeyPassphrase = clientKeyPassphrase ;
365
- this .username = username ;
366
- this .password = password ;
367
- this .oauthToken = oauthToken ;
368
- this .websocketPingInterval = websocketPingInterval ;
369
- this .connectionTimeout = connectionTimeout ;
370
-
371
- this .requestConfig = new RequestConfig (watchReconnectLimit , watchReconnectInterval ,
372
- requestTimeout , scaleTimeout , loggingInterval ,
373
- requestRetryBackoffLimit , requestRetryBackoffInterval , uploadRequestTimeout );
374
- this .requestConfig .setImpersonateUsername (impersonateUsername );
375
- this .requestConfig .setImpersonateGroups (impersonateGroups );
376
- this .requestConfig .setImpersonateExtras (impersonateExtras );
356
+ this (masterUrl , apiVersion , namespace , trustCerts , disableHostnameVerification , caCertFile , caCertData ,
357
+ clientCertFile , clientCertData , clientKeyFile , clientKeyData , clientKeyAlgo , clientKeyPassphrase , username ,
358
+ password , oauthToken , autoOAuthToken , watchReconnectInterval , watchReconnectLimit , connectionTimeout , requestTimeout ,
359
+ scaleTimeout , loggingInterval , maxConcurrentRequests , maxConcurrentRequestsPerHost , http2Disable ,
360
+ httpProxy , httpsProxy , noProxy , userAgent , tlsVersions , websocketPingInterval , proxyUsername , proxyPassword ,
361
+ trustStoreFile , trustStorePassphrase , keyStoreFile , keyStorePassphrase , impersonateUsername , impersonateGroups ,
362
+ impersonateExtras , oauthTokenProvider , customHeaders , requestRetryBackoffLimit , requestRetryBackoffInterval ,
363
+ uploadRequestTimeout , onlyHttpWatches , currentContext , contexts , false );
364
+ }
377
365
378
- this .http2Disable = http2Disable ;
379
- this .httpProxy = httpProxy ;
380
- this .httpsProxy = httpsProxy ;
381
- this .noProxy = noProxy ;
382
- this .proxyUsername = proxyUsername ;
383
- this .proxyPassword = proxyPassword ;
384
- this .userAgent = userAgent ;
385
- this .tlsVersions = tlsVersions ;
386
- this .trustStoreFile = trustStoreFile ;
387
- this .trustStorePassphrase = trustStorePassphrase ;
388
- this .keyStoreFile = keyStoreFile ;
389
- this .keyStorePassphrase = keyStorePassphrase ;
390
- this .oauthTokenProvider = oauthTokenProvider ;
391
- this .customHeaders = customHeaders ;
366
+ @ Buildable (builderPackage = "io.fabric8.kubernetes.api.builder" , editableEnabled = false )
367
+ public Config (String masterUrl , String apiVersion , String namespace , boolean trustCerts , boolean disableHostnameVerification ,
368
+ String caCertFile , String caCertData , String clientCertFile , String clientCertData , String clientKeyFile ,
369
+ String clientKeyData , String clientKeyAlgo , String clientKeyPassphrase , String username , String password ,
370
+ String oauthToken , String autoOAuthToken , int watchReconnectInterval , int watchReconnectLimit , int connectionTimeout ,
371
+ int requestTimeout ,
372
+ long scaleTimeout , int loggingInterval , int maxConcurrentRequests , int maxConcurrentRequestsPerHost ,
373
+ boolean http2Disable , String httpProxy , String httpsProxy , String [] noProxy ,
374
+ String userAgent , TlsVersion [] tlsVersions , long websocketPingInterval , String proxyUsername ,
375
+ String proxyPassword , String trustStoreFile , String trustStorePassphrase , String keyStoreFile , String keyStorePassphrase ,
376
+ String impersonateUsername , String [] impersonateGroups , Map <String , List <String >> impersonateExtras ,
377
+ OAuthTokenProvider oauthTokenProvider , Map <String , String > customHeaders , int requestRetryBackoffLimit ,
378
+ int requestRetryBackoffInterval , int uploadRequestTimeout , boolean onlyHttpWatches , NamedContext currentContext ,
379
+ List <NamedContext > contexts , boolean autoConfigure ) {
380
+ if (autoConfigure && !disableAutoConfig ()) {
381
+ autoConfigure (this , null );
382
+ }
383
+ if (Utils .isNotNullOrEmpty (apiVersion )) {
384
+ this .apiVersion = apiVersion ;
385
+ }
386
+ if (Utils .isNotNullOrEmpty (namespace )) {
387
+ this .namespace = namespace ;
388
+ }
389
+ if (trustCerts ) {
390
+ this .trustCerts = trustCerts ;
391
+ }
392
+ if (disableHostnameVerification ) {
393
+ this .disableHostnameVerification = disableHostnameVerification ;
394
+ }
395
+ if (Utils .isNotNullOrEmpty (caCertData )) {
396
+ this .caCertData = caCertData ;
397
+ }
398
+ if (Utils .isNotNullOrEmpty (caCertFile )) {
399
+ this .caCertFile = caCertFile ;
400
+ }
401
+ if (Utils .isNotNullOrEmpty (clientCertFile )) {
402
+ this .clientCertFile = clientCertFile ;
403
+ }
404
+ if (Utils .isNotNullOrEmpty (clientCertData )) {
405
+ this .clientCertData = clientCertData ;
406
+ }
407
+ if (Utils .isNotNullOrEmpty (clientKeyFile )) {
408
+ this .clientKeyFile = clientKeyFile ;
409
+ }
410
+ if (Utils .isNotNullOrEmpty (clientKeyData )) {
411
+ this .clientKeyData = clientKeyData ;
412
+ }
413
+ if (Utils .isNotNullOrEmpty (clientKeyAlgo ) && !clientKeyAlgo .equals ("RSA" )) {
414
+ this .clientKeyAlgo = clientKeyAlgo ;
415
+ }
416
+ if (Utils .isNotNullOrEmpty (clientKeyPassphrase ) && !clientKeyPassphrase .equals ("changeit" )) {
417
+ this .clientKeyPassphrase = clientKeyPassphrase ;
418
+ }
419
+ if (Utils .isNotNullOrEmpty (username )) {
420
+ this .username = username ;
421
+ }
422
+ if (Utils .isNotNullOrEmpty (password )) {
423
+ this .password = password ;
424
+ }
425
+ if (Utils .isNotNullOrEmpty (oauthToken )) {
426
+ this .oauthToken = oauthToken ;
427
+ }
428
+ if (websocketPingInterval != DEFAULT_WEBSOCKET_PING_INTERVAL ) {
429
+ this .websocketPingInterval = websocketPingInterval ;
430
+ }
431
+ if (connectionTimeout != DEFAULT_CONNECTION_TIMEOUT ) {
432
+ this .connectionTimeout = connectionTimeout ;
433
+ }
434
+ if (http2Disable ) {
435
+ this .http2Disable = http2Disable ;
436
+ }
437
+ if (Utils .isNotNullOrEmpty (httpProxy )) {
438
+ this .httpProxy = httpProxy ;
439
+ }
440
+ if (Utils .isNotNullOrEmpty (httpsProxy )) {
441
+ this .httpsProxy = httpsProxy ;
442
+ }
443
+ if (Utils .isNotNullOrEmpty (noProxy )) {
444
+ this .noProxy = noProxy ;
445
+ }
446
+ if (Utils .isNotNullOrEmpty (proxyUsername )) {
447
+ this .proxyUsername = proxyUsername ;
448
+ }
449
+ if (Utils .isNotNullOrEmpty (proxyPassword )) {
450
+ this .proxyPassword = proxyPassword ;
451
+ }
452
+ if (Utils .isNotNullOrEmpty (userAgent )) {
453
+ this .userAgent = userAgent ;
454
+ }
455
+ if (tlsVersions != null && tlsVersions .length > 0 && !Arrays .equals (tlsVersions , DEFAULT_TLS_VERSIONS_LIST )) {
456
+ this .tlsVersions = tlsVersions ;
457
+ }
458
+ if (Utils .isNotNullOrEmpty (trustStoreFile )) {
459
+ this .trustStoreFile = trustStoreFile ;
460
+ }
461
+ if (Utils .isNotNullOrEmpty (trustStorePassphrase )) {
462
+ this .trustStorePassphrase = trustStorePassphrase ;
463
+ }
464
+ if (Utils .isNotNullOrEmpty (keyStoreFile )) {
465
+ this .keyStoreFile = keyStoreFile ;
466
+ }
467
+ if (Utils .isNotNullOrEmpty (keyStorePassphrase )) {
468
+ this .keyStorePassphrase = keyStorePassphrase ;
469
+ }
470
+ if (Utils .isNotNull (oauthTokenProvider )) {
471
+ this .oauthTokenProvider = oauthTokenProvider ;
472
+ }
473
+ if (Utils .isNotNullOrEmpty (customHeaders )) {
474
+ this .customHeaders = customHeaders ;
475
+ }
392
476
393
477
//We need to keep this after ssl configuration & masterUrl
394
478
//We set the masterUrl because it's needed by ensureHttps
395
- this .masterUrl = masterUrl ;
396
- this .masterUrl = ensureEndsWithSlash (ensureHttps (masterUrl , this ));
397
- this .maxConcurrentRequests = maxConcurrentRequests ;
398
- this .maxConcurrentRequestsPerHost = maxConcurrentRequestsPerHost ;
399
- this .autoOAuthToken = autoOAuthToken ;
400
- this .onlyHttpWatches = onlyHttpWatches ;
401
- this .contexts = contexts ;
402
- this .currentContext = currentContext ;
479
+ if (Utils .isNotNullOrEmpty (masterUrl ) && !masterUrl .equals (DEFAULT_MASTER_URL )) {
480
+ this .masterUrl = masterUrl ;
481
+ this .masterUrl = ensureEndsWithSlash (ensureHttps (masterUrl , this ));
482
+ }
483
+ if (maxConcurrentRequests != DEFAULT_MAX_CONCURRENT_REQUESTS ) {
484
+ this .maxConcurrentRequests = maxConcurrentRequests ;
485
+ }
486
+ if (maxConcurrentRequestsPerHost != DEFAULT_MAX_CONCURRENT_REQUESTS_PER_HOST ) {
487
+ this .maxConcurrentRequestsPerHost = maxConcurrentRequestsPerHost ;
488
+ }
489
+ if (Utils .isNotNullOrEmpty (autoOAuthToken )) {
490
+ this .autoOAuthToken = autoOAuthToken ;
491
+ }
492
+ if (onlyHttpWatches ) {
493
+ this .onlyHttpWatches = onlyHttpWatches ;
494
+ }
495
+ if (contexts != null && !contexts .isEmpty ()) {
496
+ this .contexts = contexts ;
497
+ }
498
+ if (currentContext != null ) {
499
+ this .currentContext = currentContext ;
500
+ }
501
+
502
+ RequestConfig autoConfiguredRequestConfig = this .requestConfig ;
503
+ this .requestConfig = mergeRequestConfig (new RequestConfig (watchReconnectLimit , watchReconnectInterval ,
504
+ requestTimeout , scaleTimeout , loggingInterval ,
505
+ requestRetryBackoffLimit , requestRetryBackoffInterval , uploadRequestTimeout ), autoConfiguredRequestConfig );
506
+ this .requestConfig .setImpersonateUsername (
507
+ Optional .ofNullable (impersonateUsername ).orElse (autoConfiguredRequestConfig .getImpersonateUsername ()));
508
+ this .requestConfig .setImpersonateGroups (
509
+ Utils .isNotNullOrEmpty (impersonateGroups ) ? impersonateGroups : autoConfiguredRequestConfig .getImpersonateGroups ());
510
+ this .requestConfig .setImpersonateExtras (
511
+ Utils .isNotNullOrEmpty (impersonateExtras ) ? impersonateExtras : autoConfiguredRequestConfig .getImpersonateExtras ());
512
+ }
513
+
514
+ private RequestConfig mergeRequestConfig (RequestConfig userProvidedRequestConfig , RequestConfig autoConfiguredRequestConfig ) {
515
+ RequestConfigBuilder requestConfigBuilder = new RequestConfigBuilder (userProvidedRequestConfig );
516
+ if (userProvidedRequestConfig .getRequestTimeout () == DEFAULT_REQUEST_TIMEOUT
517
+ && autoConfiguredRequestConfig .getRequestTimeout () != DEFAULT_REQUEST_TIMEOUT ) {
518
+ requestConfigBuilder .withRequestTimeout (autoConfiguredRequestConfig .getRequestTimeout ());
519
+ }
520
+ if (userProvidedRequestConfig .getWatchReconnectLimit () == -1 && autoConfiguredRequestConfig .getWatchReconnectLimit () > 0 ) {
521
+ requestConfigBuilder .withWatchReconnectLimit (autoConfiguredRequestConfig .getWatchReconnectLimit ());
522
+ }
523
+ if (userProvidedRequestConfig .getWatchReconnectInterval () == DEFAULT_WATCH_RECONNECT_INTERVAL
524
+ && autoConfiguredRequestConfig .getWatchReconnectInterval () != DEFAULT_WATCH_RECONNECT_INTERVAL ) {
525
+ requestConfigBuilder .withWatchReconnectInterval (autoConfiguredRequestConfig .getWatchReconnectInterval ());
526
+ }
527
+ if (userProvidedRequestConfig .getRequestTimeout () == DEFAULT_REQUEST_TIMEOUT
528
+ && autoConfiguredRequestConfig .getRequestTimeout () != DEFAULT_REQUEST_TIMEOUT ) {
529
+ requestConfigBuilder .withRequestTimeout (autoConfiguredRequestConfig .getRequestTimeout ());
530
+ }
531
+ if (userProvidedRequestConfig .getScaleTimeout () == DEFAULT_SCALE_TIMEOUT
532
+ && autoConfiguredRequestConfig .getScaleTimeout () != DEFAULT_SCALE_TIMEOUT ) {
533
+ requestConfigBuilder .withScaleTimeout (autoConfiguredRequestConfig .getScaleTimeout ());
534
+ }
535
+ if (userProvidedRequestConfig .getRequestRetryBackoffLimit () == DEFAULT_REQUEST_RETRY_BACKOFFLIMIT
536
+ && autoConfiguredRequestConfig .getRequestRetryBackoffLimit () != DEFAULT_REQUEST_RETRY_BACKOFFLIMIT ) {
537
+ requestConfigBuilder .withRequestRetryBackoffLimit (autoConfiguredRequestConfig .getRequestRetryBackoffLimit ());
538
+ }
539
+ if (userProvidedRequestConfig .getRequestRetryBackoffInterval () == DEFAULT_REQUEST_RETRY_BACKOFFINTERVAL
540
+ && autoConfiguredRequestConfig .getRequestRetryBackoffInterval () != DEFAULT_REQUEST_RETRY_BACKOFFINTERVAL ) {
541
+ requestConfigBuilder .withRequestRetryBackoffInterval (autoConfiguredRequestConfig .getRequestRetryBackoffInterval ());
542
+ }
543
+ if (userProvidedRequestConfig .getUploadRequestTimeout () == DEFAULT_UPLOAD_REQUEST_TIMEOUT
544
+ && autoConfiguredRequestConfig .getRequestTimeout () != DEFAULT_UPLOAD_REQUEST_TIMEOUT ) {
545
+ requestConfigBuilder .withUploadRequestTimeout (autoConfiguredRequestConfig .getUploadRequestTimeout ());
546
+ }
547
+ return requestConfigBuilder .build ();
403
548
}
404
549
405
550
public static void configFromSysPropsOrEnvVars (Config config ) {
0 commit comments