@@ -52,8 +52,7 @@ public class ClientBuilder {
52
52
* Creates an {@link ApiClient} by calling {@link #standard()} and {@link #build()}.
53
53
*
54
54
* @return An <tt>ApiClient</tt> configured using the precedence specified for {@link #standard()}.
55
- * @throws IOException
56
- * if the configuration file or a file specified in a configuration file cannot be read.
55
+ * @throws IOException if the configuration file or a file specified in a configuration file cannot be read.
57
56
*/
58
57
public static ApiClient defaultClient () throws IOException {
59
58
return ClientBuilder .standard ().build ();
@@ -63,23 +62,22 @@ public static ApiClient defaultClient() throws IOException {
63
62
* Creates a builder which is pre-configured in the following way
64
63
*
65
64
* <ul>
66
- * <li>If $KUBECONFIG is defined, use that config file.</li>
67
- * <li>If $HOME/.kube/config can be found, use that.</li>
68
- * <li>If the in-cluster service account can be found, assume in cluster config.</li>
69
- * <li>Default to localhost:8080 as a last resort.</li>
65
+ * <li>If $KUBECONFIG is defined, use that config file.</li>
66
+ * <li>If $HOME/.kube/config can be found, use that.</li>
67
+ * <li>If the in-cluster service account can be found, assume in cluster config.</li>
68
+ * <li>Default to localhost:8080 as a last resort.</li>
70
69
* </ul>
71
70
*
72
71
* @return <tt>ClientBuilder</tt> pre-configured using the above precedence
73
- * @throws IOException
74
- * if the configuration file or a file specified in a configuration file cannot be read.
72
+ * @throws IOException if the configuration file or a file specified in a configuration file cannot be read.
75
73
*/
76
74
public static ClientBuilder standard () throws IOException {
77
75
final FileReader kubeConfigReader = findConfigFromEnv ();
78
- if (kubeConfigReader != null ) {
76
+ if (kubeConfigReader != null ) {
79
77
return kubeconfig (loadKubeConfig (kubeConfigReader ));
80
78
}
81
79
final FileReader configReader = findConfigInHomeDir ();
82
- if (configReader != null ) {
80
+ if (configReader != null ) {
83
81
return kubeconfig (loadKubeConfig (configReader ));
84
82
}
85
83
final File clusterCa = new File (SERVICEACCOUNT_CA_PATH );
@@ -89,25 +87,26 @@ public static ClientBuilder standard() throws IOException {
89
87
return new ClientBuilder ();
90
88
}
91
89
92
- private static FileReader findConfigFromEnv () {
93
- try {
94
- String kubeConfig = System .getenv (ENV_KUBECONFIG );
95
- if (kubeConfig == null ) {
96
- return null ;
97
- }
90
+ private static FileReader findConfigFromEnv () throws FileNotFoundException {
91
+ String kubeConfigPath = System .getenv (ENV_KUBECONFIG );
92
+ if (kubeConfigPath == null ) {
93
+ return null ;
94
+ }
95
+ final File kubeConfig = new File (kubeConfigPath );
96
+ if (kubeConfig .exists ()) {
98
97
return new FileReader (kubeConfig );
99
- } catch ( FileNotFoundException e ) {
100
- log .info ("Could not find file specified in $KUBECONFIG" );
98
+ } else {
99
+ log .debug ("Could not find file specified in $KUBECONFIG" );
101
100
return null ;
102
101
}
103
102
}
104
103
105
- private static FileReader findConfigInHomeDir () {
106
- try {
107
- File config = new File ( new File ( System . getenv ( ENV_HOME ), KUBEDIR ), KUBECONFIG );
104
+ private static FileReader findConfigInHomeDir () throws FileNotFoundException {
105
+ final File config = new File ( new File ( System . getenv ( ENV_HOME ), KUBEDIR ), KUBECONFIG );
106
+ if ( config . exists ()) {
108
107
return new FileReader (config );
109
- } catch ( FileNotFoundException e ) {
110
- log .info ("Could not find ~/.kube/config" );
108
+ } else {
109
+ log .debug ("Could not find ~/.kube/config" );
111
110
return null ;
112
111
}
113
112
}
@@ -116,8 +115,7 @@ private static FileReader findConfigInHomeDir() {
116
115
* Creates a builder which is pre-configured from the cluster configuration.
117
116
*
118
117
* @return <tt>ClientBuilder</tt> configured from the cluster configuration.
119
- * @throws IOException
120
- * if the Service Account Token Path or CA Path is not readable.
118
+ * @throws IOException if the Service Account Token Path or CA Path is not readable.
121
119
*/
122
120
public static ClientBuilder cluster () throws IOException {
123
121
final ClientBuilder builder = new ClientBuilder ();
@@ -139,11 +137,9 @@ public static ClientBuilder cluster() throws IOException {
139
137
*
140
138
* To load a <tt>KubeConfig</tt>, see {@link KubeConfig#loadKubeConfig(Reader)}.
141
139
*
142
- * @param config
143
- * The {@link KubeConfig} to configure the builder from.
140
+ * @param config The {@link KubeConfig} to configure the builder from.
144
141
* @return <tt>ClientBuilder</tt> configured from the provided <tt>KubeConfig</tt>
145
- * @throws IOException
146
- * if the files specified in the provided <tt>KubeConfig</tt> are not readable
142
+ * @throws IOException if the files specified in the provided <tt>KubeConfig</tt> are not readable
147
143
*/
148
144
public static ClientBuilder kubeconfig (KubeConfig config ) throws IOException {
149
145
final ClientBuilder builder = new ClientBuilder ();
@@ -157,17 +153,14 @@ public static ClientBuilder kubeconfig(KubeConfig config) throws IOException {
157
153
}
158
154
}
159
155
160
- if (config .verifySSL ()) {
161
- final byte [] caBytes = KubeConfig .getDataOrFile (config .getCertificateAuthorityData (),
162
- config .getCertificateAuthorityFile ());
163
- if (caBytes != null ) {
164
- builder .setCertificateAuthority (caBytes );
165
- }
166
- builder .setVerifyingSsl (true );
167
- } else {
168
- builder .setVerifyingSsl (false );
156
+ final byte [] caBytes = KubeConfig .getDataOrFile (config .getCertificateAuthorityData (),
157
+ config .getCertificateAuthorityFile ());
158
+ if (caBytes != null ) {
159
+ builder .setCertificateAuthority (caBytes );
169
160
}
170
161
162
+ builder .setVerifyingSsl (config .verifySSL ());
163
+
171
164
builder .setBasePath (server );
172
165
builder .setAuthentication (new KubeconfigAuthentication (config ));
173
166
return builder ;
@@ -193,7 +186,6 @@ public ClientBuilder setAuthentication(final Authentication authentication) {
193
186
194
187
public ClientBuilder setCertificateAuthority (final byte [] caCertBytes ) {
195
188
this .caCertBytes = caCertBytes ;
196
- this .verifyingSsl = true ;
197
189
return this ;
198
190
}
199
191
0 commit comments