Skip to content

Commit b282bcb

Browse files
committed
Add a very simple example.
1 parent 1db144d commit b282bcb

File tree

4 files changed

+91
-0
lines changed

4 files changed

+91
-0
lines changed

examples/README.md

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Running examples
2+
3+
```sh
4+
export REPO_ROOT=/path/to/client-java/repo
5+
6+
cd ${REPO_ROOT}/kubernetes
7+
mvn install
8+
9+
cd ${REPO_ROOT}/examples
10+
mvn package
11+
mvn exec:java -Dexec.mainClass="io.kubernetes.client.examples.Example"
12+
```
13+

examples/pom.xml

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<project
2+
xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<groupId>io.kubernetes</groupId>
6+
<artifactId>client-java-examples</artifactId>
7+
<version>1.0-SNAPSHOT</version>
8+
<packaging>jar</packaging>
9+
<name>client-java-examples</name>
10+
<url>https://github.com/kubernetes-client/java</url>
11+
<dependencies>
12+
<dependency>
13+
<groupId>io.kubernetes</groupId>
14+
<artifactId>client-java</artifactId>
15+
<version>1.0-SNAPSHOT</version>
16+
</dependency>
17+
</dependencies>
18+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package io.kubernetes.client.examples;
2+
3+
import io.kubernetes.client.ApiClient;
4+
import io.kubernetes.client.ApiException;
5+
import io.kubernetes.client.Configuration;
6+
import io.kubernetes.client.apis.CoreV1Api;
7+
import io.kubernetes.client.models.V1Pod;
8+
import io.kubernetes.client.models.V1PodList;
9+
10+
/**
11+
* A simple example of how to use the Java API
12+
*
13+
* Requires kubectl proxy running
14+
*
15+
* Easiest way to run this:
16+
* mvn exec:java -Dex.mainClass="io.kubernetes.client.examples.Example"
17+
*
18+
* From inside $REPO_DIR/kubernetes
19+
*/
20+
public class Example {
21+
public static void main(String[] args) throws ApiException{
22+
ApiClient client = new ApiClient();
23+
client.setBasePath("http://localhost:8001");
24+
Configuration.setDefaultApiClient(client);
25+
26+
CoreV1Api api = new CoreV1Api();
27+
V1PodList list = api.listPodForAllNamespaces(null, null, null, null, null, null);
28+
for (V1Pod item : list.getItems()) {
29+
System.out.println(item.getMetadata().getName());
30+
}
31+
}
32+
}

pom.xml

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<project
2+
xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<artifactId>parent</artifactId>
6+
<groupId>io.kubernetes</groupId>
7+
<version>1.0-SNAPSHOT</version>
8+
<packaging>pom</packaging>
9+
<modules>
10+
<module>kubernetes</module>
11+
<module>examples</module>
12+
</modules>
13+
<build>
14+
<pluginManagement>
15+
<plugins>
16+
<plugin>
17+
<groupId>org.codehaus.mojo</groupId>
18+
<artifactId>exec-maven-plugin</artifactId>
19+
<version>1.6.0</version>
20+
<configuration>
21+
<skip>true</skip>
22+
<mainClass>none</mainClass>
23+
</configuration>
24+
</plugin>
25+
</plugins>
26+
</pluginManagement>
27+
</build>
28+
</project>

0 commit comments

Comments
 (0)