Skip to content

Commit 3988b5c

Browse files
committed
Respond to comments.
1 parent 6ec0ebd commit 3988b5c

File tree

2 files changed

+16
-18
lines changed

2 files changed

+16
-18
lines changed

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import com.google.common.io.ByteStreams;
2222
import io.kubernetes.client.common.KubernetesObject;
2323
import io.kubernetes.client.extended.kubectl.KubectlExec;
24-
import io.kubernetes.client.extended.kubectl.KubectlLog;
2524
import io.kubernetes.client.extended.kubectl.exception.KubectlException;
2625
import io.kubernetes.client.openapi.ApiClient;
2726
import io.kubernetes.client.openapi.models.V1Deployment;
@@ -87,9 +86,9 @@ public static void main(String[] args)
8786
switch (verb) {
8887
case "log":
8988
name = args[1];
90-
KubectlLog log = log();
91-
log.name(name).namespace(ns).container(cli.getOptionValue("c", "")).execute();
92-
ByteStreams.copy(log.stream(), System.out);
89+
ByteStreams.copy(
90+
log().name(name).namespace(ns).container(cli.getOptionValue("c", "")).execute(),
91+
System.out);
9392
System.exit(0);
9493
case "scale":
9594
kind = args[1];

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

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,48 +12,47 @@
1212
*/
1313
package io.kubernetes.client.extended.kubectl;
1414

15+
import static com.google.common.base.Strings.isNullOrEmpty;
16+
1517
import io.kubernetes.client.PodLogs;
1618
import io.kubernetes.client.extended.kubectl.exception.KubectlException;
1719
import io.kubernetes.client.openapi.ApiClient;
1820
import io.kubernetes.client.openapi.ApiException;
19-
import io.kubernetes.client.openapi.models.V1ObjectMeta;
2021
import io.kubernetes.client.openapi.models.V1Pod;
2122
import java.io.IOException;
2223
import java.io.InputStream;
2324

2425
public class KubectlLog extends Kubectl.ResourceAndContainerBuilder<V1Pod, KubectlLog>
25-
implements Kubectl.Executable<V1Pod> {
26+
implements Kubectl.Executable<InputStream> {
2627
private InputStream result;
2728

2829
KubectlLog(ApiClient client) {
2930
super(client, V1Pod.class);
3031
}
3132

32-
public InputStream stream() {
33-
return result;
34-
}
35-
3633
@Override
37-
public V1Pod execute() throws KubectlException {
34+
public InputStream execute() throws KubectlException {
3835
validate();
39-
V1Pod pod = new V1Pod().metadata(new V1ObjectMeta().name(name).namespace(namespace));
4036

4137
PodLogs logs = new PodLogs(apiClient);
4238
String ns = (this.namespace == null ? "default" : this.namespace);
4339
try {
44-
result = logs.streamNamespacedPodLog(this.name, ns, this.container);
40+
return logs.streamNamespacedPodLog(this.name, ns, this.container);
4541
} catch (ApiException | IOException ex) {
4642
throw new KubectlException(ex);
4743
}
48-
return pod;
4944
}
5045

5146
private void validate() throws KubectlException {
52-
if (name == null || name.length() == 0) {
53-
throw new KubectlException("missing name!");
47+
StringBuilder msg = new StringBuilder();
48+
if (isNullOrEmpty(name)) {
49+
msg.append("missing name! ");
50+
}
51+
if (isNullOrEmpty(container)) {
52+
msg.append("missing container!");
5453
}
55-
if (container == null || name.length() == 0) {
56-
throw new KubectlException("missing container!");
54+
if (msg.length() > 0) {
55+
throw new KubectlException(msg.toString());
5756
}
5857
}
5958
}

0 commit comments

Comments
 (0)