diff --git a/examples/pom.xml b/examples/pom.xml
index b51efabad1..72ed8a821f 100644
--- a/examples/pom.xml
+++ b/examples/pom.xml
@@ -72,6 +72,19 @@
+
+ com.coveo
+ fmt-maven-plugin
+ 2.2.0
+
+
+ test
+
+ check
+
+
+
+
diff --git a/examples/src/main/java/io/kubernetes/client/examples/AttachExample.java b/examples/src/main/java/io/kubernetes/client/examples/AttachExample.java
index e0cbaafd60..22ea714f59 100644
--- a/examples/src/main/java/io/kubernetes/client/examples/AttachExample.java
+++ b/examples/src/main/java/io/kubernetes/client/examples/AttachExample.java
@@ -12,67 +12,66 @@
*/
package io.kubernetes.client.examples;
+import com.google.common.io.ByteStreams;
import io.kubernetes.client.ApiClient;
import io.kubernetes.client.ApiException;
-import io.kubernetes.client.Configuration;
import io.kubernetes.client.Attach;
-import io.kubernetes.client.apis.CoreV1Api;
-import io.kubernetes.client.models.V1Pod;
-import io.kubernetes.client.models.V1PodList;
+import io.kubernetes.client.Configuration;
import io.kubernetes.client.util.Config;
-
-import com.google.common.io.ByteStreams;
-
import java.io.BufferedReader;
-import java.io.InputStreamReader;
import java.io.IOException;
+import java.io.InputStreamReader;
import java.io.OutputStream;
/**
* A simple example of how to use the Java API
- *
- *
Easiest way to run this:
- * mvn exec:java -Dexec.mainClass="io.kubernetes.client.examples.AttachExample"
- *
+ *
+ *
Easiest way to run this: mvn exec:java
+ * -Dexec.mainClass="io.kubernetes.client.examples.AttachExample"
+ *
*
From inside $REPO_DIR/examples
*/
public class AttachExample {
- public static void main(String[] args) throws IOException, ApiException, InterruptedException {
- ApiClient client = Config.defaultClient();
- Configuration.setDefaultApiClient(client);
+ public static void main(String[] args) throws IOException, ApiException, InterruptedException {
+ ApiClient client = Config.defaultClient();
+ Configuration.setDefaultApiClient(client);
- Attach attach = new Attach();
- final Attach.AttachResult result = attach.attach("default", "nginx-4217019353-k5sn9", true);
+ Attach attach = new Attach();
+ final Attach.AttachResult result = attach.attach("default", "nginx-4217019353-k5sn9", true);
- new Thread(new Runnable() {
- public void run() {
+ new Thread(
+ new Runnable() {
+ public void run() {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
OutputStream output = result.getStandardInputStream();
try {
- while (true) {
- String line = in.readLine();
- output.write(line.getBytes());
- output.write('\n');
- output.flush();
- }
+ while (true) {
+ String line = in.readLine();
+ output.write(line.getBytes());
+ output.write('\n');
+ output.flush();
+ }
} catch (IOException ex) {
- ex.printStackTrace();
+ ex.printStackTrace();
}
- }
- }).start();
+ }
+ })
+ .start();
- new Thread(new Runnable() {
- public void run() {
+ new Thread(
+ new Runnable() {
+ public void run() {
try {
- ByteStreams.copy(result.getStandardOutputStream(), System.out);
+ ByteStreams.copy(result.getStandardOutputStream(), System.out);
} catch (IOException ex) {
- ex.printStackTrace();
+ ex.printStackTrace();
}
- }
- }).start();
+ }
+ })
+ .start();
- Thread.sleep(10*1000);
- result.close();
- System.exit(0);
- }
+ Thread.sleep(10 * 1000);
+ result.close();
+ System.exit(0);
+ }
}
diff --git a/examples/src/main/java/io/kubernetes/client/examples/Example.java b/examples/src/main/java/io/kubernetes/client/examples/Example.java
index 196fa81529..3135c0c981 100644
--- a/examples/src/main/java/io/kubernetes/client/examples/Example.java
+++ b/examples/src/main/java/io/kubernetes/client/examples/Example.java
@@ -19,27 +19,26 @@
import io.kubernetes.client.models.V1Pod;
import io.kubernetes.client.models.V1PodList;
import io.kubernetes.client.util.Config;
-
import java.io.IOException;
-import java.util.logging.Logger;
/**
* A simple example of how to use the Java API
- *
- *
Easiest way to run this:
- * mvn exec:java -Dexec.mainClass="io.kubernetes.client.examples.Example"
- *
+ *
+ *
Easiest way to run this: mvn exec:java
+ * -Dexec.mainClass="io.kubernetes.client.examples.Example"
+ *
*
From inside $REPO_DIR/examples
*/
public class Example {
- public static void main(String[] args) throws IOException, ApiException{
- ApiClient client = Config.defaultClient();
- Configuration.setDefaultApiClient(client);
+ public static void main(String[] args) throws IOException, ApiException {
+ ApiClient client = Config.defaultClient();
+ Configuration.setDefaultApiClient(client);
- CoreV1Api api = new CoreV1Api();
- V1PodList list = api.listPodForAllNamespaces(null, null, null, null, null, null, null, null, null);
- for (V1Pod item : list.getItems()) {
- System.out.println(item.getMetadata().getName());
- }
+ CoreV1Api api = new CoreV1Api();
+ V1PodList list =
+ api.listPodForAllNamespaces(null, null, null, null, null, null, null, null, null);
+ for (V1Pod item : list.getItems()) {
+ System.out.println(item.getMetadata().getName());
}
-}
\ No newline at end of file
+ }
+}
diff --git a/examples/src/main/java/io/kubernetes/client/examples/ExecExample.java b/examples/src/main/java/io/kubernetes/client/examples/ExecExample.java
index 637ed16fb4..aa1c584243 100644
--- a/examples/src/main/java/io/kubernetes/client/examples/ExecExample.java
+++ b/examples/src/main/java/io/kubernetes/client/examples/ExecExample.java
@@ -12,71 +12,68 @@
*/
package io.kubernetes.client.examples;
+import com.google.common.io.ByteStreams;
import io.kubernetes.client.ApiClient;
import io.kubernetes.client.ApiException;
import io.kubernetes.client.Configuration;
import io.kubernetes.client.Exec;
-import io.kubernetes.client.apis.CoreV1Api;
-import io.kubernetes.client.models.V1Pod;
-import io.kubernetes.client.models.V1PodList;
import io.kubernetes.client.util.Config;
-
-import com.google.common.io.ByteStreams;
-
-import java.io.BufferedReader;
-import java.io.InputStreamReader;
import java.io.IOException;
-import java.io.OutputStream;
/**
* A simple example of how to use the Java API
- *
- *
Easiest way to run this:
- * mvn exec:java -Dexec.mainClass="io.kubernetes.client.examples.Example"
- *
+ *
+ *
Easiest way to run this: mvn exec:java
+ * -Dexec.mainClass="io.kubernetes.client.examples.Example"
+ *
*
From inside $REPO_DIR/examples
*/
public class ExecExample {
- public static void main(String[] args) throws IOException, ApiException, InterruptedException {
- ApiClient client = Config.defaultClient();
- Configuration.setDefaultApiClient(client);
+ public static void main(String[] args) throws IOException, ApiException, InterruptedException {
+ ApiClient client = Config.defaultClient();
+ Configuration.setDefaultApiClient(client);
- Exec exec = new Exec();
- boolean tty = System.console() != null;
-// final Process proc = exec.exec("default", "nginx-2371676037-czqx3", new String[] {"sh", "-c", "echo foo"}, true, tty);
- final Process proc = exec.exec("default", "nginx-4217019353-k5sn9", new String[] {"sh"}, true, tty);
+ Exec exec = new Exec();
+ boolean tty = System.console() != null;
+ // final Process proc = exec.exec("default", "nginx-2371676037-czqx3", new String[]
+ // {"sh", "-c", "echo foo"}, true, tty);
+ final Process proc =
+ exec.exec("default", "nginx-4217019353-k5sn9", new String[] {"sh"}, true, tty);
-
- new Thread(new Runnable() {
- public void run() {
+ new Thread(
+ new Runnable() {
+ public void run() {
try {
- ByteStreams.copy(System.in, proc.getOutputStream());
+ ByteStreams.copy(System.in, proc.getOutputStream());
} catch (IOException ex) {
- ex.printStackTrace();
+ ex.printStackTrace();
}
- }
- }).start();
+ }
+ })
+ .start();
- new Thread(new Runnable() {
- public void run() {
+ new Thread(
+ new Runnable() {
+ public void run() {
try {
- ByteStreams.copy(proc.getInputStream(), System.out);
+ ByteStreams.copy(proc.getInputStream(), System.out);
} catch (IOException ex) {
- ex.printStackTrace();
+ ex.printStackTrace();
}
- }
- }).start();
+ }
+ })
+ .start();
- proc.waitFor();
- try {
- // Wait for buffers to flush.
- Thread.sleep(2000);
- } catch (InterruptedException ex) {
- ex.printStackTrace();
- }
+ proc.waitFor();
+ try {
+ // Wait for buffers to flush.
+ Thread.sleep(2000);
+ } catch (InterruptedException ex) {
+ ex.printStackTrace();
+ }
- proc.destroy();
+ proc.destroy();
- System.exit(0);
- }
-}
\ No newline at end of file
+ System.exit(0);
+ }
+}
diff --git a/examples/src/main/java/io/kubernetes/client/examples/LogsExample.java b/examples/src/main/java/io/kubernetes/client/examples/LogsExample.java
index 119e8ae06f..5efbc56540 100644
--- a/examples/src/main/java/io/kubernetes/client/examples/LogsExample.java
+++ b/examples/src/main/java/io/kubernetes/client/examples/LogsExample.java
@@ -12,41 +12,39 @@
*/
package io.kubernetes.client.examples;
+import com.google.common.io.ByteStreams;
import io.kubernetes.client.ApiClient;
import io.kubernetes.client.ApiException;
import io.kubernetes.client.Configuration;
import io.kubernetes.client.PodLogs;
import io.kubernetes.client.apis.CoreV1Api;
import io.kubernetes.client.models.V1Pod;
-import io.kubernetes.client.models.V1PodList;
import io.kubernetes.client.util.Config;
-
-import com.google.common.io.ByteStreams;
-
-import java.io.BufferedReader;
-import java.io.InputStream;
-import java.io.InputStreamReader;
import java.io.IOException;
-import java.io.OutputStream;
+import java.io.InputStream;
/**
* A simple example of how to use the Java API
- *
- *
Easiest way to run this:
- * mvn exec:java -Dexec.mainClass="io.kubernetes.client.examples.LogsExample"
- *
+ *
+ *
Easiest way to run this: mvn exec:java
+ * -Dexec.mainClass="io.kubernetes.client.examples.LogsExample"
+ *
*
From inside $REPO_DIR/examples
*/
public class LogsExample {
- public static void main(String[] args) throws IOException, ApiException, InterruptedException {
- ApiClient client = Config.defaultClient();
- Configuration.setDefaultApiClient(client);
- CoreV1Api coreApi = new CoreV1Api(client);
+ public static void main(String[] args) throws IOException, ApiException, InterruptedException {
+ ApiClient client = Config.defaultClient();
+ Configuration.setDefaultApiClient(client);
+ CoreV1Api coreApi = new CoreV1Api(client);
- PodLogs logs = new PodLogs();
- V1Pod pod = coreApi.listNamespacedPod("default", "false", null, null, null, null, null, null, null, null).getItems().get(0);
+ PodLogs logs = new PodLogs();
+ V1Pod pod =
+ coreApi
+ .listNamespacedPod("default", "false", null, null, null, null, null, null, null, null)
+ .getItems()
+ .get(0);
- InputStream is = logs.streamNamespacedPodLog(pod);
- ByteStreams.copy(is, System.out);
- }
+ InputStream is = logs.streamNamespacedPodLog(pod);
+ ByteStreams.copy(is, System.out);
+ }
}
diff --git a/examples/src/main/java/io/kubernetes/client/examples/PortForwardExample.java b/examples/src/main/java/io/kubernetes/client/examples/PortForwardExample.java
index 4f8ad1c575..28c910c286 100644
--- a/examples/src/main/java/io/kubernetes/client/examples/PortForwardExample.java
+++ b/examples/src/main/java/io/kubernetes/client/examples/PortForwardExample.java
@@ -12,82 +12,75 @@
*/
package io.kubernetes.client.examples;
+import com.google.common.io.ByteStreams;
import io.kubernetes.client.ApiClient;
import io.kubernetes.client.ApiException;
import io.kubernetes.client.Configuration;
import io.kubernetes.client.PortForward;
-import io.kubernetes.client.apis.CoreV1Api;
-import io.kubernetes.client.models.V1Pod;
-import io.kubernetes.client.models.V1PodList;
import io.kubernetes.client.util.Config;
-
-import com.google.common.io.ByteStreams;
-
-import java.io.BufferedReader;
-import java.io.InputStreamReader;
import java.io.IOException;
-import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.ArrayList;
import java.util.List;
-
/**
* A simple example of how to use the Java API
- *
- *
Easiest way to run this:
- * mvn exec:java -Dexec.mainClass="io.kubernetes.client.examples.PortForwardExample"
- * from inside $REPO_DIR/examples
- *
- *
Then:
- * curl localhost:8080
- * from a different terminal (but be quick about it, the socket times out pretty fast...)
- *
+ *
+ *
Easiest way to run this: mvn exec:java
+ * -Dexec.mainClass="io.kubernetes.client.examples.PortForwardExample" from inside
+ * $REPO_DIR/examples
+ *
+ *
Then: curl localhost:8080 from a different terminal (but be quick about it, the socket times
+ * out pretty fast...)
*/
public class PortForwardExample {
- public static void main(String[] args) throws IOException, ApiException, InterruptedException {
- ApiClient client = Config.defaultClient();
- Configuration.setDefaultApiClient(client);
+ public static void main(String[] args) throws IOException, ApiException, InterruptedException {
+ ApiClient client = Config.defaultClient();
+ Configuration.setDefaultApiClient(client);
- PortForward forward = new PortForward();
- List ports = new ArrayList<>();
- ports.add(8080);
- ports.add(80);
- final PortForward.PortForwardResult result =
- forward.forward("default", "nginx-d5dc44cf7-x7475", ports);
+ PortForward forward = new PortForward();
+ List ports = new ArrayList<>();
+ ports.add(8080);
+ ports.add(80);
+ final PortForward.PortForwardResult result =
+ forward.forward("default", "nginx-d5dc44cf7-x7475", ports);
- ServerSocket ss = new ServerSocket(8080);
+ ServerSocket ss = new ServerSocket(8080);
- final Socket s = ss.accept();
- System.out.println("Connected!");
+ final Socket s = ss.accept();
+ System.out.println("Connected!");
- new Thread(new Runnable() {
- public void run() {
+ new Thread(
+ new Runnable() {
+ public void run() {
try {
- ByteStreams.copy(result.getInputStream(80), s.getOutputStream());
+ ByteStreams.copy(result.getInputStream(80), s.getOutputStream());
} catch (IOException ex) {
- ex.printStackTrace();
+ ex.printStackTrace();
} catch (Exception ex) {
- ex.printStackTrace();
+ ex.printStackTrace();
}
- }
- }).start();
+ }
+ })
+ .start();
- new Thread(new Runnable() {
- public void run() {
+ new Thread(
+ new Runnable() {
+ public void run() {
try {
- ByteStreams.copy(s.getInputStream(), result.getOutboundStream(80));
+ ByteStreams.copy(s.getInputStream(), result.getOutboundStream(80));
} catch (IOException ex) {
- ex.printStackTrace();
+ ex.printStackTrace();
} catch (Exception ex) {
- ex.printStackTrace();
+ ex.printStackTrace();
}
- }
- }).start();
+ }
+ })
+ .start();
- Thread.sleep(10 * 1000);
+ Thread.sleep(10 * 1000);
- System.exit(0);
- }
+ System.exit(0);
+ }
}
diff --git a/examples/src/main/java/io/kubernetes/client/examples/ProtoExample.java b/examples/src/main/java/io/kubernetes/client/examples/ProtoExample.java
index 64d19b9b96..eaa9c8ef52 100644
--- a/examples/src/main/java/io/kubernetes/client/examples/ProtoExample.java
+++ b/examples/src/main/java/io/kubernetes/client/examples/ProtoExample.java
@@ -18,60 +18,52 @@
import io.kubernetes.client.ProtoClient;
import io.kubernetes.client.ProtoClient.ObjectOrStatus;
import io.kubernetes.client.proto.Meta.ObjectMeta;
-import io.kubernetes.client.proto.Meta.Status;
import io.kubernetes.client.proto.V1.Namespace;
import io.kubernetes.client.proto.V1.NamespaceSpec;
import io.kubernetes.client.proto.V1.Pod;
import io.kubernetes.client.proto.V1.PodList;
import io.kubernetes.client.util.Config;
-
import java.io.IOException;
-
/**
* A simple example of how to use the Java API
- *
- *
Easiest way to run this:
- * mvn exec:java -Dexec.mainClass="io.kubernetes.client.examples.ProtoExample"
- *
+ *
+ *
Easiest way to run this: mvn exec:java
+ * -Dexec.mainClass="io.kubernetes.client.examples.ProtoExample"
+ *
*
From inside $REPO_DIR/examples
*/
public class ProtoExample {
- public static void main(String[] args) throws IOException, ApiException, InterruptedException {
- ApiClient client = Config.defaultClient();
- Configuration.setDefaultApiClient(client);
-
- ProtoClient pc = new ProtoClient(client);
- ObjectOrStatus list = pc.list(PodList.newBuilder(), "/api/v1/namespaces/default/pods");
+ public static void main(String[] args) throws IOException, ApiException, InterruptedException {
+ ApiClient client = Config.defaultClient();
+ Configuration.setDefaultApiClient(client);
- if (list.object.getItemsCount() > 0) {
- Pod p = list.object.getItems(0);
- System.out.println(p);
- }
+ ProtoClient pc = new ProtoClient(client);
+ ObjectOrStatus list = pc.list(PodList.newBuilder(), "/api/v1/namespaces/default/pods");
- Namespace namespace = Namespace.newBuilder()
- .setMetadata(ObjectMeta.newBuilder()
- .setName("test").build())
- .build();
-
- ObjectOrStatus ns = pc.create(namespace, "/api/v1/namespaces", "v1", "Namespace");
- System.out.println(ns);
- if (ns.object != null) {
- namespace = ns.object.toBuilder()
- .setSpec(
- NamespaceSpec.newBuilder()
- .addFinalizers("test")
- .build()
- )
- .build();
- // This is how you would update an object, but you can't actually
- // update namespaces, so this returns a 405
- ns = pc.update(namespace, "/api/v1/namespaces/test", "v1", "Namespace");
- System.out.println(ns.status);
- }
+ if (list.object.getItemsCount() > 0) {
+ Pod p = list.object.getItems(0);
+ System.out.println(p);
+ }
- ns = pc.delete(Namespace.newBuilder(), "/api/v1/namespaces/test");
- System.out.println(ns);
+ Namespace namespace =
+ Namespace.newBuilder().setMetadata(ObjectMeta.newBuilder().setName("test").build()).build();
+ ObjectOrStatus ns = pc.create(namespace, "/api/v1/namespaces", "v1", "Namespace");
+ System.out.println(ns);
+ if (ns.object != null) {
+ namespace =
+ ns.object
+ .toBuilder()
+ .setSpec(NamespaceSpec.newBuilder().addFinalizers("test").build())
+ .build();
+ // This is how you would update an object, but you can't actually
+ // update namespaces, so this returns a 405
+ ns = pc.update(namespace, "/api/v1/namespaces/test", "v1", "Namespace");
+ System.out.println(ns.status);
}
+
+ ns = pc.delete(Namespace.newBuilder(), "/api/v1/namespaces/test");
+ System.out.println(ns);
+ }
}
diff --git a/examples/src/main/java/io/kubernetes/client/examples/WatchExample.java b/examples/src/main/java/io/kubernetes/client/examples/WatchExample.java
index fa9bccb42d..4b5afab4d0 100644
--- a/examples/src/main/java/io/kubernetes/client/examples/WatchExample.java
+++ b/examples/src/main/java/io/kubernetes/client/examples/WatchExample.java
@@ -20,28 +20,27 @@
import io.kubernetes.client.models.V1Namespace;
import io.kubernetes.client.util.Config;
import io.kubernetes.client.util.Watch;
-
import java.io.IOException;
import java.util.concurrent.TimeUnit;
-/**
- * A simple example of how to use Watch API to watch changes in Namespace list.
- */
+/** A simple example of how to use Watch API to watch changes in Namespace list. */
public class WatchExample {
- public static void main(String[] args) throws IOException, ApiException{
- ApiClient client = Config.defaultClient();
- client.getHttpClient().setReadTimeout(60, TimeUnit.SECONDS);
- Configuration.setDefaultApiClient(client);
+ public static void main(String[] args) throws IOException, ApiException {
+ ApiClient client = Config.defaultClient();
+ client.getHttpClient().setReadTimeout(60, TimeUnit.SECONDS);
+ Configuration.setDefaultApiClient(client);
- CoreV1Api api = new CoreV1Api();
+ CoreV1Api api = new CoreV1Api();
- Watch watch = Watch.createWatch(
- client,
- api.listNamespaceCall(null, null, null, null, null, 5, null, null, Boolean.TRUE, null, null),
- new TypeToken>(){}.getType());
+ Watch watch =
+ Watch.createWatch(
+ client,
+ api.listNamespaceCall(
+ null, null, null, null, null, 5, null, null, Boolean.TRUE, null, null),
+ new TypeToken>() {}.getType());
- for (Watch.Response item : watch) {
- System.out.printf("%s : %s%n", item.type, item.object.getMetadata().getName());
- }
+ for (Watch.Response item : watch) {
+ System.out.printf("%s : %s%n", item.type, item.object.getMetadata().getName());
}
+ }
}
diff --git a/examples/src/main/java/io/kubernetes/client/examples/WebSocketsExample.java b/examples/src/main/java/io/kubernetes/client/examples/WebSocketsExample.java
index a7d4d5f0cb..39c0aee123 100644
--- a/examples/src/main/java/io/kubernetes/client/examples/WebSocketsExample.java
+++ b/examples/src/main/java/io/kubernetes/client/examples/WebSocketsExample.java
@@ -17,46 +17,48 @@
import io.kubernetes.client.ApiException;
import io.kubernetes.client.util.Config;
import io.kubernetes.client.util.WebSockets;
-
import java.io.BufferedReader;
-import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
-import java.io.OutputStream;
import java.io.Reader;
/**
- * This is a pretty low level, most people won't need to use WebSockets
- * directly.
+ * This is a pretty low level, most people won't need to use WebSockets directly.
*
- * If you do need to run it, you can run:
- * mvn exec:java \
- * -Dexec.mainClass=io.kubernetes.client.examples.WebSocketsExample \
- * -Dexec.args=/api/v1/namespaces/default/pods//attach?stdout=true
+ *
If you do need to run it, you can run: mvn exec:java \
+ * -Dexec.mainClass=io.kubernetes.client.examples.WebSocketsExample \
+ * -Dexec.args=/api/v1/namespaces/default/pods//attach?stdout=true
*
- * Note that you'd think 'watch' calls were WebSockets, but you'd be wrong,
- * they're straight HTTP GET calls.
+ *
Note that you'd think 'watch' calls were WebSockets, but you'd be wrong, they're straight HTTP
+ * GET calls.
*/
public class WebSocketsExample {
- public static void main(String... args) throws ApiException, IOException {
- final ApiClient client = Config.defaultClient();
- WebSockets.stream(args[0], "GET", client, new WebSockets.SocketListener() {
- public void open(String protocol, WebSocket socket) {}
- public void close() {
- // Trigger shutdown of the dispatcher's executor so this process can exit cleanly.
- client.getHttpClient().getDispatcher().getExecutorService().shutdown();
- }
- public void bytesMessage(InputStream is) {}
- public void textMessage(Reader in) {
- try {
- BufferedReader reader = new BufferedReader(in);
- for (String line = reader.readLine(); line != null; line = reader.readLine()) {
- System.out.println(line);
- }
- } catch (IOException ex) {
- ex.printStackTrace();
- }
+ public static void main(String... args) throws ApiException, IOException {
+ final ApiClient client = Config.defaultClient();
+ WebSockets.stream(
+ args[0],
+ "GET",
+ client,
+ new WebSockets.SocketListener() {
+ public void open(String protocol, WebSocket socket) {}
+
+ public void close() {
+ // Trigger shutdown of the dispatcher's executor so this process can exit cleanly.
+ client.getHttpClient().getDispatcher().getExecutorService().shutdown();
+ }
+
+ public void bytesMessage(InputStream is) {}
+
+ public void textMessage(Reader in) {
+ try {
+ BufferedReader reader = new BufferedReader(in);
+ for (String line = reader.readLine(); line != null; line = reader.readLine()) {
+ System.out.println(line);
+ }
+ } catch (IOException ex) {
+ ex.printStackTrace();
}
+ }
});
- }
+ }
}
diff --git a/target/checkout b/target/checkout
deleted file mode 160000
index 02bb7ab2ee..0000000000
--- a/target/checkout
+++ /dev/null
@@ -1 +0,0 @@
-Subproject commit 02bb7ab2ee7495b2a64148e9033b2cb9777f68e2
diff --git a/util/pom.xml b/util/pom.xml
index f30e3ef6fd..bc8166f71f 100644
--- a/util/pom.xml
+++ b/util/pom.xml
@@ -103,6 +103,19 @@
pertest
+
+ com.coveo
+ fmt-maven-plugin
+ 2.2.0
+
+
+ test
+
+ check
+
+
+
+
diff --git a/util/src/main/java/io/kubernetes/client/Attach.java b/util/src/main/java/io/kubernetes/client/Attach.java
index b09f21023a..05c251c443 100644
--- a/util/src/main/java/io/kubernetes/client/Attach.java
+++ b/util/src/main/java/io/kubernetes/client/Attach.java
@@ -13,153 +13,160 @@
package io.kubernetes.client;
import io.kubernetes.client.models.V1Pod;
-import io.kubernetes.client.util.WebSockets;
import io.kubernetes.client.util.WebSocketStreamHandler;
-
-import java.io.InputStream;
+import io.kubernetes.client.util.WebSockets;
import java.io.IOException;
+import java.io.InputStream;
import java.io.OutputStream;
public class Attach {
- private ApiClient apiClient;
-
- /**
- * Simple Attach API constructor, uses default configuration
- */
- public Attach() {
- this(Configuration.getDefaultApiClient());
+ private ApiClient apiClient;
+
+ /** Simple Attach API constructor, uses default configuration */
+ public Attach() {
+ this(Configuration.getDefaultApiClient());
+ }
+
+ /**
+ * Attach API Constructor
+ *
+ * @param apiClient The api client to use.
+ */
+ public Attach(ApiClient apiClient) {
+ this.apiClient = apiClient;
+ }
+
+ /**
+ * Get the API client for these Attach operations.
+ *
+ * @return The API client that will be used.
+ */
+ public ApiClient getApiClient() {
+ return apiClient;
+ }
+
+ /**
+ * Set the API client for subsequent Attach operations.
+ *
+ * @param apiClient The new API client to use.
+ */
+ public void setApiClient(ApiClient apiClient) {
+ this.apiClient = apiClient;
+ }
+
+ private String makePath(
+ String namespace, String name, String container, boolean stdin, boolean tty) {
+ return "/api/v1/namespaces/"
+ + namespace
+ + "/pods/"
+ + name
+ + "/attach?"
+ + "stdin="
+ + stdin
+ + "&tty="
+ + tty
+ + (container != null ? "&container=" + container : "");
+ }
+
+ /**
+ * Attach to a running AttachResult in a container. If there are multiple containers in the pod,
+ * uses the first container in the Pod.
+ *
+ * @param namespace The namespace of the Pod
+ * @param name The name of the Pod
+ * @param stdin If true, pass a stdin stream into the container
+ */
+ public AttachResult attach(String namespace, String name, boolean stdin)
+ throws ApiException, IOException {
+ return attach(namespace, name, null, stdin, false);
+ }
+
+ /**
+ * Attach to a running AttachResult in a container. If there are multiple containers in the pod,
+ * uses the first container in the Pod.
+ *
+ * @param pod The pod where the command is run.
+ * @param stdin If true, pass a stdin stream into the container
+ */
+ public AttachResult attach(V1Pod pod, boolean stdin) throws ApiException, IOException {
+ return attach(pod, stdin, false);
+ }
+
+ /**
+ * Attach to a running AttachResult in a container. If there are multiple containers in the pod,
+ * uses the first container in the Pod.
+ *
+ * @param pod The pod where the command is run.
+ * @param stdin If true, pass a stdin stream into the container
+ * @param tty If true, stdin is a tty.
+ */
+ public AttachResult attach(V1Pod pod, boolean stdin, boolean tty)
+ throws ApiException, IOException {
+ return attach(pod, null, stdin, tty);
+ }
+
+ /**
+ * Attach to a running AttachResult in a container. If there are multiple containers in the pod,
+ * uses the first container in the Pod.
+ *
+ * @param pod The pod where the command is run.
+ * @param container The container in the Pod where the command is run.
+ * @param stdin If true, pass a stdin stream into the container.
+ * @param tty If true, stdin is a TTY (only applies if stdin is true)
+ */
+ public AttachResult attach(V1Pod pod, String container, boolean stdin, boolean tty)
+ throws ApiException, IOException {
+ return attach(
+ pod.getMetadata().getNamespace(), pod.getMetadata().getName(), container, stdin, tty);
+ }
+
+ /**
+ * Attach to a running AttachResult in a container. If there are multiple containers in the pod,
+ * uses the first container in the Pod.
+ *
+ * @param namespace The namespace of the Pod
+ * @param name The name of the Pod
+ * @param container The container in the Pod where the command is run.
+ * @param stdin If true, pass a stdin stream into the container.
+ * @param tty If true, stdin is a TTY (only applies if stdin is true)
+ */
+ public AttachResult attach(
+ String namespace, String name, String container, boolean stdin, boolean tty)
+ throws ApiException, IOException {
+ String path = makePath(namespace, name, container, stdin, tty);
+
+ WebSocketStreamHandler handler = new WebSocketStreamHandler();
+ AttachResult result = new AttachResult(handler);
+ WebSockets.stream(path, "GET", apiClient, handler);
+
+ return result;
+ }
+
+ /**
+ * AttachResult contains the result of an Attach call, it includes streams for stdout stderr and
+ * stdin.
+ */
+ public static class AttachResult implements java.io.Closeable {
+ private WebSocketStreamHandler handler;
+
+ public AttachResult(WebSocketStreamHandler handler) throws IOException {
+ this.handler = handler;
}
- /**
- * Attach API Constructor
- * @param apiClient The api client to use.
- */
- public Attach(ApiClient apiClient) {
- this.apiClient = apiClient;
+ public OutputStream getStandardInputStream() {
+ return handler.getOutputStream(0);
}
- /**
- * Get the API client for these Attach operations.
- * @return The API client that will be used.
- */
- public ApiClient getApiClient() {
- return apiClient;
+ public InputStream getStandardOutputStream() throws IOException {
+ return handler.getInputStream(1);
}
- /**
- * Set the API client for subsequent Attach operations.
- * @param apiClient The new API client to use.
- */
- public void setApiClient(ApiClient apiClient) {
- this.apiClient = apiClient;
+ public InputStream getErrorStream() throws IOException {
+ return handler.getInputStream(2);
}
- private String makePath(String namespace, String name, String container, boolean stdin, boolean tty) {
- return "/api/v1/namespaces/" +
- namespace +
- "/pods/" +
- name +
- "/attach?" +
- "stdin=" + stdin +
- "&tty=" + tty +
- (container != null ? "&container=" + container : "");
- }
-
- /**
- * Attach to a running AttachResult in a container. If there are multiple containers in the pod, uses
- * the first container in the Pod.
- *
- * @param namespace The namespace of the Pod
- * @param name The name of the Pod
- * @param stdin If true, pass a stdin stream into the container
- */
- public AttachResult attach(String namespace, String name, boolean stdin) throws ApiException, IOException {
- return attach(namespace, name, null, stdin, false);
- }
-
- /**
- * Attach to a running AttachResult in a container. If there are multiple containers in the pod, uses
- * the first container in the Pod.
- *
- * @param pod The pod where the command is run.
- * @param stdin If true, pass a stdin stream into the container
- */
- public AttachResult attach(V1Pod pod, boolean stdin) throws ApiException, IOException {
- return attach(pod, stdin, false);
- }
-
-
- /**
- * Attach to a running AttachResult in a container. If there are multiple containers in the pod, uses
- * the first container in the Pod.
- *
- * @param pod The pod where the command is run.
- * @param stdin If true, pass a stdin stream into the container
- * @param tty If true, stdin is a tty.
- */
- public AttachResult attach(V1Pod pod, boolean stdin, boolean tty) throws ApiException, IOException {
- return attach(pod, null, stdin, tty);
- }
-
- /**
- * Attach to a running AttachResult in a container. If there are multiple containers in the pod, uses
- * the first container in the Pod.
- *
- * @param pod The pod where the command is run.
- * @param container The container in the Pod where the command is run.
- * @param stdin If true, pass a stdin stream into the container.
- * @param tty If true, stdin is a TTY (only applies if stdin is true)
- */
- public AttachResult attach(V1Pod pod, String container, boolean stdin, boolean tty) throws ApiException, IOException {
- return attach(pod.getMetadata().getNamespace(), pod.getMetadata().getName(), container, stdin, tty);
- }
-
- /**
- * Attach to a running AttachResult in a container. If there are multiple containers in the pod, uses
- * the first container in the Pod.
- *
- * @param namespace The namespace of the Pod
- * @param name The name of the Pod
- * @param container The container in the Pod where the command is run.
- * @param stdin If true, pass a stdin stream into the container.
- * @param tty If true, stdin is a TTY (only applies if stdin is true)
- */
- public AttachResult attach(String namespace, String name, String container, boolean stdin, boolean tty) throws ApiException, IOException {
- String path = makePath(namespace, name, container, stdin, tty);
-
- WebSocketStreamHandler handler = new WebSocketStreamHandler();
- AttachResult result = new AttachResult(handler);
- WebSockets.stream(path, "GET", apiClient, handler);
-
- return result;
- }
-
- /**
- * AttachResult contains the result of an Attach call, it includes streams for stdout
- * stderr and stdin.
- */
- public static class AttachResult implements java.io.Closeable {
- private WebSocketStreamHandler handler;
-
-
- public AttachResult(WebSocketStreamHandler handler) throws IOException {
- this.handler = handler;
- }
-
- public OutputStream getStandardInputStream() {
- return handler.getOutputStream(0);
- }
-
- public InputStream getStandardOutputStream() throws IOException {
- return handler.getInputStream(1);
- }
-
- public InputStream getErrorStream() throws IOException {
- return handler.getInputStream(2);
- }
-
- public void close() {
- handler.close();
- }
+ public void close() {
+ handler.close();
}
-}
\ No newline at end of file
+ }
+}
diff --git a/util/src/main/java/io/kubernetes/client/Exec.java b/util/src/main/java/io/kubernetes/client/Exec.java
index edb5dd2320..cf7af31260 100644
--- a/util/src/main/java/io/kubernetes/client/Exec.java
+++ b/util/src/main/java/io/kubernetes/client/Exec.java
@@ -15,185 +15,206 @@
import io.kubernetes.client.models.V1Pod;
import io.kubernetes.client.util.WebSocketStreamHandler;
import io.kubernetes.client.util.WebSockets;
-import org.apache.commons.lang3.StringUtils;
-
-import java.io.InputStream;
import java.io.IOException;
+import java.io.InputStream;
import java.io.OutputStream;
+import org.apache.commons.lang3.StringUtils;
public class Exec {
- private ApiClient apiClient;
-
- /**
- * Simple Exec API constructor, uses default configuration
- */
- public Exec() {
- this(Configuration.getDefaultApiClient());
- }
-
- /**
- * Exec API Constructor
- * @param apiClient The api client to use.
- */
- public Exec(ApiClient apiClient) {
- this.apiClient = apiClient;
- }
-
- /**
- * Get the API client for these exec operations.
- * @return The API client that will be used.
- */
- public ApiClient getApiClient() {
- return apiClient;
- }
-
- /**
- * Set the API client for subsequent exec operations.
- * @param apiClient The new API client to use.
- */
- public void setApiClient(ApiClient apiClient) {
- this.apiClient = apiClient;
- }
-
- private String makePath(String namespace, String name, String[] command, String container, boolean stdin, boolean tty) {
- String path = "/api/v1/namespaces/" +
- namespace +
- "/pods/" +
- name +
- "/exec?" +
- "stdin=" + stdin +
- "&tty=" + tty +
- (container != null ? "&container=" + container : "") +
- "&command=" + StringUtils.join(command, "&command=");
- return path;
- }
-
- /**
- * Execute a command in a container. If there are multiple containers in the pod, uses
- * the first container in the Pod.
- *
- * @param namespace The namespace of the Pod
- * @param name The name of the Pod
- * @param command The command to run
- * @param stdin If true, pass a stdin stream into the container
- */
- public Process exec(String namespace, String name, String[] command, boolean stdin) throws ApiException, IOException {
- return exec(namespace, name, command, null, stdin, false);
+ private ApiClient apiClient;
+
+ /** Simple Exec API constructor, uses default configuration */
+ public Exec() {
+ this(Configuration.getDefaultApiClient());
+ }
+
+ /**
+ * Exec API Constructor
+ *
+ * @param apiClient The api client to use.
+ */
+ public Exec(ApiClient apiClient) {
+ this.apiClient = apiClient;
+ }
+
+ /**
+ * Get the API client for these exec operations.
+ *
+ * @return The API client that will be used.
+ */
+ public ApiClient getApiClient() {
+ return apiClient;
+ }
+
+ /**
+ * Set the API client for subsequent exec operations.
+ *
+ * @param apiClient The new API client to use.
+ */
+ public void setApiClient(ApiClient apiClient) {
+ this.apiClient = apiClient;
+ }
+
+ private String makePath(
+ String namespace,
+ String name,
+ String[] command,
+ String container,
+ boolean stdin,
+ boolean tty) {
+ String path =
+ "/api/v1/namespaces/"
+ + namespace
+ + "/pods/"
+ + name
+ + "/exec?"
+ + "stdin="
+ + stdin
+ + "&tty="
+ + tty
+ + (container != null ? "&container=" + container : "")
+ + "&command="
+ + StringUtils.join(command, "&command=");
+ return path;
+ }
+
+ /**
+ * Execute a command in a container. If there are multiple containers in the pod, uses the first
+ * container in the Pod.
+ *
+ * @param namespace The namespace of the Pod
+ * @param name The name of the Pod
+ * @param command The command to run
+ * @param stdin If true, pass a stdin stream into the container
+ */
+ public Process exec(String namespace, String name, String[] command, boolean stdin)
+ throws ApiException, IOException {
+ return exec(namespace, name, command, null, stdin, false);
+ }
+
+ /**
+ * Execute a command in a container. If there are multiple containers in the pod, uses the first
+ * container in the Pod.
+ *
+ * @param pod The pod where the command is run.
+ * @param command The command to run
+ * @param stdin If true, pass a stdin stream into the container
+ */
+ public Process exec(V1Pod pod, String[] command, boolean stdin) throws ApiException, IOException {
+ return exec(pod, command, null, stdin, false);
+ }
+
+ /**
+ * Execute a command in a container. If there are multiple containers in the pod, uses the first
+ * container in the Pod.
+ *
+ * @param namespace The namespace of the Pod
+ * @param name The name of the Pod
+ * @param command The command to run
+ * @param stdin If true, pass a stdin stream into the container
+ * @param tty If true, stdin is a tty.
+ */
+ public Process exec(String namespace, String name, String[] command, boolean stdin, boolean tty)
+ throws ApiException, IOException {
+ return exec(namespace, name, command, null, stdin, tty);
+ }
+
+ /**
+ * Execute a command in a container. If there are multiple containers in the pod, uses the first
+ * container in the Pod.
+ *
+ * @param pod The pod where the command is run.
+ * @param command The command to run
+ * @param stdin If true, pass a stdin stream into the container
+ * @param tty If true, stdin is a tty.
+ */
+ public Process exec(V1Pod pod, String[] command, boolean stdin, boolean tty)
+ throws ApiException, IOException {
+ return exec(pod, command, null, stdin, tty);
+ }
+
+ /**
+ * Execute a command in a container. If there are multiple containers in the pod, uses the first
+ * container in the Pod.
+ *
+ * @param pod The pod where the command is run.
+ * @param command The command to run
+ * @param container The container in the Pod where the command is run.
+ * @param stdin If true, pass a stdin stream into the container.
+ * @param tty If true, stdin is a TTY (only applies if stdin is true)
+ */
+ public Process exec(V1Pod pod, String[] command, String container, boolean stdin, boolean tty)
+ throws ApiException, IOException {
+ return exec(
+ pod.getMetadata().getNamespace(),
+ pod.getMetadata().getName(),
+ command,
+ container,
+ stdin,
+ tty);
+ }
+
+ /**
+ * Execute a command in a container. If there are multiple containers in the pod, uses the first
+ * container in the Pod.
+ *
+ * @param namespace The namespace of the Pod
+ * @param name The name of the Pod
+ * @param command The command to run
+ * @param container The container in the Pod where the command is run.
+ * @param stdin If true, pass a stdin stream into the container.
+ * @param tty If true, stdin is a TTY (only applies if stdin is true)
+ */
+ public Process exec(
+ String namespace, String name, String[] command, String container, boolean stdin, boolean tty)
+ throws ApiException, IOException {
+ String path = makePath(namespace, name, command, container, stdin, tty);
+
+ WebSocketStreamHandler handler = new WebSocketStreamHandler();
+ ExecProcess exec = new ExecProcess(handler);
+ WebSockets.stream(path, "GET", apiClient, handler);
+
+ return exec;
+ }
+
+ private static class ExecProcess extends Process {
+ WebSocketStreamHandler streamHandler;
+ private int statusCode;
+
+ public ExecProcess(WebSocketStreamHandler handler) throws IOException {
+ this.streamHandler = handler;
+ this.statusCode = -1;
}
- /**
- * Execute a command in a container. If there are multiple containers in the pod, uses
- * the first container in the Pod.
- *
- * @param pod The pod where the command is run.
- * @param command The command to run
- * @param stdin If true, pass a stdin stream into the container
- */
- public Process exec(V1Pod pod, String[] command, boolean stdin) throws ApiException, IOException {
- return exec(pod, command, null, stdin, false);
+ @Override
+ public OutputStream getOutputStream() {
+ return streamHandler.getOutputStream(0);
}
- /**
- * Execute a command in a container. If there are multiple containers in the pod, uses
- * the first container in the Pod.
- *
- * @param namespace The namespace of the Pod
- * @param name The name of the Pod
- * @param command The command to run
- * @param stdin If true, pass a stdin stream into the container
- * @param tty If true, stdin is a tty.
- */
- public Process exec(String namespace, String name, String[] command, boolean stdin, boolean tty) throws ApiException, IOException {
- return exec(namespace, name, command, null, stdin, tty);
+ @Override
+ public InputStream getInputStream() {
+ return streamHandler.getInputStream(1);
}
- /**
- * Execute a command in a container. If there are multiple containers in the pod, uses
- * the first container in the Pod.
- *
- * @param pod The pod where the command is run.
- * @param command The command to run
- * @param stdin If true, pass a stdin stream into the container
- * @param tty If true, stdin is a tty.
- */
- public Process exec(V1Pod pod, String[] command, boolean stdin, boolean tty) throws ApiException, IOException {
- return exec(pod, command, null, stdin, tty);
+ @Override
+ public InputStream getErrorStream() {
+ return streamHandler.getInputStream(2);
}
- /**
- * Execute a command in a container. If there are multiple containers in the pod, uses
- * the first container in the Pod.
- *
- * @param pod The pod where the command is run.
- * @param command The command to run
- * @param container The container in the Pod where the command is run.
- * @param stdin If true, pass a stdin stream into the container.
- * @param tty If true, stdin is a TTY (only applies if stdin is true)
- */
- public Process exec(V1Pod pod, String[] command, String container, boolean stdin, boolean tty) throws ApiException, IOException {
- return exec(pod.getMetadata().getNamespace(), pod.getMetadata().getName(), command, container, stdin, tty);
+ @Override
+ public int waitFor() throws InterruptedException {
+ synchronized (this) {
+ this.wait();
+ }
+ return statusCode;
}
- /**
- * Execute a command in a container. If there are multiple containers in the pod, uses
- * the first container in the Pod.
- *
- * @param namespace The namespace of the Pod
- * @param name The name of the Pod
- * @param command The command to run
- * @param container The container in the Pod where the command is run.
- * @param stdin If true, pass a stdin stream into the container.
- * @param tty If true, stdin is a TTY (only applies if stdin is true)
- */
- public Process exec(String namespace, String name, String[] command, String container, boolean stdin, boolean tty) throws ApiException, IOException {
- String path = makePath(namespace, name, command, container, stdin, tty);
-
- WebSocketStreamHandler handler = new WebSocketStreamHandler();
- ExecProcess exec = new ExecProcess(handler);
- WebSockets.stream(path, "GET", apiClient, handler);
-
- return exec;
+ public int exitValue() {
+ return statusCode;
}
- private static class ExecProcess extends Process {
- WebSocketStreamHandler streamHandler;
- private int statusCode;
-
-
- public ExecProcess(WebSocketStreamHandler handler) throws IOException {
- this.streamHandler = handler;
- this.statusCode = -1;
- }
-
- @Override
- public OutputStream getOutputStream() {
- return streamHandler.getOutputStream(0);
- }
-
- @Override
- public InputStream getInputStream() {
- return streamHandler.getInputStream(1);
- }
-
- @Override
- public InputStream getErrorStream() {
- return streamHandler.getInputStream(2);
- }
-
- @Override
- public int waitFor() throws InterruptedException {
- synchronized(this) {
- this.wait();
- }
- return statusCode;
- }
-
- public int exitValue() {
- return statusCode;
- }
-
- public void destroy() {
- streamHandler.close();
- }
+ public void destroy() {
+ streamHandler.close();
}
-}
\ No newline at end of file
+ }
+}
diff --git a/util/src/main/java/io/kubernetes/client/PodLogs.java b/util/src/main/java/io/kubernetes/client/PodLogs.java
index 8ac149597c..f696e5d6d5 100644
--- a/util/src/main/java/io/kubernetes/client/PodLogs.java
+++ b/util/src/main/java/io/kubernetes/client/PodLogs.java
@@ -12,65 +12,82 @@
*/
package io.kubernetes.client;
+import com.squareup.okhttp.Call;
+import com.squareup.okhttp.Response;
import io.kubernetes.client.apis.CoreV1Api;
import io.kubernetes.client.models.V1Pod;
-
-import java.io.InputStream;
import java.io.IOException;
+import java.io.InputStream;
-import com.squareup.okhttp.Call;
-import com.squareup.okhttp.Response;
-
-/**
- * Utility class offering streaming access to Pod logs.
- */
+/** Utility class offering streaming access to Pod logs. */
public class PodLogs {
- private ApiClient apiClient;
- private CoreV1Api coreClient;
+ private ApiClient apiClient;
+ private CoreV1Api coreClient;
- /**
- * Simple PodLogs API constructor, uses default configuration
- */
- public PodLogs() {
- this(Configuration.getDefaultApiClient());
- }
+ /** Simple PodLogs API constructor, uses default configuration */
+ public PodLogs() {
+ this(Configuration.getDefaultApiClient());
+ }
- /**
- * PodLogs API Constructor
- * @param apiClient The api client to use.
- */
- public PodLogs(ApiClient apiClient) {
- this.apiClient = apiClient;
- this.coreClient = new CoreV1Api(apiClient);
- }
+ /**
+ * PodLogs API Constructor
+ *
+ * @param apiClient The api client to use.
+ */
+ public PodLogs(ApiClient apiClient) {
+ this.apiClient = apiClient;
+ this.coreClient = new CoreV1Api(apiClient);
+ }
- /**
- * Get the API client for these Logs operations.
- * @return The API client that will be used.
- */
- public ApiClient getApiClient() {
- return apiClient;
- }
+ /**
+ * Get the API client for these Logs operations.
+ *
+ * @return The API client that will be used.
+ */
+ public ApiClient getApiClient() {
+ return apiClient;
+ }
- public InputStream streamNamespacedPodLog(V1Pod pod) throws ApiException, IOException {
- return streamNamespacedPodLog(pod.getMetadata().getNamespace(), pod.getMetadata().getName(),
- pod.getSpec().getContainers().get(0).getName());
- }
-
- // Important note. You must close this stream or else you can leak connections.
- public InputStream streamNamespacedPodLog(String namespace, String name, String container) throws ApiException, IOException {
- return streamNamespacedPodLog(namespace, name, container, null, null, false);
- }
+ public InputStream streamNamespacedPodLog(V1Pod pod) throws ApiException, IOException {
+ return streamNamespacedPodLog(
+ pod.getMetadata().getNamespace(),
+ pod.getMetadata().getName(),
+ pod.getSpec().getContainers().get(0).getName());
+ }
+ // Important note. You must close this stream or else you can leak connections.
+ public InputStream streamNamespacedPodLog(String namespace, String name, String container)
+ throws ApiException, IOException {
+ return streamNamespacedPodLog(namespace, name, container, null, null, false);
+ }
- // Important note. You must close this stream or else you can leak connections.
- public InputStream streamNamespacedPodLog(String namespace, String name, String container,
- Integer sinceSeconds, Integer tailLines, boolean timestamps) throws ApiException, IOException {
- Call call = coreClient.readNamespacedPodLogCall(name, namespace, container, true, null, "false", false, sinceSeconds, tailLines, timestamps, null, null);
- Response response = call.execute();
- if (!response.isSuccessful()) {
- throw new ApiException("Logs request failed: " + response.code());
- }
- return response.body().byteStream();
+ // Important note. You must close this stream or else you can leak connections.
+ public InputStream streamNamespacedPodLog(
+ String namespace,
+ String name,
+ String container,
+ Integer sinceSeconds,
+ Integer tailLines,
+ boolean timestamps)
+ throws ApiException, IOException {
+ Call call =
+ coreClient.readNamespacedPodLogCall(
+ name,
+ namespace,
+ container,
+ true,
+ null,
+ "false",
+ false,
+ sinceSeconds,
+ tailLines,
+ timestamps,
+ null,
+ null);
+ Response response = call.execute();
+ if (!response.isSuccessful()) {
+ throw new ApiException("Logs request failed: " + response.code());
}
+ return response.body().byteStream();
+ }
}
diff --git a/util/src/main/java/io/kubernetes/client/PortForward.java b/util/src/main/java/io/kubernetes/client/PortForward.java
index 4b01584bcd..81cc47a8c2 100644
--- a/util/src/main/java/io/kubernetes/client/PortForward.java
+++ b/util/src/main/java/io/kubernetes/client/PortForward.java
@@ -1,193 +1,190 @@
package io.kubernetes.client;
-import io.kubernetes.client.Configuration;
import io.kubernetes.client.models.V1Pod;
-import io.kubernetes.client.util.WebSockets;
import io.kubernetes.client.util.WebSocketStreamHandler;
-
-import java.io.InputStream;
+import io.kubernetes.client.util.WebSockets;
import java.io.IOException;
+import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
/**
- * Utility class for setting up port-forwarding connections.
- * Uses the WebSockets API, not the SPDY API (which the Go client uses)
- *
- * The protocol is undocumented as far as I can tell, but the PR that added
- * it is here:
+ * Utility class for setting up port-forwarding connections. Uses the WebSockets API, not the SPDY
+ * API (which the Go client uses)
+ *
+ *
The protocol is undocumented as far as I can tell, but the PR that added it is here:
* https://github.com/kubernetes/kubernetes/pull/33684
- *
- * And the protocol is:
- *
- * ws://server/api/v1/namespaces//pods//portforward?ports=80&ports=8080
- *
- * I/O for first port (80) is on Channel 0
- * Err for first port (80) is on Channel 1
- * I/O for second port (8080) is on Channel 2
- * Err for second port (8080) is on Channel 3
- *
- *
- * The first two bytes of each output stream is the port that is being forwarded
- * in little-endian format.
+ *
+ *
I/O for first port (80) is on Channel 0 Err for first port (80) is on Channel 1 I/O for second
+ * port (8080) is on Channel 2 Err for second port (8080) is on Channel 3
+ *
+ *
The first two bytes of each output stream is the port that is being forwarded in little-endian
+ * format.
*/
public class PortForward {
- private ApiClient apiClient;
-
- /**
- * Simple PortForward API constructor, uses default configuration
- */
- public PortForward() {
- this(Configuration.getDefaultApiClient());
+ private ApiClient apiClient;
+
+ /** Simple PortForward API constructor, uses default configuration */
+ public PortForward() {
+ this(Configuration.getDefaultApiClient());
+ }
+
+ /**
+ * PortForward API Constructor
+ *
+ * @param apiClient The api client to use.
+ */
+ public PortForward(ApiClient apiClient) {
+ this.apiClient = apiClient;
+ }
+
+ /**
+ * Get the API client for these PortForward operations.
+ *
+ * @return The API client that will be used.
+ */
+ public ApiClient getApiClient() {
+ return apiClient;
+ }
+
+ /**
+ * Set the API client for subsequent PortForward operations.
+ *
+ * @param apiClient The new API client to use.
+ */
+ public void setApiClient(ApiClient apiClient) {
+ this.apiClient = apiClient;
+ }
+
+ private String makePath(String namespace, String name) {
+ return "/api/v1/namespaces/" + namespace + "/pods/" + name + "/portforward";
+ }
+
+ /**
+ * PortForward to a container
+ *
+ * @param pod The pod where the port forward is run.
+ * @param ports The ports to forward
+ * @return The result of the Port Forward request.
+ */
+ public PortForwardResult forward(V1Pod pod, List ports)
+ throws ApiException, IOException {
+ return forward(pod.getMetadata().getNamespace(), pod.getMetadata().getNamespace(), ports);
+ }
+
+ /**
+ * PortForward to a container.
+ *
+ * @param namespace The namespace of the Pod
+ * @param name The name of the Pod
+ * @param ports The ports to forward
+ * @return The result of the Port Forward request.
+ */
+ public PortForwardResult forward(String namespace, String name, List ports)
+ throws ApiException, IOException {
+ String path = makePath(namespace, name);
+ WebSocketStreamHandler handler = new WebSocketStreamHandler();
+ PortForwardResult result = new PortForwardResult(handler, ports);
+ List queryParams = new ArrayList<>();
+ for (Integer port : ports) {
+ queryParams.add(new Pair("ports", port.toString()));
}
+ WebSockets.stream(path, "GET", queryParams, apiClient, handler);
- /**
- * PortForward API Constructor
- * @param apiClient The api client to use.
- */
- public PortForward(ApiClient apiClient) {
- this.apiClient = apiClient;
- }
+ // Wait for streams to start.
+ result.init();
+
+ return result;
+ }
+
+ /**
+ * PortForwardResult contains the result of an Attach call, it includes streams for stdout stderr
+ * and stdin.
+ */
+ public static class PortForwardResult {
+ private WebSocketStreamHandler handler;
+ private HashMap streams;
+ private List ports;
/**
- * Get the API client for these PortForward operations.
- * @return The API client that will be used.
+ * Constructor
+ *
+ * @param handler The web socket handler
+ * @param ports The list of ports that are being forwarded.
*/
- public ApiClient getApiClient() {
- return apiClient;
+ public PortForwardResult(WebSocketStreamHandler handler, List ports)
+ throws IOException {
+ this.handler = handler;
+ this.streams = new HashMap<>();
+ this.ports = ports;
}
- /**
- * Set the API client for subsequent PortForward operations.
- * @param apiClient The new API client to use.
- */
- public void setApiClient(ApiClient apiClient) {
- this.apiClient = apiClient;
+ /** Initialize the connection. Must be called after the web socket has been opened. */
+ public void init() throws IOException {
+ for (int i = 0; i < ports.size(); i++) {
+ InputStream is = handler.getInputStream(i * 2);
+ byte[] data = new byte[2];
+ is.read(data);
+ int port = (data[0] & 0xFF) + (data[1] & 0xFF) * 256;
+ streams.put(port, i);
+ }
}
- private String makePath(String namespace, String name) {
- return "/api/v1/namespaces/" +
- namespace +
- "/pods/" +
- name +
- "/portforward";
+ private int findPortIndex(int portNumber) {
+ Integer ix = streams.get(portNumber);
+ if (ix == null) {
+ return -1;
+ }
+ return ix.intValue();
}
/**
- * PortForward to a container
- *
- * @param pod The pod where the port forward is run.
- * @param ports The ports to forward
- * @return The result of the Port Forward request.
+ * Get the output stream for the specified port number (e.g. 80)
+ *
+ * @param port The port number to get the stream for.
+ * @return The OutputStream for the specified port, null if there is no such port.
*/
- public PortForwardResult forward(V1Pod pod, List ports) throws ApiException, IOException {
- return forward(pod.getMetadata().getNamespace(), pod.getMetadata().getNamespace(), ports);
+ public OutputStream getOutboundStream(int port) {
+ int portIndex = findPortIndex(port);
+ if (portIndex == -1) {
+ return null;
+ }
+ return handler.getOutputStream(portIndex * 2);
}
/**
- * PortForward to a container.
- *
- * @param namespace The namespace of the Pod
- * @param name The name of the Pod
- * @param ports The ports to forward
- * @return The result of the Port Forward request.
+ * Get the error stream for a port number (e.g. 80)
+ *
+ * @param port The port number to get the stream for.
+ * @return The error stream, or null if there is no such port.
*/
- public PortForwardResult forward(String namespace, String name, List ports) throws ApiException, IOException {
- String path = makePath(namespace, name);
- WebSocketStreamHandler handler = new WebSocketStreamHandler();
- PortForwardResult result = new PortForwardResult(handler, ports);
- List queryParams = new ArrayList<>();
- for (Integer port : ports) {
- queryParams.add(new Pair("ports", port.toString()));
- }
- WebSockets.stream(path, "GET", queryParams, apiClient, handler);
-
- // Wait for streams to start.
- result.init();
-
- return result;
+ public OutputStream getErrorStream(int port) {
+ int portIndex = findPortIndex(port);
+ if (portIndex == -1) {
+ return null;
+ }
+ return handler.getOutputStream(portIndex * 2 + 1);
}
/**
- * PortForwardResult contains the result of an Attach call, it includes streams for stdout
- * stderr and stdin.
+ * Get the input stream for a port number (e.g. 80)
+ *
+ * @param port The port number to get the stream for.
+ * @return The input stream, or null if no such port exists.
*/
- public static class PortForwardResult {
- private WebSocketStreamHandler handler;
- private HashMap streams;
- private List ports;
-
- /**
- * Constructor
- * @param handler The web socket handler
- * @param ports The list of ports that are being forwarded.
- */
- public PortForwardResult(WebSocketStreamHandler handler, List ports) throws IOException {
- this.handler = handler;
- this.streams = new HashMap<>();
- this.ports = ports;
- }
-
- /**
- * Initialize the connection. Must be called after the web socket has been opened.
- */
- public void init() throws IOException {
- for (int i = 0; i < ports.size(); i++) {
- InputStream is = handler.getInputStream(i * 2);
- byte[] data = new byte[2];
- is.read(data);
- int port = (data[0] & 0xFF) + (data[1] & 0xFF) * 256;
- streams.put(port, i);
- }
- }
-
- private int findPortIndex(int portNumber) {
- Integer ix = streams.get(portNumber);
- if (ix == null) {
- return -1;
- }
- return ix.intValue();
- }
-
- /**
- * Get the output stream for the specified port number (e.g. 80)
- * @param port The port number to get the stream for.
- * @return The OutputStream for the specified port, null if there is no such port.
- */
- public OutputStream getOutboundStream(int port) {
- int portIndex = findPortIndex(port);
- if (portIndex == -1) {
- return null;
- }
- return handler.getOutputStream(portIndex * 2);
- }
-
- /**
- * Get the error stream for a port number (e.g. 80)
- * @param port The port number to get the stream for.
- * @return The error stream, or null if there is no such port.
- */
- public OutputStream getErrorStream(int port) {
- int portIndex = findPortIndex(port);
- if (portIndex == -1) {
- return null;
- }
- return handler.getOutputStream(portIndex * 2 + 1);
- }
-
- /**
- * Get the input stream for a port number (e.g. 80)
- * @param port The port number to get the stream for.
- * @return The input stream, or null if no such port exists.
- */
- public InputStream getInputStream(int port) throws IOException {
- int portIndex = findPortIndex(port);
- if (portIndex == -1) {
- return null;
- }
- return handler.getInputStream(portIndex * 2);
- }
+ public InputStream getInputStream(int port) throws IOException {
+ int portIndex = findPortIndex(port);
+ if (portIndex == -1) {
+ return null;
+ }
+ return handler.getInputStream(portIndex * 2);
}
-}
\ No newline at end of file
+ }
+}
diff --git a/util/src/main/java/io/kubernetes/client/ProtoClient.java b/util/src/main/java/io/kubernetes/client/ProtoClient.java
index 9844f5f991..780ae423f3 100644
--- a/util/src/main/java/io/kubernetes/client/ProtoClient.java
+++ b/util/src/main/java/io/kubernetes/client/ProtoClient.java
@@ -1,11 +1,5 @@
package io.kubernetes.client;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashMap;
-
import com.google.common.io.ByteStreams;
import com.google.common.primitives.Bytes;
import com.google.protobuf.Message;
@@ -13,235 +7,288 @@
import com.squareup.okhttp.Request;
import com.squareup.okhttp.RequestBody;
import com.squareup.okhttp.Response;
-
import io.kubernetes.client.proto.Meta.DeleteOptions;
import io.kubernetes.client.proto.Meta.Status;
import io.kubernetes.client.proto.Runtime.TypeMeta;
import io.kubernetes.client.proto.Runtime.Unknown;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
public class ProtoClient {
- /**
- * ObjectOrStatus is an object that is the return from a method call
- * it holds either an API Object or an API Status object, but not both.
- * Only one field may be non-null at a time.
- *
- * Oh, how I long for multi-return...
- */
- public static class ObjectOrStatus {
- public ObjectOrStatus(T obj, Status status) {
- this.object = obj;
- this.status = status;
- }
-
- public T object;
- public Status status;
-
- public String toString() {
- if (object != null) {
- return object.toString();
- }
- return status.toString();
- }
+ /**
+ * ObjectOrStatus is an object that is the return from a method call it holds either an API Object
+ * or an API Status object, but not both. Only one field may be non-null at a time.
+ *
+ *
Oh, how I long for multi-return...
+ */
+ public static class ObjectOrStatus {
+ public ObjectOrStatus(T obj, Status status) {
+ this.object = obj;
+ this.status = status;
}
- private ApiClient apiClient;
- // Magic number for the beginning of proto encoded.
- // https://github.com/kubernetes/apimachinery/blob/master/pkg/runtime/serializer/protobuf/protobuf.go#L42
- private static final byte[] MAGIC = new byte[] { 0x6b, 0x38, 0x73, 0x00 };
- private static final String MEDIA_TYPE = "application/vnd.kubernetes.protobuf";
-
- /**
- * Simple Protocol Budder API client constructor, uses default configuration
- */
- public ProtoClient() {
- this(Configuration.getDefaultApiClient());
- }
+ public T object;
+ public Status status;
- /**
- * ProtocolBuffer Client Constructor
- * @param apiClient The api client to use.
- */
- public ProtoClient(ApiClient apiClient) {
- this.apiClient = apiClient;
+ public String toString() {
+ if (object != null) {
+ return object.toString();
+ }
+ return status.toString();
}
+ }
- /**
- * Get the API client for these ProtocolBuffer operations.
- * @return The API client that will be used.
- */
- public ApiClient getApiClient() {
- return apiClient;
- }
+ private ApiClient apiClient;
+ // Magic number for the beginning of proto encoded.
+ // https://github.com/kubernetes/apimachinery/blob/master/pkg/runtime/serializer/protobuf/protobuf.go#L42
+ private static final byte[] MAGIC = new byte[] {0x6b, 0x38, 0x73, 0x00};
+ private static final String MEDIA_TYPE = "application/vnd.kubernetes.protobuf";
- /**
- * Set the API client for subsequent ProtocolBuffer operations.
- * @param apiClient The new API client to use.
- */
- public void setApiClient(ApiClient apiClient) {
- this.apiClient = apiClient;
- }
+ /** Simple Protocol Budder API client constructor, uses default configuration */
+ public ProtoClient() {
+ this(Configuration.getDefaultApiClient());
+ }
- /**
- * Get a Kubernetes API object using protocol buffer encoding.
- * @param builder The appropriate Builder for the object receveived from the request.
- * @param path The URL path to call (e.g. /api/v1/namespaces/default/pods/pod-name)
- * @return An ObjectOrStatus which contains the Object requested, or a Status about the request.
- */
- public ObjectOrStatus get(T.Builder builder, String path) throws ApiException, IOException {
- return request(builder, path, "GET", null, null, null);
- }
+ /**
+ * ProtocolBuffer Client Constructor
+ *
+ * @param apiClient The api client to use.
+ */
+ public ProtoClient(ApiClient apiClient) {
+ this.apiClient = apiClient;
+ }
- /**
- * List is fluent, semantic sugar method on top of get, which is intended
- * to convey that the object is a List of objects rather than a single object
- * @param builder The appropriate Builder for the object receveived from the request.
- * @param path The URL path to call (e.g. /api/v1/namespaces/default/pods/pod-name)
- * @return An ObjectOrStatus which contains the Object requested, or a Status about the request.
- */
- public ObjectOrStatus list(T.Builder builder, String path) throws ApiException, IOException {
- return get(builder, path);
- }
+ /**
+ * Get the API client for these ProtocolBuffer operations.
+ *
+ * @return The API client that will be used.
+ */
+ public ApiClient getApiClient() {
+ return apiClient;
+ }
- /**
- * Create a Kubernetes API object using protocol buffer encoding. Performs a POST
- * @param obj The object to create
- * @param path The URL path to call
- * @param apiVersion The api version to use
- * @param kind The kind of the object
- * @return An ObjectOrStatus which contains the Object requested, or a Status about the request.
- */
- public ObjectOrStatus create(T obj, String path, String apiVersion, String kind)
- throws ApiException, IOException {
- return request(obj.newBuilderForType(), path, "POST", obj, apiVersion, kind);
- }
+ /**
+ * Set the API client for subsequent ProtocolBuffer operations.
+ *
+ * @param apiClient The new API client to use.
+ */
+ public void setApiClient(ApiClient apiClient) {
+ this.apiClient = apiClient;
+ }
- /**
- * Update a Kubernetes API object using protocol buffer encoding. Performs a PUT
- * @param obj The object to create
- * @param path The URL path to call
- * @param apiVersion The api version to use
- * @param kind The kind of the object
- * @return An ObjectOrStatus which contains the Object requested, or a Status about the request.
- */
- public ObjectOrStatus update(T obj, String path, String apiVersion, String kind)
- throws ApiException, IOException {
- return request(obj.newBuilderForType(), path, "PUT", obj, apiVersion, kind);
- }
+ /**
+ * Get a Kubernetes API object using protocol buffer encoding.
+ *
+ * @param builder The appropriate Builder for the object receveived from the request.
+ * @param path The URL path to call (e.g. /api/v1/namespaces/default/pods/pod-name)
+ * @return An ObjectOrStatus which contains the Object requested, or a Status about the request.
+ */
+ public ObjectOrStatus get(T.Builder builder, String path)
+ throws ApiException, IOException {
+ return request(builder, path, "GET", null, null, null);
+ }
+
+ /**
+ * List is fluent, semantic sugar method on top of get, which is intended to convey that the
+ * object is a List of objects rather than a single object
+ *
+ * @param builder The appropriate Builder for the object receveived from the request.
+ * @param path The URL path to call (e.g. /api/v1/namespaces/default/pods/pod-name)
+ * @return An ObjectOrStatus which contains the Object requested, or a Status about the request.
+ */
+ public ObjectOrStatus list(T.Builder builder, String path)
+ throws ApiException, IOException {
+ return get(builder, path);
+ }
+
+ /**
+ * Create a Kubernetes API object using protocol buffer encoding. Performs a POST
+ *
+ * @param obj The object to create
+ * @param path The URL path to call
+ * @param apiVersion The api version to use
+ * @param kind The kind of the object
+ * @return An ObjectOrStatus which contains the Object requested, or a Status about the request.
+ */
+ public ObjectOrStatus create(
+ T obj, String path, String apiVersion, String kind) throws ApiException, IOException {
+ return request(obj.newBuilderForType(), path, "POST", obj, apiVersion, kind);
+ }
- /**
- * Delete a kubernetes API object using protocol buffer encoding.
- * @param builder The builder for the response
- * @param path The path to call in the API server
- * @return The response status
- */
- public ObjectOrStatus delete(T.Builder builder, String path) throws ApiException, IOException {
- return request(builder, path, "DELETE", null, null, null);
+ /**
+ * Update a Kubernetes API object using protocol buffer encoding. Performs a PUT
+ *
+ * @param obj The object to create
+ * @param path The URL path to call
+ * @param apiVersion The api version to use
+ * @param kind The kind of the object
+ * @return An ObjectOrStatus which contains the Object requested, or a Status about the request.
+ */
+ public ObjectOrStatus update(
+ T obj, String path, String apiVersion, String kind) throws ApiException, IOException {
+ return request(obj.newBuilderForType(), path, "PUT", obj, apiVersion, kind);
+ }
+
+ /**
+ * Delete a kubernetes API object using protocol buffer encoding.
+ *
+ * @param builder The builder for the response
+ * @param path The path to call in the API server
+ * @return The response status
+ */
+ public ObjectOrStatus delete(T.Builder builder, String path)
+ throws ApiException, IOException {
+ return request(builder, path, "DELETE", null, null, null);
+ }
+
+ /**
+ * Delete a kubernetes API object using protocol buffer encoding.
+ *
+ * @param builder The builder for the response
+ * @param path The path to call in the API server
+ * @param deleteOptions optional deleteOptions
+ * @return The response status
+ */
+ public ObjectOrStatus delete(
+ T.Builder builder, String path, DeleteOptions deleteOptions)
+ throws ApiException, IOException {
+ if (deleteOptions == null) {
+ return delete(builder, path);
}
- /**
- * Delete a kubernetes API object using protocol buffer encoding.
- * @param builder The builder for the response
- * @param path The path to call in the API server
- * @param deleteOptions optional deleteOptions
- * @return The response status
- */
- public ObjectOrStatus delete(T.Builder builder, String path, DeleteOptions deleteOptions) throws ApiException, IOException {
- if (deleteOptions == null) {
- return delete(builder,path);
- }
-
- HashMap headers = new HashMap<>();
- headers.put("Content-Type", MEDIA_TYPE);
- headers.put("Accept", MEDIA_TYPE);
- String[] localVarAuthNames = new String[] { "BearerToken" };
- Request request = apiClient.buildRequest(path, "DELETE", new ArrayList(), new ArrayList(), null,
- headers, new HashMap(), localVarAuthNames, null);
- byte[] bytes = encode(deleteOptions, "v1", "DeleteOptions");
- request = request.newBuilder().delete(RequestBody.create(MediaType.parse(MEDIA_TYPE), bytes)).build();
- Response resp = apiClient.getHttpClient().newCall(request).execute();
- Unknown u = parse(resp.body().byteStream());
- resp.body().close();
-
- if (u.getTypeMeta().getApiVersion().equals("v1") &&
- u.getTypeMeta().getKind().equals("Status")) {
- Status status = Status.newBuilder().mergeFrom(u.getRaw()).build();
- return new ObjectOrStatus(null, status);
- }
-
- return new ObjectOrStatus((T) builder.mergeFrom(u.getRaw()).build(), null);
+ HashMap headers = new HashMap<>();
+ headers.put("Content-Type", MEDIA_TYPE);
+ headers.put("Accept", MEDIA_TYPE);
+ String[] localVarAuthNames = new String[] {"BearerToken"};
+ Request request =
+ apiClient.buildRequest(
+ path,
+ "DELETE",
+ new ArrayList(),
+ new ArrayList(),
+ null,
+ headers,
+ new HashMap(),
+ localVarAuthNames,
+ null);
+ byte[] bytes = encode(deleteOptions, "v1", "DeleteOptions");
+ request =
+ request.newBuilder().delete(RequestBody.create(MediaType.parse(MEDIA_TYPE), bytes)).build();
+ Response resp = apiClient.getHttpClient().newCall(request).execute();
+ Unknown u = parse(resp.body().byteStream());
+ resp.body().close();
+
+ if (u.getTypeMeta().getApiVersion().equals("v1")
+ && u.getTypeMeta().getKind().equals("Status")) {
+ Status status = Status.newBuilder().mergeFrom(u.getRaw()).build();
+ return new ObjectOrStatus(null, status);
}
- /**
- * Generic protocol buffer based HTTP request.
- * Not intended for general consumption, but public for advance use cases.
- * @param builder The appropriate Builder for the object receveived from the request.
- * @param method The HTTP method (e.g. GET) for this request.
- * @param path The URL path to call (e.g. /api/v1/namespaces/default/pods/pod-name)
- * @param body The body to send with the request (optional)
- * @param apiVersion The 'apiVersion' to use when encoding, required if body is non-null, ignored otherwise.
- * @param kind The 'kind' field to use when encoding, required if body is non-null, ignored otherwise.
- * @return An ObjectOrStatus which contains the Object requested, or a Status about the request.
- */
- public ObjectOrStatus request(T.Builder builder, String path, String method, T body, String apiVersion,
- String kind) throws ApiException, IOException {
- HashMap headers = new HashMap<>();
- headers.put("Content-Type", MEDIA_TYPE);
- headers.put("Accept", MEDIA_TYPE);
- String[] localVarAuthNames = new String[] { "BearerToken" };
- Request request = apiClient.buildRequest(path, method, new ArrayList(), new ArrayList(), null,
- headers, new HashMap(), localVarAuthNames, null);
- if (body != null) {
- byte[] bytes = encode(body, apiVersion, kind);
- switch (method) {
- case "POST":
- request = request.newBuilder().post(RequestBody.create(MediaType.parse(MEDIA_TYPE), bytes)).build();
- break;
- case "PUT":
- request = request.newBuilder().put(RequestBody.create(MediaType.parse(MEDIA_TYPE), bytes)).build();
- break;
- case "PATCH":
- request = request.newBuilder().patch(RequestBody.create(MediaType.parse(MEDIA_TYPE), bytes)).build();
- break;
- default:
- throw new ApiException("Unknown proto client API method: " + method);
- }
- }
- Response resp = apiClient.getHttpClient().newCall(request).execute();
- Unknown u = parse(resp.body().byteStream());
- resp.body().close();
-
- if (u.getTypeMeta().getApiVersion().equals("v1") &&
- u.getTypeMeta().getKind().equals("Status")) {
- Status status = Status.newBuilder().mergeFrom(u.getRaw()).build();
- return new ObjectOrStatus(null, status);
- }
-
- return new ObjectOrStatus((T) builder.mergeFrom(u.getRaw()).build(), null);
+ return new ObjectOrStatus((T) builder.mergeFrom(u.getRaw()).build(), null);
+ }
+
+ /**
+ * Generic protocol buffer based HTTP request. Not intended for general consumption, but public
+ * for advance use cases.
+ *
+ * @param builder The appropriate Builder for the object receveived from the request.
+ * @param method The HTTP method (e.g. GET) for this request.
+ * @param path The URL path to call (e.g. /api/v1/namespaces/default/pods/pod-name)
+ * @param body The body to send with the request (optional)
+ * @param apiVersion The 'apiVersion' to use when encoding, required if body is non-null, ignored
+ * otherwise.
+ * @param kind The 'kind' field to use when encoding, required if body is non-null, ignored
+ * otherwise.
+ * @return An ObjectOrStatus which contains the Object requested, or a Status about the request.
+ */
+ public ObjectOrStatus request(
+ T.Builder builder, String path, String method, T body, String apiVersion, String kind)
+ throws ApiException, IOException {
+ HashMap headers = new HashMap<>();
+ headers.put("Content-Type", MEDIA_TYPE);
+ headers.put("Accept", MEDIA_TYPE);
+ String[] localVarAuthNames = new String[] {"BearerToken"};
+ Request request =
+ apiClient.buildRequest(
+ path,
+ method,
+ new ArrayList(),
+ new ArrayList(),
+ null,
+ headers,
+ new HashMap(),
+ localVarAuthNames,
+ null);
+ if (body != null) {
+ byte[] bytes = encode(body, apiVersion, kind);
+ switch (method) {
+ case "POST":
+ request =
+ request
+ .newBuilder()
+ .post(RequestBody.create(MediaType.parse(MEDIA_TYPE), bytes))
+ .build();
+ break;
+ case "PUT":
+ request =
+ request
+ .newBuilder()
+ .put(RequestBody.create(MediaType.parse(MEDIA_TYPE), bytes))
+ .build();
+ break;
+ case "PATCH":
+ request =
+ request
+ .newBuilder()
+ .patch(RequestBody.create(MediaType.parse(MEDIA_TYPE), bytes))
+ .build();
+ break;
+ default:
+ throw new ApiException("Unknown proto client API method: " + method);
+ }
}
+ Response resp = apiClient.getHttpClient().newCall(request).execute();
+ Unknown u = parse(resp.body().byteStream());
+ resp.body().close();
- // This isn't really documented anywhere except the code, but
- // the proto-buf format is:
- // * 4 byte magic number
- // * Protocol Buffer encoded object of type runtime.Unknown
- // * the 'raw' field in that object contains a Protocol Buffer
- // encoding of the actual object.
- // TODO: Document this somewhere proper.
-
- private byte[] encode(Message msg, String apiVersion, String kind) {
- // It is unfortunate that we have to include apiVersion and kind,
- // since we should be able to extract it from the Message, but
- // for now at least, those fields are missing from the proto-buffer.
- Unknown u = Unknown.newBuilder().setTypeMeta(TypeMeta.newBuilder().setApiVersion(apiVersion).setKind(kind))
- .setRaw(msg.toByteString()).build();
- return Bytes.concat(MAGIC, u.toByteArray());
+ if (u.getTypeMeta().getApiVersion().equals("v1")
+ && u.getTypeMeta().getKind().equals("Status")) {
+ Status status = Status.newBuilder().mergeFrom(u.getRaw()).build();
+ return new ObjectOrStatus(null, status);
}
- private Unknown parse(InputStream stream) throws ApiException, IOException {
- byte[] magic = new byte[4];
- ByteStreams.readFully(stream, magic);
- if (!Arrays.equals(magic, MAGIC)) {
- throw new ApiException("Unexpected magic number: " + magic);
- }
- return Unknown.parseFrom(stream);
+ return new ObjectOrStatus((T) builder.mergeFrom(u.getRaw()).build(), null);
+ }
+
+ // This isn't really documented anywhere except the code, but
+ // the proto-buf format is:
+ // * 4 byte magic number
+ // * Protocol Buffer encoded object of type runtime.Unknown
+ // * the 'raw' field in that object contains a Protocol Buffer
+ // encoding of the actual object.
+ // TODO: Document this somewhere proper.
+
+ private byte[] encode(Message msg, String apiVersion, String kind) {
+ // It is unfortunate that we have to include apiVersion and kind,
+ // since we should be able to extract it from the Message, but
+ // for now at least, those fields are missing from the proto-buffer.
+ Unknown u =
+ Unknown.newBuilder()
+ .setTypeMeta(TypeMeta.newBuilder().setApiVersion(apiVersion).setKind(kind))
+ .setRaw(msg.toByteString())
+ .build();
+ return Bytes.concat(MAGIC, u.toByteArray());
+ }
+
+ private Unknown parse(InputStream stream) throws ApiException, IOException {
+ byte[] magic = new byte[4];
+ ByteStreams.readFully(stream, magic);
+ if (!Arrays.equals(magic, MAGIC)) {
+ throw new ApiException("Unexpected magic number: " + magic);
}
+ return Unknown.parseFrom(stream);
+ }
}
diff --git a/util/src/main/java/io/kubernetes/client/util/ClientBuilder.java b/util/src/main/java/io/kubernetes/client/util/ClientBuilder.java
index 3734ab8726..80ff36c279 100644
--- a/util/src/main/java/io/kubernetes/client/util/ClientBuilder.java
+++ b/util/src/main/java/io/kubernetes/client/util/ClientBuilder.java
@@ -12,6 +12,14 @@
*/
package io.kubernetes.client.util;
+import static io.kubernetes.client.util.Config.ENV_KUBECONFIG;
+import static io.kubernetes.client.util.Config.ENV_SERVICE_HOST;
+import static io.kubernetes.client.util.Config.ENV_SERVICE_PORT;
+import static io.kubernetes.client.util.Config.SERVICEACCOUNT_CA_PATH;
+import static io.kubernetes.client.util.Config.SERVICEACCOUNT_TOKEN_PATH;
+import static io.kubernetes.client.util.KubeConfig.*;
+
+import io.kubernetes.client.ApiClient;
import io.kubernetes.client.util.credentials.AccessTokenAuthentication;
import io.kubernetes.client.util.credentials.Authentication;
import io.kubernetes.client.util.credentials.KubeconfigAuthentication;
@@ -20,25 +28,13 @@
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
-
import java.io.Reader;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Paths;
import org.apache.log4j.Logger;
-import io.kubernetes.client.ApiClient;
-
-import static io.kubernetes.client.util.Config.ENV_KUBECONFIG;
-import static io.kubernetes.client.util.Config.ENV_SERVICE_HOST;
-import static io.kubernetes.client.util.Config.ENV_SERVICE_PORT;
-import static io.kubernetes.client.util.Config.SERVICEACCOUNT_CA_PATH;
-import static io.kubernetes.client.util.Config.SERVICEACCOUNT_TOKEN_PATH;
-import static io.kubernetes.client.util.KubeConfig.*;
-
-/**
- * A Builder which allows the construction of {@link ApiClient}s in a fluent fashion.
- */
+/** A Builder which allows the construction of {@link ApiClient}s in a fluent fashion. */
public class ClientBuilder {
private static final Logger log = Logger.getLogger(ClientBuilder.class);
@@ -51,8 +47,10 @@ public class ClientBuilder {
/**
* Creates an {@link ApiClient} by calling {@link #standard()} and {@link #build()}.
*
- * @return An ApiClient configured using the precedence specified for {@link #standard()}.
- * @throws IOException if the configuration file or a file specified in a configuration file cannot be read.
+ * @return An ApiClient configured using the precedence specified for {@link
+ * #standard()}.
+ * @throws IOException if the configuration file or a file specified in a configuration file
+ * cannot be read.
*/
public static ApiClient defaultClient() throws IOException {
return ClientBuilder.standard().build();
@@ -62,14 +60,15 @@ public static ApiClient defaultClient() throws IOException {
* Creates a builder which is pre-configured in the following way
*
*
- *
If $KUBECONFIG is defined, use that config file.
- *
If $HOME/.kube/config can be found, use that.
- *
If the in-cluster service account can be found, assume in cluster config.
- *
Default to localhost:8080 as a last resort.
+ *
If $KUBECONFIG is defined, use that config file.
+ *
If $HOME/.kube/config can be found, use that.
+ *
If the in-cluster service account can be found, assume in cluster config.
+ *
Default to localhost:8080 as a last resort.
*
*
* @return ClientBuilder pre-configured using the above precedence
- * @throws IOException if the configuration file or a file specified in a configuration file cannot be read.
+ * @throws IOException if the configuration file or a file specified in a configuration file
+ * cannot be read.
*/
public static ClientBuilder standard() throws IOException {
final FileReader kubeConfigReader = findConfigFromEnv();
@@ -103,7 +102,7 @@ private static FileReader findConfigFromEnv() throws FileNotFoundException {
private static FileReader findConfigInHomeDir() throws FileNotFoundException {
final File config = new File(new File(System.getenv(ENV_HOME), KUBEDIR), KUBECONFIG);
- if(config.exists()) {
+ if (config.exists()) {
return new FileReader(config);
} else {
log.debug("Could not find ~/.kube/config");
@@ -124,8 +123,9 @@ public static ClientBuilder cluster() throws IOException {
final String port = System.getenv(ENV_SERVICE_PORT);
builder.setBasePath("https://" + host + ":" + port);
- final String token = new String(Files.readAllBytes(Paths.get(SERVICEACCOUNT_TOKEN_PATH)),
- Charset.defaultCharset());
+ final String token =
+ new String(
+ Files.readAllBytes(Paths.get(SERVICEACCOUNT_TOKEN_PATH)), Charset.defaultCharset());
builder.setCertificateAuthority(Files.readAllBytes(Paths.get(SERVICEACCOUNT_CA_PATH)));
builder.setAuthentication(new AccessTokenAuthentication(token));
@@ -135,7 +135,7 @@ public static ClientBuilder cluster() throws IOException {
/**
* Creates a builder which is pre-configured from a {@link KubeConfig}.
*
- * To load a KubeConfig, see {@link KubeConfig#loadKubeConfig(Reader)}.
+ *
To load a KubeConfig, see {@link KubeConfig#loadKubeConfig(Reader)}.
*
* @param config The {@link KubeConfig} to configure the builder from.
* @return ClientBuilder configured from the provided KubeConfig
@@ -153,8 +153,9 @@ public static ClientBuilder kubeconfig(KubeConfig config) throws IOException {
}
}
- final byte[] caBytes = KubeConfig.getDataOrFile(config.getCertificateAuthorityData(),
- config.getCertificateAuthorityFile());
+ final byte[] caBytes =
+ KubeConfig.getDataOrFile(
+ config.getCertificateAuthorityData(), config.getCertificateAuthorityFile());
if (caBytes != null) {
builder.setCertificateAuthority(caBytes);
}
@@ -220,4 +221,4 @@ public ApiClient build() {
return client;
}
-}
\ No newline at end of file
+}
diff --git a/util/src/main/java/io/kubernetes/client/util/Config.java b/util/src/main/java/io/kubernetes/client/util/Config.java
index ff4270975c..98cced0345 100644
--- a/util/src/main/java/io/kubernetes/client/util/Config.java
+++ b/util/src/main/java/io/kubernetes/client/util/Config.java
@@ -15,97 +15,91 @@
import io.kubernetes.client.ApiClient;
import io.kubernetes.client.util.credentials.AccessTokenAuthentication;
import io.kubernetes.client.util.credentials.UsernamePasswordAuthentication;
-import org.apache.log4j.Logger;
-
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
+import org.apache.log4j.Logger;
public class Config {
- public static final String SERVICEACCOUNT_ROOT =
- "/var/run/secrets/kubernetes.io/serviceaccount";
- public static final String SERVICEACCOUNT_CA_PATH =
- SERVICEACCOUNT_ROOT + "/ca.crt";
- public static final String SERVICEACCOUNT_TOKEN_PATH =
- SERVICEACCOUNT_ROOT + "/token";
- public static final String ENV_KUBECONFIG = "KUBECONFIG";
- public static final String ENV_SERVICE_HOST = "KUBERNETES_SERVICE_HOST";
- public static final String ENV_SERVICE_PORT = "KUBERNETES_SERVICE_PORT";
- // The last resort host to try
- public static final String DEFAULT_FALLBACK_HOST = "http://localhost:8080";
-
- private static final Logger log = Logger.getLogger(Config.class);
-
- public static ApiClient fromCluster() throws IOException {
- return ClientBuilder.cluster().build();
- }
-
- public static ApiClient fromUrl(String url) {
- return fromUrl(url, true);
- }
-
- public static ApiClient fromUrl(String url, boolean validateSSL) {
- return new ApiClient()
- .setBasePath(url)
- .setVerifyingSsl(validateSSL);
- }
-
- public static ApiClient fromUserPassword(String url, String user, String password) {
- return fromUserPassword(url, user, password, true);
- }
-
- public static ApiClient fromUserPassword(String url, String user, String password, boolean validateSSL) {
- return new ClientBuilder()
- .setBasePath(url)
- .setAuthentication(new UsernamePasswordAuthentication(user, password))
- .setVerifyingSsl(validateSSL)
- .build();
- }
-
- public static ApiClient fromToken(String url, String token) {
- return fromToken(url, token, true);
- }
-
- public static ApiClient fromToken(String url, String token, boolean validateSSL) {
- return new ClientBuilder()
- .setBasePath(url)
- .setAuthentication(new AccessTokenAuthentication(token))
- .setVerifyingSsl(validateSSL)
- .build();
- }
-
- public static ApiClient fromConfig(String fileName) throws IOException {
- return fromConfig(new FileReader(fileName));
- }
-
- public static ApiClient fromConfig(InputStream stream) throws IOException {
- return fromConfig(new InputStreamReader(stream));
- }
-
- public static ApiClient fromConfig(Reader input) throws IOException {
- return fromConfig(KubeConfig.loadKubeConfig(input));
- }
-
- public static ApiClient fromConfig(KubeConfig config) throws IOException {
- return ClientBuilder
- .kubeconfig(config)
- .build();
- }
-
- /**
- * Easy client creation, follows this plan
- *
- *
If $KUBECONFIG is defined, use that config file.
- *
If $HOME/.kube/config can be found, use that.
- *
If the in-cluster service account can be found, assume in cluster config.
- *
Default to localhost:8080 as a last resort.
- *
- *
- * @return The best APIClient given the previously described rules
- */
- public static ApiClient defaultClient() throws IOException {
- return ClientBuilder.standard().build();
- }
+ public static final String SERVICEACCOUNT_ROOT = "/var/run/secrets/kubernetes.io/serviceaccount";
+ public static final String SERVICEACCOUNT_CA_PATH = SERVICEACCOUNT_ROOT + "/ca.crt";
+ public static final String SERVICEACCOUNT_TOKEN_PATH = SERVICEACCOUNT_ROOT + "/token";
+ public static final String ENV_KUBECONFIG = "KUBECONFIG";
+ public static final String ENV_SERVICE_HOST = "KUBERNETES_SERVICE_HOST";
+ public static final String ENV_SERVICE_PORT = "KUBERNETES_SERVICE_PORT";
+ // The last resort host to try
+ public static final String DEFAULT_FALLBACK_HOST = "http://localhost:8080";
+
+ private static final Logger log = Logger.getLogger(Config.class);
+
+ public static ApiClient fromCluster() throws IOException {
+ return ClientBuilder.cluster().build();
+ }
+
+ public static ApiClient fromUrl(String url) {
+ return fromUrl(url, true);
+ }
+
+ public static ApiClient fromUrl(String url, boolean validateSSL) {
+ return new ApiClient().setBasePath(url).setVerifyingSsl(validateSSL);
+ }
+
+ public static ApiClient fromUserPassword(String url, String user, String password) {
+ return fromUserPassword(url, user, password, true);
+ }
+
+ public static ApiClient fromUserPassword(
+ String url, String user, String password, boolean validateSSL) {
+ return new ClientBuilder()
+ .setBasePath(url)
+ .setAuthentication(new UsernamePasswordAuthentication(user, password))
+ .setVerifyingSsl(validateSSL)
+ .build();
+ }
+
+ public static ApiClient fromToken(String url, String token) {
+ return fromToken(url, token, true);
+ }
+
+ public static ApiClient fromToken(String url, String token, boolean validateSSL) {
+ return new ClientBuilder()
+ .setBasePath(url)
+ .setAuthentication(new AccessTokenAuthentication(token))
+ .setVerifyingSsl(validateSSL)
+ .build();
+ }
+
+ public static ApiClient fromConfig(String fileName) throws IOException {
+ return fromConfig(new FileReader(fileName));
+ }
+
+ public static ApiClient fromConfig(InputStream stream) throws IOException {
+ return fromConfig(new InputStreamReader(stream));
+ }
+
+ public static ApiClient fromConfig(Reader input) throws IOException {
+ return fromConfig(KubeConfig.loadKubeConfig(input));
+ }
+
+ public static ApiClient fromConfig(KubeConfig config) throws IOException {
+ return ClientBuilder.kubeconfig(config).build();
+ }
+
+ /**
+ * Easy client creation, follows this plan
+ *
+ *
+ *
If $KUBECONFIG is defined, use that config file.
+ *
If $HOME/.kube/config can be found, use that.
+ *
If the in-cluster service account can be found, assume in cluster config.
+ *
Default to localhost:8080 as a last resort.
+ *
+ *
+ * @return The best APIClient given the previously described rules
+ */
+ public static ApiClient defaultClient() throws IOException {
+ return ClientBuilder.standard().build();
+ }
}
diff --git a/util/src/main/java/io/kubernetes/client/util/KubeConfig.java b/util/src/main/java/io/kubernetes/client/util/KubeConfig.java
index 0bd1d7b2c2..4c2f36f25b 100644
--- a/util/src/main/java/io/kubernetes/client/util/KubeConfig.java
+++ b/util/src/main/java/io/kubernetes/client/util/KubeConfig.java
@@ -12,14 +12,7 @@
*/
package io.kubernetes.client.util;
-import com.google.common.base.Charsets;
import io.kubernetes.client.util.authenticators.Authenticator;
-import java.nio.file.Paths;
-import org.apache.commons.codec.binary.Base64;
-import org.apache.log4j.Logger;
-import org.yaml.snakeyaml.Yaml;
-import org.yaml.snakeyaml.constructor.SafeConstructor;
-
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
@@ -27,224 +20,222 @@
import java.io.Reader;
import java.nio.file.FileSystems;
import java.nio.file.Files;
+import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
+import org.apache.commons.codec.binary.Base64;
+import org.apache.log4j.Logger;
+import org.yaml.snakeyaml.Yaml;
+import org.yaml.snakeyaml.constructor.SafeConstructor;
-/**
- * KubeConfig represents a kubernetes client configuration
- */
+/** KubeConfig represents a kubernetes client configuration */
public class KubeConfig {
- // Defaults for where to find a kubeconfig file
- public static final String ENV_HOME = "HOME";
- public static final String KUBEDIR = ".kube";
- public static final String KUBECONFIG = "config";
- private static Map authenticators = new HashMap<>();
-
- // Note to the reader: I considered creating a Config object
- // and parsing into that instead of using Maps, but honestly
- // this seemed cleaner than a bunch of boilerplate classes
-
- private ArrayList