|
19 | 19 | import io.kubernetes.client.util.authenticators.Authenticator; |
20 | 20 | import io.kubernetes.client.util.authenticators.AzureActiveDirectoryAuthenticator; |
21 | 21 | import io.kubernetes.client.util.authenticators.GCPAuthenticator; |
| 22 | +import java.io.File; |
22 | 23 | import java.io.IOException; |
23 | 24 | import java.io.InputStream; |
24 | 25 | import java.io.InputStreamReader; |
@@ -61,6 +62,7 @@ public class KubeConfig { |
61 | 62 | String currentNamespace; |
62 | 63 | Object preferences; |
63 | 64 | ConfigPersister persister; |
| 65 | + private File file; |
64 | 66 |
|
65 | 67 | public static void registerAuthenticator(Authenticator auth) { |
66 | 68 | synchronized (authenticators) { |
@@ -283,9 +285,18 @@ private String tokenViaExecCredential(Map<String, Object> execMap) { |
283 | 285 | } |
284 | 286 |
|
285 | 287 | private JsonElement runExec(String command, List<String> args, List<Map<String, String>> env) { |
286 | | - // TODO relativize command to basedir of config file (requires KubeConfig to be given a basedir) |
287 | 288 | List<String> argv = new ArrayList<>(); |
288 | | - argv.add(command); |
| 289 | + if (command.startsWith("./")) { |
| 290 | + // TODO spec is unclear on what should be treated as a “relative command path” |
| 291 | + File resolvedCommand = new File(file.getParentFile(), command); |
| 292 | + if (!resolvedCommand.isFile()) { |
| 293 | + log.error("No such file: {}", resolvedCommand); |
| 294 | + return null; |
| 295 | + } |
| 296 | + argv.add(resolvedCommand.getAbsolutePath()); |
| 297 | + } else { |
| 298 | + argv.add(command); |
| 299 | + } |
289 | 300 | if (args != null) { |
290 | 301 | argv.addAll(args); |
291 | 302 | } |
@@ -337,6 +348,15 @@ public void setPersistConfig(ConfigPersister persister) { |
337 | 348 | this.persister = persister; |
338 | 349 | } |
339 | 350 |
|
| 351 | + /** |
| 352 | + * Indicates a file from which this configuration was loaded. |
| 353 | + * |
| 354 | + * @param file a file path, available for use when resolving relative file paths |
| 355 | + */ |
| 356 | + public void setFile(File file) { |
| 357 | + this.file = file; |
| 358 | + } |
| 359 | + |
340 | 360 | public void setPreferences(Object preferences) { |
341 | 361 | this.preferences = preferences; |
342 | 362 | } |
|
0 commit comments