Skip to content

Commit af95235

Browse files
committed
kubectl exec follow-up/refactors
1 parent abdc530 commit af95235

File tree

3 files changed

+11
-14
lines changed

3 files changed

+11
-14
lines changed

examples/src/main/java/io/kubernetes/client/examples/KubectlExample.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,14 @@ public static void main(String[] args)
110110
System.exit(0);
111111
case "exec":
112112
name = args[1];
113-
String[] command = Arrays.copyOfRange(args, 1, args.length);
113+
String[] command = Arrays.copyOfRange(args, 2, args.length);
114114
KubectlExec e =
115-
exec(client).namespace(ns).name(name).container(cli.getOptionValue("c", ""));
116-
e.execute();
117-
System.exit(e.exitCode());
115+
exec(client)
116+
.namespace(ns)
117+
.name(name)
118+
.command(command)
119+
.container(cli.getOptionValue("c", ""));
120+
System.exit(e.execute());
118121
default:
119122
System.out.println("Unknown verb: " + verb);
120123
System.exit(-1);

extended/src/main/java/io/kubernetes/client/extended/kubectl/KubectlAnnotate.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import org.apache.commons.lang.StringUtils;
2525

2626
public class KubectlAnnotate<ApiType extends KubernetesObject>
27-
extends Kubectl.ResourceBuilder<KubectlAnnotate<ApiType>>
27+
extends Kubectl.ResourceBuilder<ApiType, KubectlAnnotate<ApiType>>
2828
implements Kubectl.Executable<ApiType> {
2929

3030
private final ApiClient apiClient;

extended/src/main/java/io/kubernetes/client/extended/kubectl/KubectlExec.java

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,10 @@
2424
import java.io.OutputStream;
2525

2626
public class KubectlExec extends Kubectl.ResourceAndContainerBuilder<V1Pod, KubectlExec>
27-
implements Kubectl.Executable<V1Pod> {
27+
implements Kubectl.Executable<Integer> {
2828
private String[] command;
2929
private boolean stdin;
3030
private boolean tty;
31-
private int result;
3231

3332
KubectlExec(ApiClient client) {
3433
super(client, V1Pod.class);
@@ -49,12 +48,8 @@ public KubectlExec tty(boolean tty) {
4948
return this;
5049
}
5150

52-
public int exitCode() {
53-
return result;
54-
}
55-
5651
@Override
57-
public V1Pod execute() throws KubectlException {
52+
public Integer execute() throws KubectlException {
5853
V1Pod pod = new V1Pod().metadata(new V1ObjectMeta().name(name).namespace(namespace));
5954

6055
Exec exec = new Exec(apiClient);
@@ -65,11 +60,10 @@ public V1Pod execute() throws KubectlException {
6560
if (stdin) {
6661
copyAsync(System.in, proc.getOutputStream());
6762
}
68-
this.result = proc.waitFor();
63+
return proc.waitFor();
6964
} catch (InterruptedException | ApiException | IOException ex) {
7065
throw new KubectlException(ex);
7166
}
72-
return pod;
7367
}
7468

7569
private static void copyAsync(InputStream in, OutputStream out) {

0 commit comments

Comments
 (0)