File tree Expand file tree Collapse file tree 2 files changed +32
-1
lines changed
main/java/io/kubernetes/client/util
test/java/io/kubernetes/client/util Expand file tree Collapse file tree 2 files changed +32
-1
lines changed Original file line number Diff line number Diff line change @@ -104,10 +104,14 @@ public static ClientBuilder standard(boolean persistConfig) throws IOException {
104
104
}
105
105
106
106
private static File findConfigFromEnv () {
107
- String kubeConfigPath = System .getenv (ENV_KUBECONFIG );
107
+ final KubeConfigEnvParser kubeConfigEnvParser = new KubeConfigEnvParser ();
108
+
109
+ final String kubeConfigPath =
110
+ kubeConfigEnvParser .parseKubeConfigPath (System .getenv (ENV_KUBECONFIG ));
108
111
if (kubeConfigPath == null ) {
109
112
return null ;
110
113
}
114
+
111
115
final File kubeConfig = new File (kubeConfigPath );
112
116
if (kubeConfig .exists ()) {
113
117
return kubeConfig ;
@@ -117,6 +121,24 @@ private static File findConfigFromEnv() {
117
121
}
118
122
}
119
123
124
+ private static class KubeConfigEnvParser {
125
+ private String parseKubeConfigPath (String kubeConfigEnv ) {
126
+ if (kubeConfigEnv == null ) {
127
+ return null ;
128
+ }
129
+
130
+ final String [] filePaths = kubeConfigEnv .split (File .pathSeparator );
131
+ final String kubeConfigPath = filePaths [0 ];
132
+ if (filePaths .length > 1 ) {
133
+ log .warn (
134
+ "Found multiple kubeconfigs files, $KUBECONFIG: " + kubeConfigEnv + " using first: {}" ,
135
+ kubeConfigPath );
136
+ }
137
+
138
+ return kubeConfigPath ;
139
+ }
140
+ }
141
+
120
142
private static File findHomeDir () {
121
143
final String envHome = System .getenv (ENV_HOME );
122
144
if (envHome != null && envHome .length () > 0 ) {
Original file line number Diff line number Diff line change 21
21
import com .google .common .io .Resources ;
22
22
import io .kubernetes .client .ApiClient ;
23
23
import io .kubernetes .client .util .credentials .Authentication ;
24
+ import java .io .File ;
24
25
import java .io .IOException ;
25
26
import java .nio .file .Files ;
26
27
import java .nio .file .Paths ;
@@ -76,6 +77,14 @@ public void testDefaultClientReadsKubeConfig() throws Exception {
76
77
assertEquals ("http://kubeconfig.dir.com" , client .getBasePath ());
77
78
}
78
79
80
+ @ Test
81
+ public void testDefaultClientReadsKubeConfigMultiple () throws Exception {
82
+ final String kubeConfigEnv = KUBECONFIG_FILE_PATH + File .pathSeparator + "/non-existent" ;
83
+ environmentVariables .set ("KUBECONFIG" , kubeConfigEnv );
84
+ final ApiClient client = ClientBuilder .defaultClient ();
85
+ assertEquals ("http://kubeconfig.dir.com" , client .getBasePath ());
86
+ }
87
+
79
88
@ Test
80
89
public void testKubeconfigPreferredOverHomeDir () throws Exception {
81
90
environmentVariables .set ("HOME" , HOME_PATH );
You can’t perform that action at this time.
0 commit comments