Skip to content

Commit 11d0e2e

Browse files
committed
adding examples subproject for release-10.0.0
1 parent 712ab4f commit 11d0e2e

37 files changed

+2791
-51
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
FROM openjdk:8-jre
2+
3+
COPY target/client-java-examples-*-SNAPSHOT-jar-with-dependencies.jar /examples.jar
4+
5+
CMD ["java", "-jar", "/examples.jar"]
6+
7+
Lines changed: 13 additions & 0 deletions
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+
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/bin/bash
2+
3+
# creates a pod and runs
4+
# Example.java(list pods for all namespaces) on starting of pod
5+
6+
# Exit on any error.
7+
set -e
8+
9+
if ! which minikube > /dev/null; then
10+
echo "This script requires minikube installed."
11+
exit 100
12+
fi
13+
14+
dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
15+
16+
export REPO_ROOT=${dir}/..
17+
18+
cd ${REPO_ROOT}
19+
mvn install
20+
21+
cd ${REPO_ROOT}/examples
22+
mvn package
23+
24+
eval $(minikube docker-env)
25+
docker build -t test/examples:1.0 .
26+
kubectl apply -f test.yaml

examples/examples-release-10/pom.xml

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" 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">
2+
<modelVersion>4.0.0</modelVersion>
3+
4+
<parent>
5+
<groupId>io.kubernetes</groupId>
6+
<artifactId>client-java-examples-parent</artifactId>
7+
<version>1.0.0-SNAPSHOT</version>
8+
<relativePath>../pom.xml</relativePath>
9+
</parent>
10+
11+
<artifactId>client-java-examples-release-10</artifactId>
12+
<packaging>bundle</packaging>
13+
<name>client-java-examples-release-10</name>
14+
15+
<properties>
16+
<kubernetes.client.version>10.0.0</kubernetes.client.version>
17+
</properties>
18+
<dependencies>
19+
<dependency>
20+
<groupId>io.prometheus</groupId>
21+
<artifactId>simpleclient</artifactId>
22+
<version>0.9.0</version>
23+
</dependency>
24+
<dependency>
25+
<groupId>io.prometheus</groupId>
26+
<artifactId>simpleclient_httpserver</artifactId>
27+
<version>0.9.0</version>
28+
</dependency>
29+
<dependency>
30+
<groupId>io.kubernetes</groupId>
31+
<artifactId>client-java-api</artifactId>
32+
<version>${kubernetes.client.version}</version>
33+
</dependency>
34+
<dependency>
35+
<groupId>io.kubernetes</groupId>
36+
<artifactId>client-java</artifactId>
37+
<version>${kubernetes.client.version}</version>
38+
</dependency>
39+
<dependency>
40+
<groupId>io.kubernetes</groupId>
41+
<artifactId>client-java-extended</artifactId>
42+
<version>${kubernetes.client.version}</version>
43+
</dependency>
44+
<dependency>
45+
<groupId>io.kubernetes</groupId>
46+
<artifactId>client-java-spring-integration</artifactId>
47+
<version>${kubernetes.client.version}</version>
48+
</dependency>
49+
<dependency>
50+
<groupId>io.kubernetes</groupId>
51+
<artifactId>client-java-proto</artifactId>
52+
<version>${kubernetes.client.version}</version>
53+
</dependency>
54+
<dependency>
55+
<groupId>com.google.guava</groupId>
56+
<artifactId>guava</artifactId>
57+
</dependency>
58+
<dependency>
59+
<groupId>commons-cli</groupId>
60+
<artifactId>commons-cli</artifactId>
61+
</dependency>
62+
<dependency>
63+
<groupId>io.kubernetes</groupId>
64+
<artifactId>client-java-cert-manager-models</artifactId>
65+
<version>10.0.0</version>
66+
</dependency>
67+
<dependency>
68+
<groupId>io.kubernetes</groupId>
69+
<artifactId>client-java-prometheus-operator-models</artifactId>
70+
<version>10.0.0</version>
71+
</dependency>
72+
<!-- test dependencies -->
73+
<dependency>
74+
<groupId>junit</groupId>
75+
<artifactId>junit</artifactId>
76+
<scope>test</scope>
77+
</dependency>
78+
<dependency>
79+
<groupId>com.github.tomakehurst</groupId>
80+
<artifactId>wiremock</artifactId>
81+
<scope>test</scope>
82+
</dependency>
83+
</dependencies>
84+
<build>
85+
<plugins>
86+
<plugin>
87+
<groupId>org.apache.felix</groupId>
88+
<artifactId>maven-bundle-plugin</artifactId>
89+
<extensions>true</extensions>
90+
</plugin>
91+
<plugin>
92+
<groupId>org.apache.maven.plugins</groupId>
93+
<artifactId>maven-deploy-plugin</artifactId>
94+
<version>2.8.2</version>
95+
<configuration>
96+
<skip>true</skip>
97+
</configuration>
98+
</plugin>
99+
<plugin>
100+
<groupId>org.apache.maven.plugins</groupId>
101+
<artifactId>maven-assembly-plugin</artifactId>
102+
<executions>
103+
<execution>
104+
<phase>package</phase>
105+
<goals>
106+
<goal>single</goal>
107+
</goals>
108+
<configuration>
109+
<archive>
110+
<manifest>
111+
<mainClass>io.kubernetes.client.examples.Example</mainClass>
112+
</manifest>
113+
</archive>
114+
<descriptorRefs>
115+
<descriptorRef>jar-with-dependencies</descriptorRef>
116+
</descriptorRefs>
117+
</configuration>
118+
</execution>
119+
</executions>
120+
</plugin>
121+
</plugins>
122+
</build>
123+
124+
</project>
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/*
2+
Copyright 2020 The Kubernetes Authors.
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
http://www.apache.org/licenses/LICENSE-2.0
7+
Unless required by applicable law or agreed to in writing, software
8+
distributed under the License is distributed on an "AS IS" BASIS,
9+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
See the License for the specific language governing permissions and
11+
limitations under the License.
12+
*/
13+
package io.kubernetes.client.examples;
14+
15+
import com.google.common.io.ByteStreams;
16+
import io.kubernetes.client.Attach;
17+
import io.kubernetes.client.openapi.ApiClient;
18+
import io.kubernetes.client.openapi.ApiException;
19+
import io.kubernetes.client.openapi.Configuration;
20+
import io.kubernetes.client.util.Config;
21+
import java.io.BufferedReader;
22+
import java.io.IOException;
23+
import java.io.InputStreamReader;
24+
import java.io.OutputStream;
25+
26+
/**
27+
* A simple example of how to use the Java API
28+
*
29+
* <p>Easiest way to run this: mvn exec:java
30+
* -Dexec.mainClass="io.kubernetes.client.examples.AttachExample"
31+
*
32+
* <p>From inside $REPO_DIR/examples
33+
*/
34+
public class AttachExample {
35+
public static void main(String[] args) throws IOException, ApiException, InterruptedException {
36+
ApiClient client = Config.defaultClient();
37+
Configuration.setDefaultApiClient(client);
38+
39+
Attach attach = new Attach();
40+
final Attach.AttachResult result = attach.attach("default", "nginx-4217019353-k5sn9", true);
41+
42+
new Thread(
43+
new Runnable() {
44+
public void run() {
45+
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
46+
OutputStream output = result.getStandardInputStream();
47+
try {
48+
while (true) {
49+
String line = in.readLine();
50+
output.write(line.getBytes());
51+
output.write('\n');
52+
output.flush();
53+
}
54+
} catch (IOException ex) {
55+
ex.printStackTrace();
56+
}
57+
}
58+
})
59+
.start();
60+
61+
new Thread(
62+
new Runnable() {
63+
public void run() {
64+
try {
65+
ByteStreams.copy(result.getStandardOutputStream(), System.out);
66+
} catch (IOException ex) {
67+
ex.printStackTrace();
68+
}
69+
}
70+
})
71+
.start();
72+
73+
Thread.sleep(10 * 1000);
74+
result.close();
75+
System.exit(0);
76+
}
77+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
Copyright 2020 The Kubernetes Authors.
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
http://www.apache.org/licenses/LICENSE-2.0
7+
Unless required by applicable law or agreed to in writing, software
8+
distributed under the License is distributed on an "AS IS" BASIS,
9+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
See the License for the specific language governing permissions and
11+
limitations under the License.
12+
*/
13+
package io.kubernetes.client.examples;
14+
15+
import io.cert.manager.models.V1alpha2IssuerSpecSelfSigned;
16+
import io.cert.manager.models.V1beta1Issuer;
17+
import io.cert.manager.models.V1beta1IssuerList;
18+
import io.cert.manager.models.V1beta1IssuerSpec;
19+
import io.kubernetes.client.openapi.models.V1ObjectMeta;
20+
import io.kubernetes.client.util.ClientBuilder;
21+
import io.kubernetes.client.util.generic.GenericKubernetesApi;
22+
import java.io.IOException;
23+
24+
/**
25+
* This sample creates a self signed issuer "self-signed-issuer" in default namespace on a
26+
* Kubernetes cluster where cert-manager is installed
27+
*/
28+
public class CertManagerExample {
29+
public static void main(String[] args) throws IOException {
30+
GenericKubernetesApi<V1beta1Issuer, V1beta1IssuerList> issuerApi =
31+
new GenericKubernetesApi<>(
32+
V1beta1Issuer.class,
33+
V1beta1IssuerList.class,
34+
"cert-manager.io",
35+
"v1beta1",
36+
"issuers",
37+
ClientBuilder.defaultClient());
38+
issuerApi.create(
39+
new V1beta1Issuer()
40+
.metadata(new V1ObjectMeta().namespace("default").name("self-signed-issuer"))
41+
.kind("Issuer")
42+
.apiVersion("cert-manager.io/v1beta1")
43+
.spec(new V1beta1IssuerSpec().selfSigned(new V1alpha2IssuerSpecSelfSigned())));
44+
}
45+
}

0 commit comments

Comments
 (0)