Class GenericKubernetesApi<ApiType extends io.kubernetes.client.common.KubernetesObject,ApiListType extends io.kubernetes.client.common.KubernetesListObject>

java.lang.Object
io.kubernetes.client.util.generic.GenericKubernetesApi<ApiType,ApiListType>
Type Parameters:
ApiType - the api type parameter
ApiListType - the api list type parameter
Direct Known Subclasses:
DynamicKubernetesApi

public class GenericKubernetesApi<ApiType extends io.kubernetes.client.common.KubernetesObject,ApiListType extends io.kubernetes.client.common.KubernetesListObject> extends Object
The Generic kubernetes api provides a unified client interface for not only the non-core-group built-in resources from kubernetes but also the custom-resources models meet the following requirements:

1. there's a `V1ObjectMeta` field in the model along with its getter/setter. 2. there's a `V1ListMeta` field in the list model along with its getter/setter. - supports Gson serialization/deserialization. 3. the generic kubernetes api covers all the basic operations over the custom resources including {get, list, watch, create, update, patch, delete}.

The Generic kubernetes api is expected to have the following behaviors upon failures where KubernetesApiResponse.isSuccess() returns false:

- For kubernetes-defined failures, the server will return a V1Status with 4xx/5xx code. The status object will be nested in KubernetesApiResponse.getStatus() - For the other unknown reason (including network, JVM..), throws an unchecked exception.

  • Constructor Details

    • GenericKubernetesApi

      public GenericKubernetesApi(Class<ApiType> apiTypeClass, Class<ApiListType> apiListTypeClass, String apiGroup, String apiVersion, String resourcePlural)
      Instantiates a new Generic kubernetes api.
      Parameters:
      apiTypeClass - the api type class
      apiListTypeClass - the api list type class
      apiGroup - the api group
      apiVersion - the api version
      resourcePlural - the resource plural
    • GenericKubernetesApi

      public GenericKubernetesApi(Class<ApiType> apiTypeClass, Class<ApiListType> apiListTypeClass, String apiGroup, String apiVersion, String resourcePlural, io.kubernetes.client.openapi.ApiClient apiClient)
      Instantiates a new Generic kubernetes api.
      Parameters:
      apiTypeClass - the api type class, e.g. V1Job.class
      apiListTypeClass - the api list type class e.g V1JobList.class
      apiGroup - the api group
      apiVersion - the api version
      resourcePlural - the resource plural, e.g. "jobs"
      apiClient - the api client
    • GenericKubernetesApi

      public GenericKubernetesApi(Class<ApiType> apiTypeClass, Class<ApiListType> apiListTypeClass, String apiGroup, String apiVersion, String resourcePlural, io.kubernetes.client.openapi.apis.CustomObjectsApi customObjectsApi)
      Instantiates a new Generic kubernetes api with the ApiClient specified.
      Parameters:
      apiTypeClass - the api type class, e.g. V1Job.class
      apiListTypeClass - the api list type class e.g V1JobList.class
      apiGroup - the api group
      apiVersion - the api version
      resourcePlural - the resource plural, e.g. "jobs"
      customObjectsApi - the custom objects api
  • Method Details

    • get

      public KubernetesApiResponse<ApiType> get(String name)
      Get kubernetes api response.
      Parameters:
      name - the name
      Returns:
      the kubernetes api response
    • get

      public KubernetesApiResponse<ApiType> get(String namespace, String name)
      Get kubernetes api response under the namespace.
      Parameters:
      namespace - the namespace
      name - the name
      Returns:
      the kubernetes api response
    • list

      List kubernetes api response cluster-scoped.
      Returns:
      the kubernetes api response
    • list

      public KubernetesApiResponse<ApiListType> list(String namespace)
      List kubernetes api response under the namespace.
      Parameters:
      namespace - the namespace
      Returns:
      the kubernetes api response
    • create

      public KubernetesApiResponse<ApiType> create(ApiType object)
      Create kubernetes api response, if the namespace in the object is present, it will send a namespace-scoped requests, vice versa.
      Parameters:
      object - the object
      Returns:
      the kubernetes api response
    • update

      public KubernetesApiResponse<ApiType> update(ApiType object)
      Create kubernetes api response, if the namespace in the object is present, it will send a namespace-scoped requests, vice versa.
      Parameters:
      object - the object
      Returns:
      the kubernetes api response
    • patch

      public KubernetesApiResponse<ApiType> patch(String name, String patchType, io.kubernetes.client.custom.V1Patch patch)
      Patch kubernetes api response.
      Parameters:
      name - the name
      patchType - the patch type, supported values defined in V1Patch
      patch - the string patch content
      Returns:
      the kubernetes api response
    • patch

      public KubernetesApiResponse<ApiType> patch(String namespace, String name, String patchType, io.kubernetes.client.custom.V1Patch patch)
      Patch kubernetes api response under the namespace.
      Parameters:
      namespace - the namespace
      name - the name
      patchType - the patch type, supported values defined in V1Patch
      patch - the string patch content
      Returns:
      the kubernetes api response
    • delete

      public KubernetesApiResponse<ApiType> delete(String name)
      Delete kubernetes api response.
      Parameters:
      name - the name
      Returns:
      the kubernetes api response
    • delete

      public KubernetesApiResponse<ApiType> delete(String namespace, String name)
      Delete kubernetes api response under the namespace.
      Parameters:
      namespace - the namespace
      name - the name
      Returns:
      the kubernetes api response
    • watch

      public Watchable<ApiType> watch() throws io.kubernetes.client.openapi.ApiException
      Creates a cluster-scoped Watch on the resource.
      Returns:
      the watchable
      Throws:
      io.kubernetes.client.openapi.ApiException - the api exception
    • watch

      public Watchable<ApiType> watch(String namespace) throws io.kubernetes.client.openapi.ApiException
      Creates a namespace-scoped Watch on the resource.
      Parameters:
      namespace - the namespace
      Returns:
      the watchable
      Throws:
      io.kubernetes.client.openapi.ApiException - the api exception
    • get

      public KubernetesApiResponse<ApiType> get(String name, GetOptions getOptions)
      Get kubernetes api response.
      Parameters:
      name - the name
      getOptions - the get options
      Returns:
      the kubernetes api response
    • get

      public KubernetesApiResponse<ApiType> get(String namespace, String name, GetOptions getOptions)
      Get kubernetes api response.
      Parameters:
      namespace - the namespace
      name - the name
      getOptions - the get options
      Returns:
      the kubernetes api response
    • list

      public KubernetesApiResponse<ApiListType> list(ListOptions listOptions)
      List kubernetes api response.
      Parameters:
      listOptions - the list options
      Returns:
      the kubernetes api response
    • list

      public KubernetesApiResponse<ApiListType> list(String namespace, ListOptions listOptions)
      List kubernetes api response.
      Parameters:
      namespace - the namespace
      listOptions - the list options
      Returns:
      the kubernetes api response
    • create

      public KubernetesApiResponse<ApiType> create(ApiType object, CreateOptions createOptions)
      Create kubernetes api response.
      Parameters:
      object - the object
      createOptions - the create options
      Returns:
      the kubernetes api response
    • create

      public KubernetesApiResponse<ApiType> create(String namespace, ApiType object, CreateOptions createOptions)
    • update

      public KubernetesApiResponse<ApiType> update(ApiType object, UpdateOptions updateOptions)
      Update kubernetes api response.
      Parameters:
      object - the object
      updateOptions - the update options
      Returns:
      the kubernetes api response
    • updateStatus

      public KubernetesApiResponse<ApiType> updateStatus(ApiType object, Function<ApiType,Object> status)
      Create kubernetes api response, if the namespace in the object is present, it will send a namespace-scoped requests, vice versa.
      Parameters:
      object - the object
      status - function to extract the status from the object
      Returns:
      the kubernetes api response
    • updateStatus

      public KubernetesApiResponse<ApiType> updateStatus(ApiType object, Function<ApiType,Object> status, UpdateOptions updateOptions)
      Update status of kubernetes api response.
      Parameters:
      object - the object
      status - function to extract the status from the object
      updateOptions - the update options
      Returns:
      the kubernetes api response
    • patch

      public KubernetesApiResponse<ApiType> patch(String name, String patchType, io.kubernetes.client.custom.V1Patch patch, PatchOptions patchOptions)
      Patch kubernetes api response.
      Parameters:
      name - the name
      patchType - the patch type
      patch - the patch
      patchOptions - the patch options
      Returns:
      the kubernetes api response
    • patch

      public KubernetesApiResponse<ApiType> patch(String namespace, String name, String patchType, io.kubernetes.client.custom.V1Patch patch, PatchOptions patchOptions)
      Patch kubernetes api response.
      Parameters:
      namespace - the namespace
      name - the name
      patchType - the patch type
      patch - the patch
      patchOptions - the patch options
      Returns:
      the kubernetes api response
    • delete

      public KubernetesApiResponse<ApiType> delete(String name, DeleteOptions deleteOptions)
      Delete kubernetes api response.
      Parameters:
      name - the name
      deleteOptions - the delete options
      Returns:
      the kubernetes api response
    • delete

      public KubernetesApiResponse<ApiType> delete(String namespace, String name, DeleteOptions deleteOptions)
      Delete kubernetes api response.
      Parameters:
      namespace - the namespace
      name - the name
      deleteOptions - the delete options
      Returns:
      the kubernetes api response
    • watch

      public Watchable<ApiType> watch(ListOptions listOptions) throws io.kubernetes.client.openapi.ApiException
      Watch watchable.
      Parameters:
      listOptions - the list options
      Returns:
      the watchable
      Throws:
      io.kubernetes.client.openapi.ApiException - the api exception
    • watch

      public Watchable<ApiType> watch(String namespace, ListOptions listOptions) throws io.kubernetes.client.openapi.ApiException
      Watch watchable.
      Parameters:
      namespace - the namespace
      listOptions - the list options
      Returns:
      the watchable
      Throws:
      io.kubernetes.client.openapi.ApiException - the api exception