Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not discard auth command if no args #4121

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -6,6 +6,7 @@
* Fix #3745: the client will throw better exceptions when a namespace is not discernible for an operation
* Fix #4106: removed listing from projectrequests
* Fix #4081: moving Versionable.withResourceVersion to a method on WatchAndWaitable and removing Waitable from the return type
* Fix #3733: The authentication command from the .kube/config won't be discarded if no arguments are specified

#### Improvements
* Remove `setIntVal`, `setStrVal`, `setKind` setters from `IntOrString` class to avoid invalid combinations
Expand Down
Expand Up @@ -766,9 +766,10 @@ 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()) {
command += " " + String.join(" ", args);
}
argv.add(command);
return argv;
}

Expand Down
Expand Up @@ -582,6 +582,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