Skip to content

Commit

Permalink
Merge pull request #2800 from yue9944882/example-19
Browse files Browse the repository at this point in the history
Cut a new example module for 19 client major version
  • Loading branch information
k8s-ci-robot authored Sep 26, 2023
2 parents a344e8c + bf1cb76 commit fb57d24
Show file tree
Hide file tree
Showing 51 changed files with 3,019 additions and 20 deletions.
10 changes: 5 additions & 5 deletions examples/examples-release-18/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,27 +30,27 @@
<dependency>
<groupId>io.kubernetes</groupId>
<artifactId>client-java-api</artifactId>
<version>${project.version}</version>
<version>18.0.1</version>
</dependency>
<dependency>
<groupId>io.kubernetes</groupId>
<artifactId>client-java</artifactId>
<version>${project.version}</version>
<version>18.0.1</version>
</dependency>
<dependency>
<groupId>io.kubernetes</groupId>
<artifactId>client-java-extended</artifactId>
<version>${project.version}</version>
<version>18.0.1</version>
</dependency>
<dependency>
<groupId>io.kubernetes</groupId>
<artifactId>client-java-spring-integration</artifactId>
<version>${project.version}</version>
<version>18.0.1</version>
</dependency>
<dependency>
<groupId>io.kubernetes</groupId>
<artifactId>client-java-proto</artifactId>
<version>${project.version}</version>
<version>18.0.1</version>
</dependency>
<dependency>
<groupId>commons-cli</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ public static void main(String[] args) throws IOException {
null,
params.resourceVersion,
null,
null,
params.timeoutSeconds,
params.watch,
null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public static void main(String[] args) throws IOException, ApiException {

CoreV1Api api = new CoreV1Api();
V1PodList list =
api.listPodForAllNamespaces(null, null, null, null, null, null, null, null, null, null, null);
api.listPodForAllNamespaces(null, null, null, null, null, null, null, null, null, null);
for (V1Pod item : list.getItems()) {
System.out.println(item.getMetadata().getName());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public static void main(String[] args) {
public static List<String> getAllNameSpaces() throws ApiException {
V1NamespaceList listNamespace =
COREV1_API.listNamespace(
null, null, null, null, null, null, null, null, null, null, null);
null, null, null, null, null, null, null, null, null, null);
List<String> list =
listNamespace.getItems().stream()
.map(v1Namespace -> v1Namespace.getMetadata().getName())
Expand All @@ -119,7 +119,7 @@ public static List<String> getAllNameSpaces() throws ApiException {
public static List<String> getPods() throws ApiException {
V1PodList v1podList =
COREV1_API.listPodForAllNamespaces(
null, null, null, null, null, null, null, null, null, null, null);
null, null, null, null, null, null, null, null, null, null);
List<String> podList =
v1podList.getItems().stream()
.map(v1Pod -> v1Pod.getMetadata().getName())
Expand Down Expand Up @@ -168,7 +168,6 @@ public static List<String> getNamespacedPod(String namespace, String label) thro
null,
null,
null,
null,
TIME_OUT_VALUE,
Boolean.FALSE);
List<String> listPods =
Expand Down Expand Up @@ -196,7 +195,6 @@ public static List<String> getServices() throws ApiException {
null,
null,
null,
null,
TIME_OUT_VALUE,
Boolean.FALSE);
return listNamespacedService.getItems().stream()
Expand Down Expand Up @@ -227,7 +225,6 @@ public static void scaleDeployment(String deploymentName, int numberOfReplicas)
null,
null,
null,
null,
Boolean.FALSE);

List<V1Deployment> appsV1DeploymentItems = listNamespacedDeployment.getItems();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public static void main(String[] args) throws IOException, ApiException {

V1PodList list =
api.listNamespacedPod(
"default", null, null, null, null, null, null, null, null, null, null, null);
"default", null, null, null, null, null, null, null, null, null, null);
for (V1Pod item : list.getItems()) {
System.out.println(item.getMetadata().getName());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public static void main(String[] args) throws IOException, ApiException {

// invokes the CoreV1Api client
V1PodList list =
api.listPodForAllNamespaces(null, null, null, null, null, null, null, null, null, null, null);
api.listPodForAllNamespaces(null, null, null, null, null, null, null, null, null, null);
for (V1Pod item : list.getItems()) {
System.out.println(item.getMetadata().getName());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ public static void main(String[] args) throws Exception {
null,
params.resourceVersion,
null,
null,
params.timeoutSeconds,
params.watch,
null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public static void main(String[] args) throws IOException, ApiException {

// invokes the CoreV1Api client
V1PodList list =
api.listPodForAllNamespaces(null, null, null, null, null, null, null, null, null, null, null);
api.listPodForAllNamespaces(null, null, null, null, null, null, null, null, null, null);
for (V1Pod item : list.getItems()) {
System.out.println(item.getMetadata().getName());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public static void main(String[] args) throws IOException, ApiException, Interru
V1Pod pod =
coreApi
.listNamespacedPod(
"default", "false", null, null, null, null, null, null, null, null, null, null)
"default", "false", null, null, null, null, null, null, null, null, null)
.getItems()
.get(0);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ public static void main(String[] args) throws IOException {
param.getLimit(),
null,
null,
null,
1,
null,
null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public static void main(String[] args) throws IOException, ApiException {
while (true) {
// A request that should return 200
V1PodList list =
api.listPodForAllNamespaces(null, null, null, null, null, null, null, null, null, null, null);
api.listPodForAllNamespaces( null, null, null, null, null, null, null, null, null, null);
// A request that should return 404
try {
V1Pod pod = api.readNamespacedPod("foo", "bar", null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public static void main(String[] args) throws IOException, ApiException {
Watch.createWatch(
client,
api.listNamespaceCall(
null, null, null, null, null, null, null, null, null, null, Boolean.TRUE, null),
null, null, null, null, null, null, null, null, null, Boolean.TRUE, null),
new TypeToken<Watch.Response<V1Namespace>>() {}.getType());

try {
Expand Down
7 changes: 7 additions & 0 deletions examples/examples-release-19/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM openjdk:8-jre

COPY target/client-java-examples-*-SNAPSHOT-jar-with-dependencies.jar /examples.jar

CMD ["java", "-jar", "/examples.jar"]


13 changes: 13 additions & 0 deletions examples/examples-release-19/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Running examples

```sh
export REPO_ROOT=/path/to/client-java/repo

cd ${REPO_ROOT}/
mvn install

cd ${REPO_ROOT}/examples/examples-15
mvn compile
mvn exec:java -Dexec.mainClass="io.kubernetes.client.examples.Example"
```

26 changes: 26 additions & 0 deletions examples/examples-release-19/createPod.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash

# creates a pod and runs
# Example.java(list pods for all namespaces) on starting of pod

# Exit on any error.
set -e

if ! which minikube > /dev/null; then
echo "This script requires minikube installed."
exit 100
fi

dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

export REPO_ROOT=${dir}/..

cd ${REPO_ROOT}
mvn install

cd ${REPO_ROOT}/examples
mvn package

eval $(minikube docker-env)
docker build -t test/examples:1.0 .
kubectl apply -f test.yaml
107 changes: 107 additions & 0 deletions examples/examples-release-19/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
<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">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>io.kubernetes</groupId>
<artifactId>client-java-examples-parent</artifactId>
<version>19.0.0-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>

<artifactId>client-java-examples-release-19</artifactId>
<name>client-java-examples-release-19</name>

<dependencies>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>io.prometheus</groupId>
<artifactId>simpleclient</artifactId>
<version>0.15.0</version>
</dependency>
<dependency>
<groupId>io.prometheus</groupId>
<artifactId>simpleclient_httpserver</artifactId>
<version>0.15.0</version>
</dependency>
<dependency>
<groupId>io.kubernetes</groupId>
<artifactId>client-java-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.kubernetes</groupId>
<artifactId>client-java</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.kubernetes</groupId>
<artifactId>client-java-extended</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.kubernetes</groupId>
<artifactId>client-java-spring-integration</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.kubernetes</groupId>
<artifactId>client-java-proto</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>commons-cli</groupId>
<artifactId>commons-cli</artifactId>
</dependency>
<dependency>
<groupId>io.kubernetes</groupId>
<artifactId>client-java-cert-manager-models</artifactId>
<version>10.0.1</version>
</dependency>
<dependency>
<groupId>io.kubernetes</groupId>
<artifactId>client-java-prometheus-operator-models</artifactId>
<version>10.0.1</version>
</dependency>
<!-- test dependencies -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.github.tomakehurst</groupId>
<artifactId>wiremock</artifactId>
<scope>test</scope>
</dependency>
<!--for spring controller example-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>${spring.boot.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
<version>${spring.boot.version}</version>
</dependency>

</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>3.1.1</version>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
Copyright 2020 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package io.kubernetes.client.examples;

import io.kubernetes.client.Attach;
import io.kubernetes.client.openapi.ApiClient;
import io.kubernetes.client.openapi.ApiException;
import io.kubernetes.client.openapi.Configuration;
import io.kubernetes.client.util.Config;
import io.kubernetes.client.util.Streams;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;

/**
* A simple example of how to use the Java API
*
* <p>Easiest way to run this: mvn exec:java
* -Dexec.mainClass="io.kubernetes.client.examples.AttachExample"
*
* <p>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);

Attach attach = new Attach();
final Attach.AttachResult result = attach.attach("default", "nginx-4217019353-k5sn9", true);

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();
}
} catch (IOException ex) {
ex.printStackTrace();
}
}
})
.start();

new Thread(
new Runnable() {
public void run() {
try {
Streams.copy(result.getStandardOutputStream(), System.out);
} catch (IOException ex) {
ex.printStackTrace();
}
}
})
.start();

Thread.sleep(10 * 1000);
result.close();
System.exit(0);
}
}
Loading

0 comments on commit fb57d24

Please sign in to comment.