Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package io.kubernetes.client.examples;

import com.google.common.annotations.Beta;
import io.kubernetes.client.extended.generic.GenericKubernetesApi;
import io.kubernetes.client.extended.generic.KubernetesApiResponse;
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 java.util.Arrays;

@Beta
public class GenericClientExample {

public static void main(String[] args) throws Exception {

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<V1Pod, V1PodList> podClient =
new GenericKubernetesApi<>(V1Pod.class, V1PodList.class, "", "v1", "pods", apiClient);

KubernetesApiResponse<V1Pod> createResponse = podClient.create(pod);
if (!createResponse.isSuccess()) {
throw new RuntimeException(createResponse.getStatus().toString());
}
System.out.println("Created!");

KubernetesApiResponse<V1Pod> deleteResponse = podClient.delete("default", "foo");
if (!deleteResponse.isSuccess()) {
throw new RuntimeException(deleteResponse.getStatus().toString());
}
if (deleteResponse.getObject() != null) {
System.out.println(
"Received after-deletion status of the requested object, will be deleting in background!");
}
System.out.println("Deleted!");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import io.kubernetes.client.util.Watch;
import io.kubernetes.client.util.Watchable;
import io.kubernetes.client.util.exception.ObjectMetaReflectException;
import java.net.SocketTimeoutException;
import java.io.IOException;
import okhttp3.Call;
import okhttp3.HttpUrl;

Expand Down Expand Up @@ -669,7 +669,7 @@ private <DataType> KubernetesApiResponse<DataType> executeCall(
JsonElement element = apiClient.<JsonElement>execute(call, JsonElement.class).getData();
return getKubernetesApiResponse(dataClass, element, apiClient.getJSON().getGson());
} catch (ApiException e) {
if (e.getCause() instanceof SocketTimeoutException) {
if (e.getCause() instanceof IOException) {
throw new IllegalStateException(e.getCause()); // make this a checked exception?
}
V1Status status = apiClient.getJSON().deserialize(e.getResponseBody(), V1Status.class);
Expand Down