Skip to content

Commit f843269

Browse files
committed
Broader interpretation of “relative command path”.
1 parent 93b87f4 commit f843269

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import java.nio.charset.StandardCharsets;
2828
import java.nio.file.FileSystems;
2929
import java.nio.file.Files;
30+
import java.nio.file.Path;
3031
import java.nio.file.Paths;
3132
import java.util.ArrayList;
3233
import java.util.HashMap;
@@ -294,14 +295,17 @@ private String tokenViaExecCredential(Map<String, Object> execMap) {
294295

295296
private JsonElement runExec(String command, List<String> args, List<Map<String, String>> env) {
296297
List<String> argv = new ArrayList<>();
297-
if (command.startsWith("./")) {
298-
// TODO spec is unclear on what should be treated as a “relative command path”
299-
File resolvedCommand = new File(file.getParentFile(), command);
300-
if (!resolvedCommand.isFile()) {
298+
if (command.contains("/") || command.contains("\\")) {
299+
// Spec is unclear on what should be treated as a “relative command path”.
300+
// This clause should cover anything not resolved from $PATH / %Path%.
301+
Path resolvedCommand = file.toPath().getParent().resolve(command).normalize();
302+
if (!Files.exists(resolvedCommand)) {
301303
log.error("No such file: {}", resolvedCommand);
302304
return null;
303305
}
304-
argv.add(resolvedCommand.getAbsolutePath());
306+
// Not checking isRegularFile or isExecutable here; leave that to ProcessBuilder.start.
307+
log.debug("Resolved {} to {}", command, resolvedCommand);
308+
argv.add(resolvedCommand.toString());
305309
} else {
306310
argv.add(command);
307311
}

0 commit comments

Comments
 (0)