17
17
import static io .kubernetes .client .util .Config .ENV_SERVICE_PORT ;
18
18
import static io .kubernetes .client .util .Config .SERVICEACCOUNT_CA_PATH ;
19
19
import static io .kubernetes .client .util .Config .SERVICEACCOUNT_TOKEN_PATH ;
20
- import static io .kubernetes .client .util .KubeConfig .*;
20
+ import static io .kubernetes .client .util .KubeConfig .ENV_HOME ;
21
+ import static io .kubernetes .client .util .KubeConfig .KUBECONFIG ;
22
+ import static io .kubernetes .client .util .KubeConfig .KUBEDIR ;
21
23
22
24
import io .kubernetes .client .ApiClient ;
23
25
import io .kubernetes .client .util .credentials .AccessTokenAuthentication ;
@@ -77,7 +79,7 @@ public static ClientBuilder standard(boolean persistConfig) throws IOException {
77
79
final File kubeConfig = findConfigFromEnv ();
78
80
if (kubeConfig != null ) {
79
81
try (FileReader kubeConfigReader = new FileReader (kubeConfig )) {
80
- KubeConfig kc = loadKubeConfig (kubeConfigReader );
82
+ KubeConfig kc = KubeConfig . loadKubeConfig (kubeConfigReader );
81
83
if (persistConfig ) {
82
84
kc .setPersistConfig (new FilePersister (kubeConfig ));
83
85
}
@@ -87,7 +89,7 @@ public static ClientBuilder standard(boolean persistConfig) throws IOException {
87
89
final File config = findConfigInHomeDir ();
88
90
if (config != null ) {
89
91
try (FileReader configReader = new FileReader (config )) {
90
- KubeConfig kc = loadKubeConfig (configReader );
92
+ KubeConfig kc = KubeConfig . loadKubeConfig (configReader );
91
93
if (persistConfig ) {
92
94
kc .setPersistConfig (new FilePersister (config ));
93
95
}
@@ -115,14 +117,44 @@ private static File findConfigFromEnv() {
115
117
}
116
118
}
117
119
118
- private static File findConfigInHomeDir () {
119
- final File config = new File (new File ( System .getenv (ENV_HOME ), KUBEDIR ), KUBECONFIG );
120
+ private static File findHomeDir () {
121
+ final File config = new File (System .getenv (ENV_HOME ));
120
122
if (config .exists ()) {
121
123
return config ;
122
- } else {
123
- log .debug ("Could not find ~/.kube/config" );
124
- return null ;
125
124
}
125
+ if (System .getProperty ("os.name" ).toLowerCase ().startsWith ("windows" )) {
126
+ String homeDrive = System .getenv ("HOMEDRIVE" );
127
+ String homePath = System .getenv ("HOMEPATH" );
128
+ if (homeDrive != null
129
+ && homeDrive .length () > 0
130
+ && homePath != null
131
+ && homePath .length () > 0 ) {
132
+ File homeDir = new File (new File (homeDrive ), homePath );
133
+ if (homeDir .exists ()) {
134
+ return homeDir ;
135
+ }
136
+ }
137
+ String userProfile = System .getenv ("USERPROFILE" );
138
+ if (userProfile != null && userProfile .length () > 0 ) {
139
+ File profileDir = new File (userProfile );
140
+ if (profileDir .exists ()) {
141
+ return profileDir ;
142
+ }
143
+ }
144
+ }
145
+ return null ;
146
+ }
147
+
148
+ private static File findConfigInHomeDir () {
149
+ final File homeDir = findHomeDir ();
150
+ if (homeDir != null ) {
151
+ final File config = new File (new File (homeDir , KUBEDIR ), KUBECONFIG );
152
+ if (config .exists ()) {
153
+ return config ;
154
+ }
155
+ }
156
+ log .debug ("Could not find ~/.kube/config" );
157
+ return null ;
126
158
}
127
159
128
160
/**
0 commit comments