From 523f1253e972ffca4f0159fb86cbcda15b15ca2e Mon Sep 17 00:00:00 2001 From: Min Jin Date: Thu, 23 Oct 2025 11:38:18 -0700 Subject: [PATCH] remove release 17~20 example as it's 5 release ago Signed-off-by: Min Jin --- examples/examples-release-17/Dockerfile | 7 - examples/examples-release-17/README.md | 13 - examples/examples-release-17/createPod.sh | 26 -- examples/examples-release-17/pom.xml | 93 ------ .../client/examples/AttachExample.java | 77 ----- .../client/examples/CertManagerExample.java | 45 --- .../client/examples/ControllerExample.java | 163 --------- .../client/examples/CopyExample.java | 51 --- .../client/examples/DynamicClientExample.java | 42 --- .../kubernetes/client/examples/Example.java | 44 --- .../client/examples/ExecExample.java | 96 ------ .../client/examples/ExpandedExample.java | 274 --------------- .../client/examples/FluentExample.java | 75 ----- .../client/examples/GenericClientExample.java | 63 ---- .../examples/InClusterClientExample.java | 58 ---- .../client/examples/InformerExample.java | 106 ------ .../examples/KubeConfigFileClientExample.java | 58 ---- .../client/examples/KubectlExample.java | 311 ------------------ .../examples/LeaderElectionExample.java | 56 ---- .../client/examples/LogsExample.java | 51 --- .../client/examples/MetricsExample.java | 68 ---- .../client/examples/PagerExample.java | 72 ---- .../client/examples/ParseExample.java | 64 ---- .../client/examples/PatchExample.java | 129 -------- .../client/examples/PortForwardExample.java | 87 ----- .../client/examples/PromOpExample.java | 43 --- .../client/examples/PrometheusExample.java | 66 ---- .../client/examples/ProtoExample.java | 69 ---- .../examples/SpringControllerExample.java | 147 --------- .../examples/SpringLoadBalancerExample.java | 68 ---- .../client/examples/WatchExample.java | 54 --- .../client/examples/WebSocketsExample.java | 74 ----- .../client/examples/YamlExample.java | 109 ------ .../src/main/resources/application.properties | 2 - .../client/examples/ExampleTest.java | 57 ---- examples/examples-release-17/test-svc.yaml | 11 - examples/examples-release-17/test.yaml | 16 - examples/examples-release-18/Dockerfile | 7 - examples/examples-release-18/README.md | 13 - examples/examples-release-18/createPod.sh | 26 -- examples/examples-release-18/pom.xml | 94 ------ .../client/examples/AttachExample.java | 77 ----- .../client/examples/CertManagerExample.java | 45 --- .../client/examples/ControllerExample.java | 163 --------- .../client/examples/CopyExample.java | 51 --- .../examples/DeployRolloutRestartExample.java | 140 -------- .../client/examples/DynamicClientExample.java | 42 --- .../kubernetes/client/examples/Example.java | 44 --- .../client/examples/ExecExample.java | 96 ------ .../client/examples/ExpandedExample.java | 274 --------------- .../client/examples/FluentExample.java | 75 ----- .../client/examples/GenericClientExample.java | 63 ---- .../examples/InClusterClientExample.java | 58 ---- .../client/examples/InformerExample.java | 106 ------ .../examples/KubeConfigFileClientExample.java | 58 ---- .../client/examples/KubectlExample.java | 311 ------------------ .../examples/LeaderElectionExample.java | 56 ---- .../client/examples/LogsExample.java | 51 --- .../client/examples/MetricsExample.java | 68 ---- .../client/examples/PagerExample.java | 72 ---- .../client/examples/ParseExample.java | 64 ---- .../client/examples/PatchExample.java | 130 -------- .../client/examples/PortForwardExample.java | 87 ----- .../client/examples/PromOpExample.java | 43 --- .../client/examples/PrometheusExample.java | 66 ---- .../client/examples/ProtoExample.java | 69 ---- .../examples/SpringControllerExample.java | 147 --------- .../examples/SpringLoadBalancerExample.java | 68 ---- .../client/examples/WatchExample.java | 54 --- .../client/examples/WebSocketsExample.java | 74 ----- .../client/examples/YamlExample.java | 109 ------ .../src/main/resources/application.properties | 2 - .../client/examples/ExampleTest.java | 57 ---- examples/examples-release-18/test-svc.yaml | 11 - examples/examples-release-18/test.yaml | 16 - examples/examples-release-19/Dockerfile | 7 - examples/examples-release-19/README.md | 13 - examples/examples-release-19/createPod.sh | 26 -- examples/examples-release-19/pom.xml | 93 ------ .../client/examples/AttachExample.java | 77 ----- .../client/examples/CertManagerExample.java | 45 --- .../client/examples/ControllerExample.java | 164 --------- .../client/examples/CopyExample.java | 51 --- .../examples/DeployRolloutRestartExample.java | 140 -------- .../client/examples/DynamicClientExample.java | 42 --- .../kubernetes/client/examples/Example.java | 44 --- .../client/examples/ExecExample.java | 96 ------ .../client/examples/ExpandedExample.java | 277 ---------------- .../client/examples/FluentExample.java | 75 ----- .../client/examples/GenericClientExample.java | 63 ---- .../examples/InClusterClientExample.java | 58 ---- .../client/examples/InformerExample.java | 107 ------ .../examples/KubeConfigFileClientExample.java | 58 ---- .../client/examples/KubectlExample.java | 311 ------------------ .../examples/LeaderElectionExample.java | 56 ---- .../client/examples/LogsExample.java | 51 --- .../client/examples/MetricsExample.java | 68 ---- .../client/examples/PagerExample.java | 73 ---- .../client/examples/ParseExample.java | 64 ---- .../client/examples/PatchExample.java | 130 -------- .../client/examples/PortForwardExample.java | 87 ----- .../client/examples/PromOpExample.java | 43 --- .../client/examples/PrometheusExample.java | 66 ---- .../client/examples/ProtoExample.java | 69 ---- .../examples/SpringControllerExample.java | 147 --------- .../examples/SpringLoadBalancerExample.java | 68 ---- .../client/examples/WatchExample.java | 54 --- .../client/examples/WebSocketsExample.java | 74 ----- .../client/examples/YamlExample.java | 109 ------ .../src/main/resources/application.properties | 2 - .../client/examples/ExampleTest.java | 57 ---- examples/examples-release-19/test-svc.yaml | 11 - examples/examples-release-19/test.yaml | 16 - examples/examples-release-20/Dockerfile | 7 - examples/examples-release-20/README.md | 13 - examples/examples-release-20/createPod.sh | 26 -- examples/examples-release-20/pom.xml | 99 ------ .../client/examples/AttachExample.java | 77 ----- .../client/examples/CertManagerExample.java | 45 --- .../client/examples/ControllerExample.java | 156 --------- .../client/examples/CopyExample.java | 51 --- .../examples/DeployRolloutRestartExample.java | 138 -------- .../client/examples/DynamicClientExample.java | 42 --- .../examples/EKSAuthenticationExample.java | 53 --- .../kubernetes/client/examples/Example.java | 44 --- .../client/examples/ExecExample.java | 96 ------ .../client/examples/ExpandedExample.java | 244 -------------- .../client/examples/FluentExample.java | 74 ----- .../client/examples/GenericClientExample.java | 63 ---- .../examples/InClusterClientExample.java | 58 ---- .../client/examples/InformerExample.java | 99 ------ .../examples/KubeConfigFileClientExample.java | 58 ---- .../client/examples/KubectlExample.java | 311 ------------------ .../examples/LeaderElectionExample.java | 56 ---- .../client/examples/LogsExample.java | 51 --- .../client/examples/MetricsExample.java | 68 ---- .../client/examples/PagerExample.java | 65 ---- .../client/examples/ParseExample.java | 64 ---- .../client/examples/PatchExample.java | 117 ------- .../client/examples/PortForwardExample.java | 87 ----- .../client/examples/PromOpExample.java | 43 --- .../client/examples/PrometheusExample.java | 66 ---- .../client/examples/ProtoExample.java | 69 ---- .../examples/SpringControllerExample.java | 147 --------- .../examples/SpringLoadBalancerExample.java | 68 ---- .../client/examples/WatchExample.java | 55 ---- .../client/examples/WebSocketsExample.java | 74 ----- .../client/examples/YamlExample.java | 103 ------ .../src/main/resources/application.properties | 2 - .../client/examples/ExampleTest.java | 57 ---- examples/examples-release-20/test-svc.yaml | 11 - examples/examples-release-20/test.yaml | 16 - examples/pom.xml | 4 - 153 files changed, 11801 deletions(-) delete mode 100644 examples/examples-release-17/Dockerfile delete mode 100644 examples/examples-release-17/README.md delete mode 100755 examples/examples-release-17/createPod.sh delete mode 100644 examples/examples-release-17/pom.xml delete mode 100644 examples/examples-release-17/src/main/java/io/kubernetes/client/examples/AttachExample.java delete mode 100644 examples/examples-release-17/src/main/java/io/kubernetes/client/examples/CertManagerExample.java delete mode 100644 examples/examples-release-17/src/main/java/io/kubernetes/client/examples/ControllerExample.java delete mode 100644 examples/examples-release-17/src/main/java/io/kubernetes/client/examples/CopyExample.java delete mode 100644 examples/examples-release-17/src/main/java/io/kubernetes/client/examples/DynamicClientExample.java delete mode 100644 examples/examples-release-17/src/main/java/io/kubernetes/client/examples/Example.java delete mode 100644 examples/examples-release-17/src/main/java/io/kubernetes/client/examples/ExecExample.java delete mode 100644 examples/examples-release-17/src/main/java/io/kubernetes/client/examples/ExpandedExample.java delete mode 100644 examples/examples-release-17/src/main/java/io/kubernetes/client/examples/FluentExample.java delete mode 100644 examples/examples-release-17/src/main/java/io/kubernetes/client/examples/GenericClientExample.java delete mode 100644 examples/examples-release-17/src/main/java/io/kubernetes/client/examples/InClusterClientExample.java delete mode 100644 examples/examples-release-17/src/main/java/io/kubernetes/client/examples/InformerExample.java delete mode 100644 examples/examples-release-17/src/main/java/io/kubernetes/client/examples/KubeConfigFileClientExample.java delete mode 100644 examples/examples-release-17/src/main/java/io/kubernetes/client/examples/KubectlExample.java delete mode 100644 examples/examples-release-17/src/main/java/io/kubernetes/client/examples/LeaderElectionExample.java delete mode 100644 examples/examples-release-17/src/main/java/io/kubernetes/client/examples/LogsExample.java delete mode 100644 examples/examples-release-17/src/main/java/io/kubernetes/client/examples/MetricsExample.java delete mode 100644 examples/examples-release-17/src/main/java/io/kubernetes/client/examples/PagerExample.java delete mode 100644 examples/examples-release-17/src/main/java/io/kubernetes/client/examples/ParseExample.java delete mode 100644 examples/examples-release-17/src/main/java/io/kubernetes/client/examples/PatchExample.java delete mode 100644 examples/examples-release-17/src/main/java/io/kubernetes/client/examples/PortForwardExample.java delete mode 100644 examples/examples-release-17/src/main/java/io/kubernetes/client/examples/PromOpExample.java delete mode 100644 examples/examples-release-17/src/main/java/io/kubernetes/client/examples/PrometheusExample.java delete mode 100644 examples/examples-release-17/src/main/java/io/kubernetes/client/examples/ProtoExample.java delete mode 100644 examples/examples-release-17/src/main/java/io/kubernetes/client/examples/SpringControllerExample.java delete mode 100644 examples/examples-release-17/src/main/java/io/kubernetes/client/examples/SpringLoadBalancerExample.java delete mode 100644 examples/examples-release-17/src/main/java/io/kubernetes/client/examples/WatchExample.java delete mode 100644 examples/examples-release-17/src/main/java/io/kubernetes/client/examples/WebSocketsExample.java delete mode 100644 examples/examples-release-17/src/main/java/io/kubernetes/client/examples/YamlExample.java delete mode 100644 examples/examples-release-17/src/main/resources/application.properties delete mode 100644 examples/examples-release-17/src/test/java/io/kubernetes/client/examples/ExampleTest.java delete mode 100644 examples/examples-release-17/test-svc.yaml delete mode 100644 examples/examples-release-17/test.yaml delete mode 100644 examples/examples-release-18/Dockerfile delete mode 100644 examples/examples-release-18/README.md delete mode 100755 examples/examples-release-18/createPod.sh delete mode 100644 examples/examples-release-18/pom.xml delete mode 100644 examples/examples-release-18/src/main/java/io/kubernetes/client/examples/AttachExample.java delete mode 100644 examples/examples-release-18/src/main/java/io/kubernetes/client/examples/CertManagerExample.java delete mode 100644 examples/examples-release-18/src/main/java/io/kubernetes/client/examples/ControllerExample.java delete mode 100644 examples/examples-release-18/src/main/java/io/kubernetes/client/examples/CopyExample.java delete mode 100644 examples/examples-release-18/src/main/java/io/kubernetes/client/examples/DeployRolloutRestartExample.java delete mode 100644 examples/examples-release-18/src/main/java/io/kubernetes/client/examples/DynamicClientExample.java delete mode 100644 examples/examples-release-18/src/main/java/io/kubernetes/client/examples/Example.java delete mode 100644 examples/examples-release-18/src/main/java/io/kubernetes/client/examples/ExecExample.java delete mode 100644 examples/examples-release-18/src/main/java/io/kubernetes/client/examples/ExpandedExample.java delete mode 100644 examples/examples-release-18/src/main/java/io/kubernetes/client/examples/FluentExample.java delete mode 100644 examples/examples-release-18/src/main/java/io/kubernetes/client/examples/GenericClientExample.java delete mode 100644 examples/examples-release-18/src/main/java/io/kubernetes/client/examples/InClusterClientExample.java delete mode 100644 examples/examples-release-18/src/main/java/io/kubernetes/client/examples/InformerExample.java delete mode 100644 examples/examples-release-18/src/main/java/io/kubernetes/client/examples/KubeConfigFileClientExample.java delete mode 100644 examples/examples-release-18/src/main/java/io/kubernetes/client/examples/KubectlExample.java delete mode 100644 examples/examples-release-18/src/main/java/io/kubernetes/client/examples/LeaderElectionExample.java delete mode 100644 examples/examples-release-18/src/main/java/io/kubernetes/client/examples/LogsExample.java delete mode 100644 examples/examples-release-18/src/main/java/io/kubernetes/client/examples/MetricsExample.java delete mode 100644 examples/examples-release-18/src/main/java/io/kubernetes/client/examples/PagerExample.java delete mode 100644 examples/examples-release-18/src/main/java/io/kubernetes/client/examples/ParseExample.java delete mode 100644 examples/examples-release-18/src/main/java/io/kubernetes/client/examples/PatchExample.java delete mode 100644 examples/examples-release-18/src/main/java/io/kubernetes/client/examples/PortForwardExample.java delete mode 100644 examples/examples-release-18/src/main/java/io/kubernetes/client/examples/PromOpExample.java delete mode 100644 examples/examples-release-18/src/main/java/io/kubernetes/client/examples/PrometheusExample.java delete mode 100644 examples/examples-release-18/src/main/java/io/kubernetes/client/examples/ProtoExample.java delete mode 100644 examples/examples-release-18/src/main/java/io/kubernetes/client/examples/SpringControllerExample.java delete mode 100644 examples/examples-release-18/src/main/java/io/kubernetes/client/examples/SpringLoadBalancerExample.java delete mode 100644 examples/examples-release-18/src/main/java/io/kubernetes/client/examples/WatchExample.java delete mode 100644 examples/examples-release-18/src/main/java/io/kubernetes/client/examples/WebSocketsExample.java delete mode 100644 examples/examples-release-18/src/main/java/io/kubernetes/client/examples/YamlExample.java delete mode 100644 examples/examples-release-18/src/main/resources/application.properties delete mode 100644 examples/examples-release-18/src/test/java/io/kubernetes/client/examples/ExampleTest.java delete mode 100644 examples/examples-release-18/test-svc.yaml delete mode 100644 examples/examples-release-18/test.yaml delete mode 100644 examples/examples-release-19/Dockerfile delete mode 100644 examples/examples-release-19/README.md delete mode 100755 examples/examples-release-19/createPod.sh delete mode 100644 examples/examples-release-19/pom.xml delete mode 100644 examples/examples-release-19/src/main/java/io/kubernetes/client/examples/AttachExample.java delete mode 100644 examples/examples-release-19/src/main/java/io/kubernetes/client/examples/CertManagerExample.java delete mode 100644 examples/examples-release-19/src/main/java/io/kubernetes/client/examples/ControllerExample.java delete mode 100644 examples/examples-release-19/src/main/java/io/kubernetes/client/examples/CopyExample.java delete mode 100644 examples/examples-release-19/src/main/java/io/kubernetes/client/examples/DeployRolloutRestartExample.java delete mode 100644 examples/examples-release-19/src/main/java/io/kubernetes/client/examples/DynamicClientExample.java delete mode 100644 examples/examples-release-19/src/main/java/io/kubernetes/client/examples/Example.java delete mode 100644 examples/examples-release-19/src/main/java/io/kubernetes/client/examples/ExecExample.java delete mode 100644 examples/examples-release-19/src/main/java/io/kubernetes/client/examples/ExpandedExample.java delete mode 100644 examples/examples-release-19/src/main/java/io/kubernetes/client/examples/FluentExample.java delete mode 100644 examples/examples-release-19/src/main/java/io/kubernetes/client/examples/GenericClientExample.java delete mode 100644 examples/examples-release-19/src/main/java/io/kubernetes/client/examples/InClusterClientExample.java delete mode 100644 examples/examples-release-19/src/main/java/io/kubernetes/client/examples/InformerExample.java delete mode 100644 examples/examples-release-19/src/main/java/io/kubernetes/client/examples/KubeConfigFileClientExample.java delete mode 100644 examples/examples-release-19/src/main/java/io/kubernetes/client/examples/KubectlExample.java delete mode 100644 examples/examples-release-19/src/main/java/io/kubernetes/client/examples/LeaderElectionExample.java delete mode 100644 examples/examples-release-19/src/main/java/io/kubernetes/client/examples/LogsExample.java delete mode 100644 examples/examples-release-19/src/main/java/io/kubernetes/client/examples/MetricsExample.java delete mode 100644 examples/examples-release-19/src/main/java/io/kubernetes/client/examples/PagerExample.java delete mode 100644 examples/examples-release-19/src/main/java/io/kubernetes/client/examples/ParseExample.java delete mode 100644 examples/examples-release-19/src/main/java/io/kubernetes/client/examples/PatchExample.java delete mode 100644 examples/examples-release-19/src/main/java/io/kubernetes/client/examples/PortForwardExample.java delete mode 100644 examples/examples-release-19/src/main/java/io/kubernetes/client/examples/PromOpExample.java delete mode 100644 examples/examples-release-19/src/main/java/io/kubernetes/client/examples/PrometheusExample.java delete mode 100644 examples/examples-release-19/src/main/java/io/kubernetes/client/examples/ProtoExample.java delete mode 100644 examples/examples-release-19/src/main/java/io/kubernetes/client/examples/SpringControllerExample.java delete mode 100644 examples/examples-release-19/src/main/java/io/kubernetes/client/examples/SpringLoadBalancerExample.java delete mode 100644 examples/examples-release-19/src/main/java/io/kubernetes/client/examples/WatchExample.java delete mode 100644 examples/examples-release-19/src/main/java/io/kubernetes/client/examples/WebSocketsExample.java delete mode 100644 examples/examples-release-19/src/main/java/io/kubernetes/client/examples/YamlExample.java delete mode 100644 examples/examples-release-19/src/main/resources/application.properties delete mode 100644 examples/examples-release-19/src/test/java/io/kubernetes/client/examples/ExampleTest.java delete mode 100644 examples/examples-release-19/test-svc.yaml delete mode 100644 examples/examples-release-19/test.yaml delete mode 100644 examples/examples-release-20/Dockerfile delete mode 100644 examples/examples-release-20/README.md delete mode 100755 examples/examples-release-20/createPod.sh delete mode 100644 examples/examples-release-20/pom.xml delete mode 100644 examples/examples-release-20/src/main/java/io/kubernetes/client/examples/AttachExample.java delete mode 100644 examples/examples-release-20/src/main/java/io/kubernetes/client/examples/CertManagerExample.java delete mode 100644 examples/examples-release-20/src/main/java/io/kubernetes/client/examples/ControllerExample.java delete mode 100644 examples/examples-release-20/src/main/java/io/kubernetes/client/examples/CopyExample.java delete mode 100644 examples/examples-release-20/src/main/java/io/kubernetes/client/examples/DeployRolloutRestartExample.java delete mode 100644 examples/examples-release-20/src/main/java/io/kubernetes/client/examples/DynamicClientExample.java delete mode 100644 examples/examples-release-20/src/main/java/io/kubernetes/client/examples/EKSAuthenticationExample.java delete mode 100644 examples/examples-release-20/src/main/java/io/kubernetes/client/examples/Example.java delete mode 100644 examples/examples-release-20/src/main/java/io/kubernetes/client/examples/ExecExample.java delete mode 100644 examples/examples-release-20/src/main/java/io/kubernetes/client/examples/ExpandedExample.java delete mode 100644 examples/examples-release-20/src/main/java/io/kubernetes/client/examples/FluentExample.java delete mode 100644 examples/examples-release-20/src/main/java/io/kubernetes/client/examples/GenericClientExample.java delete mode 100644 examples/examples-release-20/src/main/java/io/kubernetes/client/examples/InClusterClientExample.java delete mode 100644 examples/examples-release-20/src/main/java/io/kubernetes/client/examples/InformerExample.java delete mode 100644 examples/examples-release-20/src/main/java/io/kubernetes/client/examples/KubeConfigFileClientExample.java delete mode 100644 examples/examples-release-20/src/main/java/io/kubernetes/client/examples/KubectlExample.java delete mode 100644 examples/examples-release-20/src/main/java/io/kubernetes/client/examples/LeaderElectionExample.java delete mode 100644 examples/examples-release-20/src/main/java/io/kubernetes/client/examples/LogsExample.java delete mode 100644 examples/examples-release-20/src/main/java/io/kubernetes/client/examples/MetricsExample.java delete mode 100644 examples/examples-release-20/src/main/java/io/kubernetes/client/examples/PagerExample.java delete mode 100644 examples/examples-release-20/src/main/java/io/kubernetes/client/examples/ParseExample.java delete mode 100644 examples/examples-release-20/src/main/java/io/kubernetes/client/examples/PatchExample.java delete mode 100644 examples/examples-release-20/src/main/java/io/kubernetes/client/examples/PortForwardExample.java delete mode 100644 examples/examples-release-20/src/main/java/io/kubernetes/client/examples/PromOpExample.java delete mode 100644 examples/examples-release-20/src/main/java/io/kubernetes/client/examples/PrometheusExample.java delete mode 100644 examples/examples-release-20/src/main/java/io/kubernetes/client/examples/ProtoExample.java delete mode 100644 examples/examples-release-20/src/main/java/io/kubernetes/client/examples/SpringControllerExample.java delete mode 100644 examples/examples-release-20/src/main/java/io/kubernetes/client/examples/SpringLoadBalancerExample.java delete mode 100644 examples/examples-release-20/src/main/java/io/kubernetes/client/examples/WatchExample.java delete mode 100644 examples/examples-release-20/src/main/java/io/kubernetes/client/examples/WebSocketsExample.java delete mode 100644 examples/examples-release-20/src/main/java/io/kubernetes/client/examples/YamlExample.java delete mode 100644 examples/examples-release-20/src/main/resources/application.properties delete mode 100644 examples/examples-release-20/src/test/java/io/kubernetes/client/examples/ExampleTest.java delete mode 100644 examples/examples-release-20/test-svc.yaml delete mode 100644 examples/examples-release-20/test.yaml diff --git a/examples/examples-release-17/Dockerfile b/examples/examples-release-17/Dockerfile deleted file mode 100644 index ac90eb1d67..0000000000 --- a/examples/examples-release-17/Dockerfile +++ /dev/null @@ -1,7 +0,0 @@ -FROM openjdk:8-jre - -COPY target/client-java-examples-*-SNAPSHOT-jar-with-dependencies.jar /examples.jar - -CMD ["java", "-jar", "/examples.jar"] - - diff --git a/examples/examples-release-17/README.md b/examples/examples-release-17/README.md deleted file mode 100644 index c6e02e41fd..0000000000 --- a/examples/examples-release-17/README.md +++ /dev/null @@ -1,13 +0,0 @@ -# Running examples - -```sh -export REPO_ROOT=/path/to/client-java/repo - -cd ${REPO_ROOT}/ -mvn install - -cd ${REPO_ROOT}/examples/examples-14 -mvn compile -mvn exec:java -Dexec.mainClass="io.kubernetes.client.examples.Example" -``` - diff --git a/examples/examples-release-17/createPod.sh b/examples/examples-release-17/createPod.sh deleted file mode 100755 index 18a9841317..0000000000 --- a/examples/examples-release-17/createPod.sh +++ /dev/null @@ -1,26 +0,0 @@ -#!/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 diff --git a/examples/examples-release-17/pom.xml b/examples/examples-release-17/pom.xml deleted file mode 100644 index 47e293465d..0000000000 --- a/examples/examples-release-17/pom.xml +++ /dev/null @@ -1,93 +0,0 @@ - - 4.0.0 - - client-java-examples-release-17 - client-java-examples-release-17 - io.kubernetes - 25.0.0-SNAPSHOT - - - - io.kubernetes - client-java-api - 17.0.0 - - - io.kubernetes - client-java - 17.0.0 - - - io.kubernetes - client-java-extended - 17.0.0 - - - io.kubernetes - client-java-spring-integration - 17.0.0 - - - io.kubernetes - client-java-proto - 17.0.0 - - - commons-cli - commons-cli - 1.10.0 - - - io.kubernetes - client-java-cert-manager-models - 10.0.1 - - - io.kubernetes - client-java-prometheus-operator-models - 10.0.1 - - - - org.junit.jupiter - junit-jupiter - ${junit-jupiter.version} - test - - - org.wiremock - wiremock - 3.13.1 - test - - - - - - - com.diffplug.spotless - spotless-maven-plugin - 2.46.1 - - - org.sonatype.plugins - nexus-staging-maven-plugin - true - - true - - - - org.apache.maven.plugins - maven-deploy-plugin - - true - - - - - - 5.13.4 - 3.5.4 - - \ No newline at end of file diff --git a/examples/examples-release-17/src/main/java/io/kubernetes/client/examples/AttachExample.java b/examples/examples-release-17/src/main/java/io/kubernetes/client/examples/AttachExample.java deleted file mode 100644 index 7f753b8d8f..0000000000 --- a/examples/examples-release-17/src/main/java/io/kubernetes/client/examples/AttachExample.java +++ /dev/null @@ -1,77 +0,0 @@ -/* -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 - * - *

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); - - 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); - } -} diff --git a/examples/examples-release-17/src/main/java/io/kubernetes/client/examples/CertManagerExample.java b/examples/examples-release-17/src/main/java/io/kubernetes/client/examples/CertManagerExample.java deleted file mode 100644 index b616a18ee9..0000000000 --- a/examples/examples-release-17/src/main/java/io/kubernetes/client/examples/CertManagerExample.java +++ /dev/null @@ -1,45 +0,0 @@ -/* -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.cert.manager.models.V1alpha2IssuerSpecSelfSigned; -import io.cert.manager.models.V1beta1Issuer; -import io.cert.manager.models.V1beta1IssuerList; -import io.cert.manager.models.V1beta1IssuerSpec; -import io.kubernetes.client.openapi.models.V1ObjectMeta; -import io.kubernetes.client.util.ClientBuilder; -import io.kubernetes.client.util.generic.GenericKubernetesApi; -import java.io.IOException; - -/** - * This sample creates a self signed issuer "self-signed-issuer" in default namespace on a - * Kubernetes cluster where cert-manager is installed - */ -public class CertManagerExample { - public static void main(String[] args) throws IOException { - GenericKubernetesApi issuerApi = - new GenericKubernetesApi<>( - V1beta1Issuer.class, - V1beta1IssuerList.class, - "cert-manager.io", - "v1beta1", - "issuers", - ClientBuilder.defaultClient()); - issuerApi.create( - new V1beta1Issuer() - .metadata(new V1ObjectMeta().namespace("default").name("self-signed-issuer")) - .kind("Issuer") - .apiVersion("cert-manager.io/v1beta1") - .spec(new V1beta1IssuerSpec().selfSigned(new V1alpha2IssuerSpecSelfSigned()))); - } -} diff --git a/examples/examples-release-17/src/main/java/io/kubernetes/client/examples/ControllerExample.java b/examples/examples-release-17/src/main/java/io/kubernetes/client/examples/ControllerExample.java deleted file mode 100644 index fed0e544d3..0000000000 --- a/examples/examples-release-17/src/main/java/io/kubernetes/client/examples/ControllerExample.java +++ /dev/null @@ -1,163 +0,0 @@ -/* -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.extended.controller.Controller; -import io.kubernetes.client.extended.controller.ControllerManager; -import io.kubernetes.client.extended.controller.LeaderElectingController; -import io.kubernetes.client.extended.controller.builder.ControllerBuilder; -import io.kubernetes.client.extended.controller.reconciler.Reconciler; -import io.kubernetes.client.extended.controller.reconciler.Request; -import io.kubernetes.client.extended.controller.reconciler.Result; -import io.kubernetes.client.extended.event.EventType; -import io.kubernetes.client.extended.event.legacy.EventBroadcaster; -import io.kubernetes.client.extended.event.legacy.EventRecorder; -import io.kubernetes.client.extended.event.legacy.LegacyEventBroadcaster; -import io.kubernetes.client.extended.leaderelection.LeaderElectionConfig; -import io.kubernetes.client.extended.leaderelection.LeaderElector; -import io.kubernetes.client.extended.leaderelection.resourcelock.EndpointsLock; -import io.kubernetes.client.informer.SharedIndexInformer; -import io.kubernetes.client.informer.SharedInformerFactory; -import io.kubernetes.client.informer.cache.Lister; -import io.kubernetes.client.openapi.ApiClient; -import io.kubernetes.client.openapi.apis.CoreV1Api; -import io.kubernetes.client.openapi.models.V1EventSource; -import io.kubernetes.client.openapi.models.V1Node; -import io.kubernetes.client.openapi.models.V1NodeList; -import io.kubernetes.client.util.CallGeneratorParams; -import java.io.IOException; -import java.time.Duration; -import java.util.concurrent.TimeUnit; -import okhttp3.OkHttpClient; - -public class ControllerExample { - public static void main(String[] args) throws IOException { - - CoreV1Api coreV1Api = new CoreV1Api(); - ApiClient apiClient = coreV1Api.getApiClient(); - OkHttpClient httpClient = - apiClient.getHttpClient().newBuilder().readTimeout(0, TimeUnit.SECONDS).build(); - apiClient.setHttpClient(httpClient); - - // instantiating an informer-factory, and there should be only one informer-factory - // globally. - SharedInformerFactory informerFactory = new SharedInformerFactory(); - // registering node-informer into the informer-factory. - SharedIndexInformer nodeInformer = - informerFactory.sharedIndexInformerFor( - (CallGeneratorParams params) -> { - return coreV1Api.listNodeCall( - null, - null, - null, - null, - null, - null, - params.resourceVersion, - null, - params.timeoutSeconds, - params.watch, - null); - }, - V1Node.class, - V1NodeList.class); - informerFactory.startAllRegisteredInformers(); - - EventBroadcaster eventBroadcaster = new LegacyEventBroadcaster(coreV1Api); - - // nodeReconciler prints node information on events - NodePrintingReconciler nodeReconciler = - new NodePrintingReconciler( - nodeInformer, - eventBroadcaster.newRecorder( - new V1EventSource().host("localhost").component("node-printer"))); - - // Use builder library to construct a default controller. - Controller controller = - ControllerBuilder.defaultBuilder(informerFactory) - .watch( - (workQueue) -> - ControllerBuilder.controllerWatchBuilder(V1Node.class, workQueue) - .withWorkQueueKeyFunc( - (V1Node node) -> - new Request(node.getMetadata().getName())) // optional, default to - .withOnAddFilter( - (V1Node createdNode) -> - createdNode - .getMetadata() - .getName() - .startsWith("docker-")) // optional, set onAdd filter - .withOnUpdateFilter( - (V1Node oldNode, V1Node newNode) -> - newNode - .getMetadata() - .getName() - .startsWith("docker-")) // optional, set onUpdate filter - .withOnDeleteFilter( - (V1Node deletedNode, Boolean stateUnknown) -> - deletedNode - .getMetadata() - .getName() - .startsWith("docker-")) // optional, set onDelete filter - .build()) - .withReconciler(nodeReconciler) // required, set the actual reconciler - .withName("node-printing-controller") // optional, set name for controller - .withWorkerCount(4) // optional, set worker thread count - .withReadyFunc(nodeInformer::hasSynced) // optional, only starts controller when the - // cache has synced up - .build(); - - // Use builder library to manage one or multiple controllers. - ControllerManager controllerManager = - ControllerBuilder.controllerManagerBuilder(informerFactory) - .addController(controller) - .build(); - - LeaderElectingController leaderElectingController = - new LeaderElectingController( - new LeaderElector( - new LeaderElectionConfig( - new EndpointsLock("kube-system", "leader-election", "foo"), - Duration.ofMillis(10000), - Duration.ofMillis(8000), - Duration.ofMillis(5000))), - controllerManager); - - leaderElectingController.run(); - } - - static class NodePrintingReconciler implements Reconciler { - - private Lister nodeLister; - private EventRecorder eventRecorder; - - public NodePrintingReconciler( - SharedIndexInformer nodeInformer, EventRecorder recorder) { - this.nodeLister = new Lister<>(nodeInformer.getIndexer()); - this.eventRecorder = recorder; - } - - @Override - public Result reconcile(Request request) { - V1Node node = this.nodeLister.get(request.getName()); - System.out.println("triggered reconciling " + node.getMetadata().getName()); - this.eventRecorder.event( - node, - EventType.Normal, - "Print Node", - "Successfully printed %s", - node.getMetadata().getName()); - return new Result(false); - } - } -} diff --git a/examples/examples-release-17/src/main/java/io/kubernetes/client/examples/CopyExample.java b/examples/examples-release-17/src/main/java/io/kubernetes/client/examples/CopyExample.java deleted file mode 100644 index bbb6575676..0000000000 --- a/examples/examples-release-17/src/main/java/io/kubernetes/client/examples/CopyExample.java +++ /dev/null @@ -1,51 +0,0 @@ -/* -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.Copy; -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 io.kubernetes.client.util.exception.CopyNotSupportedException; -import java.io.IOException; -import java.io.InputStream; -import java.nio.file.Paths; - -/** - * A simple example of how to use the Java API - * - *

Easiest way to run this: mvn exec:java - * -Dexec.mainClass="io.kubernetes.client.examples.CopyExample" - * - *

From inside $REPO_DIR/examples - */ -public class CopyExample { - public static void main(String[] args) - throws IOException, ApiException, InterruptedException, CopyNotSupportedException { - String podName = "kube-addon-manager-minikube"; - String namespace = "kube-system"; - - ApiClient client = Config.defaultClient(); - Configuration.setDefaultApiClient(client); - - Copy copy = new Copy(); - InputStream dataStream = copy.copyFileFromPod(namespace, podName, "/etc/motd"); - Streams.copy(dataStream, System.out); - - copy.copyDirectoryFromPod(namespace, podName, null, "/etc", Paths.get("/tmp/etc")); - - System.out.println("Done!"); - } -} diff --git a/examples/examples-release-17/src/main/java/io/kubernetes/client/examples/DynamicClientExample.java b/examples/examples-release-17/src/main/java/io/kubernetes/client/examples/DynamicClientExample.java deleted file mode 100644 index b8cb04616d..0000000000 --- a/examples/examples-release-17/src/main/java/io/kubernetes/client/examples/DynamicClientExample.java +++ /dev/null @@ -1,42 +0,0 @@ -/* -Copyright 2021 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.openapi.ApiClient; -import io.kubernetes.client.openapi.ApiException; -import io.kubernetes.client.util.ClientBuilder; -import io.kubernetes.client.util.generic.dynamic.DynamicKubernetesApi; -import io.kubernetes.client.util.generic.dynamic.DynamicKubernetesObject; -import java.io.IOException; - -public class DynamicClientExample { - - public static void main(String[] args) throws IOException, ApiException { - - ApiClient apiClient = ClientBuilder.standard().build(); - - // retrieving the latest state of the default namespace - DynamicKubernetesApi dynamicApi = new DynamicKubernetesApi("", "v1", "namespaces", apiClient); - DynamicKubernetesObject defaultNamespace = - dynamicApi.get("default").throwsApiException().getObject(); - - // attaching a "foo=bar" label to the default namespace - defaultNamespace.setMetadata(defaultNamespace.getMetadata().putLabelsItem("foo", "bar")); - DynamicKubernetesObject updatedDefaultNamespace = - dynamicApi.update(defaultNamespace).throwsApiException().getObject(); - - System.out.println(updatedDefaultNamespace); - - apiClient.getHttpClient().connectionPool().evictAll(); - } -} diff --git a/examples/examples-release-17/src/main/java/io/kubernetes/client/examples/Example.java b/examples/examples-release-17/src/main/java/io/kubernetes/client/examples/Example.java deleted file mode 100644 index 95d7fa51bc..0000000000 --- a/examples/examples-release-17/src/main/java/io/kubernetes/client/examples/Example.java +++ /dev/null @@ -1,44 +0,0 @@ -/* -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.openapi.ApiClient; -import io.kubernetes.client.openapi.ApiException; -import io.kubernetes.client.openapi.Configuration; -import io.kubernetes.client.openapi.apis.CoreV1Api; -import io.kubernetes.client.openapi.models.V1Pod; -import io.kubernetes.client.openapi.models.V1PodList; -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.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); - - CoreV1Api api = new CoreV1Api(); - V1PodList list = - api.listPodForAllNamespaces(null, null, null, null, null, null, null, null, null, null); - for (V1Pod item : list.getItems()) { - System.out.println(item.getMetadata().getName()); - } - } -} diff --git a/examples/examples-release-17/src/main/java/io/kubernetes/client/examples/ExecExample.java b/examples/examples-release-17/src/main/java/io/kubernetes/client/examples/ExecExample.java deleted file mode 100644 index acea8e815a..0000000000 --- a/examples/examples-release-17/src/main/java/io/kubernetes/client/examples/ExecExample.java +++ /dev/null @@ -1,96 +0,0 @@ -/* -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.Exec; -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.IOException; -import org.apache.commons.cli.CommandLine; -import org.apache.commons.cli.CommandLineParser; -import org.apache.commons.cli.DefaultParser; -import org.apache.commons.cli.Option; -import org.apache.commons.cli.Options; -import org.apache.commons.cli.ParseException; - -/** - * A simple example of how to use the Java API - * - *

Easiest way to run this: mvn exec:java - * -Dexec.mainClass="io.kubernetes.client.examples.ExecExample" - * - *

From inside $REPO_DIR/examples - */ -public class ExecExample { - public static void main(String[] args) - throws IOException, ApiException, InterruptedException, ParseException { - final Options options = new Options(); - options.addOption(new Option("p", "pod", true, "The name of the pod")); - options.addOption(new Option("n", "namespace", true, "The namespace of the pod")); - - CommandLineParser parser = new DefaultParser(); - CommandLine cmd = parser.parse(options, args); - - String podName = cmd.getOptionValue("p", "nginx-dbddb74b8-s4cx5"); - String namespace = cmd.getOptionValue("n", "default"); - args = cmd.getArgs(); - - ApiClient client = Config.defaultClient(); - Configuration.setDefaultApiClient(client); - - Exec exec = new Exec(); - boolean tty = System.console() != null; - // final Process proc = exec.exec("default", "nginx-4217019353-k5sn9", new String[] - // {"sh", "-c", "echo foo"}, true, tty); - final Process proc = - exec.exec(namespace, podName, args.length == 0 ? new String[] {"sh"} : args, true, tty); - - Thread in = - new Thread( - new Runnable() { - public void run() { - try { - Streams.copy(System.in, proc.getOutputStream()); - } catch (IOException ex) { - ex.printStackTrace(); - } - } - }); - in.start(); - - Thread out = - new Thread( - new Runnable() { - public void run() { - try { - Streams.copy(proc.getInputStream(), System.out); - } catch (IOException ex) { - ex.printStackTrace(); - } - } - }); - out.start(); - - proc.waitFor(); - - // wait for any last output; no need to wait for input thread - out.join(); - - proc.destroy(); - - System.exit(proc.exitValue()); - } -} diff --git a/examples/examples-release-17/src/main/java/io/kubernetes/client/examples/ExpandedExample.java b/examples/examples-release-17/src/main/java/io/kubernetes/client/examples/ExpandedExample.java deleted file mode 100644 index 8701bda841..0000000000 --- a/examples/examples-release-17/src/main/java/io/kubernetes/client/examples/ExpandedExample.java +++ /dev/null @@ -1,274 +0,0 @@ -/* -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.openapi.ApiClient; -import io.kubernetes.client.openapi.ApiException; -import io.kubernetes.client.openapi.Configuration; -import io.kubernetes.client.openapi.apis.AppsV1Api; -import io.kubernetes.client.openapi.apis.CoreV1Api; -import io.kubernetes.client.openapi.models.V1Deployment; -import io.kubernetes.client.openapi.models.V1DeploymentList; -import io.kubernetes.client.openapi.models.V1DeploymentSpec; -import io.kubernetes.client.openapi.models.V1NamespaceList; -import io.kubernetes.client.openapi.models.V1PodList; -import io.kubernetes.client.openapi.models.V1ServiceList; -import io.kubernetes.client.util.Config; -import java.io.IOException; -import java.util.List; -import java.util.Optional; -import java.util.stream.Collectors; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * A simple example of how to use the Java API - * - *

Easiest way to run this: mvn exec:java - * -Dexec.mainClass="io.kubernetes.client.examples.ExpandedExample" - * - *

From inside $REPO_DIR/examples - */ -public class ExpandedExample { - - private static CoreV1Api COREV1_API; - private static final String DEFAULT_NAME_SPACE = "default"; - private static final Integer TIME_OUT_VALUE = 180; - private static final Logger LOGGER = LoggerFactory.getLogger(ExpandedExample.class); - - /** - * Main method - * - * @param args - */ - public static void main(String[] args) { - try { - ApiClient client = Config.defaultClient(); - // To change the context of k8s cluster, you can use - // io.kubernetes.client.util.KubeConfig - Configuration.setDefaultApiClient(client); - COREV1_API = new CoreV1Api(client); - - // ScaleUp/ScaleDown the Deployment pod - // Please change the name of Deployment? - System.out.println("----- Scale Deployment Start -----"); - scaleDeployment("account-service", 5); - - // List all of the namespaces and pods - List nameSpaces = getAllNameSpaces(); - nameSpaces.stream() - .forEach( - namespace -> { - try { - System.out.println("----- " + namespace + " -----"); - getNamespacedPod(namespace).stream().forEach(System.out::println); - } catch (ApiException ex) { - LOGGER.warn("Couldn't get the pods in namespace:{}", namespace, ex); - } - }); - - // Print all of the Services - System.out.println("----- Print list all Services Start -----"); - List services = getServices(); - services.stream().forEach(System.out::println); - System.out.println("----- Print list all Services End -----"); - - // Print log of specific pod. In this example show the first pod logs. - System.out.println("----- Print Log of Specific Pod Start -----"); - String firstPodName = getPods().get(0); - printLog(DEFAULT_NAME_SPACE, firstPodName); - System.out.println("----- Print Log of Specific Pod End -----"); - } catch (ApiException | IOException ex) { - LOGGER.warn("Exception had occured ", ex); - } - } - - /** - * Get all namespaces in k8s cluster - * - * @return - * @throws ApiException - */ - public static List getAllNameSpaces() throws ApiException { - V1NamespaceList listNamespace = - COREV1_API.listNamespace( - "true", null, null, null, null, 0, null, null, Integer.MAX_VALUE, Boolean.FALSE); - List list = - listNamespace.getItems().stream() - .map(v1Namespace -> v1Namespace.getMetadata().getName()) - .collect(Collectors.toList()); - return list; - } - - /** - * List all pod names in all namespaces in k8s cluster - * - * @return - * @throws ApiException - */ - public static List getPods() throws ApiException { - V1PodList v1podList = - COREV1_API.listPodForAllNamespaces( - null, null, null, null, null, null, null, null, null, null); - List podList = - v1podList.getItems().stream() - .map(v1Pod -> v1Pod.getMetadata().getName()) - .collect(Collectors.toList()); - return podList; - } - - /** - * List all pod in the default namespace - * - * @return - * @throws ApiException - */ - public static List getNamespacedPod() throws ApiException { - return getNamespacedPod(DEFAULT_NAME_SPACE, null); - } - - /** - * List pod in specific namespace - * - * @param namespace - * @return - * @throws ApiException - */ - public static List getNamespacedPod(String namespace) throws ApiException { - return getNamespacedPod(namespace, null); - } - - /** - * List pod in specific namespace with label - * - * @param namespace - * @param label - * @return - * @throws ApiException - */ - public static List getNamespacedPod(String namespace, String label) throws ApiException { - V1PodList listNamespacedPod = - COREV1_API.listNamespacedPod( - namespace, - null, - null, - null, - null, - label, - Integer.MAX_VALUE, - null, - null, - TIME_OUT_VALUE, - Boolean.FALSE); - List listPods = - listNamespacedPod.getItems().stream() - .map(v1pod -> v1pod.getMetadata().getName()) - .collect(Collectors.toList()); - return listPods; - } - - /** - * List all Services in default namespace - * - * @return - * @throws ApiException - */ - public static List getServices() throws ApiException { - V1ServiceList listNamespacedService = - COREV1_API.listNamespacedService( - DEFAULT_NAME_SPACE, - null, - null, - null, - null, - null, - Integer.MAX_VALUE, - null, - null, - TIME_OUT_VALUE, - Boolean.FALSE); - return listNamespacedService.getItems().stream() - .map(v1service -> v1service.getMetadata().getName()) - .collect(Collectors.toList()); - } - - /** - * Scale up/down the number of pod in Deployment - * - * @param deploymentName - * @param numberOfReplicas - * @throws ApiException - */ - public static void scaleDeployment(String deploymentName, int numberOfReplicas) - throws ApiException { - AppsV1Api appsV1Api = new AppsV1Api(); - appsV1Api.setApiClient(COREV1_API.getApiClient()); - V1DeploymentList listNamespacedDeployment = - appsV1Api.listNamespacedDeployment( - DEFAULT_NAME_SPACE, - null, - null, - null, - null, - null, - null, - null, - null, - null, - Boolean.FALSE); - - List appsV1DeploymentItems = listNamespacedDeployment.getItems(); - Optional findedDeployment = - appsV1DeploymentItems.stream() - .filter( - (V1Deployment deployment) -> - deployment.getMetadata().getName().equals(deploymentName)) - .findFirst(); - findedDeployment.ifPresent( - (V1Deployment deploy) -> { - try { - V1DeploymentSpec newSpec = deploy.getSpec().replicas(numberOfReplicas); - V1Deployment newDeploy = deploy.spec(newSpec); - appsV1Api.replaceNamespacedDeployment( - deploymentName, DEFAULT_NAME_SPACE, newDeploy, null, null, null, null); - } catch (ApiException ex) { - LOGGER.warn("Scale the pod failed for Deployment:{}", deploymentName, ex); - } - }); - } - - /** - * Print out the Log for specific Pods - * - * @param namespace - * @param podName - * @throws ApiException - */ - public static void printLog(String namespace, String podName) throws ApiException { - // https://github.com/kubernetes-client/java/blob/master/kubernetes/docs/CoreV1Api.md#readNamespacedPodLog - String readNamespacedPodLog = - COREV1_API.readNamespacedPodLog( - podName, - namespace, - null, - Boolean.FALSE, - null, - Integer.MAX_VALUE, - null, - Boolean.FALSE, - Integer.MAX_VALUE, - 40, - Boolean.FALSE); - System.out.println(readNamespacedPodLog); - } -} diff --git a/examples/examples-release-17/src/main/java/io/kubernetes/client/examples/FluentExample.java b/examples/examples-release-17/src/main/java/io/kubernetes/client/examples/FluentExample.java deleted file mode 100644 index 8e48cc51b3..0000000000 --- a/examples/examples-release-17/src/main/java/io/kubernetes/client/examples/FluentExample.java +++ /dev/null @@ -1,75 +0,0 @@ -/* -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.openapi.ApiClient; -import io.kubernetes.client.openapi.ApiException; -import io.kubernetes.client.openapi.Configuration; -import io.kubernetes.client.openapi.apis.CoreV1Api; -import io.kubernetes.client.openapi.models.V1Container; -import io.kubernetes.client.openapi.models.V1ObjectMeta; -import io.kubernetes.client.openapi.models.V1Pod; -import io.kubernetes.client.openapi.models.V1PodBuilder; -import io.kubernetes.client.openapi.models.V1PodList; -import io.kubernetes.client.openapi.models.V1PodSpec; -import io.kubernetes.client.util.Config; -import java.io.IOException; -import java.util.Arrays; - -/** - * A simple example of how to use the Java API - * - *

Easiest way to run this: mvn exec:java - * -Dexec.mainClass="io.kubernetes.client.examples.FluentExample" - * - *

From inside $REPO_DIR/examples - */ -public class FluentExample { - public static void main(String[] args) throws IOException, ApiException { - ApiClient client = Config.defaultClient(); - Configuration.setDefaultApiClient(client); - - CoreV1Api api = new CoreV1Api(); - - V1Pod pod = - new V1PodBuilder() - .withNewMetadata() - .withName("apod") - .endMetadata() - .withNewSpec() - .addNewContainer() - .withName("www") - .withImage("nginx") - .endContainer() - .endSpec() - .build(); - - api.createNamespacedPod("default", pod, null, null, null, null); - - V1Pod pod2 = - new V1Pod() - .metadata(new V1ObjectMeta().name("anotherpod")) - .spec( - new V1PodSpec() - .containers(Arrays.asList(new V1Container().name("www").image("nginx")))); - - api.createNamespacedPod("default", pod2, null, null, null, null); - - V1PodList list = - api.listNamespacedPod( - "default", null, null, null, null, null, null, null, null, null, null); - for (V1Pod item : list.getItems()) { - System.out.println(item.getMetadata().getName()); - } - } -} diff --git a/examples/examples-release-17/src/main/java/io/kubernetes/client/examples/GenericClientExample.java b/examples/examples-release-17/src/main/java/io/kubernetes/client/examples/GenericClientExample.java deleted file mode 100644 index ddfb1243b8..0000000000 --- a/examples/examples-release-17/src/main/java/io/kubernetes/client/examples/GenericClientExample.java +++ /dev/null @@ -1,63 +0,0 @@ -/* -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.custom.V1Patch; -import io.kubernetes.client.openapi.ApiClient; -import io.kubernetes.client.openapi.models.V1Container; -import io.kubernetes.client.openapi.models.V1ObjectMeta; -import io.kubernetes.client.openapi.models.V1Pod; -import io.kubernetes.client.openapi.models.V1PodList; -import io.kubernetes.client.openapi.models.V1PodSpec; -import io.kubernetes.client.util.ClientBuilder; -import io.kubernetes.client.util.generic.GenericKubernetesApi; -import java.util.Arrays; - -public class GenericClientExample { - - public static void main(String[] args) throws Exception { - - // The following codes demonstrates using generic client to manipulate pods - V1Pod pod = - new V1Pod() - .metadata(new V1ObjectMeta().name("foo").namespace("default")) - .spec( - new V1PodSpec() - .containers(Arrays.asList(new V1Container().name("c").image("test")))); - - ApiClient apiClient = ClientBuilder.standard().build(); - GenericKubernetesApi podClient = - new GenericKubernetesApi<>(V1Pod.class, V1PodList.class, "", "v1", "pods", apiClient); - - V1Pod latestPod = podClient.create(pod).throwsApiException().getObject(); - System.out.println("Created!"); - - V1Pod patchedPod = - podClient - .patch( - "default", - "foo", - V1Patch.PATCH_FORMAT_STRATEGIC_MERGE_PATCH, - new V1Patch("{\"metadata\":{\"finalizers\":[\"example.io/foo\"]}}")) - .throwsApiException() - .getObject(); - System.out.println("Patched!"); - - V1Pod deletedPod = podClient.delete("default", "foo").throwsApiException().getObject(); - if (deletedPod != null) { - System.out.println( - "Received after-deletion status of the requested object, will be deleting in background!"); - } - System.out.println("Deleted!"); - } -} diff --git a/examples/examples-release-17/src/main/java/io/kubernetes/client/examples/InClusterClientExample.java b/examples/examples-release-17/src/main/java/io/kubernetes/client/examples/InClusterClientExample.java deleted file mode 100644 index 7ab705b440..0000000000 --- a/examples/examples-release-17/src/main/java/io/kubernetes/client/examples/InClusterClientExample.java +++ /dev/null @@ -1,58 +0,0 @@ -/* -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.openapi.ApiClient; -import io.kubernetes.client.openapi.ApiException; -import io.kubernetes.client.openapi.Configuration; -import io.kubernetes.client.openapi.apis.CoreV1Api; -import io.kubernetes.client.openapi.models.V1Pod; -import io.kubernetes.client.openapi.models.V1PodList; -import io.kubernetes.client.util.ClientBuilder; -import java.io.IOException; - -/** - * A simple example of how to use the Java API inside a kubernetes cluster - * - *

Easiest way to run this: mvn exec:java - * -Dexec.mainClass="io.kubernetes.client.examples.InClusterClientExample" - * - *

From inside $REPO_DIR/examples - */ -public class InClusterClientExample { - public static void main(String[] args) throws IOException, ApiException { - - // loading the in-cluster config, including: - // 1. service-account CA - // 2. service-account bearer-token - // 3. service-account namespace - // 4. master endpoints(ip, port) from pre-set environment variables - ApiClient client = ClientBuilder.cluster().build(); - - // if you prefer not to refresh service account token, please use: - // ApiClient client = ClientBuilder.oldCluster().build(); - - // set the global default api-client to the in-cluster one from above - Configuration.setDefaultApiClient(client); - - // the CoreV1Api loads default api-client from global configuration. - CoreV1Api api = new CoreV1Api(); - - // invokes the CoreV1Api client - V1PodList list = - api.listPodForAllNamespaces(null, null, null, null, null, null, null, null, null, null); - for (V1Pod item : list.getItems()) { - System.out.println(item.getMetadata().getName()); - } - } -} diff --git a/examples/examples-release-17/src/main/java/io/kubernetes/client/examples/InformerExample.java b/examples/examples-release-17/src/main/java/io/kubernetes/client/examples/InformerExample.java deleted file mode 100644 index bae1ef3595..0000000000 --- a/examples/examples-release-17/src/main/java/io/kubernetes/client/examples/InformerExample.java +++ /dev/null @@ -1,106 +0,0 @@ -/* -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.informer.ResourceEventHandler; -import io.kubernetes.client.informer.SharedIndexInformer; -import io.kubernetes.client.informer.SharedInformerFactory; -import io.kubernetes.client.informer.cache.Lister; -import io.kubernetes.client.openapi.ApiClient; -import io.kubernetes.client.openapi.apis.CoreV1Api; -import io.kubernetes.client.openapi.models.V1Node; -import io.kubernetes.client.openapi.models.V1NodeList; -import io.kubernetes.client.openapi.models.V1ObjectMeta; -import io.kubernetes.client.util.CallGeneratorParams; -import java.util.concurrent.TimeUnit; -import okhttp3.OkHttpClient; - -/** - * A simple example of how to use the Java API - * - *

Easiest way to run this: mvn exec:java - * -Dexec.mainClass="io.kubernetes.client.examples.InformerExample" - * - *

From inside $REPO_DIR/examples - */ -public class InformerExample { - public static void main(String[] args) throws Exception { - CoreV1Api coreV1Api = new CoreV1Api(); - ApiClient apiClient = coreV1Api.getApiClient(); - OkHttpClient httpClient = - apiClient.getHttpClient().newBuilder().readTimeout(0, TimeUnit.SECONDS).build(); - apiClient.setHttpClient(httpClient); - - SharedInformerFactory factory = new SharedInformerFactory(apiClient); - - // Node informer - SharedIndexInformer nodeInformer = - factory.sharedIndexInformerFor( - (CallGeneratorParams params) -> { - // **NOTE**: - // The following "CallGeneratorParams" lambda merely generates a stateless - // HTTPs requests, the effective apiClient is the one specified when constructing - // the informer-factory. - return coreV1Api.listNodeCall( - null, - null, - null, - null, - null, - null, - params.resourceVersion, - null, - params.timeoutSeconds, - params.watch, - null); - }, - V1Node.class, - V1NodeList.class); - - nodeInformer.addEventHandler( - new ResourceEventHandler() { - @Override - public void onAdd(V1Node node) { - System.out.printf("%s node added!\n", node.getMetadata().getName()); - } - - @Override - public void onUpdate(V1Node oldNode, V1Node newNode) { - System.out.printf( - "%s => %s node updated!\n", - oldNode.getMetadata().getName(), newNode.getMetadata().getName()); - } - - @Override - public void onDelete(V1Node node, boolean deletedFinalStateUnknown) { - System.out.printf("%s node deleted!\n", node.getMetadata().getName()); - } - }); - - factory.startAllRegisteredInformers(); - - V1Node nodeToCreate = new V1Node(); - V1ObjectMeta metadata = new V1ObjectMeta(); - metadata.setName("noxu"); - nodeToCreate.setMetadata(metadata); - V1Node createdNode = coreV1Api.createNode(nodeToCreate, null, null, null, null); - Thread.sleep(3000); - - Lister nodeLister = new Lister(nodeInformer.getIndexer()); - V1Node node = nodeLister.get("noxu"); - System.out.printf("noxu created! %s\n", node.getMetadata().getCreationTimestamp()); - factory.stopAllRegisteredInformers(); - Thread.sleep(3000); - System.out.println("informer stopped.."); - } -} diff --git a/examples/examples-release-17/src/main/java/io/kubernetes/client/examples/KubeConfigFileClientExample.java b/examples/examples-release-17/src/main/java/io/kubernetes/client/examples/KubeConfigFileClientExample.java deleted file mode 100644 index 95c94a1e80..0000000000 --- a/examples/examples-release-17/src/main/java/io/kubernetes/client/examples/KubeConfigFileClientExample.java +++ /dev/null @@ -1,58 +0,0 @@ -/* -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.openapi.ApiClient; -import io.kubernetes.client.openapi.ApiException; -import io.kubernetes.client.openapi.Configuration; -import io.kubernetes.client.openapi.apis.CoreV1Api; -import io.kubernetes.client.openapi.models.V1Pod; -import io.kubernetes.client.openapi.models.V1PodList; -import io.kubernetes.client.util.ClientBuilder; -import io.kubernetes.client.util.KubeConfig; -import java.io.FileReader; -import java.io.IOException; - -/** - * A simple example of how to use the Java API from an application outside a kubernetes cluster - * - *

Easiest way to run this: mvn exec:java - * -Dexec.mainClass="io.kubernetes.client.examples.KubeConfigFileClientExample" - * - *

From inside $REPO_DIR/examples - */ -public class KubeConfigFileClientExample { - public static void main(String[] args) throws IOException, ApiException { - - // file path to your KubeConfig - - String kubeConfigPath = System.getenv("HOME") + "/.kube/config"; - - // loading the out-of-cluster config, a kubeconfig from file-system - ApiClient client = - ClientBuilder.kubeconfig(KubeConfig.loadKubeConfig(new FileReader(kubeConfigPath))).build(); - - // set the global default api-client to the out-of-cluster one from above - Configuration.setDefaultApiClient(client); - - // the CoreV1Api loads default api-client from global configuration. - CoreV1Api api = new CoreV1Api(); - - // invokes the CoreV1Api client - V1PodList list = - api.listPodForAllNamespaces(null, null, null, null, null, null, null, null, null, null); - for (V1Pod item : list.getItems()) { - System.out.println(item.getMetadata().getName()); - } - } -} diff --git a/examples/examples-release-17/src/main/java/io/kubernetes/client/examples/KubectlExample.java b/examples/examples-release-17/src/main/java/io/kubernetes/client/examples/KubectlExample.java deleted file mode 100644 index 2619c9f271..0000000000 --- a/examples/examples-release-17/src/main/java/io/kubernetes/client/examples/KubectlExample.java +++ /dev/null @@ -1,311 +0,0 @@ -/* -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 static io.kubernetes.client.extended.kubectl.Kubectl.apiResources; -import static io.kubernetes.client.extended.kubectl.Kubectl.copy; -import static io.kubernetes.client.extended.kubectl.Kubectl.cordon; -import static io.kubernetes.client.extended.kubectl.Kubectl.delete; -import static io.kubernetes.client.extended.kubectl.Kubectl.drain; -import static io.kubernetes.client.extended.kubectl.Kubectl.exec; -import static io.kubernetes.client.extended.kubectl.Kubectl.label; -import static io.kubernetes.client.extended.kubectl.Kubectl.log; -import static io.kubernetes.client.extended.kubectl.Kubectl.portforward; -import static io.kubernetes.client.extended.kubectl.Kubectl.scale; -import static io.kubernetes.client.extended.kubectl.Kubectl.taint; -import static io.kubernetes.client.extended.kubectl.Kubectl.top; -import static io.kubernetes.client.extended.kubectl.Kubectl.uncordon; -import static io.kubernetes.client.extended.kubectl.Kubectl.version; -import static io.kubernetes.client.extended.kubectl.KubectlTop.podMetricSum; - -import io.kubernetes.client.common.KubernetesObject; -import io.kubernetes.client.custom.NodeMetrics; -import io.kubernetes.client.custom.PodMetrics; -import io.kubernetes.client.extended.kubectl.KubectlExec; -import io.kubernetes.client.extended.kubectl.KubectlPortForward; -import io.kubernetes.client.extended.kubectl.exception.KubectlException; -import io.kubernetes.client.openapi.ApiClient; -import io.kubernetes.client.openapi.models.V1Deployment; -import io.kubernetes.client.openapi.models.V1Node; -import io.kubernetes.client.openapi.models.V1Pod; -import io.kubernetes.client.openapi.models.V1ReplicationController; -import io.kubernetes.client.openapi.models.V1Service; -import io.kubernetes.client.util.Config; -import io.kubernetes.client.util.Streams; -import java.util.Arrays; -import java.util.List; -import org.apache.commons.cli.CommandLine; -import org.apache.commons.cli.DefaultParser; -import org.apache.commons.cli.Option; -import org.apache.commons.cli.Options; -import org.apache.commons.cli.ParseException; -import org.apache.commons.lang3.tuple.Pair; - -/** - * A Java equivalent for the kubectl command line tool. Not nearly as complete. - * - *

Easiest way to run this: mvn exec:java - * -Dexec.mainClass="io.kubernetes.client.examples.KubectlExample" -Dexec.args="log some-pod" - * - *

From inside $REPO_DIR/examples - */ -public class KubectlExample { - static Class getClassForKind(String kind) { - switch (kind) { - case "pod": - case "pods": - return V1Pod.class; - case "deployment": - case "deployments": - return V1Deployment.class; - case "service": - case "services": - return V1Service.class; - case "node": - case "nodes": - return V1Node.class; - case "replicationcontroller": - case "replicationcontrollers": - return V1ReplicationController.class; - } - return null; - } - - private static final String PADDING = " "; - - private static String pad(String value) { - while (value.length() < PADDING.length()) { - value += " "; - } - return value; - } - - public static void main(String[] args) - throws java.io.IOException, KubectlException, ParseException { - ApiClient client = Config.defaultClient(); - - Options options = new Options(); - options.addOption(new Option("n", "namespace", true, "The namespace for the resource")); - options.addOption(new Option("r", "replicas", true, "The number of replicas to scale to")); - options.addOption(new Option("c", "container", true, "The container in a pod to connect to")); - DefaultParser parser = new DefaultParser(); - CommandLine cli = parser.parse(options, args); - - args = cli.getArgs(); - String verb = args[0]; - String ns = cli.getOptionValue("n", "default"); - String kind = null; - String name = null; - - switch (verb) { - case "delete": - kind = args[1]; - name = args[2]; - delete(getClassForKind(kind)).namespace(ns).name(name).execute(); - case "drain": - name = args[1]; - drain().apiClient(client).name(name).execute(); - System.out.println("Node drained"); - System.exit(0); - case "cordon": - name = args[1]; - cordon().apiClient(client).name(name).execute(); - System.out.println("Node cordoned"); - System.exit(0); - case "uncordon": - name = args[1]; - uncordon().apiClient(client).name(name).execute(); - System.out.println("Node uncordoned"); - System.exit(0); - case "top": - String what = args[1]; - switch (what) { - case "nodes": - case "node": - List> nodes = - top(V1Node.class, NodeMetrics.class).apiClient(client).metric("cpu").execute(); - System.out.println(pad("Node") + "\tCPU\t\tMemory"); - for (Pair node : nodes) { - System.out.println( - pad(node.getLeft().getMetadata().getName()) - + "\t" - + node.getRight().getUsage().get("cpu").getNumber() - + "\t" - + node.getRight().getUsage().get("memory").getNumber()); - } - System.exit(0); - case "pods": - case "pod": - List> pods = - top(V1Pod.class, PodMetrics.class) - .apiClient(client) - .namespace(ns) - .metric("cpu") - .execute(); - System.out.println(pad("Pod") + "\tCPU\t\tMemory"); - for (Pair pod : pods) { - System.out.println( - pad(pod.getLeft().getMetadata().getName()) - + "\t" - + podMetricSum(pod.getRight(), "cpu") - + "\t" - + podMetricSum(pod.getRight(), "memory")); - } - System.exit(0); - } - System.err.println("Unknown top argument: " + what); - System.exit(-1); - case "cp": - String from = args[1]; - String to = args[2]; - if (from.indexOf(":") != -1) { - String[] parts = from.split(":"); - name = parts[0]; - from = parts[1]; - copy() - .apiClient(client) - .namespace(ns) - .name(name) - .container(cli.getOptionValue("c", "")) - .fromPod(from) - .to(to) - .execute(); - } else if (to.indexOf(":") != -1) { - String[] parts = to.split(":"); - name = parts[0]; - to = parts[1]; - copy() - .apiClient(client) - .namespace(ns) - .name(name) - .container(cli.getOptionValue("c", "")) - .from(from) - .toPod(to) - .execute(); - } else { - System.err.println("Missing pod name for copy."); - System.exit(-1); - } - System.out.println("Copied " + from + " -> " + to); - System.exit(0); - case "taint": - name = args[1]; - String taintSpec = args[2]; - boolean remove = taintSpec.endsWith("-"); - int ix = taintSpec.indexOf("="); - int ix2 = taintSpec.indexOf(":"); - - if (remove) { - taintSpec = taintSpec.substring(0, taintSpec.length() - 2); - String key = ix == -1 ? taintSpec : taintSpec.substring(0, ix); - String effect = ix == -1 ? null : taintSpec.substring(ix + 1); - - if (effect == null) { - taint().apiClient(client).name(name).removeTaint(key).execute(); - } else { - taint().apiClient(client).name(name).removeTaint(key, effect).execute(); - } - System.exit(0); - } - if (ix2 == -1) { - System.err.println("key:effect or key=value:effect is required."); - System.exit(-1); - } - String key = taintSpec.substring(0, ix == -1 ? ix2 : ix); - String value = ix == -1 ? null : taintSpec.substring(ix + 1, ix2); - String effect = taintSpec.substring(ix2 + 1); - - if (value == null) { - taint().apiClient(client).name(name).addTaint(key, effect).execute(); - } else { - taint().apiClient(client).name(name).addTaint(key, value, effect).execute(); - } - System.exit(0); - case "portforward": - name = args[1]; - KubectlPortForward forward = portforward().apiClient(client).name(name).namespace(ns); - for (int i = 2; i < args.length; i++) { - String port = args[i]; - String[] ports = port.split(":"); - System.out.println("Forwarding " + ns + "/" + name + " " + ports[0] + "->" + ports[1]); - forward.ports(Integer.parseInt(ports[0]), Integer.parseInt(ports[1])); - } - forward.execute(); - System.exit(0); - case "log": - name = args[1]; - Streams.copy( - log() - .apiClient(client) - .name(name) - .namespace(ns) - .container(cli.getOptionValue("c", "")) - .execute(), - System.out); - System.exit(0); - case "scale": - kind = args[1]; - name = args[2]; - if (!cli.hasOption("r")) { - System.err.println("--replicas is required"); - System.exit(-3); - } - int replicas = Integer.parseInt(cli.getOptionValue("r")); - scale(getClassForKind(kind)) - .apiClient(client) - .namespace(ns) - .name(name) - .replicas(replicas) - .execute(); - System.out.println("Deployment scaled."); - System.exit(0); - case "version": - System.out.println(version().apiClient(client)); - System.exit(0); - case "label": - kind = args[1]; - name = args[2]; - String labelKey = args[3]; - String labelValue = args[4]; - Class clazz = getClassForKind(kind); - if (clazz == null) { - System.err.println("Unknown kind: " + kind); - System.exit(-2); - } - label(clazz).apiClient(client).namespace(ns).name(name).addLabel(labelKey, labelValue); - System.exit(0); - case "exec": - name = args[1]; - String[] command = Arrays.copyOfRange(args, 2, args.length); - KubectlExec e = - exec() - .apiClient(client) - .namespace(ns) - .name(name) - .command(command) - .container(cli.getOptionValue("c", "")); - System.exit(e.execute()); - case "api-resources": - apiResources().apiClient(client).execute().stream() - .forEach( - r -> - System.out.printf( - "%s\t\t%s\t\t%s\t\t%s\n", - r.getResourcePlural(), r.getGroup(), r.getKind(), r.getNamespaced())); - System.exit(0); - default: - System.out.println("Unknown verb: " + verb); - System.exit(-1); - } - } -} diff --git a/examples/examples-release-17/src/main/java/io/kubernetes/client/examples/LeaderElectionExample.java b/examples/examples-release-17/src/main/java/io/kubernetes/client/examples/LeaderElectionExample.java deleted file mode 100644 index 0e48689602..0000000000 --- a/examples/examples-release-17/src/main/java/io/kubernetes/client/examples/LeaderElectionExample.java +++ /dev/null @@ -1,56 +0,0 @@ -/* -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.extended.leaderelection.LeaderElectionConfig; -import io.kubernetes.client.extended.leaderelection.LeaderElector; -import io.kubernetes.client.extended.leaderelection.resourcelock.EndpointsLock; -import io.kubernetes.client.openapi.ApiClient; -import io.kubernetes.client.openapi.Configuration; -import io.kubernetes.client.util.Config; -import java.time.Duration; -import java.util.UUID; - -/** - * A simple example of how to use the Java API - * - *

Easiest way to run this: mvn exec:java - * -Dexec.mainClass="io.kubernetes.client.examples.LeaderElectionExample" - * - *

From inside $REPO_DIR/examples - */ -public class LeaderElectionExample { - public static void main(String[] args) throws Exception { - ApiClient client = Config.defaultClient(); - Configuration.setDefaultApiClient(client); - - // New - String appNamespace = "default"; - String appName = "leader-election-foobar"; - String lockHolderIdentityName = UUID.randomUUID().toString(); // Anything unique - EndpointsLock lock = new EndpointsLock(appNamespace, appName, lockHolderIdentityName); - - LeaderElectionConfig leaderElectionConfig = - new LeaderElectionConfig( - lock, Duration.ofMillis(10000), Duration.ofMillis(8000), Duration.ofMillis(2000)); - try (LeaderElector leaderElector = new LeaderElector(leaderElectionConfig)) { - leaderElector.run( - () -> { - System.out.println("Do something when getting leadership."); - }, - () -> { - System.out.println("Do something when losing leadership."); - }); - } - } -} diff --git a/examples/examples-release-17/src/main/java/io/kubernetes/client/examples/LogsExample.java b/examples/examples-release-17/src/main/java/io/kubernetes/client/examples/LogsExample.java deleted file mode 100644 index dbfa157eea..0000000000 --- a/examples/examples-release-17/src/main/java/io/kubernetes/client/examples/LogsExample.java +++ /dev/null @@ -1,51 +0,0 @@ -/* -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.PodLogs; -import io.kubernetes.client.openapi.ApiClient; -import io.kubernetes.client.openapi.ApiException; -import io.kubernetes.client.openapi.Configuration; -import io.kubernetes.client.openapi.apis.CoreV1Api; -import io.kubernetes.client.openapi.models.V1Pod; -import io.kubernetes.client.util.Config; -import io.kubernetes.client.util.Streams; -import java.io.IOException; -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" - * - *

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); - - PodLogs logs = new PodLogs(); - V1Pod pod = - coreApi - .listNamespacedPod( - "default", "false", null, null, null, null, null, null, null, null, null) - .getItems() - .get(0); - - InputStream is = logs.streamNamespacedPodLog(pod); - Streams.copy(is, System.out); - } -} diff --git a/examples/examples-release-17/src/main/java/io/kubernetes/client/examples/MetricsExample.java b/examples/examples-release-17/src/main/java/io/kubernetes/client/examples/MetricsExample.java deleted file mode 100644 index 0d8c10e30b..0000000000 --- a/examples/examples-release-17/src/main/java/io/kubernetes/client/examples/MetricsExample.java +++ /dev/null @@ -1,68 +0,0 @@ -/* -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.Metrics; -import io.kubernetes.client.custom.ContainerMetrics; -import io.kubernetes.client.custom.NodeMetrics; -import io.kubernetes.client.custom.NodeMetricsList; -import io.kubernetes.client.custom.PodMetrics; -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 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.MetricsExample" - * - *

From inside $REPO_DIR/examples - */ -public class MetricsExample { - public static void main(String[] args) throws IOException, ApiException { - ApiClient client = Config.defaultClient(); - Configuration.setDefaultApiClient(client); - - Metrics metrics = new Metrics(client); - NodeMetricsList list = metrics.getNodeMetrics(); - for (NodeMetrics item : list.getItems()) { - System.out.println(item.getMetadata().getName()); - System.out.println("------------------------------"); - for (String key : item.getUsage().keySet()) { - System.out.println("\t" + key); - System.out.println("\t" + item.getUsage().get(key)); - } - System.out.println(); - } - - for (PodMetrics item : metrics.getPodMetrics("default").getItems()) { - System.out.println(item.getMetadata().getName()); - System.out.println("------------------------------"); - if (item.getContainers() == null) { - continue; - } - for (ContainerMetrics container : item.getContainers()) { - System.out.println(container.getName()); - System.out.println("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-"); - for (String key : container.getUsage().keySet()) { - System.out.println("\t" + key); - System.out.println("\t" + container.getUsage().get(key)); - } - System.out.println(); - } - } - } -} diff --git a/examples/examples-release-17/src/main/java/io/kubernetes/client/examples/PagerExample.java b/examples/examples-release-17/src/main/java/io/kubernetes/client/examples/PagerExample.java deleted file mode 100644 index b0a4ac4fa4..0000000000 --- a/examples/examples-release-17/src/main/java/io/kubernetes/client/examples/PagerExample.java +++ /dev/null @@ -1,72 +0,0 @@ -/* -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.extended.pager.Pager; -import io.kubernetes.client.openapi.ApiClient; -import io.kubernetes.client.openapi.Configuration; -import io.kubernetes.client.openapi.apis.CoreV1Api; -import io.kubernetes.client.openapi.models.V1Namespace; -import io.kubernetes.client.openapi.models.V1NamespaceList; -import io.kubernetes.client.util.Config; -import java.io.IOException; -import java.util.concurrent.TimeUnit; -import okhttp3.OkHttpClient; - -/** - * A simple example of how to use the Java API - * - *

Easiest way to run this: mvn exec:java - * -Dexec.mainClass="io.kubernetes.client.examples.PagerExample" - * - *

From inside $REPO_DIR/examples - */ -public class PagerExample { - public static void main(String[] args) throws IOException { - - ApiClient client = Config.defaultClient(); - OkHttpClient httpClient = - client.getHttpClient().newBuilder().readTimeout(60, TimeUnit.SECONDS).build(); - client.setHttpClient(httpClient); - Configuration.setDefaultApiClient(client); - CoreV1Api api = new CoreV1Api(); - int i = 0; - Pager pager = - new Pager( - (Pager.PagerParams param) -> { - try { - return api.listNamespaceCall( - null, - null, - param.getContinueToken(), - null, - null, - param.getLimit(), - null, - null, - 1, - null, - null); - } catch (Exception e) { - throw new RuntimeException(e); - } - }, - client, - 10, - V1NamespaceList.class); - for (V1Namespace namespace : pager) { - System.out.println(namespace.getMetadata().getName()); - } - System.out.println("------------------"); - } -} diff --git a/examples/examples-release-17/src/main/java/io/kubernetes/client/examples/ParseExample.java b/examples/examples-release-17/src/main/java/io/kubernetes/client/examples/ParseExample.java deleted file mode 100644 index 92866a46fe..0000000000 --- a/examples/examples-release-17/src/main/java/io/kubernetes/client/examples/ParseExample.java +++ /dev/null @@ -1,64 +0,0 @@ -/* -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.openapi.ApiClient; -import io.kubernetes.client.openapi.ApiException; -import io.kubernetes.client.util.Config; -import java.io.FileReader; -import java.io.IOException; -import java.io.StringReader; - -/** - * A simple example of how to parse a Kubernetes object. - * - *

Easiest way to run this: mvn exec:java - * -Dexec.mainClass="io.kubernetes.client.examples.ParseExample" - * - *

From inside $REPO_DIR/examples - */ -public class ParseExample { - public static void main(String[] args) throws IOException, ApiException, ClassNotFoundException { - if (args.length < 2) { - System.err.println("Usage: ParseExample "); - System.exit(1); - } - ApiClient client = Config.defaultClient(); - FileReader json = new FileReader(args[0]); - Object obj = - client - .getJSON() - .getGson() - .fromJson(json, Class.forName("io.kubernetes.client.models." + args[1])); - - String output = client.getJSON().getGson().toJson(obj); - - // Test round tripping... - Object obj2 = - client - .getJSON() - .getGson() - .fromJson( - new StringReader(output), Class.forName("io.kubernetes.client.models." + args[1])); - - String output2 = client.getJSON().getGson().toJson(obj2); - - // Validate round trip - if (!output.equals(output2)) { - System.err.println("Error, expected:\n" + output + "\nto equal\n" + output2); - System.exit(2); - } - - System.out.println(output); - } -} diff --git a/examples/examples-release-17/src/main/java/io/kubernetes/client/examples/PatchExample.java b/examples/examples-release-17/src/main/java/io/kubernetes/client/examples/PatchExample.java deleted file mode 100644 index 3f2457a47a..0000000000 --- a/examples/examples-release-17/src/main/java/io/kubernetes/client/examples/PatchExample.java +++ /dev/null @@ -1,129 +0,0 @@ -/* -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.custom.V1Patch; -import io.kubernetes.client.openapi.ApiException; -import io.kubernetes.client.openapi.Configuration; -import io.kubernetes.client.openapi.apis.AppsV1Api; -import io.kubernetes.client.openapi.models.V1Deployment; -import io.kubernetes.client.util.ClientBuilder; -import io.kubernetes.client.util.PatchUtils; -import java.io.IOException; - -/** - * A simple Example of how to use the Java API.
- * This example demonstrates patching of deployment using Json Patch and Strategic Merge Patch.
- * For generating Json Patches, refer http://jsonpatch.com. For - * generating Strategic Merge Patches, refer strategic-merge-patch.md. - * - *

- * - *

Easiest way to run this: mvn exec:java - * -Dexec.mainClass="io.kubernetes.client.examples.PatchExample" - * - *

From inside $REPO_DIR/examples - */ -public class PatchExample { - static String jsonPatchStr = - "[{\"op\":\"replace\",\"path\":\"/spec/template/spec/terminationGracePeriodSeconds\",\"value\":27}]"; - static String strategicMergePatchStr = - "{\"metadata\":{\"$deleteFromPrimitiveList/finalizers\":[\"example.com/test\"]}}"; - static String jsonDeploymentStr = - "{\"kind\":\"Deployment\",\"apiVersion\":\"apps/v1\",\"metadata\":{\"name\":\"hello-node\",\"finalizers\":[\"example.com/test\"],\"labels\":{\"run\":\"hello-node\"}},\"spec\":{\"replicas\":1,\"selector\":{\"matchLabels\":{\"run\":\"hello-node\"}},\"template\":{\"metadata\":{\"creationTimestamp\":null,\"labels\":{\"run\":\"hello-node\"}},\"spec\":{\"terminationGracePeriodSeconds\":30,\"containers\":[{\"name\":\"hello-node\",\"image\":\"hello-node:v1\",\"ports\":[{\"containerPort\":8080,\"protocol\":\"TCP\"}],\"resources\":{}}]}},\"strategy\":{}},\"status\":{}}"; - static String applyYamlStr = - "{\"kind\":\"Deployment\",\"apiVersion\":\"apps/v1\",\"metadata\":{\"name\":\"hello-node\",\"finalizers\":[\"example.com/test\"],\"labels\":{\"run\":\"hello-node\"}},\"spec\":{\"replicas\":1,\"selector\":{\"matchLabels\":{\"run\":\"hello-node\"}},\"template\":{\"metadata\":{\"creationTimestamp\":null,\"labels\":{\"run\":\"hello-node\"}},\"spec\":{\"terminationGracePeriodSeconds\":30,\"containers\":[{\"name\":\"hello-node\",\"image\":\"hello-node:v2\",\"ports\":[{\"containerPort\":8080,\"protocol\":\"TCP\"}],\"resources\":{}}]}},\"strategy\":{}},\"status\":{}}"; - - public static void main(String[] args) throws IOException { - try { - AppsV1Api api = new AppsV1Api(ClientBuilder.standard().build()); - V1Deployment body = - Configuration.getDefaultApiClient() - .getJSON() - .deserialize(jsonDeploymentStr, V1Deployment.class); - - // create a deployment - V1Deployment deploy1 = api.createNamespacedDeployment("default", body, null, null, null, null); - System.out.println("original deployment" + deploy1); - - // json-patch a deployment - V1Deployment deploy2 = - PatchUtils.patch( - V1Deployment.class, - () -> - api.patchNamespacedDeploymentCall( - "hello-node", - "default", - new V1Patch(jsonPatchStr), - null, - null, - null, - null, // field-manager is optional - null, - null), - V1Patch.PATCH_FORMAT_JSON_PATCH, - api.getApiClient()); - System.out.println("json-patched deployment" + deploy2); - - // strategic-merge-patch a deployment - V1Deployment deploy3 = - PatchUtils.patch( - V1Deployment.class, - () -> - api.patchNamespacedDeploymentCall( - "hello-node", - "default", - new V1Patch(strategicMergePatchStr), - null, - null, - null, - null, // field-manager is optional - null, - null), - V1Patch.PATCH_FORMAT_STRATEGIC_MERGE_PATCH, - api.getApiClient()); - System.out.println("strategic-merge-patched deployment" + deploy3); - - // apply-yaml a deployment, server side apply is available by default after kubernetes v1.16 - // or opt-in by turning on the feature gate for v1.14 or v1.15. - // https://kubernetes.io/docs/reference/using-api/api-concepts/#server-side-apply - V1Deployment deploy4 = - PatchUtils.patch( - V1Deployment.class, - () -> - api.patchNamespacedDeploymentCall( - "hello-node", - "default", - new V1Patch(applyYamlStr), - null, - null, - "example-field-manager", // field-manager is required for server-side apply - null, - true, - null), - V1Patch.PATCH_FORMAT_APPLY_YAML, - api.getApiClient()); - System.out.println("application/apply-patch+yaml deployment" + deploy4); - - } catch (ApiException e) { - System.out.println(e.getResponseBody()); - e.printStackTrace(); - } - } -} diff --git a/examples/examples-release-17/src/main/java/io/kubernetes/client/examples/PortForwardExample.java b/examples/examples-release-17/src/main/java/io/kubernetes/client/examples/PortForwardExample.java deleted file mode 100644 index cbe064db31..0000000000 --- a/examples/examples-release-17/src/main/java/io/kubernetes/client/examples/PortForwardExample.java +++ /dev/null @@ -1,87 +0,0 @@ -/* -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.PortForward; -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.IOException; -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...) - */ -public class PortForwardExample { - 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<>(); - int localPort = 8080; - int targetPort = 8080; - ports.add(targetPort); - final PortForward.PortForwardResult result = - forward.forward("default", "camera-viz-7949dbf7c6-lpxkd", ports); - System.out.println("Forwarding!"); - ServerSocket ss = new ServerSocket(localPort); - - final Socket s = ss.accept(); - System.out.println("Connected!"); - - new Thread( - new Runnable() { - public void run() { - try { - Streams.copy(result.getInputStream(targetPort), s.getOutputStream()); - } catch (IOException ex) { - ex.printStackTrace(); - } catch (Exception ex) { - ex.printStackTrace(); - } - } - }) - .start(); - - new Thread( - new Runnable() { - public void run() { - try { - Streams.copy(s.getInputStream(), result.getOutboundStream(targetPort)); - } catch (IOException ex) { - ex.printStackTrace(); - } catch (Exception ex) { - ex.printStackTrace(); - } - } - }) - .start(); - - Thread.sleep(10 * 1000); - - System.exit(0); - } -} diff --git a/examples/examples-release-17/src/main/java/io/kubernetes/client/examples/PromOpExample.java b/examples/examples-release-17/src/main/java/io/kubernetes/client/examples/PromOpExample.java deleted file mode 100644 index 65f38b8ce4..0000000000 --- a/examples/examples-release-17/src/main/java/io/kubernetes/client/examples/PromOpExample.java +++ /dev/null @@ -1,43 +0,0 @@ -/* -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 com.coreos.monitoring.models.V1Prometheus; -import com.coreos.monitoring.models.V1PrometheusList; -import com.coreos.monitoring.models.V1PrometheusSpec; -import io.kubernetes.client.openapi.ApiException; -import io.kubernetes.client.openapi.models.V1ObjectMeta; -import io.kubernetes.client.util.ClientBuilder; -import io.kubernetes.client.util.generic.GenericKubernetesApi; -import java.io.IOException; - -public class PromOpExample { - public static void main(String[] args) throws IOException, ApiException { - GenericKubernetesApi prometheusApi = - new GenericKubernetesApi<>( - V1Prometheus.class, - V1PrometheusList.class, - "monitoring.coreos.com", - "v1", - "prometheuses", - ClientBuilder.defaultClient()); - prometheusApi - .create( - new V1Prometheus() - .metadata(new V1ObjectMeta().namespace("default").name("my-prometheus")) - .kind("Prometheus") - .apiVersion("monitoring.coreos.com/v1") - .spec(new V1PrometheusSpec())) - .throwsApiException(); - } -} diff --git a/examples/examples-release-17/src/main/java/io/kubernetes/client/examples/PrometheusExample.java b/examples/examples-release-17/src/main/java/io/kubernetes/client/examples/PrometheusExample.java deleted file mode 100644 index d2afb10142..0000000000 --- a/examples/examples-release-17/src/main/java/io/kubernetes/client/examples/PrometheusExample.java +++ /dev/null @@ -1,66 +0,0 @@ -/* -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.monitoring.Monitoring; -import io.kubernetes.client.openapi.ApiClient; -import io.kubernetes.client.openapi.ApiException; -import io.kubernetes.client.openapi.Configuration; -import io.kubernetes.client.openapi.apis.CoreV1Api; -import io.kubernetes.client.openapi.models.V1Pod; -import io.kubernetes.client.openapi.models.V1PodList; -import io.kubernetes.client.util.Config; -import java.io.IOException; - -/** - * A simple example of how to use the Java API with Prometheus metrics - * - *

Easiest way to run this: mvn exec:java - * -Dexec.mainClass="io.kubernetes.client.examples.PrometheusExample" - * - *

From inside $REPO_DIR/examples - */ -public class PrometheusExample { - public static void main(String[] args) throws IOException, ApiException { - ApiClient client = Config.defaultClient(); - Configuration.setDefaultApiClient(client); - - // Install an HTTP Interceptor that adds metrics - Monitoring.installMetrics(client); - - // Install a simple HTTP server to serve prometheus metrics. If you already are serving - // metrics elsewhere, this is unnecessary. - Monitoring.startMetricsServer("localhost", 8080); - - CoreV1Api api = new CoreV1Api(); - - while (true) { - // A request that should return 200 - V1PodList list = - 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); - } catch (ApiException ex) { - if (ex.getCode() != 404) { - throw ex; - } - } - try { - Thread.sleep(10000); - } catch (InterruptedException ex) { - ex.printStackTrace(); - } - } - } -} diff --git a/examples/examples-release-17/src/main/java/io/kubernetes/client/examples/ProtoExample.java b/examples/examples-release-17/src/main/java/io/kubernetes/client/examples/ProtoExample.java deleted file mode 100644 index e4e05a2aa1..0000000000 --- a/examples/examples-release-17/src/main/java/io/kubernetes/client/examples/ProtoExample.java +++ /dev/null @@ -1,69 +0,0 @@ -/* -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.ProtoClient; -import io.kubernetes.client.ProtoClient.ObjectOrStatus; -import io.kubernetes.client.openapi.ApiClient; -import io.kubernetes.client.openapi.ApiException; -import io.kubernetes.client.openapi.Configuration; -import io.kubernetes.client.proto.Meta.ObjectMeta; -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" - * - *

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"); - - if (list.object.getItemsCount() > 0) { - Pod p = list.object.getItems(0); - System.out.println(p); - } - - 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/examples-release-17/src/main/java/io/kubernetes/client/examples/SpringControllerExample.java b/examples/examples-release-17/src/main/java/io/kubernetes/client/examples/SpringControllerExample.java deleted file mode 100644 index f6494a836e..0000000000 --- a/examples/examples-release-17/src/main/java/io/kubernetes/client/examples/SpringControllerExample.java +++ /dev/null @@ -1,147 +0,0 @@ -/* -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.extended.controller.Controller; -import io.kubernetes.client.extended.controller.builder.ControllerBuilder; -import io.kubernetes.client.extended.controller.builder.DefaultControllerBuilder; -import io.kubernetes.client.extended.controller.reconciler.Reconciler; -import io.kubernetes.client.extended.controller.reconciler.Request; -import io.kubernetes.client.extended.controller.reconciler.Result; -import io.kubernetes.client.informer.SharedIndexInformer; -import io.kubernetes.client.informer.SharedInformer; -import io.kubernetes.client.informer.SharedInformerFactory; -import io.kubernetes.client.informer.cache.Lister; -import io.kubernetes.client.openapi.ApiClient; -import io.kubernetes.client.openapi.models.V1Endpoints; -import io.kubernetes.client.openapi.models.V1EndpointsList; -import io.kubernetes.client.openapi.models.V1Node; -import io.kubernetes.client.openapi.models.V1NodeList; -import io.kubernetes.client.openapi.models.V1Pod; -import io.kubernetes.client.openapi.models.V1PodList; -import io.kubernetes.client.util.generic.GenericKubernetesApi; -import java.time.Duration; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.boot.CommandLineRunner; -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.stereotype.Component; - -@SpringBootApplication -public class SpringControllerExample { - - public static void main(String[] args) { - SpringApplication.run(SpringControllerExample.class, args); - } - - @Configuration - public static class AppConfig { - - @Bean - public CommandLineRunner commandLineRunner( - SharedInformerFactory sharedInformerFactory, Controller nodePrintingController) { - return args -> { - System.out.println("starting informers.."); - sharedInformerFactory.startAllRegisteredInformers(); - - System.out.println("running controller.."); - nodePrintingController.run(); - }; - } - - @Bean - public Controller nodePrintingController( - SharedInformerFactory sharedInformerFactory, NodePrintingReconciler reconciler) { - DefaultControllerBuilder builder = ControllerBuilder.defaultBuilder(sharedInformerFactory); - builder = - builder.watch( - (q) -> { - return ControllerBuilder.controllerWatchBuilder(V1Node.class, q) - .withResyncPeriod(Duration.ofMinutes(1)) - .build(); - }); - builder.withWorkerCount(2); - builder.withReadyFunc(reconciler::informerReady); - return builder.withReconciler(reconciler).withName("nodePrintingController").build(); - } - - @Bean - public SharedIndexInformer endpointsInformer( - ApiClient apiClient, SharedInformerFactory sharedInformerFactory) { - GenericKubernetesApi genericApi = - new GenericKubernetesApi<>( - V1Endpoints.class, V1EndpointsList.class, "", "v1", "endpoints", apiClient); - return sharedInformerFactory.sharedIndexInformerFor(genericApi, V1Endpoints.class, 0); - } - - @Bean - public SharedIndexInformer nodeInformer( - ApiClient apiClient, SharedInformerFactory sharedInformerFactory) { - GenericKubernetesApi genericApi = - new GenericKubernetesApi<>(V1Node.class, V1NodeList.class, "", "v1", "nodes", apiClient); - return sharedInformerFactory.sharedIndexInformerFor(genericApi, V1Node.class, 60 * 1000L); - } - - @Bean - public SharedIndexInformer podInformer( - ApiClient apiClient, SharedInformerFactory sharedInformerFactory) { - GenericKubernetesApi genericApi = - new GenericKubernetesApi<>(V1Pod.class, V1PodList.class, "", "v1", "pods", apiClient); - return sharedInformerFactory.sharedIndexInformerFor(genericApi, V1Pod.class, 0); - } - } - - @Component - public static class NodePrintingReconciler implements Reconciler { - - @Value("${namespace}") - private String namespace; - - private SharedInformer nodeInformer; - - private SharedInformer podInformer; - - private Lister nodeLister; - - private Lister podLister; - - public NodePrintingReconciler( - SharedIndexInformer nodeInformer, SharedIndexInformer podInformer) { - this.nodeInformer = nodeInformer; - this.podInformer = podInformer; - this.nodeLister = new Lister<>(nodeInformer.getIndexer(), namespace); - this.podLister = new Lister<>(podInformer.getIndexer(), namespace); - } - - // *OPTIONAL* - // If you want to hold the controller from running util some condition.. - public boolean informerReady() { - return podInformer.hasSynced() && nodeInformer.hasSynced(); - } - - @Override - public Result reconcile(Request request) { - V1Node node = nodeLister.get(request.getName()); - - System.out.println("get all pods in namespace " + namespace); - podLister.namespace(namespace).list().stream() - .map(pod -> pod.getMetadata().getName()) - .forEach(System.out::println); - - System.out.println("triggered reconciling " + node.getMetadata().getName()); - return new Result(false); - } - } -} diff --git a/examples/examples-release-17/src/main/java/io/kubernetes/client/examples/SpringLoadBalancerExample.java b/examples/examples-release-17/src/main/java/io/kubernetes/client/examples/SpringLoadBalancerExample.java deleted file mode 100644 index bafe11e421..0000000000 --- a/examples/examples-release-17/src/main/java/io/kubernetes/client/examples/SpringLoadBalancerExample.java +++ /dev/null @@ -1,68 +0,0 @@ -/* -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.extended.network.EndpointsLoadBalancer; -import io.kubernetes.client.extended.network.LoadBalancer; -import io.kubernetes.client.extended.network.RoundRobinLoadBalanceStrategy; -import io.kubernetes.client.informer.SharedIndexInformer; -import io.kubernetes.client.informer.SharedInformerFactory; -import io.kubernetes.client.informer.cache.Lister; -import io.kubernetes.client.openapi.models.V1Endpoints; -import io.kubernetes.client.spring.extended.network.endpoints.InformerEndpointsGetter; -import org.springframework.boot.CommandLineRunner; -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -@SpringBootApplication -public class SpringLoadBalancerExample { - - public static void main(String[] args) { - SpringApplication.run(SpringLoadBalancerExample.class, args); - } - - @Configuration - public static class AppConfig { - - @Bean - public CommandLineRunner loadBalancerCommandLineRunner( - SharedInformerFactory sharedInformerFactory, MyService myService) { - return args -> { - System.out.println("starting informers.."); - sharedInformerFactory.startAllRegisteredInformers(); - - System.out.println("routing default/kubernetes:"); - System.out.println(myService.defaultKubernetesLoadBalancer.getTargetIP()); - }; - } - - @Bean - public MyService myService(SharedIndexInformer lister) { - return new MyService(new Lister<>(lister.getIndexer())); - } - } - - public static class MyService { - - private LoadBalancer defaultKubernetesLoadBalancer; - - public MyService(Lister lister) { - InformerEndpointsGetter getter = new InformerEndpointsGetter(lister); - RoundRobinLoadBalanceStrategy strategy = new RoundRobinLoadBalanceStrategy(); - defaultKubernetesLoadBalancer = - new EndpointsLoadBalancer(() -> getter.get("default", "kubernetes"), strategy); - } - } -} diff --git a/examples/examples-release-17/src/main/java/io/kubernetes/client/examples/WatchExample.java b/examples/examples-release-17/src/main/java/io/kubernetes/client/examples/WatchExample.java deleted file mode 100644 index c32a74afd4..0000000000 --- a/examples/examples-release-17/src/main/java/io/kubernetes/client/examples/WatchExample.java +++ /dev/null @@ -1,54 +0,0 @@ -/* -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 com.google.gson.reflect.TypeToken; -import io.kubernetes.client.openapi.ApiClient; -import io.kubernetes.client.openapi.ApiException; -import io.kubernetes.client.openapi.Configuration; -import io.kubernetes.client.openapi.apis.CoreV1Api; -import io.kubernetes.client.openapi.models.V1Namespace; -import io.kubernetes.client.util.Config; -import io.kubernetes.client.util.Watch; -import java.io.IOException; -import java.util.concurrent.TimeUnit; -import okhttp3.OkHttpClient; - -/** 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(); - // infinite timeout - OkHttpClient httpClient = - client.getHttpClient().newBuilder().readTimeout(0, TimeUnit.SECONDS).build(); - client.setHttpClient(httpClient); - Configuration.setDefaultApiClient(client); - - CoreV1Api api = new CoreV1Api(); - - Watch watch = - Watch.createWatch( - client, - api.listNamespaceCall( - null, null, null, null, null, 5, null, null, null, Boolean.TRUE, null), - new TypeToken>() {}.getType()); - - try { - for (Watch.Response item : watch) { - System.out.printf("%s : %s%n", item.type, item.object.getMetadata().getName()); - } - } finally { - watch.close(); - } - } -} diff --git a/examples/examples-release-17/src/main/java/io/kubernetes/client/examples/WebSocketsExample.java b/examples/examples-release-17/src/main/java/io/kubernetes/client/examples/WebSocketsExample.java deleted file mode 100644 index e1f54dcd07..0000000000 --- a/examples/examples-release-17/src/main/java/io/kubernetes/client/examples/WebSocketsExample.java +++ /dev/null @@ -1,74 +0,0 @@ -/* -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.openapi.ApiClient; -import io.kubernetes.client.openapi.ApiException; -import io.kubernetes.client.util.Config; -import io.kubernetes.client.util.WebSockets; -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStream; -import java.io.Reader; -import okhttp3.WebSocket; - -/** - * 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 - * - *

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() { - private volatile WebSocket socket; - - @Override - public void open(String protocol, WebSocket socket) { - this.socket = socket; - } - - @Override - public void close() {} - - @Override - public void bytesMessage(InputStream is) {} - - @Override - public void failure(Throwable t) { - t.printStackTrace(); - } - - @Override - 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/examples/examples-release-17/src/main/java/io/kubernetes/client/examples/YamlExample.java b/examples/examples-release-17/src/main/java/io/kubernetes/client/examples/YamlExample.java deleted file mode 100644 index 67b5536ab9..0000000000 --- a/examples/examples-release-17/src/main/java/io/kubernetes/client/examples/YamlExample.java +++ /dev/null @@ -1,109 +0,0 @@ -/* -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.custom.IntOrString; -import io.kubernetes.client.openapi.ApiClient; -import io.kubernetes.client.openapi.ApiException; -import io.kubernetes.client.openapi.Configuration; -import io.kubernetes.client.openapi.apis.CoreV1Api; -import io.kubernetes.client.openapi.models.V1DeleteOptions; -import io.kubernetes.client.openapi.models.V1Pod; -import io.kubernetes.client.openapi.models.V1PodBuilder; -import io.kubernetes.client.openapi.models.V1Service; -import io.kubernetes.client.openapi.models.V1ServiceBuilder; -import io.kubernetes.client.openapi.models.V1Status; -import io.kubernetes.client.util.Config; -import io.kubernetes.client.util.Yaml; -import java.io.File; -import java.io.IOException; -import java.util.HashMap; - -/** - * A simple example of how to parse a Kubernetes object. - * - *

Easiest way to run this: mvn exec:java - * -Dexec.mainClass="io.kubernetes.client.examples.YamlExample" - * - *

From inside $REPO_DIR/examples - */ -public class YamlExample { - public static void main(String[] args) throws IOException, ApiException, ClassNotFoundException { - V1Pod pod = - new V1PodBuilder() - .withNewMetadata() - .withName("apod") - .endMetadata() - .withNewSpec() - .addNewContainer() - .withName("www") - .withImage("nginx") - .withNewResources() - .withLimits(new HashMap<>()) - .endResources() - .endContainer() - .endSpec() - .build(); - System.out.println(Yaml.dump(pod)); - - V1Service svc = - new V1ServiceBuilder() - .withNewMetadata() - .withName("aservice") - .endMetadata() - .withNewSpec() - .withSessionAffinity("ClientIP") - .withType("NodePort") - .addNewPort() - .withProtocol("TCP") - .withName("client") - .withPort(8008) - .withNodePort(8080) - .withTargetPort(new IntOrString(8080)) - .endPort() - .endSpec() - .build(); - System.out.println(Yaml.dump(svc)); - - // Read yaml configuration file, and deploy it - ApiClient client = Config.defaultClient(); - Configuration.setDefaultApiClient(client); - - // See issue #474. Not needed at most cases, but it is needed if you are using war - // packging or running this on JUnit. - Yaml.addModelMap("v1", "Service", V1Service.class); - - // Example yaml file can be found in $REPO_DIR/test-svc.yaml - File file = new File("test-svc.yaml"); - V1Service yamlSvc = (V1Service) Yaml.load(file); - - // Deployment and StatefulSet is defined in apps/v1, so you should use AppsV1Api instead of - // CoreV1API - CoreV1Api api = new CoreV1Api(); - V1Service createResult = api.createNamespacedService("default", yamlSvc, null, null, null, null); - - System.out.println(createResult); - - V1Service deleteResult = - api.deleteNamespacedService( - yamlSvc.getMetadata().getName(), - "default", - null, - null, - null, - null, - null, - new V1DeleteOptions()); - System.out.println(deleteResult); - } -} diff --git a/examples/examples-release-17/src/main/resources/application.properties b/examples/examples-release-17/src/main/resources/application.properties deleted file mode 100644 index dc886e5f48..0000000000 --- a/examples/examples-release-17/src/main/resources/application.properties +++ /dev/null @@ -1,2 +0,0 @@ -namespace=airflow -management.endpoints.web.exposure.include=prometheus \ No newline at end of file diff --git a/examples/examples-release-17/src/test/java/io/kubernetes/client/examples/ExampleTest.java b/examples/examples-release-17/src/test/java/io/kubernetes/client/examples/ExampleTest.java deleted file mode 100644 index 5ccccda5af..0000000000 --- a/examples/examples-release-17/src/test/java/io/kubernetes/client/examples/ExampleTest.java +++ /dev/null @@ -1,57 +0,0 @@ -/* -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 static com.github.tomakehurst.wiremock.client.WireMock.aResponse; -import static com.github.tomakehurst.wiremock.client.WireMock.get; -import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; -import static org.junit.jupiter.api.Assertions.assertEquals; - -import com.github.tomakehurst.wiremock.core.WireMockConfiguration; -import com.github.tomakehurst.wiremock.junit5.WireMockExtension; -import io.kubernetes.client.openapi.ApiClient; -import io.kubernetes.client.openapi.ApiException; -import io.kubernetes.client.openapi.Configuration; -import io.kubernetes.client.openapi.apis.CoreV1Api; -import io.kubernetes.client.openapi.models.V1Namespace; -import io.kubernetes.client.openapi.models.V1ObjectMeta; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.RegisterExtension; - -class ExampleTest { - private static final int PORT = 8089; - - @RegisterExtension - static WireMockExtension apiServer = - WireMockExtension.newInstance().options(WireMockConfiguration.options().port(PORT)).build(); - - @Test - void exactUrlOnly() throws ApiException { - ApiClient client = new ApiClient(); - client.setBasePath("http://localhost:" + PORT); - Configuration.setDefaultApiClient(client); - - V1Namespace ns1 = new V1Namespace().metadata(new V1ObjectMeta().name("name")); - - apiServer.stubFor( - get(urlEqualTo("/api/v1/namespaces/name")) - .willReturn( - aResponse() - .withHeader("Content-Type", "application/json") - .withBody(client.getJSON().serialize(ns1)))); - - CoreV1Api api = new CoreV1Api(); - V1Namespace ns2 = api.readNamespace("name", null); - assertEquals(ns1, ns2); - } -} diff --git a/examples/examples-release-17/test-svc.yaml b/examples/examples-release-17/test-svc.yaml deleted file mode 100644 index f225bea76f..0000000000 --- a/examples/examples-release-17/test-svc.yaml +++ /dev/null @@ -1,11 +0,0 @@ -apiVersion: v1 -kind: Service -metadata: - name: test-service -spec: - type: ClusterIP - selector: - app: test-service - ports: - - name: port-of-container - port: 8080 \ No newline at end of file diff --git a/examples/examples-release-17/test.yaml b/examples/examples-release-17/test.yaml deleted file mode 100644 index 0b46e57003..0000000000 --- a/examples/examples-release-17/test.yaml +++ /dev/null @@ -1,16 +0,0 @@ -apiVersion: v1 -kind: ReplicationController -metadata: - name: test -spec: - replicas: 1 - template: - metadata: - labels: - app: test - spec: - containers: - - name: test - image: test/examples:1.0 - command: ["/bin/sh","-c"] - args: ["java -jar /examples.jar","while :; do sleep 1; done"] diff --git a/examples/examples-release-18/Dockerfile b/examples/examples-release-18/Dockerfile deleted file mode 100644 index ac90eb1d67..0000000000 --- a/examples/examples-release-18/Dockerfile +++ /dev/null @@ -1,7 +0,0 @@ -FROM openjdk:8-jre - -COPY target/client-java-examples-*-SNAPSHOT-jar-with-dependencies.jar /examples.jar - -CMD ["java", "-jar", "/examples.jar"] - - diff --git a/examples/examples-release-18/README.md b/examples/examples-release-18/README.md deleted file mode 100644 index 80c34ea272..0000000000 --- a/examples/examples-release-18/README.md +++ /dev/null @@ -1,13 +0,0 @@ -# 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" -``` - diff --git a/examples/examples-release-18/createPod.sh b/examples/examples-release-18/createPod.sh deleted file mode 100755 index 18a9841317..0000000000 --- a/examples/examples-release-18/createPod.sh +++ /dev/null @@ -1,26 +0,0 @@ -#!/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 diff --git a/examples/examples-release-18/pom.xml b/examples/examples-release-18/pom.xml deleted file mode 100644 index 44c76a7f75..0000000000 --- a/examples/examples-release-18/pom.xml +++ /dev/null @@ -1,94 +0,0 @@ - - 4.0.0 - - client-java-examples-release-18 - client-java-examples-release-18 - io.kubernetes - 25.0.0-SNAPSHOT - - - - - io.kubernetes - client-java-api - 18.0.1 - - - io.kubernetes - client-java - 18.0.1 - - - io.kubernetes - client-java-extended - 18.0.1 - - - io.kubernetes - client-java-spring-integration - 18.0.1 - - - io.kubernetes - client-java-proto - 18.0.1 - - - commons-cli - commons-cli - 1.10.0 - - - io.kubernetes - client-java-cert-manager-models - 10.0.1 - - - io.kubernetes - client-java-prometheus-operator-models - 10.0.1 - - - - org.junit.jupiter - junit-jupiter - ${junit-jupiter.version} - test - - - org.wiremock - wiremock - 3.13.1 - test - - - - - - - com.diffplug.spotless - spotless-maven-plugin - 2.46.1 - - - org.sonatype.plugins - nexus-staging-maven-plugin - true - - true - - - - org.apache.maven.plugins - maven-deploy-plugin - - true - - - - - - 5.13.4 - 3.5.4 - - \ No newline at end of file diff --git a/examples/examples-release-18/src/main/java/io/kubernetes/client/examples/AttachExample.java b/examples/examples-release-18/src/main/java/io/kubernetes/client/examples/AttachExample.java deleted file mode 100644 index 7f753b8d8f..0000000000 --- a/examples/examples-release-18/src/main/java/io/kubernetes/client/examples/AttachExample.java +++ /dev/null @@ -1,77 +0,0 @@ -/* -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 - * - *

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); - - 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); - } -} diff --git a/examples/examples-release-18/src/main/java/io/kubernetes/client/examples/CertManagerExample.java b/examples/examples-release-18/src/main/java/io/kubernetes/client/examples/CertManagerExample.java deleted file mode 100644 index b616a18ee9..0000000000 --- a/examples/examples-release-18/src/main/java/io/kubernetes/client/examples/CertManagerExample.java +++ /dev/null @@ -1,45 +0,0 @@ -/* -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.cert.manager.models.V1alpha2IssuerSpecSelfSigned; -import io.cert.manager.models.V1beta1Issuer; -import io.cert.manager.models.V1beta1IssuerList; -import io.cert.manager.models.V1beta1IssuerSpec; -import io.kubernetes.client.openapi.models.V1ObjectMeta; -import io.kubernetes.client.util.ClientBuilder; -import io.kubernetes.client.util.generic.GenericKubernetesApi; -import java.io.IOException; - -/** - * This sample creates a self signed issuer "self-signed-issuer" in default namespace on a - * Kubernetes cluster where cert-manager is installed - */ -public class CertManagerExample { - public static void main(String[] args) throws IOException { - GenericKubernetesApi issuerApi = - new GenericKubernetesApi<>( - V1beta1Issuer.class, - V1beta1IssuerList.class, - "cert-manager.io", - "v1beta1", - "issuers", - ClientBuilder.defaultClient()); - issuerApi.create( - new V1beta1Issuer() - .metadata(new V1ObjectMeta().namespace("default").name("self-signed-issuer")) - .kind("Issuer") - .apiVersion("cert-manager.io/v1beta1") - .spec(new V1beta1IssuerSpec().selfSigned(new V1alpha2IssuerSpecSelfSigned()))); - } -} diff --git a/examples/examples-release-18/src/main/java/io/kubernetes/client/examples/ControllerExample.java b/examples/examples-release-18/src/main/java/io/kubernetes/client/examples/ControllerExample.java deleted file mode 100644 index 4fe2969a3d..0000000000 --- a/examples/examples-release-18/src/main/java/io/kubernetes/client/examples/ControllerExample.java +++ /dev/null @@ -1,163 +0,0 @@ -/* -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.extended.controller.Controller; -import io.kubernetes.client.extended.controller.ControllerManager; -import io.kubernetes.client.extended.controller.LeaderElectingController; -import io.kubernetes.client.extended.controller.builder.ControllerBuilder; -import io.kubernetes.client.extended.controller.reconciler.Reconciler; -import io.kubernetes.client.extended.controller.reconciler.Request; -import io.kubernetes.client.extended.controller.reconciler.Result; -import io.kubernetes.client.extended.event.EventType; -import io.kubernetes.client.extended.event.legacy.EventBroadcaster; -import io.kubernetes.client.extended.event.legacy.EventRecorder; -import io.kubernetes.client.extended.event.legacy.LegacyEventBroadcaster; -import io.kubernetes.client.extended.leaderelection.LeaderElectionConfig; -import io.kubernetes.client.extended.leaderelection.LeaderElector; -import io.kubernetes.client.extended.leaderelection.resourcelock.EndpointsLock; -import io.kubernetes.client.informer.SharedIndexInformer; -import io.kubernetes.client.informer.SharedInformerFactory; -import io.kubernetes.client.informer.cache.Lister; -import io.kubernetes.client.openapi.ApiClient; -import io.kubernetes.client.openapi.apis.CoreV1Api; -import io.kubernetes.client.openapi.models.V1EventSource; -import io.kubernetes.client.openapi.models.V1Node; -import io.kubernetes.client.openapi.models.V1NodeList; -import io.kubernetes.client.util.CallGeneratorParams; -import java.io.IOException; -import java.time.Duration; -import java.util.concurrent.TimeUnit; -import okhttp3.OkHttpClient; - -public class ControllerExample { - public static void main(String[] args) throws IOException { - - CoreV1Api coreV1Api = new CoreV1Api(); - ApiClient apiClient = coreV1Api.getApiClient(); - OkHttpClient httpClient = - apiClient.getHttpClient().newBuilder().readTimeout(0, TimeUnit.SECONDS).build(); - apiClient.setHttpClient(httpClient); - - // instantiating an informer-factory, and there should be only one informer-factory - // globally. - SharedInformerFactory informerFactory = new SharedInformerFactory(); - // registering node-informer into the informer-factory. - SharedIndexInformer nodeInformer = - informerFactory.sharedIndexInformerFor( - (CallGeneratorParams params) -> { - return coreV1Api.listNodeCall( - null, - null, - null, - null, - null, - null, - params.resourceVersion, - null, - params.timeoutSeconds, - params.watch, - null); - }, - V1Node.class, - V1NodeList.class); - informerFactory.startAllRegisteredInformers(); - - EventBroadcaster eventBroadcaster = new LegacyEventBroadcaster(coreV1Api); - - // nodeReconciler prints node information on events - NodePrintingReconciler nodeReconciler = - new NodePrintingReconciler( - nodeInformer, - eventBroadcaster.newRecorder( - new V1EventSource().host("localhost").component("node-printer"))); - - // Use builder library to construct a default controller. - Controller controller = - ControllerBuilder.defaultBuilder(informerFactory) - .watch( - (workQueue) -> - ControllerBuilder.controllerWatchBuilder(V1Node.class, workQueue) - .withWorkQueueKeyFunc( - (V1Node node) -> - new Request(node.getMetadata().getName())) // optional, default to - .withOnAddFilter( - (V1Node createdNode) -> - createdNode - .getMetadata() - .getName() - .startsWith("docker-")) // optional, set onAdd filter - .withOnUpdateFilter( - (V1Node oldNode, V1Node newNode) -> - newNode - .getMetadata() - .getName() - .startsWith("docker-")) // optional, set onUpdate filter - .withOnDeleteFilter( - (V1Node deletedNode, Boolean stateUnknown) -> - deletedNode - .getMetadata() - .getName() - .startsWith("docker-")) // optional, set onDelete filter - .build()) - .withReconciler(nodeReconciler) // required, set the actual reconciler - .withName("node-printing-controller") // optional, set name for controller - .withWorkerCount(4) // optional, set worker thread count - .withReadyFunc(nodeInformer::hasSynced) // optional, only starts controller when the - // cache has synced up - .build(); - - // Use builder library to manage one or multiple controllers. - ControllerManager controllerManager = - ControllerBuilder.controllerManagerBuilder(informerFactory) - .addController(controller) - .build(); - - LeaderElectingController leaderElectingController = - new LeaderElectingController( - new LeaderElector( - new LeaderElectionConfig( - new EndpointsLock("kube-system", "leader-election", "foo"), - Duration.ofMillis(10000), - Duration.ofMillis(8000), - Duration.ofMillis(5000))), - controllerManager); - - leaderElectingController.run(); - } - - static class NodePrintingReconciler implements Reconciler { - - private Lister nodeLister; - private EventRecorder eventRecorder; - - public NodePrintingReconciler( - SharedIndexInformer nodeInformer, EventRecorder recorder) { - this.nodeLister = new Lister<>(nodeInformer.getIndexer()); - this.eventRecorder = recorder; - } - - @Override - public Result reconcile(Request request) { - V1Node node = this.nodeLister.get(request.getName()); - System.out.println("triggered reconciling " + node.getMetadata().getName()); - this.eventRecorder.event( - node, - EventType.Normal, - "Print Node", - "Successfully printed %s", - node.getMetadata().getName()); - return new Result(false); - } - } -} diff --git a/examples/examples-release-18/src/main/java/io/kubernetes/client/examples/CopyExample.java b/examples/examples-release-18/src/main/java/io/kubernetes/client/examples/CopyExample.java deleted file mode 100644 index bbb6575676..0000000000 --- a/examples/examples-release-18/src/main/java/io/kubernetes/client/examples/CopyExample.java +++ /dev/null @@ -1,51 +0,0 @@ -/* -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.Copy; -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 io.kubernetes.client.util.exception.CopyNotSupportedException; -import java.io.IOException; -import java.io.InputStream; -import java.nio.file.Paths; - -/** - * A simple example of how to use the Java API - * - *

Easiest way to run this: mvn exec:java - * -Dexec.mainClass="io.kubernetes.client.examples.CopyExample" - * - *

From inside $REPO_DIR/examples - */ -public class CopyExample { - public static void main(String[] args) - throws IOException, ApiException, InterruptedException, CopyNotSupportedException { - String podName = "kube-addon-manager-minikube"; - String namespace = "kube-system"; - - ApiClient client = Config.defaultClient(); - Configuration.setDefaultApiClient(client); - - Copy copy = new Copy(); - InputStream dataStream = copy.copyFileFromPod(namespace, podName, "/etc/motd"); - Streams.copy(dataStream, System.out); - - copy.copyDirectoryFromPod(namespace, podName, null, "/etc", Paths.get("/tmp/etc")); - - System.out.println("Done!"); - } -} diff --git a/examples/examples-release-18/src/main/java/io/kubernetes/client/examples/DeployRolloutRestartExample.java b/examples/examples-release-18/src/main/java/io/kubernetes/client/examples/DeployRolloutRestartExample.java deleted file mode 100644 index 42a2524f7b..0000000000 --- a/examples/examples-release-18/src/main/java/io/kubernetes/client/examples/DeployRolloutRestartExample.java +++ /dev/null @@ -1,140 +0,0 @@ -/* -Copyright 2022 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.custom.V1Patch; -import io.kubernetes.client.openapi.ApiClient; -import io.kubernetes.client.openapi.ApiException; -import io.kubernetes.client.openapi.Configuration; -import io.kubernetes.client.openapi.apis.AppsV1Api; -import io.kubernetes.client.openapi.models.V1Container; -import io.kubernetes.client.openapi.models.V1Deployment; -import io.kubernetes.client.openapi.models.V1DeploymentBuilder; -import io.kubernetes.client.openapi.models.V1DeploymentSpec; -import io.kubernetes.client.openapi.models.V1LabelSelector; -import io.kubernetes.client.openapi.models.V1ObjectMeta; -import io.kubernetes.client.openapi.models.V1PodSpec; -import io.kubernetes.client.openapi.models.V1PodTemplateSpec; -import io.kubernetes.client.util.Config; -import io.kubernetes.client.util.PatchUtils; -import io.kubernetes.client.util.wait.Wait; -import java.io.IOException; -import java.time.Duration; -import java.time.LocalDateTime; -import java.util.Collections; - -public class DeployRolloutRestartExample { - public static void main(String[] args) throws IOException, ApiException { - ApiClient client = Config.defaultClient(); - Configuration.setDefaultApiClient(client); - AppsV1Api appsV1Api = new AppsV1Api(client); - - String deploymentName = "example-nginx"; - String imageName = "nginx:1.21.6"; - String namespace = "default"; - - // Create an example deployment - V1DeploymentBuilder deploymentBuilder = - new V1DeploymentBuilder() - .withApiVersion("apps/v1") - .withKind("Deployment") - .withMetadata(new V1ObjectMeta().name(deploymentName).namespace(namespace)) - .withSpec( - new V1DeploymentSpec() - .replicas(1) - .selector(new V1LabelSelector().putMatchLabelsItem("name", deploymentName)) - .template( - new V1PodTemplateSpec() - .metadata(new V1ObjectMeta().putLabelsItem("name", deploymentName)) - .spec( - new V1PodSpec() - .containers( - Collections.singletonList( - new V1Container() - .name(deploymentName) - .image(imageName)))))); - appsV1Api.createNamespacedDeployment( - namespace, deploymentBuilder.build(), null, null, null, null); - - // Wait until example deployment is ready - Wait.poll( - Duration.ofSeconds(3), - Duration.ofSeconds(60), - () -> { - try { - System.out.println("Waiting until example deployment is ready..."); - return appsV1Api - .readNamespacedDeployment(deploymentName, namespace, null) - .getStatus() - .getReadyReplicas() - > 0; - } catch (ApiException e) { - e.printStackTrace(); - return false; - } - }); - System.out.println("Created example deployment!"); - - // Trigger a rollout restart of the example deployment - V1Deployment runningDeployment = - appsV1Api.readNamespacedDeployment(deploymentName, namespace, null); - - // Explicitly set "restartedAt" annotation with current date/time to trigger rollout when patch - // is applied - runningDeployment - .getSpec() - .getTemplate() - .getMetadata() - .putAnnotationsItem("kubectl.kubernetes.io/restartedAt", LocalDateTime.now().toString()); - try { - String deploymentJson = client.getJSON().serialize(runningDeployment); - - PatchUtils.patch( - V1Deployment.class, - () -> - appsV1Api.patchNamespacedDeploymentCall( - deploymentName, - namespace, - new V1Patch(deploymentJson), - null, - null, - "kubectl-rollout", - null, - null, - null), - V1Patch.PATCH_FORMAT_STRATEGIC_MERGE_PATCH, - client); - - // Wait until deployment has stabilized after rollout restart - Wait.poll( - Duration.ofSeconds(3), - Duration.ofSeconds(60), - () -> { - try { - System.out.println("Waiting until example deployment restarted successfully..."); - return appsV1Api - .readNamespacedDeployment(deploymentName, namespace, null) - .getStatus() - .getReadyReplicas() - > 0; - } catch (ApiException e) { - e.printStackTrace(); - return false; - } - }); - System.out.println("Example deployment restarted successfully!"); - } catch (ApiException e) { - e.printStackTrace(); - } - } -} diff --git a/examples/examples-release-18/src/main/java/io/kubernetes/client/examples/DynamicClientExample.java b/examples/examples-release-18/src/main/java/io/kubernetes/client/examples/DynamicClientExample.java deleted file mode 100644 index b8cb04616d..0000000000 --- a/examples/examples-release-18/src/main/java/io/kubernetes/client/examples/DynamicClientExample.java +++ /dev/null @@ -1,42 +0,0 @@ -/* -Copyright 2021 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.openapi.ApiClient; -import io.kubernetes.client.openapi.ApiException; -import io.kubernetes.client.util.ClientBuilder; -import io.kubernetes.client.util.generic.dynamic.DynamicKubernetesApi; -import io.kubernetes.client.util.generic.dynamic.DynamicKubernetesObject; -import java.io.IOException; - -public class DynamicClientExample { - - public static void main(String[] args) throws IOException, ApiException { - - ApiClient apiClient = ClientBuilder.standard().build(); - - // retrieving the latest state of the default namespace - DynamicKubernetesApi dynamicApi = new DynamicKubernetesApi("", "v1", "namespaces", apiClient); - DynamicKubernetesObject defaultNamespace = - dynamicApi.get("default").throwsApiException().getObject(); - - // attaching a "foo=bar" label to the default namespace - defaultNamespace.setMetadata(defaultNamespace.getMetadata().putLabelsItem("foo", "bar")); - DynamicKubernetesObject updatedDefaultNamespace = - dynamicApi.update(defaultNamespace).throwsApiException().getObject(); - - System.out.println(updatedDefaultNamespace); - - apiClient.getHttpClient().connectionPool().evictAll(); - } -} diff --git a/examples/examples-release-18/src/main/java/io/kubernetes/client/examples/Example.java b/examples/examples-release-18/src/main/java/io/kubernetes/client/examples/Example.java deleted file mode 100644 index 2c2d1d737e..0000000000 --- a/examples/examples-release-18/src/main/java/io/kubernetes/client/examples/Example.java +++ /dev/null @@ -1,44 +0,0 @@ -/* -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.openapi.ApiClient; -import io.kubernetes.client.openapi.ApiException; -import io.kubernetes.client.openapi.Configuration; -import io.kubernetes.client.openapi.apis.CoreV1Api; -import io.kubernetes.client.openapi.models.V1Pod; -import io.kubernetes.client.openapi.models.V1PodList; -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.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); - - CoreV1Api api = new CoreV1Api(); - V1PodList list = - api.listPodForAllNamespaces(null, null, null, null, null, null, null, null, null, null); - for (V1Pod item : list.getItems()) { - System.out.println(item.getMetadata().getName()); - } - } -} diff --git a/examples/examples-release-18/src/main/java/io/kubernetes/client/examples/ExecExample.java b/examples/examples-release-18/src/main/java/io/kubernetes/client/examples/ExecExample.java deleted file mode 100644 index acea8e815a..0000000000 --- a/examples/examples-release-18/src/main/java/io/kubernetes/client/examples/ExecExample.java +++ /dev/null @@ -1,96 +0,0 @@ -/* -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.Exec; -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.IOException; -import org.apache.commons.cli.CommandLine; -import org.apache.commons.cli.CommandLineParser; -import org.apache.commons.cli.DefaultParser; -import org.apache.commons.cli.Option; -import org.apache.commons.cli.Options; -import org.apache.commons.cli.ParseException; - -/** - * A simple example of how to use the Java API - * - *

Easiest way to run this: mvn exec:java - * -Dexec.mainClass="io.kubernetes.client.examples.ExecExample" - * - *

From inside $REPO_DIR/examples - */ -public class ExecExample { - public static void main(String[] args) - throws IOException, ApiException, InterruptedException, ParseException { - final Options options = new Options(); - options.addOption(new Option("p", "pod", true, "The name of the pod")); - options.addOption(new Option("n", "namespace", true, "The namespace of the pod")); - - CommandLineParser parser = new DefaultParser(); - CommandLine cmd = parser.parse(options, args); - - String podName = cmd.getOptionValue("p", "nginx-dbddb74b8-s4cx5"); - String namespace = cmd.getOptionValue("n", "default"); - args = cmd.getArgs(); - - ApiClient client = Config.defaultClient(); - Configuration.setDefaultApiClient(client); - - Exec exec = new Exec(); - boolean tty = System.console() != null; - // final Process proc = exec.exec("default", "nginx-4217019353-k5sn9", new String[] - // {"sh", "-c", "echo foo"}, true, tty); - final Process proc = - exec.exec(namespace, podName, args.length == 0 ? new String[] {"sh"} : args, true, tty); - - Thread in = - new Thread( - new Runnable() { - public void run() { - try { - Streams.copy(System.in, proc.getOutputStream()); - } catch (IOException ex) { - ex.printStackTrace(); - } - } - }); - in.start(); - - Thread out = - new Thread( - new Runnable() { - public void run() { - try { - Streams.copy(proc.getInputStream(), System.out); - } catch (IOException ex) { - ex.printStackTrace(); - } - } - }); - out.start(); - - proc.waitFor(); - - // wait for any last output; no need to wait for input thread - out.join(); - - proc.destroy(); - - System.exit(proc.exitValue()); - } -} diff --git a/examples/examples-release-18/src/main/java/io/kubernetes/client/examples/ExpandedExample.java b/examples/examples-release-18/src/main/java/io/kubernetes/client/examples/ExpandedExample.java deleted file mode 100644 index 68cf868fa8..0000000000 --- a/examples/examples-release-18/src/main/java/io/kubernetes/client/examples/ExpandedExample.java +++ /dev/null @@ -1,274 +0,0 @@ -/* -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.openapi.ApiClient; -import io.kubernetes.client.openapi.ApiException; -import io.kubernetes.client.openapi.Configuration; -import io.kubernetes.client.openapi.apis.AppsV1Api; -import io.kubernetes.client.openapi.apis.CoreV1Api; -import io.kubernetes.client.openapi.models.V1Deployment; -import io.kubernetes.client.openapi.models.V1DeploymentList; -import io.kubernetes.client.openapi.models.V1DeploymentSpec; -import io.kubernetes.client.openapi.models.V1NamespaceList; -import io.kubernetes.client.openapi.models.V1PodList; -import io.kubernetes.client.openapi.models.V1ServiceList; -import io.kubernetes.client.util.Config; -import java.io.IOException; -import java.util.List; -import java.util.Optional; -import java.util.stream.Collectors; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * A simple example of how to use the Java API - * - *

Easiest way to run this: mvn exec:java - * -Dexec.mainClass="io.kubernetes.client.examples.ExpandedExample" - * - *

From inside $REPO_DIR/examples - */ -public class ExpandedExample { - - private static CoreV1Api COREV1_API; - private static final String DEFAULT_NAME_SPACE = "default"; - private static final Integer TIME_OUT_VALUE = 180; - private static final Logger LOGGER = LoggerFactory.getLogger(ExpandedExample.class); - - /** - * Main method - * - * @param args - */ - public static void main(String[] args) { - try { - ApiClient client = Config.defaultClient(); - // To change the context of k8s cluster, you can use - // io.kubernetes.client.util.KubeConfig - Configuration.setDefaultApiClient(client); - COREV1_API = new CoreV1Api(client); - - // ScaleUp/ScaleDown the Deployment pod - // Please change the name of Deployment? - System.out.println("----- Scale Deployment Start -----"); - scaleDeployment("account-service", 5); - - // List all of the namaspaces and pods - List nameSpaces = getAllNameSpaces(); - nameSpaces.stream() - .forEach( - namespace -> { - try { - System.out.println("----- " + namespace + " -----"); - getNamespacedPod(namespace).stream().forEach(System.out::println); - } catch (ApiException ex) { - LOGGER.warn("Couldn't get the pods in namespace:{}", namespace, ex); - } - }); - - // Print all of the Services - System.out.println("----- Print list all Services Start -----"); - List services = getServices(); - services.stream().forEach(System.out::println); - System.out.println("----- Print list all Services End -----"); - - // Print log of specific pod. In this example show the first pod logs. - System.out.println("----- Print Log of Specific Pod Start -----"); - String firstPodName = getPods().get(0); - printLog(DEFAULT_NAME_SPACE, firstPodName); - System.out.println("----- Print Log of Specific Pod End -----"); - } catch (ApiException | IOException ex) { - LOGGER.warn("Exception had occured ", ex); - } - } - - /** - * Get all namespaces in k8s cluster - * - * @return - * @throws ApiException - */ - public static List getAllNameSpaces() throws ApiException { - V1NamespaceList listNamespace = - COREV1_API.listNamespace( - null, null, null, null, null, null, null, null, null, null); - List list = - listNamespace.getItems().stream() - .map(v1Namespace -> v1Namespace.getMetadata().getName()) - .collect(Collectors.toList()); - return list; - } - - /** - * List all pod names in all namespaces in k8s cluster - * - * @return - * @throws ApiException - */ - public static List getPods() throws ApiException { - V1PodList v1podList = - COREV1_API.listPodForAllNamespaces( - null, null, null, null, null, null, null, null, null, null); - List podList = - v1podList.getItems().stream() - .map(v1Pod -> v1Pod.getMetadata().getName()) - .collect(Collectors.toList()); - return podList; - } - - /** - * List all pod in the default namespace - * - * @return - * @throws ApiException - */ - public static List getNamespacedPod() throws ApiException { - return getNamespacedPod(DEFAULT_NAME_SPACE, null); - } - - /** - * List pod in specific namespace - * - * @param namespace - * @return - * @throws ApiException - */ - public static List getNamespacedPod(String namespace) throws ApiException { - return getNamespacedPod(namespace, null); - } - - /** - * List pod in specific namespace with label - * - * @param namespace - * @param label - * @return - * @throws ApiException - */ - public static List getNamespacedPod(String namespace, String label) throws ApiException { - V1PodList listNamespacedPod = - COREV1_API.listNamespacedPod( - namespace, - null, - null, - null, - null, - label, - null, - null, - null, - TIME_OUT_VALUE, - Boolean.FALSE); - List listPods = - listNamespacedPod.getItems().stream() - .map(v1pod -> v1pod.getMetadata().getName()) - .collect(Collectors.toList()); - return listPods; - } - - /** - * List all Services in default namespace - * - * @return - * @throws ApiException - */ - public static List getServices() throws ApiException { - V1ServiceList listNamespacedService = - COREV1_API.listNamespacedService( - DEFAULT_NAME_SPACE, - null, - null, - null, - null, - null, - null, - null, - null, - TIME_OUT_VALUE, - Boolean.FALSE); - return listNamespacedService.getItems().stream() - .map(v1service -> v1service.getMetadata().getName()) - .collect(Collectors.toList()); - } - - /** - * Scale up/down the number of pod in Deployment - * - * @param deploymentName - * @param numberOfReplicas - * @throws ApiException - */ - public static void scaleDeployment(String deploymentName, int numberOfReplicas) - throws ApiException { - AppsV1Api appsV1Api = new AppsV1Api(); - appsV1Api.setApiClient(COREV1_API.getApiClient()); - V1DeploymentList listNamespacedDeployment = - appsV1Api.listNamespacedDeployment( - DEFAULT_NAME_SPACE, - null, - null, - null, - null, - null, - null, - null, - null, - null, - Boolean.FALSE); - - List appsV1DeploymentItems = listNamespacedDeployment.getItems(); - Optional findedDeployment = - appsV1DeploymentItems.stream() - .filter( - (V1Deployment deployment) -> - deployment.getMetadata().getName().equals(deploymentName)) - .findFirst(); - findedDeployment.ifPresent( - (V1Deployment deploy) -> { - try { - V1DeploymentSpec newSpec = deploy.getSpec().replicas(numberOfReplicas); - V1Deployment newDeploy = deploy.spec(newSpec); - appsV1Api.replaceNamespacedDeployment( - deploymentName, DEFAULT_NAME_SPACE, newDeploy, null, null, null, null); - } catch (ApiException ex) { - LOGGER.warn("Scale the pod failed for Deployment:{}", deploymentName, ex); - } - }); - } - - /** - * Print out the Log for specific Pods - * - * @param namespace - * @param podName - * @throws ApiException - */ - public static void printLog(String namespace, String podName) throws ApiException { - // https://github.com/kubernetes-client/java/blob/master/kubernetes/docs/CoreV1Api.md#readNamespacedPodLog - String readNamespacedPodLog = - COREV1_API.readNamespacedPodLog( - podName, - namespace, - null, - Boolean.FALSE, - null, - Integer.MAX_VALUE, - null, - Boolean.FALSE, - Integer.MAX_VALUE, - 40, - Boolean.FALSE); - System.out.println(readNamespacedPodLog); - } -} diff --git a/examples/examples-release-18/src/main/java/io/kubernetes/client/examples/FluentExample.java b/examples/examples-release-18/src/main/java/io/kubernetes/client/examples/FluentExample.java deleted file mode 100644 index 8e48cc51b3..0000000000 --- a/examples/examples-release-18/src/main/java/io/kubernetes/client/examples/FluentExample.java +++ /dev/null @@ -1,75 +0,0 @@ -/* -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.openapi.ApiClient; -import io.kubernetes.client.openapi.ApiException; -import io.kubernetes.client.openapi.Configuration; -import io.kubernetes.client.openapi.apis.CoreV1Api; -import io.kubernetes.client.openapi.models.V1Container; -import io.kubernetes.client.openapi.models.V1ObjectMeta; -import io.kubernetes.client.openapi.models.V1Pod; -import io.kubernetes.client.openapi.models.V1PodBuilder; -import io.kubernetes.client.openapi.models.V1PodList; -import io.kubernetes.client.openapi.models.V1PodSpec; -import io.kubernetes.client.util.Config; -import java.io.IOException; -import java.util.Arrays; - -/** - * A simple example of how to use the Java API - * - *

Easiest way to run this: mvn exec:java - * -Dexec.mainClass="io.kubernetes.client.examples.FluentExample" - * - *

From inside $REPO_DIR/examples - */ -public class FluentExample { - public static void main(String[] args) throws IOException, ApiException { - ApiClient client = Config.defaultClient(); - Configuration.setDefaultApiClient(client); - - CoreV1Api api = new CoreV1Api(); - - V1Pod pod = - new V1PodBuilder() - .withNewMetadata() - .withName("apod") - .endMetadata() - .withNewSpec() - .addNewContainer() - .withName("www") - .withImage("nginx") - .endContainer() - .endSpec() - .build(); - - api.createNamespacedPod("default", pod, null, null, null, null); - - V1Pod pod2 = - new V1Pod() - .metadata(new V1ObjectMeta().name("anotherpod")) - .spec( - new V1PodSpec() - .containers(Arrays.asList(new V1Container().name("www").image("nginx")))); - - api.createNamespacedPod("default", pod2, null, null, null, null); - - V1PodList list = - api.listNamespacedPod( - "default", null, null, null, null, null, null, null, null, null, null); - for (V1Pod item : list.getItems()) { - System.out.println(item.getMetadata().getName()); - } - } -} diff --git a/examples/examples-release-18/src/main/java/io/kubernetes/client/examples/GenericClientExample.java b/examples/examples-release-18/src/main/java/io/kubernetes/client/examples/GenericClientExample.java deleted file mode 100644 index ddfb1243b8..0000000000 --- a/examples/examples-release-18/src/main/java/io/kubernetes/client/examples/GenericClientExample.java +++ /dev/null @@ -1,63 +0,0 @@ -/* -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.custom.V1Patch; -import io.kubernetes.client.openapi.ApiClient; -import io.kubernetes.client.openapi.models.V1Container; -import io.kubernetes.client.openapi.models.V1ObjectMeta; -import io.kubernetes.client.openapi.models.V1Pod; -import io.kubernetes.client.openapi.models.V1PodList; -import io.kubernetes.client.openapi.models.V1PodSpec; -import io.kubernetes.client.util.ClientBuilder; -import io.kubernetes.client.util.generic.GenericKubernetesApi; -import java.util.Arrays; - -public class GenericClientExample { - - public static void main(String[] args) throws Exception { - - // The following codes demonstrates using generic client to manipulate pods - V1Pod pod = - new V1Pod() - .metadata(new V1ObjectMeta().name("foo").namespace("default")) - .spec( - new V1PodSpec() - .containers(Arrays.asList(new V1Container().name("c").image("test")))); - - ApiClient apiClient = ClientBuilder.standard().build(); - GenericKubernetesApi podClient = - new GenericKubernetesApi<>(V1Pod.class, V1PodList.class, "", "v1", "pods", apiClient); - - V1Pod latestPod = podClient.create(pod).throwsApiException().getObject(); - System.out.println("Created!"); - - V1Pod patchedPod = - podClient - .patch( - "default", - "foo", - V1Patch.PATCH_FORMAT_STRATEGIC_MERGE_PATCH, - new V1Patch("{\"metadata\":{\"finalizers\":[\"example.io/foo\"]}}")) - .throwsApiException() - .getObject(); - System.out.println("Patched!"); - - V1Pod deletedPod = podClient.delete("default", "foo").throwsApiException().getObject(); - if (deletedPod != null) { - System.out.println( - "Received after-deletion status of the requested object, will be deleting in background!"); - } - System.out.println("Deleted!"); - } -} diff --git a/examples/examples-release-18/src/main/java/io/kubernetes/client/examples/InClusterClientExample.java b/examples/examples-release-18/src/main/java/io/kubernetes/client/examples/InClusterClientExample.java deleted file mode 100644 index 7ab705b440..0000000000 --- a/examples/examples-release-18/src/main/java/io/kubernetes/client/examples/InClusterClientExample.java +++ /dev/null @@ -1,58 +0,0 @@ -/* -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.openapi.ApiClient; -import io.kubernetes.client.openapi.ApiException; -import io.kubernetes.client.openapi.Configuration; -import io.kubernetes.client.openapi.apis.CoreV1Api; -import io.kubernetes.client.openapi.models.V1Pod; -import io.kubernetes.client.openapi.models.V1PodList; -import io.kubernetes.client.util.ClientBuilder; -import java.io.IOException; - -/** - * A simple example of how to use the Java API inside a kubernetes cluster - * - *

Easiest way to run this: mvn exec:java - * -Dexec.mainClass="io.kubernetes.client.examples.InClusterClientExample" - * - *

From inside $REPO_DIR/examples - */ -public class InClusterClientExample { - public static void main(String[] args) throws IOException, ApiException { - - // loading the in-cluster config, including: - // 1. service-account CA - // 2. service-account bearer-token - // 3. service-account namespace - // 4. master endpoints(ip, port) from pre-set environment variables - ApiClient client = ClientBuilder.cluster().build(); - - // if you prefer not to refresh service account token, please use: - // ApiClient client = ClientBuilder.oldCluster().build(); - - // set the global default api-client to the in-cluster one from above - Configuration.setDefaultApiClient(client); - - // the CoreV1Api loads default api-client from global configuration. - CoreV1Api api = new CoreV1Api(); - - // invokes the CoreV1Api client - V1PodList list = - api.listPodForAllNamespaces(null, null, null, null, null, null, null, null, null, null); - for (V1Pod item : list.getItems()) { - System.out.println(item.getMetadata().getName()); - } - } -} diff --git a/examples/examples-release-18/src/main/java/io/kubernetes/client/examples/InformerExample.java b/examples/examples-release-18/src/main/java/io/kubernetes/client/examples/InformerExample.java deleted file mode 100644 index e8bef1ce71..0000000000 --- a/examples/examples-release-18/src/main/java/io/kubernetes/client/examples/InformerExample.java +++ /dev/null @@ -1,106 +0,0 @@ -/* -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.informer.ResourceEventHandler; -import io.kubernetes.client.informer.SharedIndexInformer; -import io.kubernetes.client.informer.SharedInformerFactory; -import io.kubernetes.client.informer.cache.Lister; -import io.kubernetes.client.openapi.ApiClient; -import io.kubernetes.client.openapi.apis.CoreV1Api; -import io.kubernetes.client.openapi.models.V1Node; -import io.kubernetes.client.openapi.models.V1NodeList; -import io.kubernetes.client.openapi.models.V1ObjectMeta; -import io.kubernetes.client.util.CallGeneratorParams; -import java.util.concurrent.TimeUnit; -import okhttp3.OkHttpClient; - -/** - * A simple example of how to use the Java API - * - *

Easiest way to run this: mvn exec:java - * -Dexec.mainClass="io.kubernetes.client.examples.InformerExample" - * - *

From inside $REPO_DIR/examples - */ -public class InformerExample { - public static void main(String[] args) throws Exception { - CoreV1Api coreV1Api = new CoreV1Api(); - ApiClient apiClient = coreV1Api.getApiClient(); - OkHttpClient httpClient = - apiClient.getHttpClient().newBuilder().readTimeout(0, TimeUnit.SECONDS).build(); - apiClient.setHttpClient(httpClient); - - SharedInformerFactory factory = new SharedInformerFactory(apiClient); - - // Node informer - SharedIndexInformer nodeInformer = - factory.sharedIndexInformerFor( - // **NOTE**: - // The following "CallGeneratorParams" lambda merely generates a stateless - // HTTPs requests, the effective apiClient is the one specified when constructing - // the informer-factory. - (CallGeneratorParams params) -> { - return coreV1Api.listNodeCall( - null, - null, - null, - null, - null, - null, - params.resourceVersion, - null, - params.timeoutSeconds, - params.watch, - null); - }, - V1Node.class, - V1NodeList.class); - - nodeInformer.addEventHandler( - new ResourceEventHandler() { - @Override - public void onAdd(V1Node node) { - System.out.printf("%s node added!\n", node.getMetadata().getName()); - } - - @Override - public void onUpdate(V1Node oldNode, V1Node newNode) { - System.out.printf( - "%s => %s node updated!\n", - oldNode.getMetadata().getName(), newNode.getMetadata().getName()); - } - - @Override - public void onDelete(V1Node node, boolean deletedFinalStateUnknown) { - System.out.printf("%s node deleted!\n", node.getMetadata().getName()); - } - }); - - factory.startAllRegisteredInformers(); - - V1Node nodeToCreate = new V1Node(); - V1ObjectMeta metadata = new V1ObjectMeta(); - metadata.setName("noxu"); - nodeToCreate.setMetadata(metadata); - V1Node createdNode = coreV1Api.createNode(nodeToCreate, null, null, null, null); - Thread.sleep(3000); - - Lister nodeLister = new Lister(nodeInformer.getIndexer()); - V1Node node = nodeLister.get("noxu"); - System.out.printf("noxu created! %s\n", node.getMetadata().getCreationTimestamp()); - factory.stopAllRegisteredInformers(); - Thread.sleep(3000); - System.out.println("informer stopped.."); - } -} diff --git a/examples/examples-release-18/src/main/java/io/kubernetes/client/examples/KubeConfigFileClientExample.java b/examples/examples-release-18/src/main/java/io/kubernetes/client/examples/KubeConfigFileClientExample.java deleted file mode 100644 index 95c94a1e80..0000000000 --- a/examples/examples-release-18/src/main/java/io/kubernetes/client/examples/KubeConfigFileClientExample.java +++ /dev/null @@ -1,58 +0,0 @@ -/* -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.openapi.ApiClient; -import io.kubernetes.client.openapi.ApiException; -import io.kubernetes.client.openapi.Configuration; -import io.kubernetes.client.openapi.apis.CoreV1Api; -import io.kubernetes.client.openapi.models.V1Pod; -import io.kubernetes.client.openapi.models.V1PodList; -import io.kubernetes.client.util.ClientBuilder; -import io.kubernetes.client.util.KubeConfig; -import java.io.FileReader; -import java.io.IOException; - -/** - * A simple example of how to use the Java API from an application outside a kubernetes cluster - * - *

Easiest way to run this: mvn exec:java - * -Dexec.mainClass="io.kubernetes.client.examples.KubeConfigFileClientExample" - * - *

From inside $REPO_DIR/examples - */ -public class KubeConfigFileClientExample { - public static void main(String[] args) throws IOException, ApiException { - - // file path to your KubeConfig - - String kubeConfigPath = System.getenv("HOME") + "/.kube/config"; - - // loading the out-of-cluster config, a kubeconfig from file-system - ApiClient client = - ClientBuilder.kubeconfig(KubeConfig.loadKubeConfig(new FileReader(kubeConfigPath))).build(); - - // set the global default api-client to the out-of-cluster one from above - Configuration.setDefaultApiClient(client); - - // the CoreV1Api loads default api-client from global configuration. - CoreV1Api api = new CoreV1Api(); - - // invokes the CoreV1Api client - V1PodList list = - api.listPodForAllNamespaces(null, null, null, null, null, null, null, null, null, null); - for (V1Pod item : list.getItems()) { - System.out.println(item.getMetadata().getName()); - } - } -} diff --git a/examples/examples-release-18/src/main/java/io/kubernetes/client/examples/KubectlExample.java b/examples/examples-release-18/src/main/java/io/kubernetes/client/examples/KubectlExample.java deleted file mode 100644 index 2619c9f271..0000000000 --- a/examples/examples-release-18/src/main/java/io/kubernetes/client/examples/KubectlExample.java +++ /dev/null @@ -1,311 +0,0 @@ -/* -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 static io.kubernetes.client.extended.kubectl.Kubectl.apiResources; -import static io.kubernetes.client.extended.kubectl.Kubectl.copy; -import static io.kubernetes.client.extended.kubectl.Kubectl.cordon; -import static io.kubernetes.client.extended.kubectl.Kubectl.delete; -import static io.kubernetes.client.extended.kubectl.Kubectl.drain; -import static io.kubernetes.client.extended.kubectl.Kubectl.exec; -import static io.kubernetes.client.extended.kubectl.Kubectl.label; -import static io.kubernetes.client.extended.kubectl.Kubectl.log; -import static io.kubernetes.client.extended.kubectl.Kubectl.portforward; -import static io.kubernetes.client.extended.kubectl.Kubectl.scale; -import static io.kubernetes.client.extended.kubectl.Kubectl.taint; -import static io.kubernetes.client.extended.kubectl.Kubectl.top; -import static io.kubernetes.client.extended.kubectl.Kubectl.uncordon; -import static io.kubernetes.client.extended.kubectl.Kubectl.version; -import static io.kubernetes.client.extended.kubectl.KubectlTop.podMetricSum; - -import io.kubernetes.client.common.KubernetesObject; -import io.kubernetes.client.custom.NodeMetrics; -import io.kubernetes.client.custom.PodMetrics; -import io.kubernetes.client.extended.kubectl.KubectlExec; -import io.kubernetes.client.extended.kubectl.KubectlPortForward; -import io.kubernetes.client.extended.kubectl.exception.KubectlException; -import io.kubernetes.client.openapi.ApiClient; -import io.kubernetes.client.openapi.models.V1Deployment; -import io.kubernetes.client.openapi.models.V1Node; -import io.kubernetes.client.openapi.models.V1Pod; -import io.kubernetes.client.openapi.models.V1ReplicationController; -import io.kubernetes.client.openapi.models.V1Service; -import io.kubernetes.client.util.Config; -import io.kubernetes.client.util.Streams; -import java.util.Arrays; -import java.util.List; -import org.apache.commons.cli.CommandLine; -import org.apache.commons.cli.DefaultParser; -import org.apache.commons.cli.Option; -import org.apache.commons.cli.Options; -import org.apache.commons.cli.ParseException; -import org.apache.commons.lang3.tuple.Pair; - -/** - * A Java equivalent for the kubectl command line tool. Not nearly as complete. - * - *

Easiest way to run this: mvn exec:java - * -Dexec.mainClass="io.kubernetes.client.examples.KubectlExample" -Dexec.args="log some-pod" - * - *

From inside $REPO_DIR/examples - */ -public class KubectlExample { - static Class getClassForKind(String kind) { - switch (kind) { - case "pod": - case "pods": - return V1Pod.class; - case "deployment": - case "deployments": - return V1Deployment.class; - case "service": - case "services": - return V1Service.class; - case "node": - case "nodes": - return V1Node.class; - case "replicationcontroller": - case "replicationcontrollers": - return V1ReplicationController.class; - } - return null; - } - - private static final String PADDING = " "; - - private static String pad(String value) { - while (value.length() < PADDING.length()) { - value += " "; - } - return value; - } - - public static void main(String[] args) - throws java.io.IOException, KubectlException, ParseException { - ApiClient client = Config.defaultClient(); - - Options options = new Options(); - options.addOption(new Option("n", "namespace", true, "The namespace for the resource")); - options.addOption(new Option("r", "replicas", true, "The number of replicas to scale to")); - options.addOption(new Option("c", "container", true, "The container in a pod to connect to")); - DefaultParser parser = new DefaultParser(); - CommandLine cli = parser.parse(options, args); - - args = cli.getArgs(); - String verb = args[0]; - String ns = cli.getOptionValue("n", "default"); - String kind = null; - String name = null; - - switch (verb) { - case "delete": - kind = args[1]; - name = args[2]; - delete(getClassForKind(kind)).namespace(ns).name(name).execute(); - case "drain": - name = args[1]; - drain().apiClient(client).name(name).execute(); - System.out.println("Node drained"); - System.exit(0); - case "cordon": - name = args[1]; - cordon().apiClient(client).name(name).execute(); - System.out.println("Node cordoned"); - System.exit(0); - case "uncordon": - name = args[1]; - uncordon().apiClient(client).name(name).execute(); - System.out.println("Node uncordoned"); - System.exit(0); - case "top": - String what = args[1]; - switch (what) { - case "nodes": - case "node": - List> nodes = - top(V1Node.class, NodeMetrics.class).apiClient(client).metric("cpu").execute(); - System.out.println(pad("Node") + "\tCPU\t\tMemory"); - for (Pair node : nodes) { - System.out.println( - pad(node.getLeft().getMetadata().getName()) - + "\t" - + node.getRight().getUsage().get("cpu").getNumber() - + "\t" - + node.getRight().getUsage().get("memory").getNumber()); - } - System.exit(0); - case "pods": - case "pod": - List> pods = - top(V1Pod.class, PodMetrics.class) - .apiClient(client) - .namespace(ns) - .metric("cpu") - .execute(); - System.out.println(pad("Pod") + "\tCPU\t\tMemory"); - for (Pair pod : pods) { - System.out.println( - pad(pod.getLeft().getMetadata().getName()) - + "\t" - + podMetricSum(pod.getRight(), "cpu") - + "\t" - + podMetricSum(pod.getRight(), "memory")); - } - System.exit(0); - } - System.err.println("Unknown top argument: " + what); - System.exit(-1); - case "cp": - String from = args[1]; - String to = args[2]; - if (from.indexOf(":") != -1) { - String[] parts = from.split(":"); - name = parts[0]; - from = parts[1]; - copy() - .apiClient(client) - .namespace(ns) - .name(name) - .container(cli.getOptionValue("c", "")) - .fromPod(from) - .to(to) - .execute(); - } else if (to.indexOf(":") != -1) { - String[] parts = to.split(":"); - name = parts[0]; - to = parts[1]; - copy() - .apiClient(client) - .namespace(ns) - .name(name) - .container(cli.getOptionValue("c", "")) - .from(from) - .toPod(to) - .execute(); - } else { - System.err.println("Missing pod name for copy."); - System.exit(-1); - } - System.out.println("Copied " + from + " -> " + to); - System.exit(0); - case "taint": - name = args[1]; - String taintSpec = args[2]; - boolean remove = taintSpec.endsWith("-"); - int ix = taintSpec.indexOf("="); - int ix2 = taintSpec.indexOf(":"); - - if (remove) { - taintSpec = taintSpec.substring(0, taintSpec.length() - 2); - String key = ix == -1 ? taintSpec : taintSpec.substring(0, ix); - String effect = ix == -1 ? null : taintSpec.substring(ix + 1); - - if (effect == null) { - taint().apiClient(client).name(name).removeTaint(key).execute(); - } else { - taint().apiClient(client).name(name).removeTaint(key, effect).execute(); - } - System.exit(0); - } - if (ix2 == -1) { - System.err.println("key:effect or key=value:effect is required."); - System.exit(-1); - } - String key = taintSpec.substring(0, ix == -1 ? ix2 : ix); - String value = ix == -1 ? null : taintSpec.substring(ix + 1, ix2); - String effect = taintSpec.substring(ix2 + 1); - - if (value == null) { - taint().apiClient(client).name(name).addTaint(key, effect).execute(); - } else { - taint().apiClient(client).name(name).addTaint(key, value, effect).execute(); - } - System.exit(0); - case "portforward": - name = args[1]; - KubectlPortForward forward = portforward().apiClient(client).name(name).namespace(ns); - for (int i = 2; i < args.length; i++) { - String port = args[i]; - String[] ports = port.split(":"); - System.out.println("Forwarding " + ns + "/" + name + " " + ports[0] + "->" + ports[1]); - forward.ports(Integer.parseInt(ports[0]), Integer.parseInt(ports[1])); - } - forward.execute(); - System.exit(0); - case "log": - name = args[1]; - Streams.copy( - log() - .apiClient(client) - .name(name) - .namespace(ns) - .container(cli.getOptionValue("c", "")) - .execute(), - System.out); - System.exit(0); - case "scale": - kind = args[1]; - name = args[2]; - if (!cli.hasOption("r")) { - System.err.println("--replicas is required"); - System.exit(-3); - } - int replicas = Integer.parseInt(cli.getOptionValue("r")); - scale(getClassForKind(kind)) - .apiClient(client) - .namespace(ns) - .name(name) - .replicas(replicas) - .execute(); - System.out.println("Deployment scaled."); - System.exit(0); - case "version": - System.out.println(version().apiClient(client)); - System.exit(0); - case "label": - kind = args[1]; - name = args[2]; - String labelKey = args[3]; - String labelValue = args[4]; - Class clazz = getClassForKind(kind); - if (clazz == null) { - System.err.println("Unknown kind: " + kind); - System.exit(-2); - } - label(clazz).apiClient(client).namespace(ns).name(name).addLabel(labelKey, labelValue); - System.exit(0); - case "exec": - name = args[1]; - String[] command = Arrays.copyOfRange(args, 2, args.length); - KubectlExec e = - exec() - .apiClient(client) - .namespace(ns) - .name(name) - .command(command) - .container(cli.getOptionValue("c", "")); - System.exit(e.execute()); - case "api-resources": - apiResources().apiClient(client).execute().stream() - .forEach( - r -> - System.out.printf( - "%s\t\t%s\t\t%s\t\t%s\n", - r.getResourcePlural(), r.getGroup(), r.getKind(), r.getNamespaced())); - System.exit(0); - default: - System.out.println("Unknown verb: " + verb); - System.exit(-1); - } - } -} diff --git a/examples/examples-release-18/src/main/java/io/kubernetes/client/examples/LeaderElectionExample.java b/examples/examples-release-18/src/main/java/io/kubernetes/client/examples/LeaderElectionExample.java deleted file mode 100644 index 0e48689602..0000000000 --- a/examples/examples-release-18/src/main/java/io/kubernetes/client/examples/LeaderElectionExample.java +++ /dev/null @@ -1,56 +0,0 @@ -/* -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.extended.leaderelection.LeaderElectionConfig; -import io.kubernetes.client.extended.leaderelection.LeaderElector; -import io.kubernetes.client.extended.leaderelection.resourcelock.EndpointsLock; -import io.kubernetes.client.openapi.ApiClient; -import io.kubernetes.client.openapi.Configuration; -import io.kubernetes.client.util.Config; -import java.time.Duration; -import java.util.UUID; - -/** - * A simple example of how to use the Java API - * - *

Easiest way to run this: mvn exec:java - * -Dexec.mainClass="io.kubernetes.client.examples.LeaderElectionExample" - * - *

From inside $REPO_DIR/examples - */ -public class LeaderElectionExample { - public static void main(String[] args) throws Exception { - ApiClient client = Config.defaultClient(); - Configuration.setDefaultApiClient(client); - - // New - String appNamespace = "default"; - String appName = "leader-election-foobar"; - String lockHolderIdentityName = UUID.randomUUID().toString(); // Anything unique - EndpointsLock lock = new EndpointsLock(appNamespace, appName, lockHolderIdentityName); - - LeaderElectionConfig leaderElectionConfig = - new LeaderElectionConfig( - lock, Duration.ofMillis(10000), Duration.ofMillis(8000), Duration.ofMillis(2000)); - try (LeaderElector leaderElector = new LeaderElector(leaderElectionConfig)) { - leaderElector.run( - () -> { - System.out.println("Do something when getting leadership."); - }, - () -> { - System.out.println("Do something when losing leadership."); - }); - } - } -} diff --git a/examples/examples-release-18/src/main/java/io/kubernetes/client/examples/LogsExample.java b/examples/examples-release-18/src/main/java/io/kubernetes/client/examples/LogsExample.java deleted file mode 100644 index e1df5964d3..0000000000 --- a/examples/examples-release-18/src/main/java/io/kubernetes/client/examples/LogsExample.java +++ /dev/null @@ -1,51 +0,0 @@ -/* -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.PodLogs; -import io.kubernetes.client.openapi.ApiClient; -import io.kubernetes.client.openapi.ApiException; -import io.kubernetes.client.openapi.Configuration; -import io.kubernetes.client.openapi.apis.CoreV1Api; -import io.kubernetes.client.openapi.models.V1Pod; -import io.kubernetes.client.util.Config; -import io.kubernetes.client.util.Streams; -import java.io.IOException; -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" - * - *

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); - - PodLogs logs = new PodLogs(); - V1Pod pod = - coreApi - .listNamespacedPod( - "default", "false", null, null, null, null, null, null, null, null, null) - .getItems() - .get(0); - - InputStream is = logs.streamNamespacedPodLog(pod); - Streams.copy(is, System.out); - } -} diff --git a/examples/examples-release-18/src/main/java/io/kubernetes/client/examples/MetricsExample.java b/examples/examples-release-18/src/main/java/io/kubernetes/client/examples/MetricsExample.java deleted file mode 100644 index 0d8c10e30b..0000000000 --- a/examples/examples-release-18/src/main/java/io/kubernetes/client/examples/MetricsExample.java +++ /dev/null @@ -1,68 +0,0 @@ -/* -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.Metrics; -import io.kubernetes.client.custom.ContainerMetrics; -import io.kubernetes.client.custom.NodeMetrics; -import io.kubernetes.client.custom.NodeMetricsList; -import io.kubernetes.client.custom.PodMetrics; -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 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.MetricsExample" - * - *

From inside $REPO_DIR/examples - */ -public class MetricsExample { - public static void main(String[] args) throws IOException, ApiException { - ApiClient client = Config.defaultClient(); - Configuration.setDefaultApiClient(client); - - Metrics metrics = new Metrics(client); - NodeMetricsList list = metrics.getNodeMetrics(); - for (NodeMetrics item : list.getItems()) { - System.out.println(item.getMetadata().getName()); - System.out.println("------------------------------"); - for (String key : item.getUsage().keySet()) { - System.out.println("\t" + key); - System.out.println("\t" + item.getUsage().get(key)); - } - System.out.println(); - } - - for (PodMetrics item : metrics.getPodMetrics("default").getItems()) { - System.out.println(item.getMetadata().getName()); - System.out.println("------------------------------"); - if (item.getContainers() == null) { - continue; - } - for (ContainerMetrics container : item.getContainers()) { - System.out.println(container.getName()); - System.out.println("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-"); - for (String key : container.getUsage().keySet()) { - System.out.println("\t" + key); - System.out.println("\t" + container.getUsage().get(key)); - } - System.out.println(); - } - } - } -} diff --git a/examples/examples-release-18/src/main/java/io/kubernetes/client/examples/PagerExample.java b/examples/examples-release-18/src/main/java/io/kubernetes/client/examples/PagerExample.java deleted file mode 100644 index b0a4ac4fa4..0000000000 --- a/examples/examples-release-18/src/main/java/io/kubernetes/client/examples/PagerExample.java +++ /dev/null @@ -1,72 +0,0 @@ -/* -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.extended.pager.Pager; -import io.kubernetes.client.openapi.ApiClient; -import io.kubernetes.client.openapi.Configuration; -import io.kubernetes.client.openapi.apis.CoreV1Api; -import io.kubernetes.client.openapi.models.V1Namespace; -import io.kubernetes.client.openapi.models.V1NamespaceList; -import io.kubernetes.client.util.Config; -import java.io.IOException; -import java.util.concurrent.TimeUnit; -import okhttp3.OkHttpClient; - -/** - * A simple example of how to use the Java API - * - *

Easiest way to run this: mvn exec:java - * -Dexec.mainClass="io.kubernetes.client.examples.PagerExample" - * - *

From inside $REPO_DIR/examples - */ -public class PagerExample { - public static void main(String[] args) throws IOException { - - ApiClient client = Config.defaultClient(); - OkHttpClient httpClient = - client.getHttpClient().newBuilder().readTimeout(60, TimeUnit.SECONDS).build(); - client.setHttpClient(httpClient); - Configuration.setDefaultApiClient(client); - CoreV1Api api = new CoreV1Api(); - int i = 0; - Pager pager = - new Pager( - (Pager.PagerParams param) -> { - try { - return api.listNamespaceCall( - null, - null, - param.getContinueToken(), - null, - null, - param.getLimit(), - null, - null, - 1, - null, - null); - } catch (Exception e) { - throw new RuntimeException(e); - } - }, - client, - 10, - V1NamespaceList.class); - for (V1Namespace namespace : pager) { - System.out.println(namespace.getMetadata().getName()); - } - System.out.println("------------------"); - } -} diff --git a/examples/examples-release-18/src/main/java/io/kubernetes/client/examples/ParseExample.java b/examples/examples-release-18/src/main/java/io/kubernetes/client/examples/ParseExample.java deleted file mode 100644 index 92866a46fe..0000000000 --- a/examples/examples-release-18/src/main/java/io/kubernetes/client/examples/ParseExample.java +++ /dev/null @@ -1,64 +0,0 @@ -/* -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.openapi.ApiClient; -import io.kubernetes.client.openapi.ApiException; -import io.kubernetes.client.util.Config; -import java.io.FileReader; -import java.io.IOException; -import java.io.StringReader; - -/** - * A simple example of how to parse a Kubernetes object. - * - *

Easiest way to run this: mvn exec:java - * -Dexec.mainClass="io.kubernetes.client.examples.ParseExample" - * - *

From inside $REPO_DIR/examples - */ -public class ParseExample { - public static void main(String[] args) throws IOException, ApiException, ClassNotFoundException { - if (args.length < 2) { - System.err.println("Usage: ParseExample "); - System.exit(1); - } - ApiClient client = Config.defaultClient(); - FileReader json = new FileReader(args[0]); - Object obj = - client - .getJSON() - .getGson() - .fromJson(json, Class.forName("io.kubernetes.client.models." + args[1])); - - String output = client.getJSON().getGson().toJson(obj); - - // Test round tripping... - Object obj2 = - client - .getJSON() - .getGson() - .fromJson( - new StringReader(output), Class.forName("io.kubernetes.client.models." + args[1])); - - String output2 = client.getJSON().getGson().toJson(obj2); - - // Validate round trip - if (!output.equals(output2)) { - System.err.println("Error, expected:\n" + output + "\nto equal\n" + output2); - System.exit(2); - } - - System.out.println(output); - } -} diff --git a/examples/examples-release-18/src/main/java/io/kubernetes/client/examples/PatchExample.java b/examples/examples-release-18/src/main/java/io/kubernetes/client/examples/PatchExample.java deleted file mode 100644 index 7eed3360d3..0000000000 --- a/examples/examples-release-18/src/main/java/io/kubernetes/client/examples/PatchExample.java +++ /dev/null @@ -1,130 +0,0 @@ -/* -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.custom.V1Patch; -import io.kubernetes.client.openapi.ApiException; -import io.kubernetes.client.openapi.Configuration; -import io.kubernetes.client.openapi.apis.AppsV1Api; -import io.kubernetes.client.openapi.models.V1Deployment; -import io.kubernetes.client.util.ClientBuilder; -import io.kubernetes.client.util.PatchUtils; -import java.io.IOException; - -/** - * A simple Example of how to use the Java API.
- * This example demonstrates patching of deployment using Json Patch and Strategic Merge Patch.
- * For generating Json Patches, refer http://jsonpatch.com. For - * generating Strategic Merge Patches, refer strategic-merge-patch.md. - * - *

- * - *

Easiest way to run this: mvn exec:java - * -Dexec.mainClass="io.kubernetes.client.examples.PatchExample" - * - *

From inside $REPO_DIR/examples - */ -public class PatchExample { - static String jsonPatchStr = - "[{\"op\":\"replace\",\"path\":\"/spec/template/spec/terminationGracePeriodSeconds\",\"value\":27}]"; - static String strategicMergePatchStr = - "{\"metadata\":{\"$deleteFromPrimitiveList/finalizers\":[\"example.com/test\"]}}"; - static String jsonDeploymentStr = - "{\"kind\":\"Deployment\",\"apiVersion\":\"apps/v1\",\"metadata\":{\"name\":\"hello-node\",\"finalizers\":[\"example.com/test\"],\"labels\":{\"run\":\"hello-node\"}},\"spec\":{\"replicas\":1,\"selector\":{\"matchLabels\":{\"run\":\"hello-node\"}},\"template\":{\"metadata\":{\"creationTimestamp\":null,\"labels\":{\"run\":\"hello-node\"}},\"spec\":{\"terminationGracePeriodSeconds\":30,\"containers\":[{\"name\":\"hello-node\",\"image\":\"hello-node:v1\",\"ports\":[{\"containerPort\":8080,\"protocol\":\"TCP\"}],\"resources\":{}}]}},\"strategy\":{}},\"status\":{}}"; - static String applyYamlStr = - "{\"kind\":\"Deployment\",\"apiVersion\":\"apps/v1\",\"metadata\":{\"name\":\"hello-node\",\"finalizers\":[\"example.com/test\"],\"labels\":{\"run\":\"hello-node\"}},\"spec\":{\"replicas\":1,\"selector\":{\"matchLabels\":{\"run\":\"hello-node\"}},\"template\":{\"metadata\":{\"creationTimestamp\":null,\"labels\":{\"run\":\"hello-node\"}},\"spec\":{\"terminationGracePeriodSeconds\":30,\"containers\":[{\"name\":\"hello-node\",\"image\":\"hello-node:v2\",\"ports\":[{\"containerPort\":8080,\"protocol\":\"TCP\"}],\"resources\":{}}]}},\"strategy\":{}},\"status\":{}}"; - - public static void main(String[] args) throws IOException { - try { - AppsV1Api api = new AppsV1Api(ClientBuilder.standard().build()); - V1Deployment body = - Configuration.getDefaultApiClient() - .getJSON() - .deserialize(jsonDeploymentStr, V1Deployment.class); - - // create a deployment - V1Deployment deploy1 = - api.createNamespacedDeployment("default", body, null, null, null, null); - System.out.println("original deployment" + deploy1); - - // json-patch a deployment - V1Deployment deploy2 = - PatchUtils.patch( - V1Deployment.class, - () -> - api.patchNamespacedDeploymentCall( - "hello-node", - "default", - new V1Patch(jsonPatchStr), - null, - null, - null, - null, // field-manager is optional - null, - null), - V1Patch.PATCH_FORMAT_JSON_PATCH, - api.getApiClient()); - System.out.println("json-patched deployment" + deploy2); - - // strategic-merge-patch a deployment - V1Deployment deploy3 = - PatchUtils.patch( - V1Deployment.class, - () -> - api.patchNamespacedDeploymentCall( - "hello-node", - "default", - new V1Patch(strategicMergePatchStr), - null, - null, - null, // field-manager is optional - null, - null, - null), - V1Patch.PATCH_FORMAT_STRATEGIC_MERGE_PATCH, - api.getApiClient()); - System.out.println("strategic-merge-patched deployment" + deploy3); - - // apply-yaml a deployment, server side apply is available by default after kubernetes v1.16 - // or opt-in by turning on the feature gate for v1.14 or v1.15. - // https://kubernetes.io/docs/reference/using-api/api-concepts/#server-side-apply - V1Deployment deploy4 = - PatchUtils.patch( - V1Deployment.class, - () -> - api.patchNamespacedDeploymentCall( - "hello-node", - "default", - new V1Patch(applyYamlStr), - null, - null, - "example-field-manager", // field-manager is required for server-side apply - null, - true, - null), - V1Patch.PATCH_FORMAT_APPLY_YAML, - api.getApiClient()); - System.out.println("application/apply-patch+yaml deployment" + deploy4); - - } catch (ApiException e) { - System.out.println(e.getResponseBody()); - e.printStackTrace(); - } - } -} diff --git a/examples/examples-release-18/src/main/java/io/kubernetes/client/examples/PortForwardExample.java b/examples/examples-release-18/src/main/java/io/kubernetes/client/examples/PortForwardExample.java deleted file mode 100644 index cbe064db31..0000000000 --- a/examples/examples-release-18/src/main/java/io/kubernetes/client/examples/PortForwardExample.java +++ /dev/null @@ -1,87 +0,0 @@ -/* -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.PortForward; -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.IOException; -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...) - */ -public class PortForwardExample { - 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<>(); - int localPort = 8080; - int targetPort = 8080; - ports.add(targetPort); - final PortForward.PortForwardResult result = - forward.forward("default", "camera-viz-7949dbf7c6-lpxkd", ports); - System.out.println("Forwarding!"); - ServerSocket ss = new ServerSocket(localPort); - - final Socket s = ss.accept(); - System.out.println("Connected!"); - - new Thread( - new Runnable() { - public void run() { - try { - Streams.copy(result.getInputStream(targetPort), s.getOutputStream()); - } catch (IOException ex) { - ex.printStackTrace(); - } catch (Exception ex) { - ex.printStackTrace(); - } - } - }) - .start(); - - new Thread( - new Runnable() { - public void run() { - try { - Streams.copy(s.getInputStream(), result.getOutboundStream(targetPort)); - } catch (IOException ex) { - ex.printStackTrace(); - } catch (Exception ex) { - ex.printStackTrace(); - } - } - }) - .start(); - - Thread.sleep(10 * 1000); - - System.exit(0); - } -} diff --git a/examples/examples-release-18/src/main/java/io/kubernetes/client/examples/PromOpExample.java b/examples/examples-release-18/src/main/java/io/kubernetes/client/examples/PromOpExample.java deleted file mode 100644 index 65f38b8ce4..0000000000 --- a/examples/examples-release-18/src/main/java/io/kubernetes/client/examples/PromOpExample.java +++ /dev/null @@ -1,43 +0,0 @@ -/* -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 com.coreos.monitoring.models.V1Prometheus; -import com.coreos.monitoring.models.V1PrometheusList; -import com.coreos.monitoring.models.V1PrometheusSpec; -import io.kubernetes.client.openapi.ApiException; -import io.kubernetes.client.openapi.models.V1ObjectMeta; -import io.kubernetes.client.util.ClientBuilder; -import io.kubernetes.client.util.generic.GenericKubernetesApi; -import java.io.IOException; - -public class PromOpExample { - public static void main(String[] args) throws IOException, ApiException { - GenericKubernetesApi prometheusApi = - new GenericKubernetesApi<>( - V1Prometheus.class, - V1PrometheusList.class, - "monitoring.coreos.com", - "v1", - "prometheuses", - ClientBuilder.defaultClient()); - prometheusApi - .create( - new V1Prometheus() - .metadata(new V1ObjectMeta().namespace("default").name("my-prometheus")) - .kind("Prometheus") - .apiVersion("monitoring.coreos.com/v1") - .spec(new V1PrometheusSpec())) - .throwsApiException(); - } -} diff --git a/examples/examples-release-18/src/main/java/io/kubernetes/client/examples/PrometheusExample.java b/examples/examples-release-18/src/main/java/io/kubernetes/client/examples/PrometheusExample.java deleted file mode 100644 index a365704030..0000000000 --- a/examples/examples-release-18/src/main/java/io/kubernetes/client/examples/PrometheusExample.java +++ /dev/null @@ -1,66 +0,0 @@ -/* -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.monitoring.Monitoring; -import io.kubernetes.client.openapi.ApiClient; -import io.kubernetes.client.openapi.ApiException; -import io.kubernetes.client.openapi.Configuration; -import io.kubernetes.client.openapi.apis.CoreV1Api; -import io.kubernetes.client.openapi.models.V1Pod; -import io.kubernetes.client.openapi.models.V1PodList; -import io.kubernetes.client.util.Config; -import java.io.IOException; - -/** - * A simple example of how to use the Java API with Prometheus metrics - * - *

Easiest way to run this: mvn exec:java - * -Dexec.mainClass="io.kubernetes.client.examples.PrometheusExample" - * - *

From inside $REPO_DIR/examples - */ -public class PrometheusExample { - public static void main(String[] args) throws IOException, ApiException { - ApiClient client = Config.defaultClient(); - Configuration.setDefaultApiClient(client); - - // Install an HTTP Interceptor that adds metrics - Monitoring.installMetrics(client); - - // Install a simple HTTP server to serve prometheus metrics. If you already are serving - // metrics elsewhere, this is unnecessary. - Monitoring.startMetricsServer("localhost", 8080); - - CoreV1Api api = new CoreV1Api(); - - while (true) { - // A request that should return 200 - V1PodList list = - 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); - } catch (ApiException ex) { - if (ex.getCode() != 404) { - throw ex; - } - } - try { - Thread.sleep(10000); - } catch (InterruptedException ex) { - ex.printStackTrace(); - } - } - } -} diff --git a/examples/examples-release-18/src/main/java/io/kubernetes/client/examples/ProtoExample.java b/examples/examples-release-18/src/main/java/io/kubernetes/client/examples/ProtoExample.java deleted file mode 100644 index e4e05a2aa1..0000000000 --- a/examples/examples-release-18/src/main/java/io/kubernetes/client/examples/ProtoExample.java +++ /dev/null @@ -1,69 +0,0 @@ -/* -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.ProtoClient; -import io.kubernetes.client.ProtoClient.ObjectOrStatus; -import io.kubernetes.client.openapi.ApiClient; -import io.kubernetes.client.openapi.ApiException; -import io.kubernetes.client.openapi.Configuration; -import io.kubernetes.client.proto.Meta.ObjectMeta; -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" - * - *

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"); - - if (list.object.getItemsCount() > 0) { - Pod p = list.object.getItems(0); - System.out.println(p); - } - - 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/examples-release-18/src/main/java/io/kubernetes/client/examples/SpringControllerExample.java b/examples/examples-release-18/src/main/java/io/kubernetes/client/examples/SpringControllerExample.java deleted file mode 100644 index f6494a836e..0000000000 --- a/examples/examples-release-18/src/main/java/io/kubernetes/client/examples/SpringControllerExample.java +++ /dev/null @@ -1,147 +0,0 @@ -/* -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.extended.controller.Controller; -import io.kubernetes.client.extended.controller.builder.ControllerBuilder; -import io.kubernetes.client.extended.controller.builder.DefaultControllerBuilder; -import io.kubernetes.client.extended.controller.reconciler.Reconciler; -import io.kubernetes.client.extended.controller.reconciler.Request; -import io.kubernetes.client.extended.controller.reconciler.Result; -import io.kubernetes.client.informer.SharedIndexInformer; -import io.kubernetes.client.informer.SharedInformer; -import io.kubernetes.client.informer.SharedInformerFactory; -import io.kubernetes.client.informer.cache.Lister; -import io.kubernetes.client.openapi.ApiClient; -import io.kubernetes.client.openapi.models.V1Endpoints; -import io.kubernetes.client.openapi.models.V1EndpointsList; -import io.kubernetes.client.openapi.models.V1Node; -import io.kubernetes.client.openapi.models.V1NodeList; -import io.kubernetes.client.openapi.models.V1Pod; -import io.kubernetes.client.openapi.models.V1PodList; -import io.kubernetes.client.util.generic.GenericKubernetesApi; -import java.time.Duration; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.boot.CommandLineRunner; -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.stereotype.Component; - -@SpringBootApplication -public class SpringControllerExample { - - public static void main(String[] args) { - SpringApplication.run(SpringControllerExample.class, args); - } - - @Configuration - public static class AppConfig { - - @Bean - public CommandLineRunner commandLineRunner( - SharedInformerFactory sharedInformerFactory, Controller nodePrintingController) { - return args -> { - System.out.println("starting informers.."); - sharedInformerFactory.startAllRegisteredInformers(); - - System.out.println("running controller.."); - nodePrintingController.run(); - }; - } - - @Bean - public Controller nodePrintingController( - SharedInformerFactory sharedInformerFactory, NodePrintingReconciler reconciler) { - DefaultControllerBuilder builder = ControllerBuilder.defaultBuilder(sharedInformerFactory); - builder = - builder.watch( - (q) -> { - return ControllerBuilder.controllerWatchBuilder(V1Node.class, q) - .withResyncPeriod(Duration.ofMinutes(1)) - .build(); - }); - builder.withWorkerCount(2); - builder.withReadyFunc(reconciler::informerReady); - return builder.withReconciler(reconciler).withName("nodePrintingController").build(); - } - - @Bean - public SharedIndexInformer endpointsInformer( - ApiClient apiClient, SharedInformerFactory sharedInformerFactory) { - GenericKubernetesApi genericApi = - new GenericKubernetesApi<>( - V1Endpoints.class, V1EndpointsList.class, "", "v1", "endpoints", apiClient); - return sharedInformerFactory.sharedIndexInformerFor(genericApi, V1Endpoints.class, 0); - } - - @Bean - public SharedIndexInformer nodeInformer( - ApiClient apiClient, SharedInformerFactory sharedInformerFactory) { - GenericKubernetesApi genericApi = - new GenericKubernetesApi<>(V1Node.class, V1NodeList.class, "", "v1", "nodes", apiClient); - return sharedInformerFactory.sharedIndexInformerFor(genericApi, V1Node.class, 60 * 1000L); - } - - @Bean - public SharedIndexInformer podInformer( - ApiClient apiClient, SharedInformerFactory sharedInformerFactory) { - GenericKubernetesApi genericApi = - new GenericKubernetesApi<>(V1Pod.class, V1PodList.class, "", "v1", "pods", apiClient); - return sharedInformerFactory.sharedIndexInformerFor(genericApi, V1Pod.class, 0); - } - } - - @Component - public static class NodePrintingReconciler implements Reconciler { - - @Value("${namespace}") - private String namespace; - - private SharedInformer nodeInformer; - - private SharedInformer podInformer; - - private Lister nodeLister; - - private Lister podLister; - - public NodePrintingReconciler( - SharedIndexInformer nodeInformer, SharedIndexInformer podInformer) { - this.nodeInformer = nodeInformer; - this.podInformer = podInformer; - this.nodeLister = new Lister<>(nodeInformer.getIndexer(), namespace); - this.podLister = new Lister<>(podInformer.getIndexer(), namespace); - } - - // *OPTIONAL* - // If you want to hold the controller from running util some condition.. - public boolean informerReady() { - return podInformer.hasSynced() && nodeInformer.hasSynced(); - } - - @Override - public Result reconcile(Request request) { - V1Node node = nodeLister.get(request.getName()); - - System.out.println("get all pods in namespace " + namespace); - podLister.namespace(namespace).list().stream() - .map(pod -> pod.getMetadata().getName()) - .forEach(System.out::println); - - System.out.println("triggered reconciling " + node.getMetadata().getName()); - return new Result(false); - } - } -} diff --git a/examples/examples-release-18/src/main/java/io/kubernetes/client/examples/SpringLoadBalancerExample.java b/examples/examples-release-18/src/main/java/io/kubernetes/client/examples/SpringLoadBalancerExample.java deleted file mode 100644 index bafe11e421..0000000000 --- a/examples/examples-release-18/src/main/java/io/kubernetes/client/examples/SpringLoadBalancerExample.java +++ /dev/null @@ -1,68 +0,0 @@ -/* -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.extended.network.EndpointsLoadBalancer; -import io.kubernetes.client.extended.network.LoadBalancer; -import io.kubernetes.client.extended.network.RoundRobinLoadBalanceStrategy; -import io.kubernetes.client.informer.SharedIndexInformer; -import io.kubernetes.client.informer.SharedInformerFactory; -import io.kubernetes.client.informer.cache.Lister; -import io.kubernetes.client.openapi.models.V1Endpoints; -import io.kubernetes.client.spring.extended.network.endpoints.InformerEndpointsGetter; -import org.springframework.boot.CommandLineRunner; -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -@SpringBootApplication -public class SpringLoadBalancerExample { - - public static void main(String[] args) { - SpringApplication.run(SpringLoadBalancerExample.class, args); - } - - @Configuration - public static class AppConfig { - - @Bean - public CommandLineRunner loadBalancerCommandLineRunner( - SharedInformerFactory sharedInformerFactory, MyService myService) { - return args -> { - System.out.println("starting informers.."); - sharedInformerFactory.startAllRegisteredInformers(); - - System.out.println("routing default/kubernetes:"); - System.out.println(myService.defaultKubernetesLoadBalancer.getTargetIP()); - }; - } - - @Bean - public MyService myService(SharedIndexInformer lister) { - return new MyService(new Lister<>(lister.getIndexer())); - } - } - - public static class MyService { - - private LoadBalancer defaultKubernetesLoadBalancer; - - public MyService(Lister lister) { - InformerEndpointsGetter getter = new InformerEndpointsGetter(lister); - RoundRobinLoadBalanceStrategy strategy = new RoundRobinLoadBalanceStrategy(); - defaultKubernetesLoadBalancer = - new EndpointsLoadBalancer(() -> getter.get("default", "kubernetes"), strategy); - } - } -} diff --git a/examples/examples-release-18/src/main/java/io/kubernetes/client/examples/WatchExample.java b/examples/examples-release-18/src/main/java/io/kubernetes/client/examples/WatchExample.java deleted file mode 100644 index 23ecce52d5..0000000000 --- a/examples/examples-release-18/src/main/java/io/kubernetes/client/examples/WatchExample.java +++ /dev/null @@ -1,54 +0,0 @@ -/* -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 com.google.gson.reflect.TypeToken; -import io.kubernetes.client.openapi.ApiClient; -import io.kubernetes.client.openapi.ApiException; -import io.kubernetes.client.openapi.Configuration; -import io.kubernetes.client.openapi.apis.CoreV1Api; -import io.kubernetes.client.openapi.models.V1Namespace; -import io.kubernetes.client.util.Config; -import io.kubernetes.client.util.Watch; -import java.io.IOException; -import java.util.concurrent.TimeUnit; -import okhttp3.OkHttpClient; - -/** 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(); - // infinite timeout - OkHttpClient httpClient = - client.getHttpClient().newBuilder().readTimeout(0, TimeUnit.SECONDS).build(); - client.setHttpClient(httpClient); - Configuration.setDefaultApiClient(client); - - CoreV1Api api = new CoreV1Api(); - - Watch watch = - Watch.createWatch( - client, - api.listNamespaceCall( - null, null, null, null, null, null, null, null, null, Boolean.TRUE, null), - new TypeToken>() {}.getType()); - - try { - for (Watch.Response item : watch) { - System.out.printf("%s : %s%n", item.type, item.object.getMetadata().getName()); - } - } finally { - watch.close(); - } - } -} diff --git a/examples/examples-release-18/src/main/java/io/kubernetes/client/examples/WebSocketsExample.java b/examples/examples-release-18/src/main/java/io/kubernetes/client/examples/WebSocketsExample.java deleted file mode 100644 index e1f54dcd07..0000000000 --- a/examples/examples-release-18/src/main/java/io/kubernetes/client/examples/WebSocketsExample.java +++ /dev/null @@ -1,74 +0,0 @@ -/* -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.openapi.ApiClient; -import io.kubernetes.client.openapi.ApiException; -import io.kubernetes.client.util.Config; -import io.kubernetes.client.util.WebSockets; -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStream; -import java.io.Reader; -import okhttp3.WebSocket; - -/** - * 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 - * - *

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() { - private volatile WebSocket socket; - - @Override - public void open(String protocol, WebSocket socket) { - this.socket = socket; - } - - @Override - public void close() {} - - @Override - public void bytesMessage(InputStream is) {} - - @Override - public void failure(Throwable t) { - t.printStackTrace(); - } - - @Override - 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/examples/examples-release-18/src/main/java/io/kubernetes/client/examples/YamlExample.java b/examples/examples-release-18/src/main/java/io/kubernetes/client/examples/YamlExample.java deleted file mode 100644 index b3f0dc6626..0000000000 --- a/examples/examples-release-18/src/main/java/io/kubernetes/client/examples/YamlExample.java +++ /dev/null @@ -1,109 +0,0 @@ -/* -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.custom.IntOrString; -import io.kubernetes.client.openapi.ApiClient; -import io.kubernetes.client.openapi.ApiException; -import io.kubernetes.client.openapi.Configuration; -import io.kubernetes.client.openapi.apis.CoreV1Api; -import io.kubernetes.client.openapi.models.V1DeleteOptions; -import io.kubernetes.client.openapi.models.V1Pod; -import io.kubernetes.client.openapi.models.V1PodBuilder; -import io.kubernetes.client.openapi.models.V1Service; -import io.kubernetes.client.openapi.models.V1ServiceBuilder; -import io.kubernetes.client.util.Config; -import io.kubernetes.client.util.Yaml; -import java.io.File; -import java.io.IOException; -import java.util.HashMap; - -/** - * A simple example of how to parse a Kubernetes object. - * - *

Easiest way to run this: mvn exec:java - * -Dexec.mainClass="io.kubernetes.client.examples.YamlExample" - * - *

From inside $REPO_DIR/examples - */ -public class YamlExample { - public static void main(String[] args) throws IOException, ApiException, ClassNotFoundException { - V1Pod pod = - new V1PodBuilder() - .withNewMetadata() - .withName("apod") - .endMetadata() - .withNewSpec() - .addNewContainer() - .withName("www") - .withImage("nginx") - .withNewResources() - .withLimits(new HashMap<>()) - .endResources() - .endContainer() - .endSpec() - .build(); - System.out.println(Yaml.dump(pod)); - - V1Service svc = - new V1ServiceBuilder() - .withNewMetadata() - .withName("aservice") - .endMetadata() - .withNewSpec() - .withSessionAffinity("ClientIP") - .withType("NodePort") - .addNewPort() - .withProtocol("TCP") - .withName("client") - .withPort(8008) - .withNodePort(8080) - .withTargetPort(new IntOrString(8080)) - .endPort() - .endSpec() - .build(); - System.out.println(Yaml.dump(svc)); - - // Read yaml configuration file, and deploy it - ApiClient client = Config.defaultClient(); - Configuration.setDefaultApiClient(client); - - // See issue #474. Not needed at most cases, but it is needed if you are using war - // packging or running this on JUnit. - Yaml.addModelMap("v1", "Service", V1Service.class); - - // Example yaml file can be found in $REPO_DIR/test-svc.yaml - File file = new File("test-svc.yaml"); - V1Service yamlSvc = (V1Service) Yaml.load(file); - - // Deployment and StatefulSet is defined in apps/v1, so you should use AppsV1Api instead of - // CoreV1API - CoreV1Api api = new CoreV1Api(); - V1Service createResult = - api.createNamespacedService("default", yamlSvc, null, null, null, null); - - System.out.println(createResult); - - V1Service deleteResult = - api.deleteNamespacedService( - yamlSvc.getMetadata().getName(), - "default", - null, - null, - null, - null, - null, - new V1DeleteOptions()); - System.out.println(deleteResult); - } -} diff --git a/examples/examples-release-18/src/main/resources/application.properties b/examples/examples-release-18/src/main/resources/application.properties deleted file mode 100644 index dc886e5f48..0000000000 --- a/examples/examples-release-18/src/main/resources/application.properties +++ /dev/null @@ -1,2 +0,0 @@ -namespace=airflow -management.endpoints.web.exposure.include=prometheus \ No newline at end of file diff --git a/examples/examples-release-18/src/test/java/io/kubernetes/client/examples/ExampleTest.java b/examples/examples-release-18/src/test/java/io/kubernetes/client/examples/ExampleTest.java deleted file mode 100644 index 5ccccda5af..0000000000 --- a/examples/examples-release-18/src/test/java/io/kubernetes/client/examples/ExampleTest.java +++ /dev/null @@ -1,57 +0,0 @@ -/* -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 static com.github.tomakehurst.wiremock.client.WireMock.aResponse; -import static com.github.tomakehurst.wiremock.client.WireMock.get; -import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; -import static org.junit.jupiter.api.Assertions.assertEquals; - -import com.github.tomakehurst.wiremock.core.WireMockConfiguration; -import com.github.tomakehurst.wiremock.junit5.WireMockExtension; -import io.kubernetes.client.openapi.ApiClient; -import io.kubernetes.client.openapi.ApiException; -import io.kubernetes.client.openapi.Configuration; -import io.kubernetes.client.openapi.apis.CoreV1Api; -import io.kubernetes.client.openapi.models.V1Namespace; -import io.kubernetes.client.openapi.models.V1ObjectMeta; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.RegisterExtension; - -class ExampleTest { - private static final int PORT = 8089; - - @RegisterExtension - static WireMockExtension apiServer = - WireMockExtension.newInstance().options(WireMockConfiguration.options().port(PORT)).build(); - - @Test - void exactUrlOnly() throws ApiException { - ApiClient client = new ApiClient(); - client.setBasePath("http://localhost:" + PORT); - Configuration.setDefaultApiClient(client); - - V1Namespace ns1 = new V1Namespace().metadata(new V1ObjectMeta().name("name")); - - apiServer.stubFor( - get(urlEqualTo("/api/v1/namespaces/name")) - .willReturn( - aResponse() - .withHeader("Content-Type", "application/json") - .withBody(client.getJSON().serialize(ns1)))); - - CoreV1Api api = new CoreV1Api(); - V1Namespace ns2 = api.readNamespace("name", null); - assertEquals(ns1, ns2); - } -} diff --git a/examples/examples-release-18/test-svc.yaml b/examples/examples-release-18/test-svc.yaml deleted file mode 100644 index f225bea76f..0000000000 --- a/examples/examples-release-18/test-svc.yaml +++ /dev/null @@ -1,11 +0,0 @@ -apiVersion: v1 -kind: Service -metadata: - name: test-service -spec: - type: ClusterIP - selector: - app: test-service - ports: - - name: port-of-container - port: 8080 \ No newline at end of file diff --git a/examples/examples-release-18/test.yaml b/examples/examples-release-18/test.yaml deleted file mode 100644 index 0b46e57003..0000000000 --- a/examples/examples-release-18/test.yaml +++ /dev/null @@ -1,16 +0,0 @@ -apiVersion: v1 -kind: ReplicationController -metadata: - name: test -spec: - replicas: 1 - template: - metadata: - labels: - app: test - spec: - containers: - - name: test - image: test/examples:1.0 - command: ["/bin/sh","-c"] - args: ["java -jar /examples.jar","while :; do sleep 1; done"] diff --git a/examples/examples-release-19/Dockerfile b/examples/examples-release-19/Dockerfile deleted file mode 100644 index ac90eb1d67..0000000000 --- a/examples/examples-release-19/Dockerfile +++ /dev/null @@ -1,7 +0,0 @@ -FROM openjdk:8-jre - -COPY target/client-java-examples-*-SNAPSHOT-jar-with-dependencies.jar /examples.jar - -CMD ["java", "-jar", "/examples.jar"] - - diff --git a/examples/examples-release-19/README.md b/examples/examples-release-19/README.md deleted file mode 100644 index 80c34ea272..0000000000 --- a/examples/examples-release-19/README.md +++ /dev/null @@ -1,13 +0,0 @@ -# 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" -``` - diff --git a/examples/examples-release-19/createPod.sh b/examples/examples-release-19/createPod.sh deleted file mode 100755 index 18a9841317..0000000000 --- a/examples/examples-release-19/createPod.sh +++ /dev/null @@ -1,26 +0,0 @@ -#!/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 diff --git a/examples/examples-release-19/pom.xml b/examples/examples-release-19/pom.xml deleted file mode 100644 index 65a70dbea7..0000000000 --- a/examples/examples-release-19/pom.xml +++ /dev/null @@ -1,93 +0,0 @@ - - 4.0.0 - - client-java-examples-release-19 - client-java-examples-release-19 - io.kubernetes - 25.0.0-SNAPSHOT - - - - io.kubernetes - client-java-api - 19.0.0 - - - io.kubernetes - client-java - 19.0.0 - - - io.kubernetes - client-java-extended - 19.0.0 - - - io.kubernetes - client-java-spring-integration - 19.0.0 - - - io.kubernetes - client-java-proto - 19.0.0 - - - commons-cli - commons-cli - 1.10.0 - - - io.kubernetes - client-java-cert-manager-models - 10.0.1 - - - io.kubernetes - client-java-prometheus-operator-models - 10.0.1 - - - - org.junit.jupiter - junit-jupiter - ${junit-jupiter.version} - test - - - org.wiremock - wiremock - 3.13.1 - test - - - - - - - com.diffplug.spotless - spotless-maven-plugin - 2.46.1 - - - org.sonatype.plugins - nexus-staging-maven-plugin - true - - true - - - - org.apache.maven.plugins - maven-deploy-plugin - - true - - - - - - 5.13.4 - 3.5.4 - - \ No newline at end of file diff --git a/examples/examples-release-19/src/main/java/io/kubernetes/client/examples/AttachExample.java b/examples/examples-release-19/src/main/java/io/kubernetes/client/examples/AttachExample.java deleted file mode 100644 index 7f753b8d8f..0000000000 --- a/examples/examples-release-19/src/main/java/io/kubernetes/client/examples/AttachExample.java +++ /dev/null @@ -1,77 +0,0 @@ -/* -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 - * - *

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); - - 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); - } -} diff --git a/examples/examples-release-19/src/main/java/io/kubernetes/client/examples/CertManagerExample.java b/examples/examples-release-19/src/main/java/io/kubernetes/client/examples/CertManagerExample.java deleted file mode 100644 index b616a18ee9..0000000000 --- a/examples/examples-release-19/src/main/java/io/kubernetes/client/examples/CertManagerExample.java +++ /dev/null @@ -1,45 +0,0 @@ -/* -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.cert.manager.models.V1alpha2IssuerSpecSelfSigned; -import io.cert.manager.models.V1beta1Issuer; -import io.cert.manager.models.V1beta1IssuerList; -import io.cert.manager.models.V1beta1IssuerSpec; -import io.kubernetes.client.openapi.models.V1ObjectMeta; -import io.kubernetes.client.util.ClientBuilder; -import io.kubernetes.client.util.generic.GenericKubernetesApi; -import java.io.IOException; - -/** - * This sample creates a self signed issuer "self-signed-issuer" in default namespace on a - * Kubernetes cluster where cert-manager is installed - */ -public class CertManagerExample { - public static void main(String[] args) throws IOException { - GenericKubernetesApi issuerApi = - new GenericKubernetesApi<>( - V1beta1Issuer.class, - V1beta1IssuerList.class, - "cert-manager.io", - "v1beta1", - "issuers", - ClientBuilder.defaultClient()); - issuerApi.create( - new V1beta1Issuer() - .metadata(new V1ObjectMeta().namespace("default").name("self-signed-issuer")) - .kind("Issuer") - .apiVersion("cert-manager.io/v1beta1") - .spec(new V1beta1IssuerSpec().selfSigned(new V1alpha2IssuerSpecSelfSigned()))); - } -} diff --git a/examples/examples-release-19/src/main/java/io/kubernetes/client/examples/ControllerExample.java b/examples/examples-release-19/src/main/java/io/kubernetes/client/examples/ControllerExample.java deleted file mode 100644 index 6e646b1a3e..0000000000 --- a/examples/examples-release-19/src/main/java/io/kubernetes/client/examples/ControllerExample.java +++ /dev/null @@ -1,164 +0,0 @@ -/* -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.extended.controller.Controller; -import io.kubernetes.client.extended.controller.ControllerManager; -import io.kubernetes.client.extended.controller.LeaderElectingController; -import io.kubernetes.client.extended.controller.builder.ControllerBuilder; -import io.kubernetes.client.extended.controller.reconciler.Reconciler; -import io.kubernetes.client.extended.controller.reconciler.Request; -import io.kubernetes.client.extended.controller.reconciler.Result; -import io.kubernetes.client.extended.event.EventType; -import io.kubernetes.client.extended.event.legacy.EventBroadcaster; -import io.kubernetes.client.extended.event.legacy.EventRecorder; -import io.kubernetes.client.extended.event.legacy.LegacyEventBroadcaster; -import io.kubernetes.client.extended.leaderelection.LeaderElectionConfig; -import io.kubernetes.client.extended.leaderelection.LeaderElector; -import io.kubernetes.client.extended.leaderelection.resourcelock.EndpointsLock; -import io.kubernetes.client.informer.SharedIndexInformer; -import io.kubernetes.client.informer.SharedInformerFactory; -import io.kubernetes.client.informer.cache.Lister; -import io.kubernetes.client.openapi.ApiClient; -import io.kubernetes.client.openapi.apis.CoreV1Api; -import io.kubernetes.client.openapi.models.V1EventSource; -import io.kubernetes.client.openapi.models.V1Node; -import io.kubernetes.client.openapi.models.V1NodeList; -import io.kubernetes.client.util.CallGeneratorParams; -import java.io.IOException; -import java.time.Duration; -import java.util.concurrent.TimeUnit; -import okhttp3.OkHttpClient; - -public class ControllerExample { - public static void main(String[] args) throws IOException { - - CoreV1Api coreV1Api = new CoreV1Api(); - ApiClient apiClient = coreV1Api.getApiClient(); - OkHttpClient httpClient = - apiClient.getHttpClient().newBuilder().readTimeout(0, TimeUnit.SECONDS).build(); - apiClient.setHttpClient(httpClient); - - // instantiating an informer-factory, and there should be only one informer-factory - // globally. - SharedInformerFactory informerFactory = new SharedInformerFactory(); - // registering node-informer into the informer-factory. - SharedIndexInformer nodeInformer = - informerFactory.sharedIndexInformerFor( - (CallGeneratorParams params) -> { - return coreV1Api.listNodeCall( - null, - null, - null, - null, - null, - null, - params.resourceVersion, - null, - null, - params.timeoutSeconds, - params.watch, - null); - }, - V1Node.class, - V1NodeList.class); - informerFactory.startAllRegisteredInformers(); - - EventBroadcaster eventBroadcaster = new LegacyEventBroadcaster(coreV1Api); - - // nodeReconciler prints node information on events - NodePrintingReconciler nodeReconciler = - new NodePrintingReconciler( - nodeInformer, - eventBroadcaster.newRecorder( - new V1EventSource().host("localhost").component("node-printer"))); - - // Use builder library to construct a default controller. - Controller controller = - ControllerBuilder.defaultBuilder(informerFactory) - .watch( - (workQueue) -> - ControllerBuilder.controllerWatchBuilder(V1Node.class, workQueue) - .withWorkQueueKeyFunc( - (V1Node node) -> - new Request(node.getMetadata().getName())) // optional, default to - .withOnAddFilter( - (V1Node createdNode) -> - createdNode - .getMetadata() - .getName() - .startsWith("docker-")) // optional, set onAdd filter - .withOnUpdateFilter( - (V1Node oldNode, V1Node newNode) -> - newNode - .getMetadata() - .getName() - .startsWith("docker-")) // optional, set onUpdate filter - .withOnDeleteFilter( - (V1Node deletedNode, Boolean stateUnknown) -> - deletedNode - .getMetadata() - .getName() - .startsWith("docker-")) // optional, set onDelete filter - .build()) - .withReconciler(nodeReconciler) // required, set the actual reconciler - .withName("node-printing-controller") // optional, set name for controller - .withWorkerCount(4) // optional, set worker thread count - .withReadyFunc(nodeInformer::hasSynced) // optional, only starts controller when the - // cache has synced up - .build(); - - // Use builder library to manage one or multiple controllers. - ControllerManager controllerManager = - ControllerBuilder.controllerManagerBuilder(informerFactory) - .addController(controller) - .build(); - - LeaderElectingController leaderElectingController = - new LeaderElectingController( - new LeaderElector( - new LeaderElectionConfig( - new EndpointsLock("kube-system", "leader-election", "foo"), - Duration.ofMillis(10000), - Duration.ofMillis(8000), - Duration.ofMillis(5000))), - controllerManager); - - leaderElectingController.run(); - } - - static class NodePrintingReconciler implements Reconciler { - - private Lister nodeLister; - private EventRecorder eventRecorder; - - public NodePrintingReconciler( - SharedIndexInformer nodeInformer, EventRecorder recorder) { - this.nodeLister = new Lister<>(nodeInformer.getIndexer()); - this.eventRecorder = recorder; - } - - @Override - public Result reconcile(Request request) { - V1Node node = this.nodeLister.get(request.getName()); - System.out.println("triggered reconciling " + node.getMetadata().getName()); - this.eventRecorder.event( - node, - EventType.Normal, - "Print Node", - "Successfully printed %s", - node.getMetadata().getName()); - return new Result(false); - } - } -} diff --git a/examples/examples-release-19/src/main/java/io/kubernetes/client/examples/CopyExample.java b/examples/examples-release-19/src/main/java/io/kubernetes/client/examples/CopyExample.java deleted file mode 100644 index bbb6575676..0000000000 --- a/examples/examples-release-19/src/main/java/io/kubernetes/client/examples/CopyExample.java +++ /dev/null @@ -1,51 +0,0 @@ -/* -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.Copy; -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 io.kubernetes.client.util.exception.CopyNotSupportedException; -import java.io.IOException; -import java.io.InputStream; -import java.nio.file.Paths; - -/** - * A simple example of how to use the Java API - * - *

Easiest way to run this: mvn exec:java - * -Dexec.mainClass="io.kubernetes.client.examples.CopyExample" - * - *

From inside $REPO_DIR/examples - */ -public class CopyExample { - public static void main(String[] args) - throws IOException, ApiException, InterruptedException, CopyNotSupportedException { - String podName = "kube-addon-manager-minikube"; - String namespace = "kube-system"; - - ApiClient client = Config.defaultClient(); - Configuration.setDefaultApiClient(client); - - Copy copy = new Copy(); - InputStream dataStream = copy.copyFileFromPod(namespace, podName, "/etc/motd"); - Streams.copy(dataStream, System.out); - - copy.copyDirectoryFromPod(namespace, podName, null, "/etc", Paths.get("/tmp/etc")); - - System.out.println("Done!"); - } -} diff --git a/examples/examples-release-19/src/main/java/io/kubernetes/client/examples/DeployRolloutRestartExample.java b/examples/examples-release-19/src/main/java/io/kubernetes/client/examples/DeployRolloutRestartExample.java deleted file mode 100644 index 42a2524f7b..0000000000 --- a/examples/examples-release-19/src/main/java/io/kubernetes/client/examples/DeployRolloutRestartExample.java +++ /dev/null @@ -1,140 +0,0 @@ -/* -Copyright 2022 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.custom.V1Patch; -import io.kubernetes.client.openapi.ApiClient; -import io.kubernetes.client.openapi.ApiException; -import io.kubernetes.client.openapi.Configuration; -import io.kubernetes.client.openapi.apis.AppsV1Api; -import io.kubernetes.client.openapi.models.V1Container; -import io.kubernetes.client.openapi.models.V1Deployment; -import io.kubernetes.client.openapi.models.V1DeploymentBuilder; -import io.kubernetes.client.openapi.models.V1DeploymentSpec; -import io.kubernetes.client.openapi.models.V1LabelSelector; -import io.kubernetes.client.openapi.models.V1ObjectMeta; -import io.kubernetes.client.openapi.models.V1PodSpec; -import io.kubernetes.client.openapi.models.V1PodTemplateSpec; -import io.kubernetes.client.util.Config; -import io.kubernetes.client.util.PatchUtils; -import io.kubernetes.client.util.wait.Wait; -import java.io.IOException; -import java.time.Duration; -import java.time.LocalDateTime; -import java.util.Collections; - -public class DeployRolloutRestartExample { - public static void main(String[] args) throws IOException, ApiException { - ApiClient client = Config.defaultClient(); - Configuration.setDefaultApiClient(client); - AppsV1Api appsV1Api = new AppsV1Api(client); - - String deploymentName = "example-nginx"; - String imageName = "nginx:1.21.6"; - String namespace = "default"; - - // Create an example deployment - V1DeploymentBuilder deploymentBuilder = - new V1DeploymentBuilder() - .withApiVersion("apps/v1") - .withKind("Deployment") - .withMetadata(new V1ObjectMeta().name(deploymentName).namespace(namespace)) - .withSpec( - new V1DeploymentSpec() - .replicas(1) - .selector(new V1LabelSelector().putMatchLabelsItem("name", deploymentName)) - .template( - new V1PodTemplateSpec() - .metadata(new V1ObjectMeta().putLabelsItem("name", deploymentName)) - .spec( - new V1PodSpec() - .containers( - Collections.singletonList( - new V1Container() - .name(deploymentName) - .image(imageName)))))); - appsV1Api.createNamespacedDeployment( - namespace, deploymentBuilder.build(), null, null, null, null); - - // Wait until example deployment is ready - Wait.poll( - Duration.ofSeconds(3), - Duration.ofSeconds(60), - () -> { - try { - System.out.println("Waiting until example deployment is ready..."); - return appsV1Api - .readNamespacedDeployment(deploymentName, namespace, null) - .getStatus() - .getReadyReplicas() - > 0; - } catch (ApiException e) { - e.printStackTrace(); - return false; - } - }); - System.out.println("Created example deployment!"); - - // Trigger a rollout restart of the example deployment - V1Deployment runningDeployment = - appsV1Api.readNamespacedDeployment(deploymentName, namespace, null); - - // Explicitly set "restartedAt" annotation with current date/time to trigger rollout when patch - // is applied - runningDeployment - .getSpec() - .getTemplate() - .getMetadata() - .putAnnotationsItem("kubectl.kubernetes.io/restartedAt", LocalDateTime.now().toString()); - try { - String deploymentJson = client.getJSON().serialize(runningDeployment); - - PatchUtils.patch( - V1Deployment.class, - () -> - appsV1Api.patchNamespacedDeploymentCall( - deploymentName, - namespace, - new V1Patch(deploymentJson), - null, - null, - "kubectl-rollout", - null, - null, - null), - V1Patch.PATCH_FORMAT_STRATEGIC_MERGE_PATCH, - client); - - // Wait until deployment has stabilized after rollout restart - Wait.poll( - Duration.ofSeconds(3), - Duration.ofSeconds(60), - () -> { - try { - System.out.println("Waiting until example deployment restarted successfully..."); - return appsV1Api - .readNamespacedDeployment(deploymentName, namespace, null) - .getStatus() - .getReadyReplicas() - > 0; - } catch (ApiException e) { - e.printStackTrace(); - return false; - } - }); - System.out.println("Example deployment restarted successfully!"); - } catch (ApiException e) { - e.printStackTrace(); - } - } -} diff --git a/examples/examples-release-19/src/main/java/io/kubernetes/client/examples/DynamicClientExample.java b/examples/examples-release-19/src/main/java/io/kubernetes/client/examples/DynamicClientExample.java deleted file mode 100644 index b8cb04616d..0000000000 --- a/examples/examples-release-19/src/main/java/io/kubernetes/client/examples/DynamicClientExample.java +++ /dev/null @@ -1,42 +0,0 @@ -/* -Copyright 2021 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.openapi.ApiClient; -import io.kubernetes.client.openapi.ApiException; -import io.kubernetes.client.util.ClientBuilder; -import io.kubernetes.client.util.generic.dynamic.DynamicKubernetesApi; -import io.kubernetes.client.util.generic.dynamic.DynamicKubernetesObject; -import java.io.IOException; - -public class DynamicClientExample { - - public static void main(String[] args) throws IOException, ApiException { - - ApiClient apiClient = ClientBuilder.standard().build(); - - // retrieving the latest state of the default namespace - DynamicKubernetesApi dynamicApi = new DynamicKubernetesApi("", "v1", "namespaces", apiClient); - DynamicKubernetesObject defaultNamespace = - dynamicApi.get("default").throwsApiException().getObject(); - - // attaching a "foo=bar" label to the default namespace - defaultNamespace.setMetadata(defaultNamespace.getMetadata().putLabelsItem("foo", "bar")); - DynamicKubernetesObject updatedDefaultNamespace = - dynamicApi.update(defaultNamespace).throwsApiException().getObject(); - - System.out.println(updatedDefaultNamespace); - - apiClient.getHttpClient().connectionPool().evictAll(); - } -} diff --git a/examples/examples-release-19/src/main/java/io/kubernetes/client/examples/Example.java b/examples/examples-release-19/src/main/java/io/kubernetes/client/examples/Example.java deleted file mode 100644 index b492ba5415..0000000000 --- a/examples/examples-release-19/src/main/java/io/kubernetes/client/examples/Example.java +++ /dev/null @@ -1,44 +0,0 @@ -/* -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.openapi.ApiClient; -import io.kubernetes.client.openapi.ApiException; -import io.kubernetes.client.openapi.Configuration; -import io.kubernetes.client.openapi.apis.CoreV1Api; -import io.kubernetes.client.openapi.models.V1Pod; -import io.kubernetes.client.openapi.models.V1PodList; -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.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); - - CoreV1Api api = new CoreV1Api(); - V1PodList list = - api.listPodForAllNamespaces(null, null, null, null, null, null, null, null, null, null, null); - for (V1Pod item : list.getItems()) { - System.out.println(item.getMetadata().getName()); - } - } -} diff --git a/examples/examples-release-19/src/main/java/io/kubernetes/client/examples/ExecExample.java b/examples/examples-release-19/src/main/java/io/kubernetes/client/examples/ExecExample.java deleted file mode 100644 index acea8e815a..0000000000 --- a/examples/examples-release-19/src/main/java/io/kubernetes/client/examples/ExecExample.java +++ /dev/null @@ -1,96 +0,0 @@ -/* -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.Exec; -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.IOException; -import org.apache.commons.cli.CommandLine; -import org.apache.commons.cli.CommandLineParser; -import org.apache.commons.cli.DefaultParser; -import org.apache.commons.cli.Option; -import org.apache.commons.cli.Options; -import org.apache.commons.cli.ParseException; - -/** - * A simple example of how to use the Java API - * - *

Easiest way to run this: mvn exec:java - * -Dexec.mainClass="io.kubernetes.client.examples.ExecExample" - * - *

From inside $REPO_DIR/examples - */ -public class ExecExample { - public static void main(String[] args) - throws IOException, ApiException, InterruptedException, ParseException { - final Options options = new Options(); - options.addOption(new Option("p", "pod", true, "The name of the pod")); - options.addOption(new Option("n", "namespace", true, "The namespace of the pod")); - - CommandLineParser parser = new DefaultParser(); - CommandLine cmd = parser.parse(options, args); - - String podName = cmd.getOptionValue("p", "nginx-dbddb74b8-s4cx5"); - String namespace = cmd.getOptionValue("n", "default"); - args = cmd.getArgs(); - - ApiClient client = Config.defaultClient(); - Configuration.setDefaultApiClient(client); - - Exec exec = new Exec(); - boolean tty = System.console() != null; - // final Process proc = exec.exec("default", "nginx-4217019353-k5sn9", new String[] - // {"sh", "-c", "echo foo"}, true, tty); - final Process proc = - exec.exec(namespace, podName, args.length == 0 ? new String[] {"sh"} : args, true, tty); - - Thread in = - new Thread( - new Runnable() { - public void run() { - try { - Streams.copy(System.in, proc.getOutputStream()); - } catch (IOException ex) { - ex.printStackTrace(); - } - } - }); - in.start(); - - Thread out = - new Thread( - new Runnable() { - public void run() { - try { - Streams.copy(proc.getInputStream(), System.out); - } catch (IOException ex) { - ex.printStackTrace(); - } - } - }); - out.start(); - - proc.waitFor(); - - // wait for any last output; no need to wait for input thread - out.join(); - - proc.destroy(); - - System.exit(proc.exitValue()); - } -} diff --git a/examples/examples-release-19/src/main/java/io/kubernetes/client/examples/ExpandedExample.java b/examples/examples-release-19/src/main/java/io/kubernetes/client/examples/ExpandedExample.java deleted file mode 100644 index bcf8d13ee1..0000000000 --- a/examples/examples-release-19/src/main/java/io/kubernetes/client/examples/ExpandedExample.java +++ /dev/null @@ -1,277 +0,0 @@ -/* -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.openapi.ApiClient; -import io.kubernetes.client.openapi.ApiException; -import io.kubernetes.client.openapi.Configuration; -import io.kubernetes.client.openapi.apis.AppsV1Api; -import io.kubernetes.client.openapi.apis.CoreV1Api; -import io.kubernetes.client.openapi.models.V1Deployment; -import io.kubernetes.client.openapi.models.V1DeploymentList; -import io.kubernetes.client.openapi.models.V1DeploymentSpec; -import io.kubernetes.client.openapi.models.V1NamespaceList; -import io.kubernetes.client.openapi.models.V1PodList; -import io.kubernetes.client.openapi.models.V1ServiceList; -import io.kubernetes.client.util.Config; -import java.io.IOException; -import java.util.List; -import java.util.Optional; -import java.util.stream.Collectors; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * A simple example of how to use the Java API - * - *

Easiest way to run this: mvn exec:java - * -Dexec.mainClass="io.kubernetes.client.examples.ExpandedExample" - * - *

From inside $REPO_DIR/examples - */ -public class ExpandedExample { - - private static CoreV1Api COREV1_API; - private static final String DEFAULT_NAME_SPACE = "default"; - private static final Integer TIME_OUT_VALUE = 180; - private static final Logger LOGGER = LoggerFactory.getLogger(ExpandedExample.class); - - /** - * Main method - * - * @param args - */ - public static void main(String[] args) { - try { - ApiClient client = Config.defaultClient(); - // To change the context of k8s cluster, you can use - // io.kubernetes.client.util.KubeConfig - Configuration.setDefaultApiClient(client); - COREV1_API = new CoreV1Api(client); - - // ScaleUp/ScaleDown the Deployment pod - // Please change the name of Deployment? - System.out.println("----- Scale Deployment Start -----"); - scaleDeployment("account-service", 5); - - // List all of the namaspaces and pods - List nameSpaces = getAllNameSpaces(); - nameSpaces.stream() - .forEach( - namespace -> { - try { - System.out.println("----- " + namespace + " -----"); - getNamespacedPod(namespace).stream().forEach(System.out::println); - } catch (ApiException ex) { - LOGGER.warn("Couldn't get the pods in namespace:{}", namespace, ex); - } - }); - - // Print all of the Services - System.out.println("----- Print list all Services Start -----"); - List services = getServices(); - services.stream().forEach(System.out::println); - System.out.println("----- Print list all Services End -----"); - - // Print log of specific pod. In this example show the first pod logs. - System.out.println("----- Print Log of Specific Pod Start -----"); - String firstPodName = getPods().get(0); - printLog(DEFAULT_NAME_SPACE, firstPodName); - System.out.println("----- Print Log of Specific Pod End -----"); - } catch (ApiException | IOException ex) { - LOGGER.warn("Exception had occured ", ex); - } - } - - /** - * Get all namespaces in k8s cluster - * - * @return - * @throws ApiException - */ - public static List getAllNameSpaces() throws ApiException { - V1NamespaceList listNamespace = - COREV1_API.listNamespace( - null, null, null, null, null, null, null, null, null, null, null); - List list = - listNamespace.getItems().stream() - .map(v1Namespace -> v1Namespace.getMetadata().getName()) - .collect(Collectors.toList()); - return list; - } - - /** - * List all pod names in all namespaces in k8s cluster - * - * @return - * @throws ApiException - */ - public static List getPods() throws ApiException { - V1PodList v1podList = - COREV1_API.listPodForAllNamespaces( - null, null, null, null, null, null, null, null, null, null, null); - List podList = - v1podList.getItems().stream() - .map(v1Pod -> v1Pod.getMetadata().getName()) - .collect(Collectors.toList()); - return podList; - } - - /** - * List all pod in the default namespace - * - * @return - * @throws ApiException - */ - public static List getNamespacedPod() throws ApiException { - return getNamespacedPod(DEFAULT_NAME_SPACE, null); - } - - /** - * List pod in specific namespace - * - * @param namespace - * @return - * @throws ApiException - */ - public static List getNamespacedPod(String namespace) throws ApiException { - return getNamespacedPod(namespace, null); - } - - /** - * List pod in specific namespace with label - * - * @param namespace - * @param label - * @return - * @throws ApiException - */ - public static List getNamespacedPod(String namespace, String label) throws ApiException { - V1PodList listNamespacedPod = - COREV1_API.listNamespacedPod( - namespace, - null, - null, - null, - null, - label, - null, - null, - null, - null, - TIME_OUT_VALUE, - Boolean.FALSE); - List listPods = - listNamespacedPod.getItems().stream() - .map(v1pod -> v1pod.getMetadata().getName()) - .collect(Collectors.toList()); - return listPods; - } - - /** - * List all Services in default namespace - * - * @return - * @throws ApiException - */ - public static List getServices() throws ApiException { - V1ServiceList listNamespacedService = - COREV1_API.listNamespacedService( - DEFAULT_NAME_SPACE, - null, - null, - null, - null, - null, - null, - null, - null, - null, - TIME_OUT_VALUE, - Boolean.FALSE); - return listNamespacedService.getItems().stream() - .map(v1service -> v1service.getMetadata().getName()) - .collect(Collectors.toList()); - } - - /** - * Scale up/down the number of pod in Deployment - * - * @param deploymentName - * @param numberOfReplicas - * @throws ApiException - */ - public static void scaleDeployment(String deploymentName, int numberOfReplicas) - throws ApiException { - AppsV1Api appsV1Api = new AppsV1Api(); - appsV1Api.setApiClient(COREV1_API.getApiClient()); - V1DeploymentList listNamespacedDeployment = - appsV1Api.listNamespacedDeployment( - DEFAULT_NAME_SPACE, - null, - null, - null, - null, - null, - null, - null, - null, - null, - null, - Boolean.FALSE); - - List appsV1DeploymentItems = listNamespacedDeployment.getItems(); - Optional findedDeployment = - appsV1DeploymentItems.stream() - .filter( - (V1Deployment deployment) -> - deployment.getMetadata().getName().equals(deploymentName)) - .findFirst(); - findedDeployment.ifPresent( - (V1Deployment deploy) -> { - try { - V1DeploymentSpec newSpec = deploy.getSpec().replicas(numberOfReplicas); - V1Deployment newDeploy = deploy.spec(newSpec); - appsV1Api.replaceNamespacedDeployment( - deploymentName, DEFAULT_NAME_SPACE, newDeploy, null, null, null, null); - } catch (ApiException ex) { - LOGGER.warn("Scale the pod failed for Deployment:{}", deploymentName, ex); - } - }); - } - - /** - * Print out the Log for specific Pods - * - * @param namespace - * @param podName - * @throws ApiException - */ - public static void printLog(String namespace, String podName) throws ApiException { - // https://github.com/kubernetes-client/java/blob/master/kubernetes/docs/CoreV1Api.md#readNamespacedPodLog - String readNamespacedPodLog = - COREV1_API.readNamespacedPodLog( - podName, - namespace, - null, - Boolean.FALSE, - null, - Integer.MAX_VALUE, - null, - Boolean.FALSE, - Integer.MAX_VALUE, - 40, - Boolean.FALSE); - System.out.println(readNamespacedPodLog); - } -} diff --git a/examples/examples-release-19/src/main/java/io/kubernetes/client/examples/FluentExample.java b/examples/examples-release-19/src/main/java/io/kubernetes/client/examples/FluentExample.java deleted file mode 100644 index 3357ac2f00..0000000000 --- a/examples/examples-release-19/src/main/java/io/kubernetes/client/examples/FluentExample.java +++ /dev/null @@ -1,75 +0,0 @@ -/* -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.openapi.ApiClient; -import io.kubernetes.client.openapi.ApiException; -import io.kubernetes.client.openapi.Configuration; -import io.kubernetes.client.openapi.apis.CoreV1Api; -import io.kubernetes.client.openapi.models.V1Container; -import io.kubernetes.client.openapi.models.V1ObjectMeta; -import io.kubernetes.client.openapi.models.V1Pod; -import io.kubernetes.client.openapi.models.V1PodBuilder; -import io.kubernetes.client.openapi.models.V1PodList; -import io.kubernetes.client.openapi.models.V1PodSpec; -import io.kubernetes.client.util.Config; -import java.io.IOException; -import java.util.Arrays; - -/** - * A simple example of how to use the Java API - * - *

Easiest way to run this: mvn exec:java - * -Dexec.mainClass="io.kubernetes.client.examples.FluentExample" - * - *

From inside $REPO_DIR/examples - */ -public class FluentExample { - public static void main(String[] args) throws IOException, ApiException { - ApiClient client = Config.defaultClient(); - Configuration.setDefaultApiClient(client); - - CoreV1Api api = new CoreV1Api(); - - V1Pod pod = - new V1PodBuilder() - .withNewMetadata() - .withName("apod") - .endMetadata() - .withNewSpec() - .addNewContainer() - .withName("www") - .withImage("nginx") - .endContainer() - .endSpec() - .build(); - - api.createNamespacedPod("default", pod, null, null, null, null); - - V1Pod pod2 = - new V1Pod() - .metadata(new V1ObjectMeta().name("anotherpod")) - .spec( - new V1PodSpec() - .containers(Arrays.asList(new V1Container().name("www").image("nginx")))); - - api.createNamespacedPod("default", pod2, null, null, null, null); - - V1PodList list = - api.listNamespacedPod( - "default", null, null, null, null, null, null, null, null, null, null, null); - for (V1Pod item : list.getItems()) { - System.out.println(item.getMetadata().getName()); - } - } -} diff --git a/examples/examples-release-19/src/main/java/io/kubernetes/client/examples/GenericClientExample.java b/examples/examples-release-19/src/main/java/io/kubernetes/client/examples/GenericClientExample.java deleted file mode 100644 index ddfb1243b8..0000000000 --- a/examples/examples-release-19/src/main/java/io/kubernetes/client/examples/GenericClientExample.java +++ /dev/null @@ -1,63 +0,0 @@ -/* -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.custom.V1Patch; -import io.kubernetes.client.openapi.ApiClient; -import io.kubernetes.client.openapi.models.V1Container; -import io.kubernetes.client.openapi.models.V1ObjectMeta; -import io.kubernetes.client.openapi.models.V1Pod; -import io.kubernetes.client.openapi.models.V1PodList; -import io.kubernetes.client.openapi.models.V1PodSpec; -import io.kubernetes.client.util.ClientBuilder; -import io.kubernetes.client.util.generic.GenericKubernetesApi; -import java.util.Arrays; - -public class GenericClientExample { - - public static void main(String[] args) throws Exception { - - // The following codes demonstrates using generic client to manipulate pods - V1Pod pod = - new V1Pod() - .metadata(new V1ObjectMeta().name("foo").namespace("default")) - .spec( - new V1PodSpec() - .containers(Arrays.asList(new V1Container().name("c").image("test")))); - - ApiClient apiClient = ClientBuilder.standard().build(); - GenericKubernetesApi podClient = - new GenericKubernetesApi<>(V1Pod.class, V1PodList.class, "", "v1", "pods", apiClient); - - V1Pod latestPod = podClient.create(pod).throwsApiException().getObject(); - System.out.println("Created!"); - - V1Pod patchedPod = - podClient - .patch( - "default", - "foo", - V1Patch.PATCH_FORMAT_STRATEGIC_MERGE_PATCH, - new V1Patch("{\"metadata\":{\"finalizers\":[\"example.io/foo\"]}}")) - .throwsApiException() - .getObject(); - System.out.println("Patched!"); - - V1Pod deletedPod = podClient.delete("default", "foo").throwsApiException().getObject(); - if (deletedPod != null) { - System.out.println( - "Received after-deletion status of the requested object, will be deleting in background!"); - } - System.out.println("Deleted!"); - } -} diff --git a/examples/examples-release-19/src/main/java/io/kubernetes/client/examples/InClusterClientExample.java b/examples/examples-release-19/src/main/java/io/kubernetes/client/examples/InClusterClientExample.java deleted file mode 100644 index 0d6134bb68..0000000000 --- a/examples/examples-release-19/src/main/java/io/kubernetes/client/examples/InClusterClientExample.java +++ /dev/null @@ -1,58 +0,0 @@ -/* -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.openapi.ApiClient; -import io.kubernetes.client.openapi.ApiException; -import io.kubernetes.client.openapi.Configuration; -import io.kubernetes.client.openapi.apis.CoreV1Api; -import io.kubernetes.client.openapi.models.V1Pod; -import io.kubernetes.client.openapi.models.V1PodList; -import io.kubernetes.client.util.ClientBuilder; -import java.io.IOException; - -/** - * A simple example of how to use the Java API inside a kubernetes cluster - * - *

Easiest way to run this: mvn exec:java - * -Dexec.mainClass="io.kubernetes.client.examples.InClusterClientExample" - * - *

From inside $REPO_DIR/examples - */ -public class InClusterClientExample { - public static void main(String[] args) throws IOException, ApiException { - - // loading the in-cluster config, including: - // 1. service-account CA - // 2. service-account bearer-token - // 3. service-account namespace - // 4. master endpoints(ip, port) from pre-set environment variables - ApiClient client = ClientBuilder.cluster().build(); - - // if you prefer not to refresh service account token, please use: - // ApiClient client = ClientBuilder.oldCluster().build(); - - // set the global default api-client to the in-cluster one from above - Configuration.setDefaultApiClient(client); - - // the CoreV1Api loads default api-client from global configuration. - CoreV1Api api = new CoreV1Api(); - - // invokes the CoreV1Api client - V1PodList list = - api.listPodForAllNamespaces(null, null, null, null, null, null, null, null, null, null, null); - for (V1Pod item : list.getItems()) { - System.out.println(item.getMetadata().getName()); - } - } -} diff --git a/examples/examples-release-19/src/main/java/io/kubernetes/client/examples/InformerExample.java b/examples/examples-release-19/src/main/java/io/kubernetes/client/examples/InformerExample.java deleted file mode 100644 index b991e7ea49..0000000000 --- a/examples/examples-release-19/src/main/java/io/kubernetes/client/examples/InformerExample.java +++ /dev/null @@ -1,107 +0,0 @@ -/* -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.informer.ResourceEventHandler; -import io.kubernetes.client.informer.SharedIndexInformer; -import io.kubernetes.client.informer.SharedInformerFactory; -import io.kubernetes.client.informer.cache.Lister; -import io.kubernetes.client.openapi.ApiClient; -import io.kubernetes.client.openapi.apis.CoreV1Api; -import io.kubernetes.client.openapi.models.V1Node; -import io.kubernetes.client.openapi.models.V1NodeList; -import io.kubernetes.client.openapi.models.V1ObjectMeta; -import io.kubernetes.client.util.CallGeneratorParams; -import java.util.concurrent.TimeUnit; -import okhttp3.OkHttpClient; - -/** - * A simple example of how to use the Java API - * - *

Easiest way to run this: mvn exec:java - * -Dexec.mainClass="io.kubernetes.client.examples.InformerExample" - * - *

From inside $REPO_DIR/examples - */ -public class InformerExample { - public static void main(String[] args) throws Exception { - CoreV1Api coreV1Api = new CoreV1Api(); - ApiClient apiClient = coreV1Api.getApiClient(); - OkHttpClient httpClient = - apiClient.getHttpClient().newBuilder().readTimeout(0, TimeUnit.SECONDS).build(); - apiClient.setHttpClient(httpClient); - - SharedInformerFactory factory = new SharedInformerFactory(apiClient); - - // Node informer - SharedIndexInformer nodeInformer = - factory.sharedIndexInformerFor( - // **NOTE**: - // The following "CallGeneratorParams" lambda merely generates a stateless - // HTTPs requests, the effective apiClient is the one specified when constructing - // the informer-factory. - (CallGeneratorParams params) -> { - return coreV1Api.listNodeCall( - null, - null, - null, - null, - null, - null, - params.resourceVersion, - null, - null, - params.timeoutSeconds, - params.watch, - null); - }, - V1Node.class, - V1NodeList.class); - - nodeInformer.addEventHandler( - new ResourceEventHandler() { - @Override - public void onAdd(V1Node node) { - System.out.printf("%s node added!\n", node.getMetadata().getName()); - } - - @Override - public void onUpdate(V1Node oldNode, V1Node newNode) { - System.out.printf( - "%s => %s node updated!\n", - oldNode.getMetadata().getName(), newNode.getMetadata().getName()); - } - - @Override - public void onDelete(V1Node node, boolean deletedFinalStateUnknown) { - System.out.printf("%s node deleted!\n", node.getMetadata().getName()); - } - }); - - factory.startAllRegisteredInformers(); - - V1Node nodeToCreate = new V1Node(); - V1ObjectMeta metadata = new V1ObjectMeta(); - metadata.setName("noxu"); - nodeToCreate.setMetadata(metadata); - V1Node createdNode = coreV1Api.createNode(nodeToCreate, null, null, null, null); - Thread.sleep(3000); - - Lister nodeLister = new Lister(nodeInformer.getIndexer()); - V1Node node = nodeLister.get("noxu"); - System.out.printf("noxu created! %s\n", node.getMetadata().getCreationTimestamp()); - factory.stopAllRegisteredInformers(); - Thread.sleep(3000); - System.out.println("informer stopped.."); - } -} diff --git a/examples/examples-release-19/src/main/java/io/kubernetes/client/examples/KubeConfigFileClientExample.java b/examples/examples-release-19/src/main/java/io/kubernetes/client/examples/KubeConfigFileClientExample.java deleted file mode 100644 index 5cb40efa6e..0000000000 --- a/examples/examples-release-19/src/main/java/io/kubernetes/client/examples/KubeConfigFileClientExample.java +++ /dev/null @@ -1,58 +0,0 @@ -/* -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.openapi.ApiClient; -import io.kubernetes.client.openapi.ApiException; -import io.kubernetes.client.openapi.Configuration; -import io.kubernetes.client.openapi.apis.CoreV1Api; -import io.kubernetes.client.openapi.models.V1Pod; -import io.kubernetes.client.openapi.models.V1PodList; -import io.kubernetes.client.util.ClientBuilder; -import io.kubernetes.client.util.KubeConfig; -import java.io.FileReader; -import java.io.IOException; - -/** - * A simple example of how to use the Java API from an application outside a kubernetes cluster - * - *

Easiest way to run this: mvn exec:java - * -Dexec.mainClass="io.kubernetes.client.examples.KubeConfigFileClientExample" - * - *

From inside $REPO_DIR/examples - */ -public class KubeConfigFileClientExample { - public static void main(String[] args) throws IOException, ApiException { - - // file path to your KubeConfig - - String kubeConfigPath = System.getenv("HOME") + "/.kube/config"; - - // loading the out-of-cluster config, a kubeconfig from file-system - ApiClient client = - ClientBuilder.kubeconfig(KubeConfig.loadKubeConfig(new FileReader(kubeConfigPath))).build(); - - // set the global default api-client to the out-of-cluster one from above - Configuration.setDefaultApiClient(client); - - // the CoreV1Api loads default api-client from global configuration. - CoreV1Api api = new CoreV1Api(); - - // invokes the CoreV1Api client - V1PodList list = - api.listPodForAllNamespaces(null, null, null, null, null, null, null, null, null, null, null); - for (V1Pod item : list.getItems()) { - System.out.println(item.getMetadata().getName()); - } - } -} diff --git a/examples/examples-release-19/src/main/java/io/kubernetes/client/examples/KubectlExample.java b/examples/examples-release-19/src/main/java/io/kubernetes/client/examples/KubectlExample.java deleted file mode 100644 index 2619c9f271..0000000000 --- a/examples/examples-release-19/src/main/java/io/kubernetes/client/examples/KubectlExample.java +++ /dev/null @@ -1,311 +0,0 @@ -/* -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 static io.kubernetes.client.extended.kubectl.Kubectl.apiResources; -import static io.kubernetes.client.extended.kubectl.Kubectl.copy; -import static io.kubernetes.client.extended.kubectl.Kubectl.cordon; -import static io.kubernetes.client.extended.kubectl.Kubectl.delete; -import static io.kubernetes.client.extended.kubectl.Kubectl.drain; -import static io.kubernetes.client.extended.kubectl.Kubectl.exec; -import static io.kubernetes.client.extended.kubectl.Kubectl.label; -import static io.kubernetes.client.extended.kubectl.Kubectl.log; -import static io.kubernetes.client.extended.kubectl.Kubectl.portforward; -import static io.kubernetes.client.extended.kubectl.Kubectl.scale; -import static io.kubernetes.client.extended.kubectl.Kubectl.taint; -import static io.kubernetes.client.extended.kubectl.Kubectl.top; -import static io.kubernetes.client.extended.kubectl.Kubectl.uncordon; -import static io.kubernetes.client.extended.kubectl.Kubectl.version; -import static io.kubernetes.client.extended.kubectl.KubectlTop.podMetricSum; - -import io.kubernetes.client.common.KubernetesObject; -import io.kubernetes.client.custom.NodeMetrics; -import io.kubernetes.client.custom.PodMetrics; -import io.kubernetes.client.extended.kubectl.KubectlExec; -import io.kubernetes.client.extended.kubectl.KubectlPortForward; -import io.kubernetes.client.extended.kubectl.exception.KubectlException; -import io.kubernetes.client.openapi.ApiClient; -import io.kubernetes.client.openapi.models.V1Deployment; -import io.kubernetes.client.openapi.models.V1Node; -import io.kubernetes.client.openapi.models.V1Pod; -import io.kubernetes.client.openapi.models.V1ReplicationController; -import io.kubernetes.client.openapi.models.V1Service; -import io.kubernetes.client.util.Config; -import io.kubernetes.client.util.Streams; -import java.util.Arrays; -import java.util.List; -import org.apache.commons.cli.CommandLine; -import org.apache.commons.cli.DefaultParser; -import org.apache.commons.cli.Option; -import org.apache.commons.cli.Options; -import org.apache.commons.cli.ParseException; -import org.apache.commons.lang3.tuple.Pair; - -/** - * A Java equivalent for the kubectl command line tool. Not nearly as complete. - * - *

Easiest way to run this: mvn exec:java - * -Dexec.mainClass="io.kubernetes.client.examples.KubectlExample" -Dexec.args="log some-pod" - * - *

From inside $REPO_DIR/examples - */ -public class KubectlExample { - static Class getClassForKind(String kind) { - switch (kind) { - case "pod": - case "pods": - return V1Pod.class; - case "deployment": - case "deployments": - return V1Deployment.class; - case "service": - case "services": - return V1Service.class; - case "node": - case "nodes": - return V1Node.class; - case "replicationcontroller": - case "replicationcontrollers": - return V1ReplicationController.class; - } - return null; - } - - private static final String PADDING = " "; - - private static String pad(String value) { - while (value.length() < PADDING.length()) { - value += " "; - } - return value; - } - - public static void main(String[] args) - throws java.io.IOException, KubectlException, ParseException { - ApiClient client = Config.defaultClient(); - - Options options = new Options(); - options.addOption(new Option("n", "namespace", true, "The namespace for the resource")); - options.addOption(new Option("r", "replicas", true, "The number of replicas to scale to")); - options.addOption(new Option("c", "container", true, "The container in a pod to connect to")); - DefaultParser parser = new DefaultParser(); - CommandLine cli = parser.parse(options, args); - - args = cli.getArgs(); - String verb = args[0]; - String ns = cli.getOptionValue("n", "default"); - String kind = null; - String name = null; - - switch (verb) { - case "delete": - kind = args[1]; - name = args[2]; - delete(getClassForKind(kind)).namespace(ns).name(name).execute(); - case "drain": - name = args[1]; - drain().apiClient(client).name(name).execute(); - System.out.println("Node drained"); - System.exit(0); - case "cordon": - name = args[1]; - cordon().apiClient(client).name(name).execute(); - System.out.println("Node cordoned"); - System.exit(0); - case "uncordon": - name = args[1]; - uncordon().apiClient(client).name(name).execute(); - System.out.println("Node uncordoned"); - System.exit(0); - case "top": - String what = args[1]; - switch (what) { - case "nodes": - case "node": - List> nodes = - top(V1Node.class, NodeMetrics.class).apiClient(client).metric("cpu").execute(); - System.out.println(pad("Node") + "\tCPU\t\tMemory"); - for (Pair node : nodes) { - System.out.println( - pad(node.getLeft().getMetadata().getName()) - + "\t" - + node.getRight().getUsage().get("cpu").getNumber() - + "\t" - + node.getRight().getUsage().get("memory").getNumber()); - } - System.exit(0); - case "pods": - case "pod": - List> pods = - top(V1Pod.class, PodMetrics.class) - .apiClient(client) - .namespace(ns) - .metric("cpu") - .execute(); - System.out.println(pad("Pod") + "\tCPU\t\tMemory"); - for (Pair pod : pods) { - System.out.println( - pad(pod.getLeft().getMetadata().getName()) - + "\t" - + podMetricSum(pod.getRight(), "cpu") - + "\t" - + podMetricSum(pod.getRight(), "memory")); - } - System.exit(0); - } - System.err.println("Unknown top argument: " + what); - System.exit(-1); - case "cp": - String from = args[1]; - String to = args[2]; - if (from.indexOf(":") != -1) { - String[] parts = from.split(":"); - name = parts[0]; - from = parts[1]; - copy() - .apiClient(client) - .namespace(ns) - .name(name) - .container(cli.getOptionValue("c", "")) - .fromPod(from) - .to(to) - .execute(); - } else if (to.indexOf(":") != -1) { - String[] parts = to.split(":"); - name = parts[0]; - to = parts[1]; - copy() - .apiClient(client) - .namespace(ns) - .name(name) - .container(cli.getOptionValue("c", "")) - .from(from) - .toPod(to) - .execute(); - } else { - System.err.println("Missing pod name for copy."); - System.exit(-1); - } - System.out.println("Copied " + from + " -> " + to); - System.exit(0); - case "taint": - name = args[1]; - String taintSpec = args[2]; - boolean remove = taintSpec.endsWith("-"); - int ix = taintSpec.indexOf("="); - int ix2 = taintSpec.indexOf(":"); - - if (remove) { - taintSpec = taintSpec.substring(0, taintSpec.length() - 2); - String key = ix == -1 ? taintSpec : taintSpec.substring(0, ix); - String effect = ix == -1 ? null : taintSpec.substring(ix + 1); - - if (effect == null) { - taint().apiClient(client).name(name).removeTaint(key).execute(); - } else { - taint().apiClient(client).name(name).removeTaint(key, effect).execute(); - } - System.exit(0); - } - if (ix2 == -1) { - System.err.println("key:effect or key=value:effect is required."); - System.exit(-1); - } - String key = taintSpec.substring(0, ix == -1 ? ix2 : ix); - String value = ix == -1 ? null : taintSpec.substring(ix + 1, ix2); - String effect = taintSpec.substring(ix2 + 1); - - if (value == null) { - taint().apiClient(client).name(name).addTaint(key, effect).execute(); - } else { - taint().apiClient(client).name(name).addTaint(key, value, effect).execute(); - } - System.exit(0); - case "portforward": - name = args[1]; - KubectlPortForward forward = portforward().apiClient(client).name(name).namespace(ns); - for (int i = 2; i < args.length; i++) { - String port = args[i]; - String[] ports = port.split(":"); - System.out.println("Forwarding " + ns + "/" + name + " " + ports[0] + "->" + ports[1]); - forward.ports(Integer.parseInt(ports[0]), Integer.parseInt(ports[1])); - } - forward.execute(); - System.exit(0); - case "log": - name = args[1]; - Streams.copy( - log() - .apiClient(client) - .name(name) - .namespace(ns) - .container(cli.getOptionValue("c", "")) - .execute(), - System.out); - System.exit(0); - case "scale": - kind = args[1]; - name = args[2]; - if (!cli.hasOption("r")) { - System.err.println("--replicas is required"); - System.exit(-3); - } - int replicas = Integer.parseInt(cli.getOptionValue("r")); - scale(getClassForKind(kind)) - .apiClient(client) - .namespace(ns) - .name(name) - .replicas(replicas) - .execute(); - System.out.println("Deployment scaled."); - System.exit(0); - case "version": - System.out.println(version().apiClient(client)); - System.exit(0); - case "label": - kind = args[1]; - name = args[2]; - String labelKey = args[3]; - String labelValue = args[4]; - Class clazz = getClassForKind(kind); - if (clazz == null) { - System.err.println("Unknown kind: " + kind); - System.exit(-2); - } - label(clazz).apiClient(client).namespace(ns).name(name).addLabel(labelKey, labelValue); - System.exit(0); - case "exec": - name = args[1]; - String[] command = Arrays.copyOfRange(args, 2, args.length); - KubectlExec e = - exec() - .apiClient(client) - .namespace(ns) - .name(name) - .command(command) - .container(cli.getOptionValue("c", "")); - System.exit(e.execute()); - case "api-resources": - apiResources().apiClient(client).execute().stream() - .forEach( - r -> - System.out.printf( - "%s\t\t%s\t\t%s\t\t%s\n", - r.getResourcePlural(), r.getGroup(), r.getKind(), r.getNamespaced())); - System.exit(0); - default: - System.out.println("Unknown verb: " + verb); - System.exit(-1); - } - } -} diff --git a/examples/examples-release-19/src/main/java/io/kubernetes/client/examples/LeaderElectionExample.java b/examples/examples-release-19/src/main/java/io/kubernetes/client/examples/LeaderElectionExample.java deleted file mode 100644 index 0e48689602..0000000000 --- a/examples/examples-release-19/src/main/java/io/kubernetes/client/examples/LeaderElectionExample.java +++ /dev/null @@ -1,56 +0,0 @@ -/* -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.extended.leaderelection.LeaderElectionConfig; -import io.kubernetes.client.extended.leaderelection.LeaderElector; -import io.kubernetes.client.extended.leaderelection.resourcelock.EndpointsLock; -import io.kubernetes.client.openapi.ApiClient; -import io.kubernetes.client.openapi.Configuration; -import io.kubernetes.client.util.Config; -import java.time.Duration; -import java.util.UUID; - -/** - * A simple example of how to use the Java API - * - *

Easiest way to run this: mvn exec:java - * -Dexec.mainClass="io.kubernetes.client.examples.LeaderElectionExample" - * - *

From inside $REPO_DIR/examples - */ -public class LeaderElectionExample { - public static void main(String[] args) throws Exception { - ApiClient client = Config.defaultClient(); - Configuration.setDefaultApiClient(client); - - // New - String appNamespace = "default"; - String appName = "leader-election-foobar"; - String lockHolderIdentityName = UUID.randomUUID().toString(); // Anything unique - EndpointsLock lock = new EndpointsLock(appNamespace, appName, lockHolderIdentityName); - - LeaderElectionConfig leaderElectionConfig = - new LeaderElectionConfig( - lock, Duration.ofMillis(10000), Duration.ofMillis(8000), Duration.ofMillis(2000)); - try (LeaderElector leaderElector = new LeaderElector(leaderElectionConfig)) { - leaderElector.run( - () -> { - System.out.println("Do something when getting leadership."); - }, - () -> { - System.out.println("Do something when losing leadership."); - }); - } - } -} diff --git a/examples/examples-release-19/src/main/java/io/kubernetes/client/examples/LogsExample.java b/examples/examples-release-19/src/main/java/io/kubernetes/client/examples/LogsExample.java deleted file mode 100644 index 6305116b5f..0000000000 --- a/examples/examples-release-19/src/main/java/io/kubernetes/client/examples/LogsExample.java +++ /dev/null @@ -1,51 +0,0 @@ -/* -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.PodLogs; -import io.kubernetes.client.openapi.ApiClient; -import io.kubernetes.client.openapi.ApiException; -import io.kubernetes.client.openapi.Configuration; -import io.kubernetes.client.openapi.apis.CoreV1Api; -import io.kubernetes.client.openapi.models.V1Pod; -import io.kubernetes.client.util.Config; -import io.kubernetes.client.util.Streams; -import java.io.IOException; -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" - * - *

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); - - PodLogs logs = new PodLogs(); - V1Pod pod = - coreApi - .listNamespacedPod( - "default", "false", null, null, null, null, null, null, null, null, null, null) - .getItems() - .get(0); - - InputStream is = logs.streamNamespacedPodLog(pod); - Streams.copy(is, System.out); - } -} diff --git a/examples/examples-release-19/src/main/java/io/kubernetes/client/examples/MetricsExample.java b/examples/examples-release-19/src/main/java/io/kubernetes/client/examples/MetricsExample.java deleted file mode 100644 index 0d8c10e30b..0000000000 --- a/examples/examples-release-19/src/main/java/io/kubernetes/client/examples/MetricsExample.java +++ /dev/null @@ -1,68 +0,0 @@ -/* -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.Metrics; -import io.kubernetes.client.custom.ContainerMetrics; -import io.kubernetes.client.custom.NodeMetrics; -import io.kubernetes.client.custom.NodeMetricsList; -import io.kubernetes.client.custom.PodMetrics; -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 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.MetricsExample" - * - *

From inside $REPO_DIR/examples - */ -public class MetricsExample { - public static void main(String[] args) throws IOException, ApiException { - ApiClient client = Config.defaultClient(); - Configuration.setDefaultApiClient(client); - - Metrics metrics = new Metrics(client); - NodeMetricsList list = metrics.getNodeMetrics(); - for (NodeMetrics item : list.getItems()) { - System.out.println(item.getMetadata().getName()); - System.out.println("------------------------------"); - for (String key : item.getUsage().keySet()) { - System.out.println("\t" + key); - System.out.println("\t" + item.getUsage().get(key)); - } - System.out.println(); - } - - for (PodMetrics item : metrics.getPodMetrics("default").getItems()) { - System.out.println(item.getMetadata().getName()); - System.out.println("------------------------------"); - if (item.getContainers() == null) { - continue; - } - for (ContainerMetrics container : item.getContainers()) { - System.out.println(container.getName()); - System.out.println("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-"); - for (String key : container.getUsage().keySet()) { - System.out.println("\t" + key); - System.out.println("\t" + container.getUsage().get(key)); - } - System.out.println(); - } - } - } -} diff --git a/examples/examples-release-19/src/main/java/io/kubernetes/client/examples/PagerExample.java b/examples/examples-release-19/src/main/java/io/kubernetes/client/examples/PagerExample.java deleted file mode 100644 index 3153775ab7..0000000000 --- a/examples/examples-release-19/src/main/java/io/kubernetes/client/examples/PagerExample.java +++ /dev/null @@ -1,73 +0,0 @@ -/* -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.extended.pager.Pager; -import io.kubernetes.client.openapi.ApiClient; -import io.kubernetes.client.openapi.Configuration; -import io.kubernetes.client.openapi.apis.CoreV1Api; -import io.kubernetes.client.openapi.models.V1Namespace; -import io.kubernetes.client.openapi.models.V1NamespaceList; -import io.kubernetes.client.util.Config; -import java.io.IOException; -import java.util.concurrent.TimeUnit; -import okhttp3.OkHttpClient; - -/** - * A simple example of how to use the Java API - * - *

Easiest way to run this: mvn exec:java - * -Dexec.mainClass="io.kubernetes.client.examples.PagerExample" - * - *

From inside $REPO_DIR/examples - */ -public class PagerExample { - public static void main(String[] args) throws IOException { - - ApiClient client = Config.defaultClient(); - OkHttpClient httpClient = - client.getHttpClient().newBuilder().readTimeout(60, TimeUnit.SECONDS).build(); - client.setHttpClient(httpClient); - Configuration.setDefaultApiClient(client); - CoreV1Api api = new CoreV1Api(); - int i = 0; - Pager pager = - new Pager( - (Pager.PagerParams param) -> { - try { - return api.listNamespaceCall( - null, - null, - param.getContinueToken(), - null, - null, - param.getLimit(), - null, - null, - null, - 1, - null, - null); - } catch (Exception e) { - throw new RuntimeException(e); - } - }, - client, - 10, - V1NamespaceList.class); - for (V1Namespace namespace : pager) { - System.out.println(namespace.getMetadata().getName()); - } - System.out.println("------------------"); - } -} diff --git a/examples/examples-release-19/src/main/java/io/kubernetes/client/examples/ParseExample.java b/examples/examples-release-19/src/main/java/io/kubernetes/client/examples/ParseExample.java deleted file mode 100644 index 92866a46fe..0000000000 --- a/examples/examples-release-19/src/main/java/io/kubernetes/client/examples/ParseExample.java +++ /dev/null @@ -1,64 +0,0 @@ -/* -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.openapi.ApiClient; -import io.kubernetes.client.openapi.ApiException; -import io.kubernetes.client.util.Config; -import java.io.FileReader; -import java.io.IOException; -import java.io.StringReader; - -/** - * A simple example of how to parse a Kubernetes object. - * - *

Easiest way to run this: mvn exec:java - * -Dexec.mainClass="io.kubernetes.client.examples.ParseExample" - * - *

From inside $REPO_DIR/examples - */ -public class ParseExample { - public static void main(String[] args) throws IOException, ApiException, ClassNotFoundException { - if (args.length < 2) { - System.err.println("Usage: ParseExample "); - System.exit(1); - } - ApiClient client = Config.defaultClient(); - FileReader json = new FileReader(args[0]); - Object obj = - client - .getJSON() - .getGson() - .fromJson(json, Class.forName("io.kubernetes.client.models." + args[1])); - - String output = client.getJSON().getGson().toJson(obj); - - // Test round tripping... - Object obj2 = - client - .getJSON() - .getGson() - .fromJson( - new StringReader(output), Class.forName("io.kubernetes.client.models." + args[1])); - - String output2 = client.getJSON().getGson().toJson(obj2); - - // Validate round trip - if (!output.equals(output2)) { - System.err.println("Error, expected:\n" + output + "\nto equal\n" + output2); - System.exit(2); - } - - System.out.println(output); - } -} diff --git a/examples/examples-release-19/src/main/java/io/kubernetes/client/examples/PatchExample.java b/examples/examples-release-19/src/main/java/io/kubernetes/client/examples/PatchExample.java deleted file mode 100644 index 7eed3360d3..0000000000 --- a/examples/examples-release-19/src/main/java/io/kubernetes/client/examples/PatchExample.java +++ /dev/null @@ -1,130 +0,0 @@ -/* -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.custom.V1Patch; -import io.kubernetes.client.openapi.ApiException; -import io.kubernetes.client.openapi.Configuration; -import io.kubernetes.client.openapi.apis.AppsV1Api; -import io.kubernetes.client.openapi.models.V1Deployment; -import io.kubernetes.client.util.ClientBuilder; -import io.kubernetes.client.util.PatchUtils; -import java.io.IOException; - -/** - * A simple Example of how to use the Java API.
- * This example demonstrates patching of deployment using Json Patch and Strategic Merge Patch.
- * For generating Json Patches, refer http://jsonpatch.com. For - * generating Strategic Merge Patches, refer strategic-merge-patch.md. - * - *

- * - *

Easiest way to run this: mvn exec:java - * -Dexec.mainClass="io.kubernetes.client.examples.PatchExample" - * - *

From inside $REPO_DIR/examples - */ -public class PatchExample { - static String jsonPatchStr = - "[{\"op\":\"replace\",\"path\":\"/spec/template/spec/terminationGracePeriodSeconds\",\"value\":27}]"; - static String strategicMergePatchStr = - "{\"metadata\":{\"$deleteFromPrimitiveList/finalizers\":[\"example.com/test\"]}}"; - static String jsonDeploymentStr = - "{\"kind\":\"Deployment\",\"apiVersion\":\"apps/v1\",\"metadata\":{\"name\":\"hello-node\",\"finalizers\":[\"example.com/test\"],\"labels\":{\"run\":\"hello-node\"}},\"spec\":{\"replicas\":1,\"selector\":{\"matchLabels\":{\"run\":\"hello-node\"}},\"template\":{\"metadata\":{\"creationTimestamp\":null,\"labels\":{\"run\":\"hello-node\"}},\"spec\":{\"terminationGracePeriodSeconds\":30,\"containers\":[{\"name\":\"hello-node\",\"image\":\"hello-node:v1\",\"ports\":[{\"containerPort\":8080,\"protocol\":\"TCP\"}],\"resources\":{}}]}},\"strategy\":{}},\"status\":{}}"; - static String applyYamlStr = - "{\"kind\":\"Deployment\",\"apiVersion\":\"apps/v1\",\"metadata\":{\"name\":\"hello-node\",\"finalizers\":[\"example.com/test\"],\"labels\":{\"run\":\"hello-node\"}},\"spec\":{\"replicas\":1,\"selector\":{\"matchLabels\":{\"run\":\"hello-node\"}},\"template\":{\"metadata\":{\"creationTimestamp\":null,\"labels\":{\"run\":\"hello-node\"}},\"spec\":{\"terminationGracePeriodSeconds\":30,\"containers\":[{\"name\":\"hello-node\",\"image\":\"hello-node:v2\",\"ports\":[{\"containerPort\":8080,\"protocol\":\"TCP\"}],\"resources\":{}}]}},\"strategy\":{}},\"status\":{}}"; - - public static void main(String[] args) throws IOException { - try { - AppsV1Api api = new AppsV1Api(ClientBuilder.standard().build()); - V1Deployment body = - Configuration.getDefaultApiClient() - .getJSON() - .deserialize(jsonDeploymentStr, V1Deployment.class); - - // create a deployment - V1Deployment deploy1 = - api.createNamespacedDeployment("default", body, null, null, null, null); - System.out.println("original deployment" + deploy1); - - // json-patch a deployment - V1Deployment deploy2 = - PatchUtils.patch( - V1Deployment.class, - () -> - api.patchNamespacedDeploymentCall( - "hello-node", - "default", - new V1Patch(jsonPatchStr), - null, - null, - null, - null, // field-manager is optional - null, - null), - V1Patch.PATCH_FORMAT_JSON_PATCH, - api.getApiClient()); - System.out.println("json-patched deployment" + deploy2); - - // strategic-merge-patch a deployment - V1Deployment deploy3 = - PatchUtils.patch( - V1Deployment.class, - () -> - api.patchNamespacedDeploymentCall( - "hello-node", - "default", - new V1Patch(strategicMergePatchStr), - null, - null, - null, // field-manager is optional - null, - null, - null), - V1Patch.PATCH_FORMAT_STRATEGIC_MERGE_PATCH, - api.getApiClient()); - System.out.println("strategic-merge-patched deployment" + deploy3); - - // apply-yaml a deployment, server side apply is available by default after kubernetes v1.16 - // or opt-in by turning on the feature gate for v1.14 or v1.15. - // https://kubernetes.io/docs/reference/using-api/api-concepts/#server-side-apply - V1Deployment deploy4 = - PatchUtils.patch( - V1Deployment.class, - () -> - api.patchNamespacedDeploymentCall( - "hello-node", - "default", - new V1Patch(applyYamlStr), - null, - null, - "example-field-manager", // field-manager is required for server-side apply - null, - true, - null), - V1Patch.PATCH_FORMAT_APPLY_YAML, - api.getApiClient()); - System.out.println("application/apply-patch+yaml deployment" + deploy4); - - } catch (ApiException e) { - System.out.println(e.getResponseBody()); - e.printStackTrace(); - } - } -} diff --git a/examples/examples-release-19/src/main/java/io/kubernetes/client/examples/PortForwardExample.java b/examples/examples-release-19/src/main/java/io/kubernetes/client/examples/PortForwardExample.java deleted file mode 100644 index cbe064db31..0000000000 --- a/examples/examples-release-19/src/main/java/io/kubernetes/client/examples/PortForwardExample.java +++ /dev/null @@ -1,87 +0,0 @@ -/* -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.PortForward; -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.IOException; -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...) - */ -public class PortForwardExample { - 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<>(); - int localPort = 8080; - int targetPort = 8080; - ports.add(targetPort); - final PortForward.PortForwardResult result = - forward.forward("default", "camera-viz-7949dbf7c6-lpxkd", ports); - System.out.println("Forwarding!"); - ServerSocket ss = new ServerSocket(localPort); - - final Socket s = ss.accept(); - System.out.println("Connected!"); - - new Thread( - new Runnable() { - public void run() { - try { - Streams.copy(result.getInputStream(targetPort), s.getOutputStream()); - } catch (IOException ex) { - ex.printStackTrace(); - } catch (Exception ex) { - ex.printStackTrace(); - } - } - }) - .start(); - - new Thread( - new Runnable() { - public void run() { - try { - Streams.copy(s.getInputStream(), result.getOutboundStream(targetPort)); - } catch (IOException ex) { - ex.printStackTrace(); - } catch (Exception ex) { - ex.printStackTrace(); - } - } - }) - .start(); - - Thread.sleep(10 * 1000); - - System.exit(0); - } -} diff --git a/examples/examples-release-19/src/main/java/io/kubernetes/client/examples/PromOpExample.java b/examples/examples-release-19/src/main/java/io/kubernetes/client/examples/PromOpExample.java deleted file mode 100644 index 65f38b8ce4..0000000000 --- a/examples/examples-release-19/src/main/java/io/kubernetes/client/examples/PromOpExample.java +++ /dev/null @@ -1,43 +0,0 @@ -/* -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 com.coreos.monitoring.models.V1Prometheus; -import com.coreos.monitoring.models.V1PrometheusList; -import com.coreos.monitoring.models.V1PrometheusSpec; -import io.kubernetes.client.openapi.ApiException; -import io.kubernetes.client.openapi.models.V1ObjectMeta; -import io.kubernetes.client.util.ClientBuilder; -import io.kubernetes.client.util.generic.GenericKubernetesApi; -import java.io.IOException; - -public class PromOpExample { - public static void main(String[] args) throws IOException, ApiException { - GenericKubernetesApi prometheusApi = - new GenericKubernetesApi<>( - V1Prometheus.class, - V1PrometheusList.class, - "monitoring.coreos.com", - "v1", - "prometheuses", - ClientBuilder.defaultClient()); - prometheusApi - .create( - new V1Prometheus() - .metadata(new V1ObjectMeta().namespace("default").name("my-prometheus")) - .kind("Prometheus") - .apiVersion("monitoring.coreos.com/v1") - .spec(new V1PrometheusSpec())) - .throwsApiException(); - } -} diff --git a/examples/examples-release-19/src/main/java/io/kubernetes/client/examples/PrometheusExample.java b/examples/examples-release-19/src/main/java/io/kubernetes/client/examples/PrometheusExample.java deleted file mode 100644 index 6fba8a4e75..0000000000 --- a/examples/examples-release-19/src/main/java/io/kubernetes/client/examples/PrometheusExample.java +++ /dev/null @@ -1,66 +0,0 @@ -/* -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.monitoring.Monitoring; -import io.kubernetes.client.openapi.ApiClient; -import io.kubernetes.client.openapi.ApiException; -import io.kubernetes.client.openapi.Configuration; -import io.kubernetes.client.openapi.apis.CoreV1Api; -import io.kubernetes.client.openapi.models.V1Pod; -import io.kubernetes.client.openapi.models.V1PodList; -import io.kubernetes.client.util.Config; -import java.io.IOException; - -/** - * A simple example of how to use the Java API with Prometheus metrics - * - *

Easiest way to run this: mvn exec:java - * -Dexec.mainClass="io.kubernetes.client.examples.PrometheusExample" - * - *

From inside $REPO_DIR/examples - */ -public class PrometheusExample { - public static void main(String[] args) throws IOException, ApiException { - ApiClient client = Config.defaultClient(); - Configuration.setDefaultApiClient(client); - - // Install an HTTP Interceptor that adds metrics - Monitoring.installMetrics(client); - - // Install a simple HTTP server to serve prometheus metrics. If you already are serving - // metrics elsewhere, this is unnecessary. - Monitoring.startMetricsServer("localhost", 8080); - - CoreV1Api api = new CoreV1Api(); - - while (true) { - // A request that should return 200 - V1PodList list = - api.listPodForAllNamespaces( null, null, null, null, null, null, null, null, null, null, null); - // A request that should return 404 - try { - V1Pod pod = api.readNamespacedPod("foo", "bar", null); - } catch (ApiException ex) { - if (ex.getCode() != 404) { - throw ex; - } - } - try { - Thread.sleep(10000); - } catch (InterruptedException ex) { - ex.printStackTrace(); - } - } - } -} diff --git a/examples/examples-release-19/src/main/java/io/kubernetes/client/examples/ProtoExample.java b/examples/examples-release-19/src/main/java/io/kubernetes/client/examples/ProtoExample.java deleted file mode 100644 index e4e05a2aa1..0000000000 --- a/examples/examples-release-19/src/main/java/io/kubernetes/client/examples/ProtoExample.java +++ /dev/null @@ -1,69 +0,0 @@ -/* -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.ProtoClient; -import io.kubernetes.client.ProtoClient.ObjectOrStatus; -import io.kubernetes.client.openapi.ApiClient; -import io.kubernetes.client.openapi.ApiException; -import io.kubernetes.client.openapi.Configuration; -import io.kubernetes.client.proto.Meta.ObjectMeta; -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" - * - *

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"); - - if (list.object.getItemsCount() > 0) { - Pod p = list.object.getItems(0); - System.out.println(p); - } - - 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/examples-release-19/src/main/java/io/kubernetes/client/examples/SpringControllerExample.java b/examples/examples-release-19/src/main/java/io/kubernetes/client/examples/SpringControllerExample.java deleted file mode 100644 index f6494a836e..0000000000 --- a/examples/examples-release-19/src/main/java/io/kubernetes/client/examples/SpringControllerExample.java +++ /dev/null @@ -1,147 +0,0 @@ -/* -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.extended.controller.Controller; -import io.kubernetes.client.extended.controller.builder.ControllerBuilder; -import io.kubernetes.client.extended.controller.builder.DefaultControllerBuilder; -import io.kubernetes.client.extended.controller.reconciler.Reconciler; -import io.kubernetes.client.extended.controller.reconciler.Request; -import io.kubernetes.client.extended.controller.reconciler.Result; -import io.kubernetes.client.informer.SharedIndexInformer; -import io.kubernetes.client.informer.SharedInformer; -import io.kubernetes.client.informer.SharedInformerFactory; -import io.kubernetes.client.informer.cache.Lister; -import io.kubernetes.client.openapi.ApiClient; -import io.kubernetes.client.openapi.models.V1Endpoints; -import io.kubernetes.client.openapi.models.V1EndpointsList; -import io.kubernetes.client.openapi.models.V1Node; -import io.kubernetes.client.openapi.models.V1NodeList; -import io.kubernetes.client.openapi.models.V1Pod; -import io.kubernetes.client.openapi.models.V1PodList; -import io.kubernetes.client.util.generic.GenericKubernetesApi; -import java.time.Duration; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.boot.CommandLineRunner; -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.stereotype.Component; - -@SpringBootApplication -public class SpringControllerExample { - - public static void main(String[] args) { - SpringApplication.run(SpringControllerExample.class, args); - } - - @Configuration - public static class AppConfig { - - @Bean - public CommandLineRunner commandLineRunner( - SharedInformerFactory sharedInformerFactory, Controller nodePrintingController) { - return args -> { - System.out.println("starting informers.."); - sharedInformerFactory.startAllRegisteredInformers(); - - System.out.println("running controller.."); - nodePrintingController.run(); - }; - } - - @Bean - public Controller nodePrintingController( - SharedInformerFactory sharedInformerFactory, NodePrintingReconciler reconciler) { - DefaultControllerBuilder builder = ControllerBuilder.defaultBuilder(sharedInformerFactory); - builder = - builder.watch( - (q) -> { - return ControllerBuilder.controllerWatchBuilder(V1Node.class, q) - .withResyncPeriod(Duration.ofMinutes(1)) - .build(); - }); - builder.withWorkerCount(2); - builder.withReadyFunc(reconciler::informerReady); - return builder.withReconciler(reconciler).withName("nodePrintingController").build(); - } - - @Bean - public SharedIndexInformer endpointsInformer( - ApiClient apiClient, SharedInformerFactory sharedInformerFactory) { - GenericKubernetesApi genericApi = - new GenericKubernetesApi<>( - V1Endpoints.class, V1EndpointsList.class, "", "v1", "endpoints", apiClient); - return sharedInformerFactory.sharedIndexInformerFor(genericApi, V1Endpoints.class, 0); - } - - @Bean - public SharedIndexInformer nodeInformer( - ApiClient apiClient, SharedInformerFactory sharedInformerFactory) { - GenericKubernetesApi genericApi = - new GenericKubernetesApi<>(V1Node.class, V1NodeList.class, "", "v1", "nodes", apiClient); - return sharedInformerFactory.sharedIndexInformerFor(genericApi, V1Node.class, 60 * 1000L); - } - - @Bean - public SharedIndexInformer podInformer( - ApiClient apiClient, SharedInformerFactory sharedInformerFactory) { - GenericKubernetesApi genericApi = - new GenericKubernetesApi<>(V1Pod.class, V1PodList.class, "", "v1", "pods", apiClient); - return sharedInformerFactory.sharedIndexInformerFor(genericApi, V1Pod.class, 0); - } - } - - @Component - public static class NodePrintingReconciler implements Reconciler { - - @Value("${namespace}") - private String namespace; - - private SharedInformer nodeInformer; - - private SharedInformer podInformer; - - private Lister nodeLister; - - private Lister podLister; - - public NodePrintingReconciler( - SharedIndexInformer nodeInformer, SharedIndexInformer podInformer) { - this.nodeInformer = nodeInformer; - this.podInformer = podInformer; - this.nodeLister = new Lister<>(nodeInformer.getIndexer(), namespace); - this.podLister = new Lister<>(podInformer.getIndexer(), namespace); - } - - // *OPTIONAL* - // If you want to hold the controller from running util some condition.. - public boolean informerReady() { - return podInformer.hasSynced() && nodeInformer.hasSynced(); - } - - @Override - public Result reconcile(Request request) { - V1Node node = nodeLister.get(request.getName()); - - System.out.println("get all pods in namespace " + namespace); - podLister.namespace(namespace).list().stream() - .map(pod -> pod.getMetadata().getName()) - .forEach(System.out::println); - - System.out.println("triggered reconciling " + node.getMetadata().getName()); - return new Result(false); - } - } -} diff --git a/examples/examples-release-19/src/main/java/io/kubernetes/client/examples/SpringLoadBalancerExample.java b/examples/examples-release-19/src/main/java/io/kubernetes/client/examples/SpringLoadBalancerExample.java deleted file mode 100644 index bafe11e421..0000000000 --- a/examples/examples-release-19/src/main/java/io/kubernetes/client/examples/SpringLoadBalancerExample.java +++ /dev/null @@ -1,68 +0,0 @@ -/* -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.extended.network.EndpointsLoadBalancer; -import io.kubernetes.client.extended.network.LoadBalancer; -import io.kubernetes.client.extended.network.RoundRobinLoadBalanceStrategy; -import io.kubernetes.client.informer.SharedIndexInformer; -import io.kubernetes.client.informer.SharedInformerFactory; -import io.kubernetes.client.informer.cache.Lister; -import io.kubernetes.client.openapi.models.V1Endpoints; -import io.kubernetes.client.spring.extended.network.endpoints.InformerEndpointsGetter; -import org.springframework.boot.CommandLineRunner; -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -@SpringBootApplication -public class SpringLoadBalancerExample { - - public static void main(String[] args) { - SpringApplication.run(SpringLoadBalancerExample.class, args); - } - - @Configuration - public static class AppConfig { - - @Bean - public CommandLineRunner loadBalancerCommandLineRunner( - SharedInformerFactory sharedInformerFactory, MyService myService) { - return args -> { - System.out.println("starting informers.."); - sharedInformerFactory.startAllRegisteredInformers(); - - System.out.println("routing default/kubernetes:"); - System.out.println(myService.defaultKubernetesLoadBalancer.getTargetIP()); - }; - } - - @Bean - public MyService myService(SharedIndexInformer lister) { - return new MyService(new Lister<>(lister.getIndexer())); - } - } - - public static class MyService { - - private LoadBalancer defaultKubernetesLoadBalancer; - - public MyService(Lister lister) { - InformerEndpointsGetter getter = new InformerEndpointsGetter(lister); - RoundRobinLoadBalanceStrategy strategy = new RoundRobinLoadBalanceStrategy(); - defaultKubernetesLoadBalancer = - new EndpointsLoadBalancer(() -> getter.get("default", "kubernetes"), strategy); - } - } -} diff --git a/examples/examples-release-19/src/main/java/io/kubernetes/client/examples/WatchExample.java b/examples/examples-release-19/src/main/java/io/kubernetes/client/examples/WatchExample.java deleted file mode 100644 index 786f84f7bd..0000000000 --- a/examples/examples-release-19/src/main/java/io/kubernetes/client/examples/WatchExample.java +++ /dev/null @@ -1,54 +0,0 @@ -/* -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 com.google.gson.reflect.TypeToken; -import io.kubernetes.client.openapi.ApiClient; -import io.kubernetes.client.openapi.ApiException; -import io.kubernetes.client.openapi.Configuration; -import io.kubernetes.client.openapi.apis.CoreV1Api; -import io.kubernetes.client.openapi.models.V1Namespace; -import io.kubernetes.client.util.Config; -import io.kubernetes.client.util.Watch; -import java.io.IOException; -import java.util.concurrent.TimeUnit; -import okhttp3.OkHttpClient; - -/** 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(); - // infinite timeout - OkHttpClient httpClient = - client.getHttpClient().newBuilder().readTimeout(0, TimeUnit.SECONDS).build(); - client.setHttpClient(httpClient); - Configuration.setDefaultApiClient(client); - - CoreV1Api api = new CoreV1Api(); - - Watch watch = - Watch.createWatch( - client, - api.listNamespaceCall( - null, null, null, null, null, null, null, null, null, null, Boolean.TRUE, null), - new TypeToken>() {}.getType()); - - try { - for (Watch.Response item : watch) { - System.out.printf("%s : %s%n", item.type, item.object.getMetadata().getName()); - } - } finally { - watch.close(); - } - } -} diff --git a/examples/examples-release-19/src/main/java/io/kubernetes/client/examples/WebSocketsExample.java b/examples/examples-release-19/src/main/java/io/kubernetes/client/examples/WebSocketsExample.java deleted file mode 100644 index e1f54dcd07..0000000000 --- a/examples/examples-release-19/src/main/java/io/kubernetes/client/examples/WebSocketsExample.java +++ /dev/null @@ -1,74 +0,0 @@ -/* -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.openapi.ApiClient; -import io.kubernetes.client.openapi.ApiException; -import io.kubernetes.client.util.Config; -import io.kubernetes.client.util.WebSockets; -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStream; -import java.io.Reader; -import okhttp3.WebSocket; - -/** - * 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 - * - *

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() { - private volatile WebSocket socket; - - @Override - public void open(String protocol, WebSocket socket) { - this.socket = socket; - } - - @Override - public void close() {} - - @Override - public void bytesMessage(InputStream is) {} - - @Override - public void failure(Throwable t) { - t.printStackTrace(); - } - - @Override - 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/examples/examples-release-19/src/main/java/io/kubernetes/client/examples/YamlExample.java b/examples/examples-release-19/src/main/java/io/kubernetes/client/examples/YamlExample.java deleted file mode 100644 index b3f0dc6626..0000000000 --- a/examples/examples-release-19/src/main/java/io/kubernetes/client/examples/YamlExample.java +++ /dev/null @@ -1,109 +0,0 @@ -/* -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.custom.IntOrString; -import io.kubernetes.client.openapi.ApiClient; -import io.kubernetes.client.openapi.ApiException; -import io.kubernetes.client.openapi.Configuration; -import io.kubernetes.client.openapi.apis.CoreV1Api; -import io.kubernetes.client.openapi.models.V1DeleteOptions; -import io.kubernetes.client.openapi.models.V1Pod; -import io.kubernetes.client.openapi.models.V1PodBuilder; -import io.kubernetes.client.openapi.models.V1Service; -import io.kubernetes.client.openapi.models.V1ServiceBuilder; -import io.kubernetes.client.util.Config; -import io.kubernetes.client.util.Yaml; -import java.io.File; -import java.io.IOException; -import java.util.HashMap; - -/** - * A simple example of how to parse a Kubernetes object. - * - *

Easiest way to run this: mvn exec:java - * -Dexec.mainClass="io.kubernetes.client.examples.YamlExample" - * - *

From inside $REPO_DIR/examples - */ -public class YamlExample { - public static void main(String[] args) throws IOException, ApiException, ClassNotFoundException { - V1Pod pod = - new V1PodBuilder() - .withNewMetadata() - .withName("apod") - .endMetadata() - .withNewSpec() - .addNewContainer() - .withName("www") - .withImage("nginx") - .withNewResources() - .withLimits(new HashMap<>()) - .endResources() - .endContainer() - .endSpec() - .build(); - System.out.println(Yaml.dump(pod)); - - V1Service svc = - new V1ServiceBuilder() - .withNewMetadata() - .withName("aservice") - .endMetadata() - .withNewSpec() - .withSessionAffinity("ClientIP") - .withType("NodePort") - .addNewPort() - .withProtocol("TCP") - .withName("client") - .withPort(8008) - .withNodePort(8080) - .withTargetPort(new IntOrString(8080)) - .endPort() - .endSpec() - .build(); - System.out.println(Yaml.dump(svc)); - - // Read yaml configuration file, and deploy it - ApiClient client = Config.defaultClient(); - Configuration.setDefaultApiClient(client); - - // See issue #474. Not needed at most cases, but it is needed if you are using war - // packging or running this on JUnit. - Yaml.addModelMap("v1", "Service", V1Service.class); - - // Example yaml file can be found in $REPO_DIR/test-svc.yaml - File file = new File("test-svc.yaml"); - V1Service yamlSvc = (V1Service) Yaml.load(file); - - // Deployment and StatefulSet is defined in apps/v1, so you should use AppsV1Api instead of - // CoreV1API - CoreV1Api api = new CoreV1Api(); - V1Service createResult = - api.createNamespacedService("default", yamlSvc, null, null, null, null); - - System.out.println(createResult); - - V1Service deleteResult = - api.deleteNamespacedService( - yamlSvc.getMetadata().getName(), - "default", - null, - null, - null, - null, - null, - new V1DeleteOptions()); - System.out.println(deleteResult); - } -} diff --git a/examples/examples-release-19/src/main/resources/application.properties b/examples/examples-release-19/src/main/resources/application.properties deleted file mode 100644 index dc886e5f48..0000000000 --- a/examples/examples-release-19/src/main/resources/application.properties +++ /dev/null @@ -1,2 +0,0 @@ -namespace=airflow -management.endpoints.web.exposure.include=prometheus \ No newline at end of file diff --git a/examples/examples-release-19/src/test/java/io/kubernetes/client/examples/ExampleTest.java b/examples/examples-release-19/src/test/java/io/kubernetes/client/examples/ExampleTest.java deleted file mode 100644 index 5ccccda5af..0000000000 --- a/examples/examples-release-19/src/test/java/io/kubernetes/client/examples/ExampleTest.java +++ /dev/null @@ -1,57 +0,0 @@ -/* -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 static com.github.tomakehurst.wiremock.client.WireMock.aResponse; -import static com.github.tomakehurst.wiremock.client.WireMock.get; -import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; -import static org.junit.jupiter.api.Assertions.assertEquals; - -import com.github.tomakehurst.wiremock.core.WireMockConfiguration; -import com.github.tomakehurst.wiremock.junit5.WireMockExtension; -import io.kubernetes.client.openapi.ApiClient; -import io.kubernetes.client.openapi.ApiException; -import io.kubernetes.client.openapi.Configuration; -import io.kubernetes.client.openapi.apis.CoreV1Api; -import io.kubernetes.client.openapi.models.V1Namespace; -import io.kubernetes.client.openapi.models.V1ObjectMeta; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.RegisterExtension; - -class ExampleTest { - private static final int PORT = 8089; - - @RegisterExtension - static WireMockExtension apiServer = - WireMockExtension.newInstance().options(WireMockConfiguration.options().port(PORT)).build(); - - @Test - void exactUrlOnly() throws ApiException { - ApiClient client = new ApiClient(); - client.setBasePath("http://localhost:" + PORT); - Configuration.setDefaultApiClient(client); - - V1Namespace ns1 = new V1Namespace().metadata(new V1ObjectMeta().name("name")); - - apiServer.stubFor( - get(urlEqualTo("/api/v1/namespaces/name")) - .willReturn( - aResponse() - .withHeader("Content-Type", "application/json") - .withBody(client.getJSON().serialize(ns1)))); - - CoreV1Api api = new CoreV1Api(); - V1Namespace ns2 = api.readNamespace("name", null); - assertEquals(ns1, ns2); - } -} diff --git a/examples/examples-release-19/test-svc.yaml b/examples/examples-release-19/test-svc.yaml deleted file mode 100644 index f225bea76f..0000000000 --- a/examples/examples-release-19/test-svc.yaml +++ /dev/null @@ -1,11 +0,0 @@ -apiVersion: v1 -kind: Service -metadata: - name: test-service -spec: - type: ClusterIP - selector: - app: test-service - ports: - - name: port-of-container - port: 8080 \ No newline at end of file diff --git a/examples/examples-release-19/test.yaml b/examples/examples-release-19/test.yaml deleted file mode 100644 index 0b46e57003..0000000000 --- a/examples/examples-release-19/test.yaml +++ /dev/null @@ -1,16 +0,0 @@ -apiVersion: v1 -kind: ReplicationController -metadata: - name: test -spec: - replicas: 1 - template: - metadata: - labels: - app: test - spec: - containers: - - name: test - image: test/examples:1.0 - command: ["/bin/sh","-c"] - args: ["java -jar /examples.jar","while :; do sleep 1; done"] diff --git a/examples/examples-release-20/Dockerfile b/examples/examples-release-20/Dockerfile deleted file mode 100644 index ac90eb1d67..0000000000 --- a/examples/examples-release-20/Dockerfile +++ /dev/null @@ -1,7 +0,0 @@ -FROM openjdk:8-jre - -COPY target/client-java-examples-*-SNAPSHOT-jar-with-dependencies.jar /examples.jar - -CMD ["java", "-jar", "/examples.jar"] - - diff --git a/examples/examples-release-20/README.md b/examples/examples-release-20/README.md deleted file mode 100644 index 80c34ea272..0000000000 --- a/examples/examples-release-20/README.md +++ /dev/null @@ -1,13 +0,0 @@ -# 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" -``` - diff --git a/examples/examples-release-20/createPod.sh b/examples/examples-release-20/createPod.sh deleted file mode 100755 index 18a9841317..0000000000 --- a/examples/examples-release-20/createPod.sh +++ /dev/null @@ -1,26 +0,0 @@ -#!/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 diff --git a/examples/examples-release-20/pom.xml b/examples/examples-release-20/pom.xml deleted file mode 100644 index 2dbf5cbb1c..0000000000 --- a/examples/examples-release-20/pom.xml +++ /dev/null @@ -1,99 +0,0 @@ - - 4.0.0 - - client-java-examples-release-20 - client-java-examples-release-20 - io.kubernetes - 25.0.0-SNAPSHOT - - - - io.kubernetes - client-java-api - 20.0.0 - - - io.kubernetes - client-java - 20.0.0 - - - io.kubernetes - client-java-extended - 20.0.0 - - - io.kubernetes - client-java-spring-integration - 20.0.0 - - - io.kubernetes - client-java-proto - 20.0.0 - - - commons-cli - commons-cli - 1.10.0 - - - io.kubernetes - client-java-cert-manager-models - 10.0.1 - - - io.kubernetes - client-java-prometheus-operator-models - 10.0.1 - - - - org.junit.jupiter - junit-jupiter - ${junit-jupiter.version} - test - - - org.wiremock - wiremock - 3.13.1 - test - - - com.amazonaws - aws-java-sdk-sts - 1.12.792 - - - - - - - - com.diffplug.spotless - spotless-maven-plugin - 2.46.1 - - - org.sonatype.plugins - nexus-staging-maven-plugin - true - - true - - - - org.apache.maven.plugins - maven-deploy-plugin - - true - - - - - - 5.13.4 - 3.5.4 - - \ No newline at end of file diff --git a/examples/examples-release-20/src/main/java/io/kubernetes/client/examples/AttachExample.java b/examples/examples-release-20/src/main/java/io/kubernetes/client/examples/AttachExample.java deleted file mode 100644 index 7f753b8d8f..0000000000 --- a/examples/examples-release-20/src/main/java/io/kubernetes/client/examples/AttachExample.java +++ /dev/null @@ -1,77 +0,0 @@ -/* -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 - * - *

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); - - 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); - } -} diff --git a/examples/examples-release-20/src/main/java/io/kubernetes/client/examples/CertManagerExample.java b/examples/examples-release-20/src/main/java/io/kubernetes/client/examples/CertManagerExample.java deleted file mode 100644 index b616a18ee9..0000000000 --- a/examples/examples-release-20/src/main/java/io/kubernetes/client/examples/CertManagerExample.java +++ /dev/null @@ -1,45 +0,0 @@ -/* -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.cert.manager.models.V1alpha2IssuerSpecSelfSigned; -import io.cert.manager.models.V1beta1Issuer; -import io.cert.manager.models.V1beta1IssuerList; -import io.cert.manager.models.V1beta1IssuerSpec; -import io.kubernetes.client.openapi.models.V1ObjectMeta; -import io.kubernetes.client.util.ClientBuilder; -import io.kubernetes.client.util.generic.GenericKubernetesApi; -import java.io.IOException; - -/** - * This sample creates a self signed issuer "self-signed-issuer" in default namespace on a - * Kubernetes cluster where cert-manager is installed - */ -public class CertManagerExample { - public static void main(String[] args) throws IOException { - GenericKubernetesApi issuerApi = - new GenericKubernetesApi<>( - V1beta1Issuer.class, - V1beta1IssuerList.class, - "cert-manager.io", - "v1beta1", - "issuers", - ClientBuilder.defaultClient()); - issuerApi.create( - new V1beta1Issuer() - .metadata(new V1ObjectMeta().namespace("default").name("self-signed-issuer")) - .kind("Issuer") - .apiVersion("cert-manager.io/v1beta1") - .spec(new V1beta1IssuerSpec().selfSigned(new V1alpha2IssuerSpecSelfSigned()))); - } -} diff --git a/examples/examples-release-20/src/main/java/io/kubernetes/client/examples/ControllerExample.java b/examples/examples-release-20/src/main/java/io/kubernetes/client/examples/ControllerExample.java deleted file mode 100644 index f79e990107..0000000000 --- a/examples/examples-release-20/src/main/java/io/kubernetes/client/examples/ControllerExample.java +++ /dev/null @@ -1,156 +0,0 @@ -/* -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.extended.controller.Controller; -import io.kubernetes.client.extended.controller.ControllerManager; -import io.kubernetes.client.extended.controller.LeaderElectingController; -import io.kubernetes.client.extended.controller.builder.ControllerBuilder; -import io.kubernetes.client.extended.controller.reconciler.Reconciler; -import io.kubernetes.client.extended.controller.reconciler.Request; -import io.kubernetes.client.extended.controller.reconciler.Result; -import io.kubernetes.client.extended.event.EventType; -import io.kubernetes.client.extended.event.legacy.EventBroadcaster; -import io.kubernetes.client.extended.event.legacy.EventRecorder; -import io.kubernetes.client.extended.event.legacy.LegacyEventBroadcaster; -import io.kubernetes.client.extended.leaderelection.LeaderElectionConfig; -import io.kubernetes.client.extended.leaderelection.LeaderElector; -import io.kubernetes.client.extended.leaderelection.resourcelock.EndpointsLock; -import io.kubernetes.client.informer.SharedIndexInformer; -import io.kubernetes.client.informer.SharedInformerFactory; -import io.kubernetes.client.informer.cache.Lister; -import io.kubernetes.client.openapi.ApiClient; -import io.kubernetes.client.openapi.apis.CoreV1Api; -import io.kubernetes.client.openapi.models.V1EventSource; -import io.kubernetes.client.openapi.models.V1Node; -import io.kubernetes.client.openapi.models.V1NodeList; -import io.kubernetes.client.util.CallGeneratorParams; -import java.io.IOException; -import java.time.Duration; -import java.util.concurrent.TimeUnit; -import okhttp3.OkHttpClient; - -public class ControllerExample { - public static void main(String[] args) throws IOException { - - CoreV1Api coreV1Api = new CoreV1Api(); - ApiClient apiClient = coreV1Api.getApiClient(); - OkHttpClient httpClient = - apiClient.getHttpClient().newBuilder().readTimeout(0, TimeUnit.SECONDS).build(); - apiClient.setHttpClient(httpClient); - - // instantiating an informer-factory, and there should be only one informer-factory - // globally. - SharedInformerFactory informerFactory = new SharedInformerFactory(); - // registering node-informer into the informer-factory. - SharedIndexInformer nodeInformer = - informerFactory.sharedIndexInformerFor( - (CallGeneratorParams params) -> { - return coreV1Api.listNode() - .resourceVersion(params.resourceVersion) - .timeoutSeconds(params.timeoutSeconds) - .watch(params.watch) - .buildCall(null); - }, - V1Node.class, - V1NodeList.class); - informerFactory.startAllRegisteredInformers(); - - EventBroadcaster eventBroadcaster = new LegacyEventBroadcaster(coreV1Api); - - // nodeReconciler prints node information on events - NodePrintingReconciler nodeReconciler = - new NodePrintingReconciler( - nodeInformer, - eventBroadcaster.newRecorder( - new V1EventSource().host("localhost").component("node-printer"))); - - // Use builder library to construct a default controller. - Controller controller = - ControllerBuilder.defaultBuilder(informerFactory) - .watch( - (workQueue) -> - ControllerBuilder.controllerWatchBuilder(V1Node.class, workQueue) - .withWorkQueueKeyFunc( - (V1Node node) -> - new Request(node.getMetadata().getName())) // optional, default to - .withOnAddFilter( - (V1Node createdNode) -> - createdNode - .getMetadata() - .getName() - .startsWith("docker-")) // optional, set onAdd filter - .withOnUpdateFilter( - (V1Node oldNode, V1Node newNode) -> - newNode - .getMetadata() - .getName() - .startsWith("docker-")) // optional, set onUpdate filter - .withOnDeleteFilter( - (V1Node deletedNode, Boolean stateUnknown) -> - deletedNode - .getMetadata() - .getName() - .startsWith("docker-")) // optional, set onDelete filter - .build()) - .withReconciler(nodeReconciler) // required, set the actual reconciler - .withName("node-printing-controller") // optional, set name for controller - .withWorkerCount(4) // optional, set worker thread count - .withReadyFunc(nodeInformer::hasSynced) // optional, only starts controller when the - // cache has synced up - .build(); - - // Use builder library to manage one or multiple controllers. - ControllerManager controllerManager = - ControllerBuilder.controllerManagerBuilder(informerFactory) - .addController(controller) - .build(); - - LeaderElectingController leaderElectingController = - new LeaderElectingController( - new LeaderElector( - new LeaderElectionConfig( - new EndpointsLock("kube-system", "leader-election", "foo"), - Duration.ofMillis(10000), - Duration.ofMillis(8000), - Duration.ofMillis(5000))), - controllerManager); - - leaderElectingController.run(); - } - - static class NodePrintingReconciler implements Reconciler { - - private Lister nodeLister; - private EventRecorder eventRecorder; - - public NodePrintingReconciler( - SharedIndexInformer nodeInformer, EventRecorder recorder) { - this.nodeLister = new Lister<>(nodeInformer.getIndexer()); - this.eventRecorder = recorder; - } - - @Override - public Result reconcile(Request request) { - V1Node node = this.nodeLister.get(request.getName()); - System.out.println("triggered reconciling " + node.getMetadata().getName()); - this.eventRecorder.event( - node, - EventType.Normal, - "Print Node", - "Successfully printed %s", - node.getMetadata().getName()); - return new Result(false); - } - } -} diff --git a/examples/examples-release-20/src/main/java/io/kubernetes/client/examples/CopyExample.java b/examples/examples-release-20/src/main/java/io/kubernetes/client/examples/CopyExample.java deleted file mode 100644 index bbb6575676..0000000000 --- a/examples/examples-release-20/src/main/java/io/kubernetes/client/examples/CopyExample.java +++ /dev/null @@ -1,51 +0,0 @@ -/* -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.Copy; -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 io.kubernetes.client.util.exception.CopyNotSupportedException; -import java.io.IOException; -import java.io.InputStream; -import java.nio.file.Paths; - -/** - * A simple example of how to use the Java API - * - *

Easiest way to run this: mvn exec:java - * -Dexec.mainClass="io.kubernetes.client.examples.CopyExample" - * - *

From inside $REPO_DIR/examples - */ -public class CopyExample { - public static void main(String[] args) - throws IOException, ApiException, InterruptedException, CopyNotSupportedException { - String podName = "kube-addon-manager-minikube"; - String namespace = "kube-system"; - - ApiClient client = Config.defaultClient(); - Configuration.setDefaultApiClient(client); - - Copy copy = new Copy(); - InputStream dataStream = copy.copyFileFromPod(namespace, podName, "/etc/motd"); - Streams.copy(dataStream, System.out); - - copy.copyDirectoryFromPod(namespace, podName, null, "/etc", Paths.get("/tmp/etc")); - - System.out.println("Done!"); - } -} diff --git a/examples/examples-release-20/src/main/java/io/kubernetes/client/examples/DeployRolloutRestartExample.java b/examples/examples-release-20/src/main/java/io/kubernetes/client/examples/DeployRolloutRestartExample.java deleted file mode 100644 index 9886e3b480..0000000000 --- a/examples/examples-release-20/src/main/java/io/kubernetes/client/examples/DeployRolloutRestartExample.java +++ /dev/null @@ -1,138 +0,0 @@ -/* -Copyright 2022 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.custom.V1Patch; -import io.kubernetes.client.openapi.ApiClient; -import io.kubernetes.client.openapi.ApiException; -import io.kubernetes.client.openapi.Configuration; -import io.kubernetes.client.openapi.apis.AppsV1Api; -import io.kubernetes.client.openapi.models.V1Container; -import io.kubernetes.client.openapi.models.V1Deployment; -import io.kubernetes.client.openapi.models.V1DeploymentBuilder; -import io.kubernetes.client.openapi.models.V1DeploymentSpec; -import io.kubernetes.client.openapi.models.V1LabelSelector; -import io.kubernetes.client.openapi.models.V1ObjectMeta; -import io.kubernetes.client.openapi.models.V1PodSpec; -import io.kubernetes.client.openapi.models.V1PodTemplateSpec; -import io.kubernetes.client.util.Config; -import io.kubernetes.client.util.PatchUtils; -import io.kubernetes.client.util.wait.Wait; -import java.io.IOException; -import java.time.Duration; -import java.time.LocalDateTime; -import java.util.Collections; - -public class DeployRolloutRestartExample { - public static void main(String[] args) throws IOException, ApiException { - ApiClient client = Config.defaultClient(); - Configuration.setDefaultApiClient(client); - AppsV1Api appsV1Api = new AppsV1Api(client); - - String deploymentName = "example-nginx"; - String imageName = "nginx:1.21.6"; - String namespace = "default"; - - // Create an example deployment - V1DeploymentBuilder deploymentBuilder = - new V1DeploymentBuilder() - .withApiVersion("apps/v1") - .withKind("Deployment") - .withMetadata(new V1ObjectMeta().name(deploymentName).namespace(namespace)) - .withSpec( - new V1DeploymentSpec() - .replicas(1) - .selector(new V1LabelSelector().putMatchLabelsItem("name", deploymentName)) - .template( - new V1PodTemplateSpec() - .metadata(new V1ObjectMeta().putLabelsItem("name", deploymentName)) - .spec( - new V1PodSpec() - .containers( - Collections.singletonList( - new V1Container() - .name(deploymentName) - .image(imageName)))))); - appsV1Api.createNamespacedDeployment( - namespace, deploymentBuilder.build()).execute(); - - // Wait until example deployment is ready - Wait.poll( - Duration.ofSeconds(3), - Duration.ofSeconds(60), - () -> { - try { - System.out.println("Waiting until example deployment is ready..."); - return appsV1Api - .readNamespacedDeployment(deploymentName, namespace) - .execute() - .getStatus() - .getReadyReplicas() - > 0; - } catch (ApiException e) { - e.printStackTrace(); - return false; - } - }); - System.out.println("Created example deployment!"); - - // Trigger a rollout restart of the example deployment - V1Deployment runningDeployment = - appsV1Api.readNamespacedDeployment(deploymentName, namespace).execute(); - - // Explicitly set "restartedAt" annotation with current date/time to trigger rollout when patch - // is applied - runningDeployment - .getSpec() - .getTemplate() - .getMetadata() - .putAnnotationsItem("kubectl.kubernetes.io/restartedAt", LocalDateTime.now().toString()); - try { - String deploymentJson = client.getJSON().serialize(runningDeployment); - - PatchUtils.patch( - V1Deployment.class, - () -> - appsV1Api.patchNamespacedDeployment( - deploymentName, - namespace, - new V1Patch(deploymentJson)) - .fieldManager("kubectl-rollout") - .buildCall(null), - V1Patch.PATCH_FORMAT_STRATEGIC_MERGE_PATCH, - client); - - // Wait until deployment has stabilized after rollout restart - Wait.poll( - Duration.ofSeconds(3), - Duration.ofSeconds(60), - () -> { - try { - System.out.println("Waiting until example deployment restarted successfully..."); - return appsV1Api - .readNamespacedDeployment(deploymentName, namespace) - .execute() - .getStatus() - .getReadyReplicas() - > 0; - } catch (ApiException e) { - e.printStackTrace(); - return false; - } - }); - System.out.println("Example deployment restarted successfully!"); - } catch (ApiException e) { - e.printStackTrace(); - } - } -} diff --git a/examples/examples-release-20/src/main/java/io/kubernetes/client/examples/DynamicClientExample.java b/examples/examples-release-20/src/main/java/io/kubernetes/client/examples/DynamicClientExample.java deleted file mode 100644 index b8cb04616d..0000000000 --- a/examples/examples-release-20/src/main/java/io/kubernetes/client/examples/DynamicClientExample.java +++ /dev/null @@ -1,42 +0,0 @@ -/* -Copyright 2021 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.openapi.ApiClient; -import io.kubernetes.client.openapi.ApiException; -import io.kubernetes.client.util.ClientBuilder; -import io.kubernetes.client.util.generic.dynamic.DynamicKubernetesApi; -import io.kubernetes.client.util.generic.dynamic.DynamicKubernetesObject; -import java.io.IOException; - -public class DynamicClientExample { - - public static void main(String[] args) throws IOException, ApiException { - - ApiClient apiClient = ClientBuilder.standard().build(); - - // retrieving the latest state of the default namespace - DynamicKubernetesApi dynamicApi = new DynamicKubernetesApi("", "v1", "namespaces", apiClient); - DynamicKubernetesObject defaultNamespace = - dynamicApi.get("default").throwsApiException().getObject(); - - // attaching a "foo=bar" label to the default namespace - defaultNamespace.setMetadata(defaultNamespace.getMetadata().putLabelsItem("foo", "bar")); - DynamicKubernetesObject updatedDefaultNamespace = - dynamicApi.update(defaultNamespace).throwsApiException().getObject(); - - System.out.println(updatedDefaultNamespace); - - apiClient.getHttpClient().connectionPool().evictAll(); - } -} diff --git a/examples/examples-release-20/src/main/java/io/kubernetes/client/examples/EKSAuthenticationExample.java b/examples/examples-release-20/src/main/java/io/kubernetes/client/examples/EKSAuthenticationExample.java deleted file mode 100644 index e1e6610a2a..0000000000 --- a/examples/examples-release-20/src/main/java/io/kubernetes/client/examples/EKSAuthenticationExample.java +++ /dev/null @@ -1,53 +0,0 @@ -/* -Copyright 2023 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 com.amazonaws.auth.DefaultAWSCredentialsProviderChain; -import com.amazonaws.auth.STSAssumeRoleSessionCredentialsProvider; -import io.kubernetes.client.openapi.ApiClient; -import io.kubernetes.client.openapi.ApiException; -import io.kubernetes.client.openapi.models.VersionInfo; -import io.kubernetes.client.util.ClientBuilder; -import io.kubernetes.client.util.credentials.EKSAuthentication; -import io.kubernetes.client.util.version.Version; - -import java.io.IOException; - -public class EKSAuthenticationExample { - public static void main(String[] args) throws IOException, ApiException { - - // Connecting an EKS cluster using {@link io.kubernetes.client.util.credentials.EKSAuthentication } - - // This role should have access to the EKS cluster. - String roleArn = "arn:aws:iam::123456789:role/TestRole"; - // Arbitrary role session name. - String roleSessionName = "test"; - // Region where the EKS cluster at. - String region = "us-west-2"; - // EKS cluster name. - String clusterName = "test-2"; - - STSAssumeRoleSessionCredentialsProvider credProvider = new STSAssumeRoleSessionCredentialsProvider( - new DefaultAWSCredentialsProviderChain().getCredentials(), - roleArn, - roleSessionName); - - ApiClient apiClient = ClientBuilder.standard() - .setAuthentication(new EKSAuthentication(credProvider, region, clusterName)) - .build(); - - Version version = new Version(apiClient); - VersionInfo versionInfo = version.getVersion(); - System.out.println(versionInfo); - } -} diff --git a/examples/examples-release-20/src/main/java/io/kubernetes/client/examples/Example.java b/examples/examples-release-20/src/main/java/io/kubernetes/client/examples/Example.java deleted file mode 100644 index 8fa5cb0f99..0000000000 --- a/examples/examples-release-20/src/main/java/io/kubernetes/client/examples/Example.java +++ /dev/null @@ -1,44 +0,0 @@ -/* -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.openapi.ApiClient; -import io.kubernetes.client.openapi.ApiException; -import io.kubernetes.client.openapi.Configuration; -import io.kubernetes.client.openapi.apis.CoreV1Api; -import io.kubernetes.client.openapi.models.V1Pod; -import io.kubernetes.client.openapi.models.V1PodList; -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.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); - - CoreV1Api api = new CoreV1Api(); - V1PodList list = api.listPodForAllNamespaces() - .execute(); - for (V1Pod item : list.getItems()) { - System.out.println(item.getMetadata().getName()); - } - } -} diff --git a/examples/examples-release-20/src/main/java/io/kubernetes/client/examples/ExecExample.java b/examples/examples-release-20/src/main/java/io/kubernetes/client/examples/ExecExample.java deleted file mode 100644 index acea8e815a..0000000000 --- a/examples/examples-release-20/src/main/java/io/kubernetes/client/examples/ExecExample.java +++ /dev/null @@ -1,96 +0,0 @@ -/* -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.Exec; -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.IOException; -import org.apache.commons.cli.CommandLine; -import org.apache.commons.cli.CommandLineParser; -import org.apache.commons.cli.DefaultParser; -import org.apache.commons.cli.Option; -import org.apache.commons.cli.Options; -import org.apache.commons.cli.ParseException; - -/** - * A simple example of how to use the Java API - * - *

Easiest way to run this: mvn exec:java - * -Dexec.mainClass="io.kubernetes.client.examples.ExecExample" - * - *

From inside $REPO_DIR/examples - */ -public class ExecExample { - public static void main(String[] args) - throws IOException, ApiException, InterruptedException, ParseException { - final Options options = new Options(); - options.addOption(new Option("p", "pod", true, "The name of the pod")); - options.addOption(new Option("n", "namespace", true, "The namespace of the pod")); - - CommandLineParser parser = new DefaultParser(); - CommandLine cmd = parser.parse(options, args); - - String podName = cmd.getOptionValue("p", "nginx-dbddb74b8-s4cx5"); - String namespace = cmd.getOptionValue("n", "default"); - args = cmd.getArgs(); - - ApiClient client = Config.defaultClient(); - Configuration.setDefaultApiClient(client); - - Exec exec = new Exec(); - boolean tty = System.console() != null; - // final Process proc = exec.exec("default", "nginx-4217019353-k5sn9", new String[] - // {"sh", "-c", "echo foo"}, true, tty); - final Process proc = - exec.exec(namespace, podName, args.length == 0 ? new String[] {"sh"} : args, true, tty); - - Thread in = - new Thread( - new Runnable() { - public void run() { - try { - Streams.copy(System.in, proc.getOutputStream()); - } catch (IOException ex) { - ex.printStackTrace(); - } - } - }); - in.start(); - - Thread out = - new Thread( - new Runnable() { - public void run() { - try { - Streams.copy(proc.getInputStream(), System.out); - } catch (IOException ex) { - ex.printStackTrace(); - } - } - }); - out.start(); - - proc.waitFor(); - - // wait for any last output; no need to wait for input thread - out.join(); - - proc.destroy(); - - System.exit(proc.exitValue()); - } -} diff --git a/examples/examples-release-20/src/main/java/io/kubernetes/client/examples/ExpandedExample.java b/examples/examples-release-20/src/main/java/io/kubernetes/client/examples/ExpandedExample.java deleted file mode 100644 index 353f7a2634..0000000000 --- a/examples/examples-release-20/src/main/java/io/kubernetes/client/examples/ExpandedExample.java +++ /dev/null @@ -1,244 +0,0 @@ -/* -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.openapi.ApiClient; -import io.kubernetes.client.openapi.ApiException; -import io.kubernetes.client.openapi.Configuration; -import io.kubernetes.client.openapi.apis.AppsV1Api; -import io.kubernetes.client.openapi.apis.CoreV1Api; -import io.kubernetes.client.openapi.models.V1Deployment; -import io.kubernetes.client.openapi.models.V1DeploymentList; -import io.kubernetes.client.openapi.models.V1DeploymentSpec; -import io.kubernetes.client.openapi.models.V1NamespaceList; -import io.kubernetes.client.openapi.models.V1PodList; -import io.kubernetes.client.openapi.models.V1ServiceList; -import io.kubernetes.client.util.Config; -import java.io.IOException; -import java.util.List; -import java.util.Optional; -import java.util.stream.Collectors; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * A simple example of how to use the Java API - * - *

Easiest way to run this: mvn exec:java - * -Dexec.mainClass="io.kubernetes.client.examples.ExpandedExample" - * - *

From inside $REPO_DIR/examples - */ -public class ExpandedExample { - - private static CoreV1Api COREV1_API; - private static final String DEFAULT_NAME_SPACE = "default"; - private static final Integer TIME_OUT_VALUE = 180; - private static final Logger LOGGER = LoggerFactory.getLogger(ExpandedExample.class); - - /** - * Main method - * - * @param args - */ - public static void main(String[] args) { - try { - ApiClient client = Config.defaultClient(); - // To change the context of k8s cluster, you can use - // io.kubernetes.client.util.KubeConfig - Configuration.setDefaultApiClient(client); - COREV1_API = new CoreV1Api(client); - - // ScaleUp/ScaleDown the Deployment pod - // Please change the name of Deployment? - System.out.println("----- Scale Deployment Start -----"); - scaleDeployment("account-service", 5); - - // List all of the namaspaces and pods - List nameSpaces = getAllNameSpaces(); - nameSpaces.stream() - .forEach( - namespace -> { - try { - System.out.println("----- " + namespace + " -----"); - getNamespacedPod(namespace).stream().forEach(System.out::println); - } catch (ApiException ex) { - LOGGER.warn("Couldn't get the pods in namespace:{}", namespace, ex); - } - }); - - // Print all of the Services - System.out.println("----- Print list all Services Start -----"); - List services = getServices(); - services.stream().forEach(System.out::println); - System.out.println("----- Print list all Services End -----"); - - // Print log of specific pod. In this example show the first pod logs. - System.out.println("----- Print Log of Specific Pod Start -----"); - String firstPodName = getPods().get(0); - printLog(DEFAULT_NAME_SPACE, firstPodName); - System.out.println("----- Print Log of Specific Pod End -----"); - } catch (ApiException | IOException ex) { - LOGGER.warn("Exception had occured ", ex); - } - } - - /** - * Get all namespaces in k8s cluster - * - * @return - * @throws ApiException - */ - public static List getAllNameSpaces() throws ApiException { - V1NamespaceList listNamespace = - COREV1_API.listNamespace().execute(); - List list = - listNamespace.getItems().stream() - .map(v1Namespace -> v1Namespace.getMetadata().getName()) - .collect(Collectors.toList()); - return list; - } - - /** - * List all pod names in all namespaces in k8s cluster - * - * @return - * @throws ApiException - */ - public static List getPods() throws ApiException { - V1PodList v1podList = - COREV1_API.listPodForAllNamespaces().execute(); - List podList = - v1podList.getItems().stream() - .map(v1Pod -> v1Pod.getMetadata().getName()) - .collect(Collectors.toList()); - return podList; - } - - /** - * List all pod in the default namespace - * - * @return - * @throws ApiException - */ - public static List getNamespacedPod() throws ApiException { - return getNamespacedPod(DEFAULT_NAME_SPACE, null); - } - - /** - * List pod in specific namespace - * - * @param namespace - * @return - * @throws ApiException - */ - public static List getNamespacedPod(String namespace) throws ApiException { - return getNamespacedPod(namespace, null); - } - - /** - * List pod in specific namespace with label - * - * @param namespace - * @param label - * @return - * @throws ApiException - */ - public static List getNamespacedPod(String namespace, String label) throws ApiException { - V1PodList listNamespacedPod = - COREV1_API.listNamespacedPod( - namespace) - .labelSelector(label) - .timeoutSeconds(TIME_OUT_VALUE) - .watch(false) - .execute(); - List listPods = - listNamespacedPod.getItems().stream() - .map(v1pod -> v1pod.getMetadata().getName()) - .collect(Collectors.toList()); - return listPods; - } - - /** - * List all Services in default namespace - * - * @return - * @throws ApiException - */ - public static List getServices() throws ApiException { - V1ServiceList listNamespacedService = - COREV1_API.listNamespacedService(DEFAULT_NAME_SPACE) - .timeoutSeconds(TIME_OUT_VALUE) - .watch(false) - .execute(); - return listNamespacedService.getItems().stream() - .map(v1service -> v1service.getMetadata().getName()) - .collect(Collectors.toList()); - } - - /** - * Scale up/down the number of pod in Deployment - * - * @param deploymentName - * @param numberOfReplicas - * @throws ApiException - */ - public static void scaleDeployment(String deploymentName, int numberOfReplicas) - throws ApiException { - AppsV1Api appsV1Api = new AppsV1Api(); - appsV1Api.setApiClient(COREV1_API.getApiClient()); - V1DeploymentList listNamespacedDeployment = - appsV1Api.listNamespacedDeployment( - DEFAULT_NAME_SPACE) - .watch(false) - .execute(); - - List appsV1DeploymentItems = listNamespacedDeployment.getItems(); - Optional findedDeployment = - appsV1DeploymentItems.stream() - .filter( - (V1Deployment deployment) -> - deployment.getMetadata().getName().equals(deploymentName)) - .findFirst(); - findedDeployment.ifPresent( - (V1Deployment deploy) -> { - try { - V1DeploymentSpec newSpec = deploy.getSpec().replicas(numberOfReplicas); - V1Deployment newDeploy = deploy.spec(newSpec); - appsV1Api.replaceNamespacedDeployment( - deploymentName, DEFAULT_NAME_SPACE, newDeploy).execute(); - } catch (ApiException ex) { - LOGGER.warn("Scale the pod failed for Deployment:{}", deploymentName, ex); - } - }); - } - - /** - * Print out the Log for specific Pods - * - * @param namespace - * @param podName - * @throws ApiException - */ - public static void printLog(String namespace, String podName) throws ApiException { - // https://github.com/kubernetes-client/java/blob/master/kubernetes/docs/CoreV1Api.md#readNamespacedPodLog - String readNamespacedPodLog = - COREV1_API.readNamespacedPodLog(podName, namespace) - .follow(false) - .limitBytes(Integer.MAX_VALUE) - .sinceSeconds(Integer.MAX_VALUE) - .tailLines(40) - .execute(); - System.out.println(readNamespacedPodLog); - } -} diff --git a/examples/examples-release-20/src/main/java/io/kubernetes/client/examples/FluentExample.java b/examples/examples-release-20/src/main/java/io/kubernetes/client/examples/FluentExample.java deleted file mode 100644 index 52c6c542a9..0000000000 --- a/examples/examples-release-20/src/main/java/io/kubernetes/client/examples/FluentExample.java +++ /dev/null @@ -1,74 +0,0 @@ -/* -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.openapi.ApiClient; -import io.kubernetes.client.openapi.ApiException; -import io.kubernetes.client.openapi.Configuration; -import io.kubernetes.client.openapi.apis.CoreV1Api; -import io.kubernetes.client.openapi.models.V1Container; -import io.kubernetes.client.openapi.models.V1ObjectMeta; -import io.kubernetes.client.openapi.models.V1Pod; -import io.kubernetes.client.openapi.models.V1PodBuilder; -import io.kubernetes.client.openapi.models.V1PodList; -import io.kubernetes.client.openapi.models.V1PodSpec; -import io.kubernetes.client.util.Config; -import java.io.IOException; -import java.util.Arrays; - -/** - * A simple example of how to use the Java API - * - *

Easiest way to run this: mvn exec:java - * -Dexec.mainClass="io.kubernetes.client.examples.FluentExample" - * - *

From inside $REPO_DIR/examples - */ -public class FluentExample { - public static void main(String[] args) throws IOException, ApiException { - ApiClient client = Config.defaultClient(); - Configuration.setDefaultApiClient(client); - - CoreV1Api api = new CoreV1Api(); - - V1Pod pod = - new V1PodBuilder() - .withNewMetadata() - .withName("apod") - .endMetadata() - .withNewSpec() - .addNewContainer() - .withName("www") - .withImage("nginx") - .endContainer() - .endSpec() - .build(); - - api.createNamespacedPod("default", pod).execute(); - - V1Pod pod2 = - new V1Pod() - .metadata(new V1ObjectMeta().name("anotherpod")) - .spec( - new V1PodSpec() - .containers(Arrays.asList(new V1Container().name("www").image("nginx")))); - - api.createNamespacedPod("default", pod2).execute(); - - V1PodList list = - api.listNamespacedPod("default").execute(); - for (V1Pod item : list.getItems()) { - System.out.println(item.getMetadata().getName()); - } - } -} diff --git a/examples/examples-release-20/src/main/java/io/kubernetes/client/examples/GenericClientExample.java b/examples/examples-release-20/src/main/java/io/kubernetes/client/examples/GenericClientExample.java deleted file mode 100644 index ddfb1243b8..0000000000 --- a/examples/examples-release-20/src/main/java/io/kubernetes/client/examples/GenericClientExample.java +++ /dev/null @@ -1,63 +0,0 @@ -/* -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.custom.V1Patch; -import io.kubernetes.client.openapi.ApiClient; -import io.kubernetes.client.openapi.models.V1Container; -import io.kubernetes.client.openapi.models.V1ObjectMeta; -import io.kubernetes.client.openapi.models.V1Pod; -import io.kubernetes.client.openapi.models.V1PodList; -import io.kubernetes.client.openapi.models.V1PodSpec; -import io.kubernetes.client.util.ClientBuilder; -import io.kubernetes.client.util.generic.GenericKubernetesApi; -import java.util.Arrays; - -public class GenericClientExample { - - public static void main(String[] args) throws Exception { - - // The following codes demonstrates using generic client to manipulate pods - V1Pod pod = - new V1Pod() - .metadata(new V1ObjectMeta().name("foo").namespace("default")) - .spec( - new V1PodSpec() - .containers(Arrays.asList(new V1Container().name("c").image("test")))); - - ApiClient apiClient = ClientBuilder.standard().build(); - GenericKubernetesApi podClient = - new GenericKubernetesApi<>(V1Pod.class, V1PodList.class, "", "v1", "pods", apiClient); - - V1Pod latestPod = podClient.create(pod).throwsApiException().getObject(); - System.out.println("Created!"); - - V1Pod patchedPod = - podClient - .patch( - "default", - "foo", - V1Patch.PATCH_FORMAT_STRATEGIC_MERGE_PATCH, - new V1Patch("{\"metadata\":{\"finalizers\":[\"example.io/foo\"]}}")) - .throwsApiException() - .getObject(); - System.out.println("Patched!"); - - V1Pod deletedPod = podClient.delete("default", "foo").throwsApiException().getObject(); - if (deletedPod != null) { - System.out.println( - "Received after-deletion status of the requested object, will be deleting in background!"); - } - System.out.println("Deleted!"); - } -} diff --git a/examples/examples-release-20/src/main/java/io/kubernetes/client/examples/InClusterClientExample.java b/examples/examples-release-20/src/main/java/io/kubernetes/client/examples/InClusterClientExample.java deleted file mode 100644 index ac53b22dd9..0000000000 --- a/examples/examples-release-20/src/main/java/io/kubernetes/client/examples/InClusterClientExample.java +++ /dev/null @@ -1,58 +0,0 @@ -/* -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.openapi.ApiClient; -import io.kubernetes.client.openapi.ApiException; -import io.kubernetes.client.openapi.Configuration; -import io.kubernetes.client.openapi.apis.CoreV1Api; -import io.kubernetes.client.openapi.models.V1Pod; -import io.kubernetes.client.openapi.models.V1PodList; -import io.kubernetes.client.util.ClientBuilder; -import java.io.IOException; - -/** - * A simple example of how to use the Java API inside a kubernetes cluster - * - *

Easiest way to run this: mvn exec:java - * -Dexec.mainClass="io.kubernetes.client.examples.InClusterClientExample" - * - *

From inside $REPO_DIR/examples - */ -public class InClusterClientExample { - public static void main(String[] args) throws IOException, ApiException { - - // loading the in-cluster config, including: - // 1. service-account CA - // 2. service-account bearer-token - // 3. service-account namespace - // 4. master endpoints(ip, port) from pre-set environment variables - ApiClient client = ClientBuilder.cluster().build(); - - // if you prefer not to refresh service account token, please use: - // ApiClient client = ClientBuilder.oldCluster().build(); - - // set the global default api-client to the in-cluster one from above - Configuration.setDefaultApiClient(client); - - // the CoreV1Api loads default api-client from global configuration. - CoreV1Api api = new CoreV1Api(); - - // invokes the CoreV1Api client - V1PodList list = - api.listPodForAllNamespaces().execute(); - for (V1Pod item : list.getItems()) { - System.out.println(item.getMetadata().getName()); - } - } -} diff --git a/examples/examples-release-20/src/main/java/io/kubernetes/client/examples/InformerExample.java b/examples/examples-release-20/src/main/java/io/kubernetes/client/examples/InformerExample.java deleted file mode 100644 index 0abf3d5cae..0000000000 --- a/examples/examples-release-20/src/main/java/io/kubernetes/client/examples/InformerExample.java +++ /dev/null @@ -1,99 +0,0 @@ -/* -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.informer.ResourceEventHandler; -import io.kubernetes.client.informer.SharedIndexInformer; -import io.kubernetes.client.informer.SharedInformerFactory; -import io.kubernetes.client.informer.cache.Lister; -import io.kubernetes.client.openapi.ApiClient; -import io.kubernetes.client.openapi.apis.CoreV1Api; -import io.kubernetes.client.openapi.models.V1Node; -import io.kubernetes.client.openapi.models.V1NodeList; -import io.kubernetes.client.openapi.models.V1ObjectMeta; -import io.kubernetes.client.util.CallGeneratorParams; -import java.util.concurrent.TimeUnit; -import okhttp3.OkHttpClient; - -/** - * A simple example of how to use the Java API - * - *

Easiest way to run this: mvn exec:java - * -Dexec.mainClass="io.kubernetes.client.examples.InformerExample" - * - *

From inside $REPO_DIR/examples - */ -public class InformerExample { - public static void main(String[] args) throws Exception { - CoreV1Api coreV1Api = new CoreV1Api(); - ApiClient apiClient = coreV1Api.getApiClient(); - OkHttpClient httpClient = - apiClient.getHttpClient().newBuilder().readTimeout(0, TimeUnit.SECONDS).build(); - apiClient.setHttpClient(httpClient); - - SharedInformerFactory factory = new SharedInformerFactory(apiClient); - - // Node informer - SharedIndexInformer nodeInformer = - factory.sharedIndexInformerFor( - // **NOTE**: - // The following "CallGeneratorParams" lambda merely generates a stateless - // HTTPs requests, the effective apiClient is the one specified when constructing - // the informer-factory. - (CallGeneratorParams params) -> { - return coreV1Api.listNode() - .resourceVersion(params.resourceVersion) - .watch(params.watch) - .timeoutSeconds(params.timeoutSeconds) - .buildCall(null); - }, - V1Node.class, - V1NodeList.class); - - nodeInformer.addEventHandler( - new ResourceEventHandler() { - @Override - public void onAdd(V1Node node) { - System.out.printf("%s node added!\n", node.getMetadata().getName()); - } - - @Override - public void onUpdate(V1Node oldNode, V1Node newNode) { - System.out.printf( - "%s => %s node updated!\n", - oldNode.getMetadata().getName(), newNode.getMetadata().getName()); - } - - @Override - public void onDelete(V1Node node, boolean deletedFinalStateUnknown) { - System.out.printf("%s node deleted!\n", node.getMetadata().getName()); - } - }); - - factory.startAllRegisteredInformers(); - - V1Node nodeToCreate = new V1Node(); - V1ObjectMeta metadata = new V1ObjectMeta(); - metadata.setName("noxu"); - nodeToCreate.setMetadata(metadata); - V1Node createdNode = coreV1Api.createNode(nodeToCreate).execute(); - Thread.sleep(3000); - - Lister nodeLister = new Lister(nodeInformer.getIndexer()); - V1Node node = nodeLister.get("noxu"); - System.out.printf("noxu created! %s\n", node.getMetadata().getCreationTimestamp()); - factory.stopAllRegisteredInformers(); - Thread.sleep(3000); - System.out.println("informer stopped.."); - } -} diff --git a/examples/examples-release-20/src/main/java/io/kubernetes/client/examples/KubeConfigFileClientExample.java b/examples/examples-release-20/src/main/java/io/kubernetes/client/examples/KubeConfigFileClientExample.java deleted file mode 100644 index 7860bd918d..0000000000 --- a/examples/examples-release-20/src/main/java/io/kubernetes/client/examples/KubeConfigFileClientExample.java +++ /dev/null @@ -1,58 +0,0 @@ -/* -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.openapi.ApiClient; -import io.kubernetes.client.openapi.ApiException; -import io.kubernetes.client.openapi.Configuration; -import io.kubernetes.client.openapi.apis.CoreV1Api; -import io.kubernetes.client.openapi.models.V1Pod; -import io.kubernetes.client.openapi.models.V1PodList; -import io.kubernetes.client.util.ClientBuilder; -import io.kubernetes.client.util.KubeConfig; -import java.io.FileReader; -import java.io.IOException; - -/** - * A simple example of how to use the Java API from an application outside a kubernetes cluster - * - *

Easiest way to run this: mvn exec:java - * -Dexec.mainClass="io.kubernetes.client.examples.KubeConfigFileClientExample" - * - *

From inside $REPO_DIR/examples - */ -public class KubeConfigFileClientExample { - public static void main(String[] args) throws IOException, ApiException { - - // file path to your KubeConfig - - String kubeConfigPath = System.getenv("HOME") + "/.kube/config"; - - // loading the out-of-cluster config, a kubeconfig from file-system - ApiClient client = - ClientBuilder.kubeconfig(KubeConfig.loadKubeConfig(new FileReader(kubeConfigPath))).build(); - - // set the global default api-client to the out-of-cluster one from above - Configuration.setDefaultApiClient(client); - - // the CoreV1Api loads default api-client from global configuration. - CoreV1Api api = new CoreV1Api(); - - // invokes the CoreV1Api client - V1PodList list = - api.listPodForAllNamespaces().execute(); - for (V1Pod item : list.getItems()) { - System.out.println(item.getMetadata().getName()); - } - } -} diff --git a/examples/examples-release-20/src/main/java/io/kubernetes/client/examples/KubectlExample.java b/examples/examples-release-20/src/main/java/io/kubernetes/client/examples/KubectlExample.java deleted file mode 100644 index 2619c9f271..0000000000 --- a/examples/examples-release-20/src/main/java/io/kubernetes/client/examples/KubectlExample.java +++ /dev/null @@ -1,311 +0,0 @@ -/* -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 static io.kubernetes.client.extended.kubectl.Kubectl.apiResources; -import static io.kubernetes.client.extended.kubectl.Kubectl.copy; -import static io.kubernetes.client.extended.kubectl.Kubectl.cordon; -import static io.kubernetes.client.extended.kubectl.Kubectl.delete; -import static io.kubernetes.client.extended.kubectl.Kubectl.drain; -import static io.kubernetes.client.extended.kubectl.Kubectl.exec; -import static io.kubernetes.client.extended.kubectl.Kubectl.label; -import static io.kubernetes.client.extended.kubectl.Kubectl.log; -import static io.kubernetes.client.extended.kubectl.Kubectl.portforward; -import static io.kubernetes.client.extended.kubectl.Kubectl.scale; -import static io.kubernetes.client.extended.kubectl.Kubectl.taint; -import static io.kubernetes.client.extended.kubectl.Kubectl.top; -import static io.kubernetes.client.extended.kubectl.Kubectl.uncordon; -import static io.kubernetes.client.extended.kubectl.Kubectl.version; -import static io.kubernetes.client.extended.kubectl.KubectlTop.podMetricSum; - -import io.kubernetes.client.common.KubernetesObject; -import io.kubernetes.client.custom.NodeMetrics; -import io.kubernetes.client.custom.PodMetrics; -import io.kubernetes.client.extended.kubectl.KubectlExec; -import io.kubernetes.client.extended.kubectl.KubectlPortForward; -import io.kubernetes.client.extended.kubectl.exception.KubectlException; -import io.kubernetes.client.openapi.ApiClient; -import io.kubernetes.client.openapi.models.V1Deployment; -import io.kubernetes.client.openapi.models.V1Node; -import io.kubernetes.client.openapi.models.V1Pod; -import io.kubernetes.client.openapi.models.V1ReplicationController; -import io.kubernetes.client.openapi.models.V1Service; -import io.kubernetes.client.util.Config; -import io.kubernetes.client.util.Streams; -import java.util.Arrays; -import java.util.List; -import org.apache.commons.cli.CommandLine; -import org.apache.commons.cli.DefaultParser; -import org.apache.commons.cli.Option; -import org.apache.commons.cli.Options; -import org.apache.commons.cli.ParseException; -import org.apache.commons.lang3.tuple.Pair; - -/** - * A Java equivalent for the kubectl command line tool. Not nearly as complete. - * - *

Easiest way to run this: mvn exec:java - * -Dexec.mainClass="io.kubernetes.client.examples.KubectlExample" -Dexec.args="log some-pod" - * - *

From inside $REPO_DIR/examples - */ -public class KubectlExample { - static Class getClassForKind(String kind) { - switch (kind) { - case "pod": - case "pods": - return V1Pod.class; - case "deployment": - case "deployments": - return V1Deployment.class; - case "service": - case "services": - return V1Service.class; - case "node": - case "nodes": - return V1Node.class; - case "replicationcontroller": - case "replicationcontrollers": - return V1ReplicationController.class; - } - return null; - } - - private static final String PADDING = " "; - - private static String pad(String value) { - while (value.length() < PADDING.length()) { - value += " "; - } - return value; - } - - public static void main(String[] args) - throws java.io.IOException, KubectlException, ParseException { - ApiClient client = Config.defaultClient(); - - Options options = new Options(); - options.addOption(new Option("n", "namespace", true, "The namespace for the resource")); - options.addOption(new Option("r", "replicas", true, "The number of replicas to scale to")); - options.addOption(new Option("c", "container", true, "The container in a pod to connect to")); - DefaultParser parser = new DefaultParser(); - CommandLine cli = parser.parse(options, args); - - args = cli.getArgs(); - String verb = args[0]; - String ns = cli.getOptionValue("n", "default"); - String kind = null; - String name = null; - - switch (verb) { - case "delete": - kind = args[1]; - name = args[2]; - delete(getClassForKind(kind)).namespace(ns).name(name).execute(); - case "drain": - name = args[1]; - drain().apiClient(client).name(name).execute(); - System.out.println("Node drained"); - System.exit(0); - case "cordon": - name = args[1]; - cordon().apiClient(client).name(name).execute(); - System.out.println("Node cordoned"); - System.exit(0); - case "uncordon": - name = args[1]; - uncordon().apiClient(client).name(name).execute(); - System.out.println("Node uncordoned"); - System.exit(0); - case "top": - String what = args[1]; - switch (what) { - case "nodes": - case "node": - List> nodes = - top(V1Node.class, NodeMetrics.class).apiClient(client).metric("cpu").execute(); - System.out.println(pad("Node") + "\tCPU\t\tMemory"); - for (Pair node : nodes) { - System.out.println( - pad(node.getLeft().getMetadata().getName()) - + "\t" - + node.getRight().getUsage().get("cpu").getNumber() - + "\t" - + node.getRight().getUsage().get("memory").getNumber()); - } - System.exit(0); - case "pods": - case "pod": - List> pods = - top(V1Pod.class, PodMetrics.class) - .apiClient(client) - .namespace(ns) - .metric("cpu") - .execute(); - System.out.println(pad("Pod") + "\tCPU\t\tMemory"); - for (Pair pod : pods) { - System.out.println( - pad(pod.getLeft().getMetadata().getName()) - + "\t" - + podMetricSum(pod.getRight(), "cpu") - + "\t" - + podMetricSum(pod.getRight(), "memory")); - } - System.exit(0); - } - System.err.println("Unknown top argument: " + what); - System.exit(-1); - case "cp": - String from = args[1]; - String to = args[2]; - if (from.indexOf(":") != -1) { - String[] parts = from.split(":"); - name = parts[0]; - from = parts[1]; - copy() - .apiClient(client) - .namespace(ns) - .name(name) - .container(cli.getOptionValue("c", "")) - .fromPod(from) - .to(to) - .execute(); - } else if (to.indexOf(":") != -1) { - String[] parts = to.split(":"); - name = parts[0]; - to = parts[1]; - copy() - .apiClient(client) - .namespace(ns) - .name(name) - .container(cli.getOptionValue("c", "")) - .from(from) - .toPod(to) - .execute(); - } else { - System.err.println("Missing pod name for copy."); - System.exit(-1); - } - System.out.println("Copied " + from + " -> " + to); - System.exit(0); - case "taint": - name = args[1]; - String taintSpec = args[2]; - boolean remove = taintSpec.endsWith("-"); - int ix = taintSpec.indexOf("="); - int ix2 = taintSpec.indexOf(":"); - - if (remove) { - taintSpec = taintSpec.substring(0, taintSpec.length() - 2); - String key = ix == -1 ? taintSpec : taintSpec.substring(0, ix); - String effect = ix == -1 ? null : taintSpec.substring(ix + 1); - - if (effect == null) { - taint().apiClient(client).name(name).removeTaint(key).execute(); - } else { - taint().apiClient(client).name(name).removeTaint(key, effect).execute(); - } - System.exit(0); - } - if (ix2 == -1) { - System.err.println("key:effect or key=value:effect is required."); - System.exit(-1); - } - String key = taintSpec.substring(0, ix == -1 ? ix2 : ix); - String value = ix == -1 ? null : taintSpec.substring(ix + 1, ix2); - String effect = taintSpec.substring(ix2 + 1); - - if (value == null) { - taint().apiClient(client).name(name).addTaint(key, effect).execute(); - } else { - taint().apiClient(client).name(name).addTaint(key, value, effect).execute(); - } - System.exit(0); - case "portforward": - name = args[1]; - KubectlPortForward forward = portforward().apiClient(client).name(name).namespace(ns); - for (int i = 2; i < args.length; i++) { - String port = args[i]; - String[] ports = port.split(":"); - System.out.println("Forwarding " + ns + "/" + name + " " + ports[0] + "->" + ports[1]); - forward.ports(Integer.parseInt(ports[0]), Integer.parseInt(ports[1])); - } - forward.execute(); - System.exit(0); - case "log": - name = args[1]; - Streams.copy( - log() - .apiClient(client) - .name(name) - .namespace(ns) - .container(cli.getOptionValue("c", "")) - .execute(), - System.out); - System.exit(0); - case "scale": - kind = args[1]; - name = args[2]; - if (!cli.hasOption("r")) { - System.err.println("--replicas is required"); - System.exit(-3); - } - int replicas = Integer.parseInt(cli.getOptionValue("r")); - scale(getClassForKind(kind)) - .apiClient(client) - .namespace(ns) - .name(name) - .replicas(replicas) - .execute(); - System.out.println("Deployment scaled."); - System.exit(0); - case "version": - System.out.println(version().apiClient(client)); - System.exit(0); - case "label": - kind = args[1]; - name = args[2]; - String labelKey = args[3]; - String labelValue = args[4]; - Class clazz = getClassForKind(kind); - if (clazz == null) { - System.err.println("Unknown kind: " + kind); - System.exit(-2); - } - label(clazz).apiClient(client).namespace(ns).name(name).addLabel(labelKey, labelValue); - System.exit(0); - case "exec": - name = args[1]; - String[] command = Arrays.copyOfRange(args, 2, args.length); - KubectlExec e = - exec() - .apiClient(client) - .namespace(ns) - .name(name) - .command(command) - .container(cli.getOptionValue("c", "")); - System.exit(e.execute()); - case "api-resources": - apiResources().apiClient(client).execute().stream() - .forEach( - r -> - System.out.printf( - "%s\t\t%s\t\t%s\t\t%s\n", - r.getResourcePlural(), r.getGroup(), r.getKind(), r.getNamespaced())); - System.exit(0); - default: - System.out.println("Unknown verb: " + verb); - System.exit(-1); - } - } -} diff --git a/examples/examples-release-20/src/main/java/io/kubernetes/client/examples/LeaderElectionExample.java b/examples/examples-release-20/src/main/java/io/kubernetes/client/examples/LeaderElectionExample.java deleted file mode 100644 index 0e48689602..0000000000 --- a/examples/examples-release-20/src/main/java/io/kubernetes/client/examples/LeaderElectionExample.java +++ /dev/null @@ -1,56 +0,0 @@ -/* -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.extended.leaderelection.LeaderElectionConfig; -import io.kubernetes.client.extended.leaderelection.LeaderElector; -import io.kubernetes.client.extended.leaderelection.resourcelock.EndpointsLock; -import io.kubernetes.client.openapi.ApiClient; -import io.kubernetes.client.openapi.Configuration; -import io.kubernetes.client.util.Config; -import java.time.Duration; -import java.util.UUID; - -/** - * A simple example of how to use the Java API - * - *

Easiest way to run this: mvn exec:java - * -Dexec.mainClass="io.kubernetes.client.examples.LeaderElectionExample" - * - *

From inside $REPO_DIR/examples - */ -public class LeaderElectionExample { - public static void main(String[] args) throws Exception { - ApiClient client = Config.defaultClient(); - Configuration.setDefaultApiClient(client); - - // New - String appNamespace = "default"; - String appName = "leader-election-foobar"; - String lockHolderIdentityName = UUID.randomUUID().toString(); // Anything unique - EndpointsLock lock = new EndpointsLock(appNamespace, appName, lockHolderIdentityName); - - LeaderElectionConfig leaderElectionConfig = - new LeaderElectionConfig( - lock, Duration.ofMillis(10000), Duration.ofMillis(8000), Duration.ofMillis(2000)); - try (LeaderElector leaderElector = new LeaderElector(leaderElectionConfig)) { - leaderElector.run( - () -> { - System.out.println("Do something when getting leadership."); - }, - () -> { - System.out.println("Do something when losing leadership."); - }); - } - } -} diff --git a/examples/examples-release-20/src/main/java/io/kubernetes/client/examples/LogsExample.java b/examples/examples-release-20/src/main/java/io/kubernetes/client/examples/LogsExample.java deleted file mode 100644 index d01eb40ab3..0000000000 --- a/examples/examples-release-20/src/main/java/io/kubernetes/client/examples/LogsExample.java +++ /dev/null @@ -1,51 +0,0 @@ -/* -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.PodLogs; -import io.kubernetes.client.openapi.ApiClient; -import io.kubernetes.client.openapi.ApiException; -import io.kubernetes.client.openapi.Configuration; -import io.kubernetes.client.openapi.apis.CoreV1Api; -import io.kubernetes.client.openapi.models.V1Pod; -import io.kubernetes.client.util.Config; -import io.kubernetes.client.util.Streams; -import java.io.IOException; -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" - * - *

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); - - PodLogs logs = new PodLogs(); - V1Pod pod = - coreApi - .listNamespacedPod("default") - .execute() - .getItems() - .get(0); - - InputStream is = logs.streamNamespacedPodLog(pod); - Streams.copy(is, System.out); - } -} diff --git a/examples/examples-release-20/src/main/java/io/kubernetes/client/examples/MetricsExample.java b/examples/examples-release-20/src/main/java/io/kubernetes/client/examples/MetricsExample.java deleted file mode 100644 index 0d8c10e30b..0000000000 --- a/examples/examples-release-20/src/main/java/io/kubernetes/client/examples/MetricsExample.java +++ /dev/null @@ -1,68 +0,0 @@ -/* -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.Metrics; -import io.kubernetes.client.custom.ContainerMetrics; -import io.kubernetes.client.custom.NodeMetrics; -import io.kubernetes.client.custom.NodeMetricsList; -import io.kubernetes.client.custom.PodMetrics; -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 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.MetricsExample" - * - *

From inside $REPO_DIR/examples - */ -public class MetricsExample { - public static void main(String[] args) throws IOException, ApiException { - ApiClient client = Config.defaultClient(); - Configuration.setDefaultApiClient(client); - - Metrics metrics = new Metrics(client); - NodeMetricsList list = metrics.getNodeMetrics(); - for (NodeMetrics item : list.getItems()) { - System.out.println(item.getMetadata().getName()); - System.out.println("------------------------------"); - for (String key : item.getUsage().keySet()) { - System.out.println("\t" + key); - System.out.println("\t" + item.getUsage().get(key)); - } - System.out.println(); - } - - for (PodMetrics item : metrics.getPodMetrics("default").getItems()) { - System.out.println(item.getMetadata().getName()); - System.out.println("------------------------------"); - if (item.getContainers() == null) { - continue; - } - for (ContainerMetrics container : item.getContainers()) { - System.out.println(container.getName()); - System.out.println("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-"); - for (String key : container.getUsage().keySet()) { - System.out.println("\t" + key); - System.out.println("\t" + container.getUsage().get(key)); - } - System.out.println(); - } - } - } -} diff --git a/examples/examples-release-20/src/main/java/io/kubernetes/client/examples/PagerExample.java b/examples/examples-release-20/src/main/java/io/kubernetes/client/examples/PagerExample.java deleted file mode 100644 index 65f0f5d08f..0000000000 --- a/examples/examples-release-20/src/main/java/io/kubernetes/client/examples/PagerExample.java +++ /dev/null @@ -1,65 +0,0 @@ -/* -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.extended.pager.Pager; -import io.kubernetes.client.openapi.ApiClient; -import io.kubernetes.client.openapi.Configuration; -import io.kubernetes.client.openapi.apis.CoreV1Api; -import io.kubernetes.client.openapi.models.V1Namespace; -import io.kubernetes.client.openapi.models.V1NamespaceList; -import io.kubernetes.client.util.Config; -import java.io.IOException; -import java.util.concurrent.TimeUnit; -import okhttp3.OkHttpClient; - -/** - * A simple example of how to use the Java API - * - *

Easiest way to run this: mvn exec:java - * -Dexec.mainClass="io.kubernetes.client.examples.PagerExample" - * - *

From inside $REPO_DIR/examples - */ -public class PagerExample { - public static void main(String[] args) throws IOException { - - ApiClient client = Config.defaultClient(); - OkHttpClient httpClient = - client.getHttpClient().newBuilder().readTimeout(60, TimeUnit.SECONDS).build(); - client.setHttpClient(httpClient); - Configuration.setDefaultApiClient(client); - CoreV1Api api = new CoreV1Api(); - int i = 0; - Pager pager = - new Pager( - (Pager.PagerParams param) -> { - try { - return api.listNamespace() - ._continue(param.getContinueToken()) - .limit(param.getLimit()) - .timeoutSeconds(1) - .buildCall(null); - } catch (Exception e) { - throw new RuntimeException(e); - } - }, - client, - 10, - V1NamespaceList.class); - for (V1Namespace namespace : pager) { - System.out.println(namespace.getMetadata().getName()); - } - System.out.println("------------------"); - } -} diff --git a/examples/examples-release-20/src/main/java/io/kubernetes/client/examples/ParseExample.java b/examples/examples-release-20/src/main/java/io/kubernetes/client/examples/ParseExample.java deleted file mode 100644 index 92866a46fe..0000000000 --- a/examples/examples-release-20/src/main/java/io/kubernetes/client/examples/ParseExample.java +++ /dev/null @@ -1,64 +0,0 @@ -/* -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.openapi.ApiClient; -import io.kubernetes.client.openapi.ApiException; -import io.kubernetes.client.util.Config; -import java.io.FileReader; -import java.io.IOException; -import java.io.StringReader; - -/** - * A simple example of how to parse a Kubernetes object. - * - *

Easiest way to run this: mvn exec:java - * -Dexec.mainClass="io.kubernetes.client.examples.ParseExample" - * - *

From inside $REPO_DIR/examples - */ -public class ParseExample { - public static void main(String[] args) throws IOException, ApiException, ClassNotFoundException { - if (args.length < 2) { - System.err.println("Usage: ParseExample "); - System.exit(1); - } - ApiClient client = Config.defaultClient(); - FileReader json = new FileReader(args[0]); - Object obj = - client - .getJSON() - .getGson() - .fromJson(json, Class.forName("io.kubernetes.client.models." + args[1])); - - String output = client.getJSON().getGson().toJson(obj); - - // Test round tripping... - Object obj2 = - client - .getJSON() - .getGson() - .fromJson( - new StringReader(output), Class.forName("io.kubernetes.client.models." + args[1])); - - String output2 = client.getJSON().getGson().toJson(obj2); - - // Validate round trip - if (!output.equals(output2)) { - System.err.println("Error, expected:\n" + output + "\nto equal\n" + output2); - System.exit(2); - } - - System.out.println(output); - } -} diff --git a/examples/examples-release-20/src/main/java/io/kubernetes/client/examples/PatchExample.java b/examples/examples-release-20/src/main/java/io/kubernetes/client/examples/PatchExample.java deleted file mode 100644 index 00e55f8c38..0000000000 --- a/examples/examples-release-20/src/main/java/io/kubernetes/client/examples/PatchExample.java +++ /dev/null @@ -1,117 +0,0 @@ -/* -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.custom.V1Patch; -import io.kubernetes.client.openapi.ApiException; -import io.kubernetes.client.openapi.Configuration; -import io.kubernetes.client.openapi.apis.AppsV1Api; -import io.kubernetes.client.openapi.models.V1Deployment; -import io.kubernetes.client.util.ClientBuilder; -import io.kubernetes.client.util.PatchUtils; -import java.io.IOException; - -/** - * A simple Example of how to use the Java API.
- * This example demonstrates patching of deployment using Json Patch and Strategic Merge Patch.
- * For generating Json Patches, refer http://jsonpatch.com. For - * generating Strategic Merge Patches, refer strategic-merge-patch.md. - * - *

- * - *

Easiest way to run this: mvn exec:java - * -Dexec.mainClass="io.kubernetes.client.examples.PatchExample" - * - *

From inside $REPO_DIR/examples - */ -public class PatchExample { - static String jsonPatchStr = - "[{\"op\":\"replace\",\"path\":\"/spec/template/spec/terminationGracePeriodSeconds\",\"value\":27}]"; - static String strategicMergePatchStr = - "{\"metadata\":{\"$deleteFromPrimitiveList/finalizers\":[\"example.com/test\"]}}"; - static String jsonDeploymentStr = - "{\"kind\":\"Deployment\",\"apiVersion\":\"apps/v1\",\"metadata\":{\"name\":\"hello-node\",\"finalizers\":[\"example.com/test\"],\"labels\":{\"run\":\"hello-node\"}},\"spec\":{\"replicas\":1,\"selector\":{\"matchLabels\":{\"run\":\"hello-node\"}},\"template\":{\"metadata\":{\"creationTimestamp\":null,\"labels\":{\"run\":\"hello-node\"}},\"spec\":{\"terminationGracePeriodSeconds\":30,\"containers\":[{\"name\":\"hello-node\",\"image\":\"hello-node:v1\",\"ports\":[{\"containerPort\":8080,\"protocol\":\"TCP\"}],\"resources\":{}}]}},\"strategy\":{}},\"status\":{}}"; - static String applyYamlStr = - "{\"kind\":\"Deployment\",\"apiVersion\":\"apps/v1\",\"metadata\":{\"name\":\"hello-node\",\"finalizers\":[\"example.com/test\"],\"labels\":{\"run\":\"hello-node\"}},\"spec\":{\"replicas\":1,\"selector\":{\"matchLabels\":{\"run\":\"hello-node\"}},\"template\":{\"metadata\":{\"creationTimestamp\":null,\"labels\":{\"run\":\"hello-node\"}},\"spec\":{\"terminationGracePeriodSeconds\":30,\"containers\":[{\"name\":\"hello-node\",\"image\":\"hello-node:v2\",\"ports\":[{\"containerPort\":8080,\"protocol\":\"TCP\"}],\"resources\":{}}]}},\"strategy\":{}},\"status\":{}}"; - - public static void main(String[] args) throws IOException { - try { - AppsV1Api api = new AppsV1Api(ClientBuilder.standard().build()); - V1Deployment body = - Configuration.getDefaultApiClient() - .getJSON() - .deserialize(jsonDeploymentStr, V1Deployment.class); - - // create a deployment - V1Deployment deploy1 = - api.createNamespacedDeployment("default", body).execute(); - System.out.println("original deployment" + deploy1); - - // json-patch a deployment - V1Deployment deploy2 = - PatchUtils.patch( - V1Deployment.class, - () -> - api.patchNamespacedDeployment( - "hello-node", - "default", - new V1Patch(jsonPatchStr)) - .buildCall(null), - V1Patch.PATCH_FORMAT_JSON_PATCH, - api.getApiClient()); - System.out.println("json-patched deployment" + deploy2); - - // strategic-merge-patch a deployment - V1Deployment deploy3 = - PatchUtils.patch( - V1Deployment.class, - () -> - api.patchNamespacedDeployment( - "hello-node", - "default", - new V1Patch(strategicMergePatchStr)) - .buildCall(null), - V1Patch.PATCH_FORMAT_STRATEGIC_MERGE_PATCH, - api.getApiClient()); - System.out.println("strategic-merge-patched deployment" + deploy3); - - // apply-yaml a deployment, server side apply is available by default after kubernetes v1.16 - // or opt-in by turning on the feature gate for v1.14 or v1.15. - // https://kubernetes.io/docs/reference/using-api/api-concepts/#server-side-apply - V1Deployment deploy4 = - PatchUtils.patch( - V1Deployment.class, - () -> - api.patchNamespacedDeployment( - "hello-node", - "default", - new V1Patch(applyYamlStr)) - .fieldManager("example-field-manager") - .force(true) - .buildCall(null), - V1Patch.PATCH_FORMAT_APPLY_YAML, - api.getApiClient()); - System.out.println("application/apply-patch+yaml deployment" + deploy4); - - } catch (ApiException e) { - System.out.println(e.getResponseBody()); - e.printStackTrace(); - } - } -} diff --git a/examples/examples-release-20/src/main/java/io/kubernetes/client/examples/PortForwardExample.java b/examples/examples-release-20/src/main/java/io/kubernetes/client/examples/PortForwardExample.java deleted file mode 100644 index cbe064db31..0000000000 --- a/examples/examples-release-20/src/main/java/io/kubernetes/client/examples/PortForwardExample.java +++ /dev/null @@ -1,87 +0,0 @@ -/* -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.PortForward; -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.IOException; -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...) - */ -public class PortForwardExample { - 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<>(); - int localPort = 8080; - int targetPort = 8080; - ports.add(targetPort); - final PortForward.PortForwardResult result = - forward.forward("default", "camera-viz-7949dbf7c6-lpxkd", ports); - System.out.println("Forwarding!"); - ServerSocket ss = new ServerSocket(localPort); - - final Socket s = ss.accept(); - System.out.println("Connected!"); - - new Thread( - new Runnable() { - public void run() { - try { - Streams.copy(result.getInputStream(targetPort), s.getOutputStream()); - } catch (IOException ex) { - ex.printStackTrace(); - } catch (Exception ex) { - ex.printStackTrace(); - } - } - }) - .start(); - - new Thread( - new Runnable() { - public void run() { - try { - Streams.copy(s.getInputStream(), result.getOutboundStream(targetPort)); - } catch (IOException ex) { - ex.printStackTrace(); - } catch (Exception ex) { - ex.printStackTrace(); - } - } - }) - .start(); - - Thread.sleep(10 * 1000); - - System.exit(0); - } -} diff --git a/examples/examples-release-20/src/main/java/io/kubernetes/client/examples/PromOpExample.java b/examples/examples-release-20/src/main/java/io/kubernetes/client/examples/PromOpExample.java deleted file mode 100644 index 65f38b8ce4..0000000000 --- a/examples/examples-release-20/src/main/java/io/kubernetes/client/examples/PromOpExample.java +++ /dev/null @@ -1,43 +0,0 @@ -/* -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 com.coreos.monitoring.models.V1Prometheus; -import com.coreos.monitoring.models.V1PrometheusList; -import com.coreos.monitoring.models.V1PrometheusSpec; -import io.kubernetes.client.openapi.ApiException; -import io.kubernetes.client.openapi.models.V1ObjectMeta; -import io.kubernetes.client.util.ClientBuilder; -import io.kubernetes.client.util.generic.GenericKubernetesApi; -import java.io.IOException; - -public class PromOpExample { - public static void main(String[] args) throws IOException, ApiException { - GenericKubernetesApi prometheusApi = - new GenericKubernetesApi<>( - V1Prometheus.class, - V1PrometheusList.class, - "monitoring.coreos.com", - "v1", - "prometheuses", - ClientBuilder.defaultClient()); - prometheusApi - .create( - new V1Prometheus() - .metadata(new V1ObjectMeta().namespace("default").name("my-prometheus")) - .kind("Prometheus") - .apiVersion("monitoring.coreos.com/v1") - .spec(new V1PrometheusSpec())) - .throwsApiException(); - } -} diff --git a/examples/examples-release-20/src/main/java/io/kubernetes/client/examples/PrometheusExample.java b/examples/examples-release-20/src/main/java/io/kubernetes/client/examples/PrometheusExample.java deleted file mode 100644 index 0635051231..0000000000 --- a/examples/examples-release-20/src/main/java/io/kubernetes/client/examples/PrometheusExample.java +++ /dev/null @@ -1,66 +0,0 @@ -/* -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.monitoring.Monitoring; -import io.kubernetes.client.openapi.ApiClient; -import io.kubernetes.client.openapi.ApiException; -import io.kubernetes.client.openapi.Configuration; -import io.kubernetes.client.openapi.apis.CoreV1Api; -import io.kubernetes.client.openapi.models.V1Pod; -import io.kubernetes.client.openapi.models.V1PodList; -import io.kubernetes.client.util.Config; -import java.io.IOException; - -/** - * A simple example of how to use the Java API with Prometheus metrics - * - *

Easiest way to run this: mvn exec:java - * -Dexec.mainClass="io.kubernetes.client.examples.PrometheusExample" - * - *

From inside $REPO_DIR/examples - */ -public class PrometheusExample { - public static void main(String[] args) throws IOException, ApiException { - ApiClient client = Config.defaultClient(); - Configuration.setDefaultApiClient(client); - - // Install an HTTP Interceptor that adds metrics - Monitoring.installMetrics(client); - - // Install a simple HTTP server to serve prometheus metrics. If you already are serving - // metrics elsewhere, this is unnecessary. - Monitoring.startMetricsServer("localhost", 8080); - - CoreV1Api api = new CoreV1Api(); - - while (true) { - // A request that should return 200 - V1PodList list = - api.listPodForAllNamespaces().execute(); - // A request that should return 404 - try { - V1Pod pod = api.readNamespacedPod("foo", "bar").execute(); - } catch (ApiException ex) { - if (ex.getCode() != 404) { - throw ex; - } - } - try { - Thread.sleep(10000); - } catch (InterruptedException ex) { - ex.printStackTrace(); - } - } - } -} diff --git a/examples/examples-release-20/src/main/java/io/kubernetes/client/examples/ProtoExample.java b/examples/examples-release-20/src/main/java/io/kubernetes/client/examples/ProtoExample.java deleted file mode 100644 index e4e05a2aa1..0000000000 --- a/examples/examples-release-20/src/main/java/io/kubernetes/client/examples/ProtoExample.java +++ /dev/null @@ -1,69 +0,0 @@ -/* -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.ProtoClient; -import io.kubernetes.client.ProtoClient.ObjectOrStatus; -import io.kubernetes.client.openapi.ApiClient; -import io.kubernetes.client.openapi.ApiException; -import io.kubernetes.client.openapi.Configuration; -import io.kubernetes.client.proto.Meta.ObjectMeta; -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" - * - *

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"); - - if (list.object.getItemsCount() > 0) { - Pod p = list.object.getItems(0); - System.out.println(p); - } - - 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/examples-release-20/src/main/java/io/kubernetes/client/examples/SpringControllerExample.java b/examples/examples-release-20/src/main/java/io/kubernetes/client/examples/SpringControllerExample.java deleted file mode 100644 index f6494a836e..0000000000 --- a/examples/examples-release-20/src/main/java/io/kubernetes/client/examples/SpringControllerExample.java +++ /dev/null @@ -1,147 +0,0 @@ -/* -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.extended.controller.Controller; -import io.kubernetes.client.extended.controller.builder.ControllerBuilder; -import io.kubernetes.client.extended.controller.builder.DefaultControllerBuilder; -import io.kubernetes.client.extended.controller.reconciler.Reconciler; -import io.kubernetes.client.extended.controller.reconciler.Request; -import io.kubernetes.client.extended.controller.reconciler.Result; -import io.kubernetes.client.informer.SharedIndexInformer; -import io.kubernetes.client.informer.SharedInformer; -import io.kubernetes.client.informer.SharedInformerFactory; -import io.kubernetes.client.informer.cache.Lister; -import io.kubernetes.client.openapi.ApiClient; -import io.kubernetes.client.openapi.models.V1Endpoints; -import io.kubernetes.client.openapi.models.V1EndpointsList; -import io.kubernetes.client.openapi.models.V1Node; -import io.kubernetes.client.openapi.models.V1NodeList; -import io.kubernetes.client.openapi.models.V1Pod; -import io.kubernetes.client.openapi.models.V1PodList; -import io.kubernetes.client.util.generic.GenericKubernetesApi; -import java.time.Duration; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.boot.CommandLineRunner; -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.stereotype.Component; - -@SpringBootApplication -public class SpringControllerExample { - - public static void main(String[] args) { - SpringApplication.run(SpringControllerExample.class, args); - } - - @Configuration - public static class AppConfig { - - @Bean - public CommandLineRunner commandLineRunner( - SharedInformerFactory sharedInformerFactory, Controller nodePrintingController) { - return args -> { - System.out.println("starting informers.."); - sharedInformerFactory.startAllRegisteredInformers(); - - System.out.println("running controller.."); - nodePrintingController.run(); - }; - } - - @Bean - public Controller nodePrintingController( - SharedInformerFactory sharedInformerFactory, NodePrintingReconciler reconciler) { - DefaultControllerBuilder builder = ControllerBuilder.defaultBuilder(sharedInformerFactory); - builder = - builder.watch( - (q) -> { - return ControllerBuilder.controllerWatchBuilder(V1Node.class, q) - .withResyncPeriod(Duration.ofMinutes(1)) - .build(); - }); - builder.withWorkerCount(2); - builder.withReadyFunc(reconciler::informerReady); - return builder.withReconciler(reconciler).withName("nodePrintingController").build(); - } - - @Bean - public SharedIndexInformer endpointsInformer( - ApiClient apiClient, SharedInformerFactory sharedInformerFactory) { - GenericKubernetesApi genericApi = - new GenericKubernetesApi<>( - V1Endpoints.class, V1EndpointsList.class, "", "v1", "endpoints", apiClient); - return sharedInformerFactory.sharedIndexInformerFor(genericApi, V1Endpoints.class, 0); - } - - @Bean - public SharedIndexInformer nodeInformer( - ApiClient apiClient, SharedInformerFactory sharedInformerFactory) { - GenericKubernetesApi genericApi = - new GenericKubernetesApi<>(V1Node.class, V1NodeList.class, "", "v1", "nodes", apiClient); - return sharedInformerFactory.sharedIndexInformerFor(genericApi, V1Node.class, 60 * 1000L); - } - - @Bean - public SharedIndexInformer podInformer( - ApiClient apiClient, SharedInformerFactory sharedInformerFactory) { - GenericKubernetesApi genericApi = - new GenericKubernetesApi<>(V1Pod.class, V1PodList.class, "", "v1", "pods", apiClient); - return sharedInformerFactory.sharedIndexInformerFor(genericApi, V1Pod.class, 0); - } - } - - @Component - public static class NodePrintingReconciler implements Reconciler { - - @Value("${namespace}") - private String namespace; - - private SharedInformer nodeInformer; - - private SharedInformer podInformer; - - private Lister nodeLister; - - private Lister podLister; - - public NodePrintingReconciler( - SharedIndexInformer nodeInformer, SharedIndexInformer podInformer) { - this.nodeInformer = nodeInformer; - this.podInformer = podInformer; - this.nodeLister = new Lister<>(nodeInformer.getIndexer(), namespace); - this.podLister = new Lister<>(podInformer.getIndexer(), namespace); - } - - // *OPTIONAL* - // If you want to hold the controller from running util some condition.. - public boolean informerReady() { - return podInformer.hasSynced() && nodeInformer.hasSynced(); - } - - @Override - public Result reconcile(Request request) { - V1Node node = nodeLister.get(request.getName()); - - System.out.println("get all pods in namespace " + namespace); - podLister.namespace(namespace).list().stream() - .map(pod -> pod.getMetadata().getName()) - .forEach(System.out::println); - - System.out.println("triggered reconciling " + node.getMetadata().getName()); - return new Result(false); - } - } -} diff --git a/examples/examples-release-20/src/main/java/io/kubernetes/client/examples/SpringLoadBalancerExample.java b/examples/examples-release-20/src/main/java/io/kubernetes/client/examples/SpringLoadBalancerExample.java deleted file mode 100644 index bafe11e421..0000000000 --- a/examples/examples-release-20/src/main/java/io/kubernetes/client/examples/SpringLoadBalancerExample.java +++ /dev/null @@ -1,68 +0,0 @@ -/* -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.extended.network.EndpointsLoadBalancer; -import io.kubernetes.client.extended.network.LoadBalancer; -import io.kubernetes.client.extended.network.RoundRobinLoadBalanceStrategy; -import io.kubernetes.client.informer.SharedIndexInformer; -import io.kubernetes.client.informer.SharedInformerFactory; -import io.kubernetes.client.informer.cache.Lister; -import io.kubernetes.client.openapi.models.V1Endpoints; -import io.kubernetes.client.spring.extended.network.endpoints.InformerEndpointsGetter; -import org.springframework.boot.CommandLineRunner; -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -@SpringBootApplication -public class SpringLoadBalancerExample { - - public static void main(String[] args) { - SpringApplication.run(SpringLoadBalancerExample.class, args); - } - - @Configuration - public static class AppConfig { - - @Bean - public CommandLineRunner loadBalancerCommandLineRunner( - SharedInformerFactory sharedInformerFactory, MyService myService) { - return args -> { - System.out.println("starting informers.."); - sharedInformerFactory.startAllRegisteredInformers(); - - System.out.println("routing default/kubernetes:"); - System.out.println(myService.defaultKubernetesLoadBalancer.getTargetIP()); - }; - } - - @Bean - public MyService myService(SharedIndexInformer lister) { - return new MyService(new Lister<>(lister.getIndexer())); - } - } - - public static class MyService { - - private LoadBalancer defaultKubernetesLoadBalancer; - - public MyService(Lister lister) { - InformerEndpointsGetter getter = new InformerEndpointsGetter(lister); - RoundRobinLoadBalanceStrategy strategy = new RoundRobinLoadBalanceStrategy(); - defaultKubernetesLoadBalancer = - new EndpointsLoadBalancer(() -> getter.get("default", "kubernetes"), strategy); - } - } -} diff --git a/examples/examples-release-20/src/main/java/io/kubernetes/client/examples/WatchExample.java b/examples/examples-release-20/src/main/java/io/kubernetes/client/examples/WatchExample.java deleted file mode 100644 index 75fe42b895..0000000000 --- a/examples/examples-release-20/src/main/java/io/kubernetes/client/examples/WatchExample.java +++ /dev/null @@ -1,55 +0,0 @@ -/* -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 com.google.gson.reflect.TypeToken; -import io.kubernetes.client.openapi.ApiClient; -import io.kubernetes.client.openapi.ApiException; -import io.kubernetes.client.openapi.Configuration; -import io.kubernetes.client.openapi.apis.CoreV1Api; -import io.kubernetes.client.openapi.models.V1Namespace; -import io.kubernetes.client.util.Config; -import io.kubernetes.client.util.Watch; -import java.io.IOException; -import java.util.concurrent.TimeUnit; -import okhttp3.OkHttpClient; - -/** 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(); - // infinite timeout - OkHttpClient httpClient = - client.getHttpClient().newBuilder().readTimeout(0, TimeUnit.SECONDS).build(); - client.setHttpClient(httpClient); - Configuration.setDefaultApiClient(client); - - CoreV1Api api = new CoreV1Api(); - - Watch watch = - Watch.createWatch( - client, - api.listNamespace() - .watch(true) - .buildCall(null), - new TypeToken>() {}.getType()); - - try { - for (Watch.Response item : watch) { - System.out.printf("%s : %s%n", item.type, item.object.getMetadata().getName()); - } - } finally { - watch.close(); - } - } -} diff --git a/examples/examples-release-20/src/main/java/io/kubernetes/client/examples/WebSocketsExample.java b/examples/examples-release-20/src/main/java/io/kubernetes/client/examples/WebSocketsExample.java deleted file mode 100644 index e1f54dcd07..0000000000 --- a/examples/examples-release-20/src/main/java/io/kubernetes/client/examples/WebSocketsExample.java +++ /dev/null @@ -1,74 +0,0 @@ -/* -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.openapi.ApiClient; -import io.kubernetes.client.openapi.ApiException; -import io.kubernetes.client.util.Config; -import io.kubernetes.client.util.WebSockets; -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStream; -import java.io.Reader; -import okhttp3.WebSocket; - -/** - * 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 - * - *

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() { - private volatile WebSocket socket; - - @Override - public void open(String protocol, WebSocket socket) { - this.socket = socket; - } - - @Override - public void close() {} - - @Override - public void bytesMessage(InputStream is) {} - - @Override - public void failure(Throwable t) { - t.printStackTrace(); - } - - @Override - 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/examples/examples-release-20/src/main/java/io/kubernetes/client/examples/YamlExample.java b/examples/examples-release-20/src/main/java/io/kubernetes/client/examples/YamlExample.java deleted file mode 100644 index 4846a1f0cb..0000000000 --- a/examples/examples-release-20/src/main/java/io/kubernetes/client/examples/YamlExample.java +++ /dev/null @@ -1,103 +0,0 @@ -/* -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.custom.IntOrString; -import io.kubernetes.client.openapi.ApiClient; -import io.kubernetes.client.openapi.ApiException; -import io.kubernetes.client.openapi.Configuration; -import io.kubernetes.client.openapi.apis.CoreV1Api; -import io.kubernetes.client.openapi.models.V1DeleteOptions; -import io.kubernetes.client.openapi.models.V1Pod; -import io.kubernetes.client.openapi.models.V1PodBuilder; -import io.kubernetes.client.openapi.models.V1Service; -import io.kubernetes.client.openapi.models.V1ServiceBuilder; -import io.kubernetes.client.util.Config; -import io.kubernetes.client.util.Yaml; -import java.io.File; -import java.io.IOException; -import java.util.HashMap; - -/** - * A simple example of how to parse a Kubernetes object. - * - *

Easiest way to run this: mvn exec:java - * -Dexec.mainClass="io.kubernetes.client.examples.YamlExample" - * - *

From inside $REPO_DIR/examples - */ -public class YamlExample { - public static void main(String[] args) throws IOException, ApiException, ClassNotFoundException { - V1Pod pod = - new V1PodBuilder() - .withNewMetadata() - .withName("apod") - .endMetadata() - .withNewSpec() - .addNewContainer() - .withName("www") - .withImage("nginx") - .withNewResources() - .withLimits(new HashMap<>()) - .endResources() - .endContainer() - .endSpec() - .build(); - System.out.println(Yaml.dump(pod)); - - V1Service svc = - new V1ServiceBuilder() - .withNewMetadata() - .withName("aservice") - .endMetadata() - .withNewSpec() - .withSessionAffinity("ClientIP") - .withType("NodePort") - .addNewPort() - .withProtocol("TCP") - .withName("client") - .withPort(8008) - .withNodePort(8080) - .withTargetPort(new IntOrString(8080)) - .endPort() - .endSpec() - .build(); - System.out.println(Yaml.dump(svc)); - - // Read yaml configuration file, and deploy it - ApiClient client = Config.defaultClient(); - Configuration.setDefaultApiClient(client); - - // See issue #474. Not needed at most cases, but it is needed if you are using war - // packging or running this on JUnit. - Yaml.addModelMap("v1", "Service", V1Service.class); - - // Example yaml file can be found in $REPO_DIR/test-svc.yaml - File file = new File("test-svc.yaml"); - V1Service yamlSvc = (V1Service) Yaml.load(file); - - // Deployment and StatefulSet is defined in apps/v1, so you should use AppsV1Api instead of - // CoreV1API - CoreV1Api api = new CoreV1Api(); - V1Service createResult = - api.createNamespacedService("default", yamlSvc).execute(); - - System.out.println(createResult); - - V1Service deleteResult = - api.deleteNamespacedService( - yamlSvc.getMetadata().getName(), - "default").execute(); - System.out.println(deleteResult); - } -} diff --git a/examples/examples-release-20/src/main/resources/application.properties b/examples/examples-release-20/src/main/resources/application.properties deleted file mode 100644 index dc886e5f48..0000000000 --- a/examples/examples-release-20/src/main/resources/application.properties +++ /dev/null @@ -1,2 +0,0 @@ -namespace=airflow -management.endpoints.web.exposure.include=prometheus \ No newline at end of file diff --git a/examples/examples-release-20/src/test/java/io/kubernetes/client/examples/ExampleTest.java b/examples/examples-release-20/src/test/java/io/kubernetes/client/examples/ExampleTest.java deleted file mode 100644 index 3fd5cea7f6..0000000000 --- a/examples/examples-release-20/src/test/java/io/kubernetes/client/examples/ExampleTest.java +++ /dev/null @@ -1,57 +0,0 @@ -/* -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 static com.github.tomakehurst.wiremock.client.WireMock.aResponse; -import static com.github.tomakehurst.wiremock.client.WireMock.get; -import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; -import static org.junit.jupiter.api.Assertions.assertEquals; - -import com.github.tomakehurst.wiremock.core.WireMockConfiguration; -import com.github.tomakehurst.wiremock.junit5.WireMockExtension; -import io.kubernetes.client.openapi.ApiClient; -import io.kubernetes.client.openapi.ApiException; -import io.kubernetes.client.openapi.Configuration; -import io.kubernetes.client.openapi.apis.CoreV1Api; -import io.kubernetes.client.openapi.models.V1Namespace; -import io.kubernetes.client.openapi.models.V1ObjectMeta; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.RegisterExtension; - -class ExampleTest { - private static final int PORT = 8089; - - @RegisterExtension - static WireMockExtension apiServer = - WireMockExtension.newInstance().options(WireMockConfiguration.options().port(PORT)).build(); - - @Test - void exactUrlOnly() throws ApiException { - ApiClient client = new ApiClient(); - client.setBasePath("http://localhost:" + PORT); - Configuration.setDefaultApiClient(client); - - V1Namespace ns1 = new V1Namespace().metadata(new V1ObjectMeta().name("name")); - - apiServer.stubFor( - get(urlEqualTo("/api/v1/namespaces/name")) - .willReturn( - aResponse() - .withHeader("Content-Type", "application/json") - .withBody(client.getJSON().serialize(ns1)))); - - CoreV1Api api = new CoreV1Api(); - V1Namespace ns2 = api.readNamespace("name").execute(); - assertEquals(ns1, ns2); - } -} diff --git a/examples/examples-release-20/test-svc.yaml b/examples/examples-release-20/test-svc.yaml deleted file mode 100644 index f225bea76f..0000000000 --- a/examples/examples-release-20/test-svc.yaml +++ /dev/null @@ -1,11 +0,0 @@ -apiVersion: v1 -kind: Service -metadata: - name: test-service -spec: - type: ClusterIP - selector: - app: test-service - ports: - - name: port-of-container - port: 8080 \ No newline at end of file diff --git a/examples/examples-release-20/test.yaml b/examples/examples-release-20/test.yaml deleted file mode 100644 index 0b46e57003..0000000000 --- a/examples/examples-release-20/test.yaml +++ /dev/null @@ -1,16 +0,0 @@ -apiVersion: v1 -kind: ReplicationController -metadata: - name: test -spec: - replicas: 1 - template: - metadata: - labels: - app: test - spec: - containers: - - name: test - image: test/examples:1.0 - command: ["/bin/sh","-c"] - args: ["java -jar /examples.jar","while :; do sleep 1; done"] diff --git a/examples/pom.xml b/examples/pom.xml index cb7b2cf019..50ece7dec9 100644 --- a/examples/pom.xml +++ b/examples/pom.xml @@ -15,10 +15,6 @@ client-java-examples-parent - examples-release-17 - examples-release-18 - examples-release-19 - examples-release-20 examples-release-latest