1717import static io .kubernetes .client .util .Config .ENV_SERVICE_PORT ;
1818import static io .kubernetes .client .util .Config .SERVICEACCOUNT_CA_PATH ;
1919import 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 ;
2123
2224import io .kubernetes .client .ApiClient ;
2325import io .kubernetes .client .util .credentials .AccessTokenAuthentication ;
@@ -77,7 +79,7 @@ public static ClientBuilder standard(boolean persistConfig) throws IOException {
7779 final File kubeConfig = findConfigFromEnv ();
7880 if (kubeConfig != null ) {
7981 try (FileReader kubeConfigReader = new FileReader (kubeConfig )) {
80- KubeConfig kc = loadKubeConfig (kubeConfigReader );
82+ KubeConfig kc = KubeConfig . loadKubeConfig (kubeConfigReader );
8183 if (persistConfig ) {
8284 kc .setPersistConfig (new FilePersister (kubeConfig ));
8385 }
@@ -87,7 +89,7 @@ public static ClientBuilder standard(boolean persistConfig) throws IOException {
8789 final File config = findConfigInHomeDir ();
8890 if (config != null ) {
8991 try (FileReader configReader = new FileReader (config )) {
90- KubeConfig kc = loadKubeConfig (configReader );
92+ KubeConfig kc = KubeConfig . loadKubeConfig (configReader );
9193 if (persistConfig ) {
9294 kc .setPersistConfig (new FilePersister (config ));
9395 }
@@ -115,14 +117,44 @@ private static File findConfigFromEnv() {
115117 }
116118 }
117119
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 ));
120122 if (config .exists ()) {
121123 return config ;
122- } else {
123- log .debug ("Could not find ~/.kube/config" );
124- return null ;
125124 }
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 ;
126158 }
127159
128160 /**
0 commit comments