Skip to content

Commit 10597c7

Browse files
author
Himanshu Pandey
committed
Set config file when using home directory
1 parent 7ae5d03 commit 10597c7

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

util/src/main/java/io/kubernetes/client/util/ClientBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public static ClientBuilder standard(boolean persistConfig) throws IOException {
9797
if (persistConfig) {
9898
kc.setPersistConfig(new FilePersister(config));
9999
}
100-
kc.setFile(kubeConfig);
100+
kc.setFile(config);
101101
return kubeconfig(kc);
102102
}
103103
}

util/src/test/java/io/kubernetes/client/util/ClientBuilderTest.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ public class ClientBuilderTest {
4949
private String userName = "userName";
5050
private String password = "password";
5151
private String apiKeyPrefix = "Bearer";
52+
public static final String KUBEDIR = ".kube";
53+
public static final String KUBECONFIG = "config";
5254

5355
@Rule public final EnvironmentVariables environmentVariables = new EnvironmentVariables();
5456

@@ -172,4 +174,13 @@ public void testOverridePatchFormat() throws IOException, ApiException {
172174
.setOverridePatchFormat(V1Patch.PATCH_FORMAT_STRATEGIC_MERGE_PATCH)
173175
.build();
174176
}
177+
178+
@Test
179+
public void testHomeDirPreferredOverKubeConfig() throws Exception {
180+
environmentVariables.set("HOME", HOME_PATH);
181+
environmentVariables.set("KUBEDIR", KUBEDIR);
182+
environmentVariables.set("KUBECONFIG", KUBECONFIG);
183+
final ApiClient client = ClientBuilder.standard().build();
184+
assertEquals("http://home.dir.com", client.getBasePath());
185+
}
175186
}

0 commit comments

Comments
 (0)