@@ -22,41 +22,36 @@ public static Config createConfig(KubernetesClientBuildConfig buildConfig) {
2222 .orElse (false );
2323 Config base = Config .autoConfigure (null );
2424 boolean trustAll = buildConfig .trustCerts ().isPresent () ? buildConfig .trustCerts ().get () : globalTrustAll ;
25- return new ConfigBuilder ()
26- .withTrustCerts (trustAll )
27- .withWatchReconnectInterval (
28- millisAsInt (buildConfig .watchReconnectInterval ()).orElse (base .getWatchReconnectInterval ()))
29- .withWatchReconnectLimit (buildConfig .watchReconnectLimit ().orElse (base .getWatchReconnectLimit ()))
30- .withConnectionTimeout (millisAsInt (buildConfig .connectionTimeout ()).orElse (base .getConnectionTimeout ()))
31- .withRequestTimeout (millisAsInt (buildConfig .requestTimeout ()).orElse (base .getRequestTimeout ()))
32- .withMasterUrl (buildConfig .apiServerUrl ().or (() -> buildConfig .masterUrl ()).orElse (base .getMasterUrl ()))
33- .withNamespace (buildConfig .namespace ().orElse (base .getNamespace ()))
34- .withUsername (buildConfig .username ().orElse (base .getUsername ()))
35- .withPassword (buildConfig .password ().orElse (base .getPassword ()))
36- .withOauthToken (buildConfig .token ().orElse (base .getOauthToken ()))
37- .withCaCertFile (buildConfig .caCertFile ().orElse (base .getCaCertFile ()))
38- .withCaCertData (buildConfig .caCertData ().orElse (base .getCaCertData ()))
39- .withClientCertFile (buildConfig .clientCertFile ().orElse (base .getClientCertFile ()))
40- .withClientCertData (buildConfig .clientCertData ().orElse (base .getClientCertData ()))
41- .withClientKeyFile (buildConfig .clientKeyFile ().orElse (base .getClientKeyFile ()))
42- .withClientKeyData (buildConfig .clientKeyData ().orElse (base .getClientKeyData ()))
43- .withClientKeyPassphrase (buildConfig .clientKeyPassphrase ().orElse (base .getClientKeyPassphrase ()))
44- .withClientKeyAlgo (buildConfig .clientKeyAlgo ().orElse (base .getClientKeyAlgo ()))
45- .withHttpProxy (buildConfig .httpProxy ().orElse (base .getHttpProxy ()))
46- .withHttpsProxy (buildConfig .httpsProxy ().orElse (base .getHttpsProxy ()))
47- .withProxyUsername (buildConfig .proxyUsername ().orElse (base .getProxyUsername ()))
48- .withProxyPassword (buildConfig .proxyPassword ().orElse (base .getProxyPassword ()))
49- .withNoProxy (buildConfig .noProxy ().map (list -> list .toArray (new String [0 ])).orElse (base .getNoProxy ()))
50- .withHttp2Disable (base .isHttp2Disable ())
51- .withRequestRetryBackoffInterval (millisAsInt (buildConfig .requestRetryBackoffInterval ())
52- .orElse (base .getRequestRetryBackoffInterval ()))
53- .withRequestRetryBackoffLimit (buildConfig .requestRetryBackoffLimit ().orElse (base .getRequestRetryBackoffLimit ()))
54- .build ();
25+ final var configBuilder = new ConfigBuilder (base ).withTrustCerts (trustAll );
26+ buildConfig .watchReconnectInterval ().ifPresent (d -> configBuilder .withWatchReconnectInterval (millisAsInt (d )));
27+ buildConfig .watchReconnectLimit ().ifPresent (configBuilder ::withWatchReconnectLimit );
28+ buildConfig .connectionTimeout ().ifPresent (d -> configBuilder .withConnectionTimeout (millisAsInt (d )));
29+ buildConfig .requestTimeout ().ifPresent (d -> configBuilder .withRequestTimeout (millisAsInt (d )));
30+ buildConfig .apiServerUrl ().or (buildConfig ::masterUrl ).ifPresent (configBuilder ::withMasterUrl );
31+ buildConfig .namespace ().ifPresent (configBuilder ::withNamespace );
32+ buildConfig .username ().ifPresent (configBuilder ::withUsername );
33+ buildConfig .password ().ifPresent (configBuilder ::withPassword );
34+ buildConfig .token ().ifPresent (configBuilder ::withOauthToken );
35+ buildConfig .caCertFile ().ifPresent (configBuilder ::withCaCertFile );
36+ buildConfig .caCertData ().ifPresent (configBuilder ::withCaCertData );
37+ buildConfig .clientCertFile ().ifPresent (configBuilder ::withClientCertFile );
38+ buildConfig .clientCertData ().ifPresent (configBuilder ::withClientCertData );
39+ buildConfig .clientKeyFile ().ifPresent (configBuilder ::withClientKeyFile );
40+ buildConfig .clientKeyData ().ifPresent (configBuilder ::withClientKeyData );
41+ buildConfig .clientKeyAlgo ().ifPresent (configBuilder ::withClientKeyAlgo );
42+ buildConfig .clientKeyPassphrase ().ifPresent (configBuilder ::withClientKeyPassphrase );
43+ buildConfig .httpProxy ().ifPresent (configBuilder ::withHttpProxy );
44+ buildConfig .httpsProxy ().ifPresent (configBuilder ::withHttpsProxy );
45+ buildConfig .proxyUsername ().ifPresent (configBuilder ::withProxyUsername );
46+ buildConfig .proxyPassword ().ifPresent (configBuilder ::withProxyPassword );
47+ buildConfig .noProxy ().ifPresent (list -> list .toArray (new String [0 ]));
48+ buildConfig .requestRetryBackoffInterval ().ifPresent (d -> configBuilder .withRequestRetryBackoffInterval (millisAsInt (d )));
49+ buildConfig .requestRetryBackoffLimit ().ifPresent (configBuilder ::withRequestRetryBackoffLimit );
50+ return configBuilder .build ();
5551 }
5652
57- @ SuppressWarnings ("OptionalUsedAsFieldOrParameterType" )
58- private static Optional <Integer > millisAsInt (Optional <Duration > duration ) {
59- return duration .map (d -> (int ) d .toMillis ());
53+ private static int millisAsInt (Duration duration ) {
54+ return (int ) duration .toMillis ();
6055 }
6156
6257 public static KubernetesClient createClient (KubernetesClientBuildConfig buildConfig ) {
@@ -66,43 +61,41 @@ public static KubernetesClient createClient(KubernetesClientBuildConfig buildCon
6661 public static KubernetesClient createClient () {
6762 org .eclipse .microprofile .config .Config config = ConfigProvider .getConfig ();
6863 Config base = Config .autoConfigure (null );
69- return new KubernetesClientBuilder ().withConfig (new ConfigBuilder ()
70- .withTrustCerts (config .getOptionalValue (PREFIX + "trust-certs" , Boolean .class ).orElse (base .isTrustCerts ()))
71- .withWatchReconnectLimit (config .getOptionalValue (PREFIX + "watch-reconnect-limit" , Integer .class )
72- .orElse (base .getWatchReconnectLimit ()))
73- .withWatchReconnectInterval ((int ) config .getOptionalValue (PREFIX + "watch-reconnect-interval" , Duration .class )
74- .orElse (Duration .ofMillis (base .getWatchReconnectInterval ())).toMillis ())
75- .withConnectionTimeout ((int ) config .getOptionalValue (PREFIX + "connection-timeout" , Duration .class )
76- .orElse (Duration .ofMillis (base .getConnectionTimeout ())).toMillis ())
77- .withRequestTimeout ((int ) config .getOptionalValue (PREFIX + "request-timeout" , Duration .class )
78- .orElse (Duration .ofMillis (base .getRequestTimeout ())).toMillis ())
79- .withMasterUrl (config .getOptionalValue (PREFIX + "api-server-url" , String .class )
80- .or (() -> config .getOptionalValue (PREFIX + "master-url" , String .class )).orElse (base .getMasterUrl ()))
81- .withNamespace (config .getOptionalValue (PREFIX + "namespace" , String .class ).orElse (base .getNamespace ()))
82- .withUsername (config .getOptionalValue (PREFIX + "username" , String .class ).orElse (base .getUsername ()))
83- .withPassword (config .getOptionalValue (PREFIX + "password" , String .class ).orElse (base .getPassword ()))
84- .withCaCertFile (config .getOptionalValue (PREFIX + "ca-cert-file" , String .class ).orElse (base .getCaCertFile ()))
85- .withCaCertData (config .getOptionalValue (PREFIX + "ca-cert-data" , String .class ).orElse (base .getCaCertData ()))
86- .withClientCertFile (
87- config .getOptionalValue (PREFIX + "client-cert-file" , String .class ).orElse (base .getClientCertFile ()))
88- .withClientCertData (
89- config .getOptionalValue (PREFIX + "client-cert-data" , String .class ).orElse (base .getClientCertData ()))
90- .withClientKeyFile (
91- config .getOptionalValue (PREFIX + "client-key-file" , String .class ).orElse (base .getClientKeyFile ()))
92- .withClientKeyData (
93- config .getOptionalValue (PREFIX + "client-key-data" , String .class ).orElse (base .getClientKeyData ()))
94- .withClientKeyPassphrase (config .getOptionalValue (PREFIX + "client-key-passphrase" , String .class )
95- .orElse (base .getClientKeyPassphrase ()))
96- .withClientKeyAlgo (
97- config .getOptionalValue (PREFIX + "client-key-algo" , String .class ).orElse (base .getClientKeyAlgo ()))
98- .withHttpProxy (config .getOptionalValue (PREFIX + "http-proxy" , String .class ).orElse (base .getHttpProxy ()))
99- .withHttpsProxy (config .getOptionalValue (PREFIX + "https-proxy" , String .class ).orElse (base .getHttpsProxy ()))
100- .withProxyUsername (
101- config .getOptionalValue (PREFIX + "proxy-username" , String .class ).orElse (base .getProxyUsername ()))
102- .withProxyPassword (
103- config .getOptionalValue (PREFIX + "proxy-password" , String .class ).orElse (base .getProxyPassword ()))
104- .withNoProxy (config .getOptionalValue (PREFIX + "no-proxy" , String [].class ).orElse (base .getNoProxy ()))
105- .build ())
106- .build ();
64+ final var configBuilder = new ConfigBuilder (base );
65+ optional (config , "trust-certs" , Boolean .class ).ifPresent (configBuilder ::withTrustCerts );
66+ optional (config , "watch-reconnect-limit" , Integer .class ).ifPresent (configBuilder ::withWatchReconnectLimit );
67+ optional (config , "watch-reconnect-interval" , Duration .class )
68+ .map (KubernetesClientUtils ::millisAsInt )
69+ .ifPresent (configBuilder ::withWatchReconnectInterval );
70+ optional (config , "connection-timeout" , Duration .class )
71+ .map (KubernetesClientUtils ::millisAsInt )
72+ .ifPresent (configBuilder ::withConnectionTimeout );
73+ optional (config , "request-timeout" , Duration .class )
74+ .map (KubernetesClientUtils ::millisAsInt )
75+ .ifPresent (configBuilder ::withRequestTimeout );
76+ optional (config , "api-server-url" , String .class )
77+ .or (() -> optional (config , "master-url" , String .class ))
78+ .ifPresent (configBuilder ::withMasterUrl );
79+ optional (config , "namespace" , String .class ).ifPresent (configBuilder ::withNamespace );
80+ optional (config , "username" , String .class ).ifPresent (configBuilder ::withUsername );
81+ optional (config , "password" , String .class ).ifPresent (configBuilder ::withPassword );
82+ optional (config , "ca-cert-file" , String .class ).ifPresent (configBuilder ::withCaCertFile );
83+ optional (config , "ca-cert-data" , String .class ).ifPresent (configBuilder ::withCaCertData );
84+ optional (config , "client-cert-file" , String .class ).ifPresent (configBuilder ::withClientCertFile );
85+ optional (config , "client-cert-data" , String .class ).ifPresent (configBuilder ::withClientCertData );
86+ optional (config , "client-key-file" , String .class ).ifPresent (configBuilder ::withClientKeyFile );
87+ optional (config , "client-key-data" , String .class ).ifPresent (configBuilder ::withClientKeyData );
88+ optional (config , "client-key-passphrase" , String .class ).ifPresent (configBuilder ::withClientKeyPassphrase );
89+ optional (config , "client-key-algo" , String .class ).ifPresent (configBuilder ::withClientKeyAlgo );
90+ optional (config , "http-proxy" , String .class ).ifPresent (configBuilder ::withHttpProxy );
91+ optional (config , "https-proxy" , String .class ).ifPresent (configBuilder ::withHttpsProxy );
92+ optional (config , "proxy-username" , String .class ).ifPresent (configBuilder ::withProxyUsername );
93+ optional (config , "proxy-password" , String .class ).ifPresent (configBuilder ::withProxyPassword );
94+ optional (config , "no-proxy" , String [].class ).ifPresent (configBuilder ::withNoProxy );
95+ return new KubernetesClientBuilder ().withConfig (configBuilder .build ()).build ();
96+ }
97+
98+ private static <T > Optional <T > optional (org .eclipse .microprofile .config .Config config , String key , Class <T > valueType ) {
99+ return config .getOptionalValue (PREFIX + key , valueType );
107100 }
108101}
0 commit comments