Skip to content

Commit

Permalink
[SP-4263 | Abhishek/Anuja] Used KubectlCommandBuilder
Browse files Browse the repository at this point in the history
  • Loading branch information
anujachaitanya committed Nov 11, 2024
1 parent 3976980 commit fadbdf8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,10 @@ static String[] getDeleteSecretCommand(final String secretName) {
if (!StringUtil.hasText(secretName)) {
throw new IllegalArgumentException("secretName is required.");
}
return new String[] {"kubectl", "--namespace", K8SUtil.getWorkloadNamespace(), "delete", "secret", secretName};
return KubectlCommandBuilder.command("delete")
.namespace(K8SUtil.getWorkloadNamespace())
.option("secret", secretName)
.build();
}

static String[] getRegistryCreateSecretCommand(final ImageRegistryAuth registryAuth, final String secretName) {
Expand All @@ -142,18 +145,14 @@ static String[] getRegistryCreateSecretCommand(final ImageRegistryAuth registryA
throw new IllegalArgumentException("secretName is required.");
}

return new String[] {
"kubectl",
"--namespace",
K8SUtil.getWorkloadNamespace(),
"create",
"secret",
"docker-registry",
secretName,
"--docker-server=" + registryAuth.getHost(),
"--docker-username=" + registryAuth.getUsername(),
"--docker-password=" + new String(registryAuth.getSecret())
};
return KubectlCommandBuilder.command("create")
.namespace(K8SUtil.getWorkloadNamespace())
.argument("secret")
.option("docker-registry", secretName)
.argument("--docker-server=" + registryAuth.getHost())
.argument("--docker-username=" + registryAuth.getUsername())
.argument("--docker-password=" + new String(registryAuth.getSecret()))
.build();
}

public static JSONObject getSecretData(final String secretName, final String secretNamespace) throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public void testGetDeleteSecretCommand() {
final String[] deleteCommand = CommandExecutioner.getDeleteSecretCommand("mysecret");
Assert.assertArrayEquals(
"Wrong delete command.",
new String[] {"kubectl", "--namespace", K8SUtil.getWorkloadNamespace(), "delete", "secret", "mysecret"},
new String[] {"kubectl", "delete", "-n", K8SUtil.getWorkloadNamespace(), "secret", "mysecret"},
deleteCommand);
}

Expand Down

0 comments on commit fadbdf8

Please sign in to comment.