|
12 | 12 | */
|
13 | 13 | package io.kubernetes.client.extended.kubectl;
|
14 | 14 |
|
| 15 | +import static com.google.common.base.Strings.isNullOrEmpty; |
| 16 | + |
15 | 17 | import io.kubernetes.client.PodLogs;
|
16 | 18 | import io.kubernetes.client.extended.kubectl.exception.KubectlException;
|
17 | 19 | import io.kubernetes.client.openapi.ApiClient;
|
18 | 20 | import io.kubernetes.client.openapi.ApiException;
|
19 |
| -import io.kubernetes.client.openapi.models.V1ObjectMeta; |
20 | 21 | import io.kubernetes.client.openapi.models.V1Pod;
|
21 | 22 | import java.io.IOException;
|
22 | 23 | import java.io.InputStream;
|
23 | 24 |
|
24 | 25 | public class KubectlLog extends Kubectl.ResourceAndContainerBuilder<V1Pod, KubectlLog>
|
25 |
| - implements Kubectl.Executable<V1Pod> { |
| 26 | + implements Kubectl.Executable<InputStream> { |
26 | 27 | private InputStream result;
|
27 | 28 |
|
28 | 29 | KubectlLog(ApiClient client) {
|
29 | 30 | super(client, V1Pod.class);
|
30 | 31 | }
|
31 | 32 |
|
32 |
| - public InputStream stream() { |
33 |
| - return result; |
34 |
| - } |
35 |
| - |
36 | 33 | @Override
|
37 |
| - public V1Pod execute() throws KubectlException { |
| 34 | + public InputStream execute() throws KubectlException { |
38 | 35 | validate();
|
39 |
| - V1Pod pod = new V1Pod().metadata(new V1ObjectMeta().name(name).namespace(namespace)); |
40 | 36 |
|
41 | 37 | PodLogs logs = new PodLogs(apiClient);
|
42 | 38 | String ns = (this.namespace == null ? "default" : this.namespace);
|
43 | 39 | try {
|
44 |
| - result = logs.streamNamespacedPodLog(this.name, ns, this.container); |
| 40 | + return logs.streamNamespacedPodLog(this.name, ns, this.container); |
45 | 41 | } catch (ApiException | IOException ex) {
|
46 | 42 | throw new KubectlException(ex);
|
47 | 43 | }
|
48 |
| - return pod; |
49 | 44 | }
|
50 | 45 |
|
51 | 46 | 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!"); |
54 | 53 | }
|
55 |
| - if (container == null || name.length() == 0) { |
56 |
| - throw new KubectlException("missing container!"); |
| 54 | + if (msg.length() > 0) { |
| 55 | + throw new KubectlException(msg.toString()); |
57 | 56 | }
|
58 | 57 | }
|
59 | 58 | }
|
0 commit comments