Skip to content

Commit 30a26f7

Browse files
authored
Merge pull request #3244 from kubernetes-client/file
Fix an NPE bug in command handling if there is no directory for the kubeconfig file.
2 parents b49e84f + 6fadadb commit 30a26f7

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,14 @@ private JsonElement runExec(String command, List<String> args, List<Map<String,
328328
if (command.contains("/") || command.contains("\\")) {
329329
// Spec is unclear on what should be treated as a “relative command path”.
330330
// This clause should cover anything not resolved from $PATH / %Path%.
331-
Path resolvedCommand = file.toPath().getParent().resolve(command).normalize();
331+
Path resolvedCommand;
332+
if (file != null) {
333+
// If we know where the Kubeconfig was located, use that as the base.
334+
resolvedCommand = file.toPath().getParent().resolve(command).normalize();
335+
} else {
336+
// Otherwise, try the current working directory
337+
resolvedCommand = Paths.get(command).normalize();
338+
}
332339
if (!Files.exists(resolvedCommand)) {
333340
log.error("No such file: {}", resolvedCommand);
334341
return null;

0 commit comments

Comments
 (0)