Skip to content

Commit

Permalink
Do not discard auth command if no args
Browse files Browse the repository at this point in the history
(cherry picked from commit 0c19ce2)
Signed-off-by: Marc Nuri <[email protected]>
  • Loading branch information
markusheiden authored and manusa committed Sep 28, 2022
1 parent 44d65ed commit fdbe6f3
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
### 5.12-SNAPSHOT

#### Bugs
* Fix #3733: The authentication command from the .kube/config won't be discarded if no arguments are specified
* Fix #4365: backport of stopped future for informers to obtain the termination exception
* Fix #4383: bump snakeyaml from 1.28 to 1.33

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -695,8 +695,8 @@ protected static List<String> getAuthenticatorCommandFromExecConfig(ExecConfig e
List<String> argv = new ArrayList<>(Utils.getCommandPlatformPrefix());
command = getCommandWithFullyQualifiedPath(command, systemPathValue);
List<String> args = exec.getArgs();
if (args != null) {
argv.add(command + " " + String.join( " ", args));
if (args != null && !args.isEmpty()) {
argv.add(command + " " + String.join(" ", args));
}
return argv;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,30 @@ void testGetAuthenticatorCommandFromExecConfig() throws IOException {
assertEquals("api-eks.example.com", commandParts.get(6));
}

@Test
void testGetAuthenticatorCommandFromExecConfigNullArgs() throws IOException {
// Given
File commandFolder = Files.createTempDirectory("test").toFile();
File commandFile = new File(commandFolder, "gke-gcloud-auth-plugin");
String systemPathValue = getTestPathValue(commandFolder);
ExecConfig execConfigNoArgs = new ExecConfigBuilder()
.withApiVersion("client.authentication.k8s.io/v1alpha1")
.withCommand(commandFile.getPath())
.build();
// Simulate "user.exec.args: null" like e.g. in the configuration for the gke-gcloud-auth-plugin.
execConfigNoArgs.setArgs(null);

// When
List<String> processBuilderArgs = Config.getAuthenticatorCommandFromExecConfig(
execConfigNoArgs, null, systemPathValue);

// Then
assertNotNull(processBuilderArgs);
assertEquals(3, processBuilderArgs.size());
assertPlatformPrefixes(processBuilderArgs);
assertEquals(commandFile.getPath(), processBuilderArgs.get(2));
}

private void assertPlatformPrefixes(List<String> processBuilderArgs) {
List<String> platformArgsExpected = Utils.getCommandPlatformPrefix();
assertEquals(platformArgsExpected.get(0), processBuilderArgs.get(0));
Expand Down

0 comments on commit fdbe6f3

Please sign in to comment.