Skip to content

Commit 5012125

Browse files
authored
Clean up the code (#1059)
1 parent b584071 commit 5012125

File tree

4 files changed

+4
-20
lines changed

4 files changed

+4
-20
lines changed

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

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919
import io.kubernetes.client.openapi.Configuration;
2020
import io.kubernetes.client.util.Config;
2121
import java.io.IOException;
22-
import java.util.ArrayList;
23-
import java.util.List;
2422
import org.apache.commons.cli.CommandLine;
2523
import org.apache.commons.cli.CommandLineParser;
2624
import org.apache.commons.cli.DefaultParser;
@@ -48,12 +46,7 @@ public static void main(String[] args)
4846

4947
String podName = cmd.getOptionValue("p", "nginx-dbddb74b8-s4cx5");
5048
String namespace = cmd.getOptionValue("n", "default");
51-
List<String> commands = new ArrayList<>();
52-
5349
args = cmd.getArgs();
54-
for (int i = 0; i < args.length; i++) {
55-
commands.add(args[i]);
56-
}
5750

5851
ApiClient client = Config.defaultClient();
5952
Configuration.setDefaultApiClient(client);
@@ -63,14 +56,7 @@ public static void main(String[] args)
6356
// final Process proc = exec.exec("default", "nginx-4217019353-k5sn9", new String[]
6457
// {"sh", "-c", "echo foo"}, true, tty);
6558
final Process proc =
66-
exec.exec(
67-
namespace,
68-
podName,
69-
commands.isEmpty()
70-
? new String[] {"sh"}
71-
: commands.toArray(new String[commands.size()]),
72-
true,
73-
tty);
59+
exec.exec(namespace, podName, args.length == 0 ? new String[] {"sh"} : args, true, tty);
7460

7561
Thread in =
7662
new Thread(

util/src/main/java/io/kubernetes/client/Copy.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,6 @@ public void copyFileToPod(
203203
} finally {
204204
proc.destroy();
205205
}
206-
207-
return;
208206
}
209207

210208
private boolean isTarPresentInContainer(String namespace, String pod, String container)
@@ -215,7 +213,7 @@ private boolean isTarPresentInContainer(String namespace, String pod, String con
215213
// This will work for POSIX based operating systems
216214
try {
217215
int status = proc.waitFor();
218-
return status == 127 ? false : true;
216+
return status != 127;
219217
} catch (InterruptedException ex) {
220218
throw new IOException(ex);
221219
} finally {

util/src/main/java/io/kubernetes/client/PortForward.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public PortForwardResult forward(String namespace, String name, List<Integer> po
110110
String path = makePath(namespace, name);
111111
WebSocketStreamHandler handler = new WebSocketStreamHandler();
112112
PortForwardResult result = new PortForwardResult(handler, ports);
113-
List<Pair> queryParams = new ArrayList<>();
113+
List<Pair> queryParams = new ArrayList<>(ports.size());
114114
for (Integer port : ports) {
115115
queryParams.add(new Pair("ports", port.toString()));
116116
}

util/src/main/java/io/kubernetes/client/informer/cache/SharedProcessor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public boolean shouldResync() {
111111
lock.writeLock().lock();
112112
boolean resyncNeeded = false;
113113
try {
114-
this.syncingListeners = new ArrayList<>();
114+
this.syncingListeners = new ArrayList<>(this.listeners.size());
115115

116116
DateTime now = DateTime.now();
117117
for (ProcessorListener listener : this.listeners) {

0 commit comments

Comments
 (0)