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 @@
-
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 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 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 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 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 extends KubernetesObject> 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 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 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 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 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 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/ 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 @@
- 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 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 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 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 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 extends KubernetesObject> 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 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 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 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 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 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/ 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 @@
- 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 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 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 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 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 extends KubernetesObject> 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 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 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 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 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 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/ 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 @@
- 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 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 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 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 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 extends KubernetesObject> 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 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 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 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 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 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/ 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 @@
- * 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.
- *
- *
- *
- *
- *
- * 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.
- *
- *
- *
- *
- *
- * 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.
- *
- *
- *
- *
- *
- * 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.
- *
- *
- *
- *
- *