Class ModelMapper

java.lang.Object
io.kubernetes.client.util.ModelMapper

public class ModelMapper extends Object
Model mapper loads pre-built kubernetes models from classpath and manages their mapping between their apiVersion and kind.
  • Field Details

    • DEFAULT_DISCOVERY_REFRESH_INTERVAL

      public static final Duration DEFAULT_DISCOVERY_REFRESH_INTERVAL
  • Constructor Details

    • ModelMapper

      public ModelMapper()
  • Method Details

    • addModelMap

      @Deprecated public static void addModelMap(String apiGroupVersion, String kind, Class<?> clazz)
      Deprecated.
      Registering concrete model classes by its apiGroupVersion (e.g. "apps/v1") and kind (e.g. "Deployment").

      Note that the the so-called apiGroupVersion equals to the "apiVersion" in the kubenretes resource yamls.

    • addModelMap

      @Deprecated public static void addModelMap(String group, String version, String kind, Class<?> clazz)
      Deprecated.
      Registering concrete model classes by its group, version and kind (e.g. "apps", "v1", "Deployment")
      Parameters:
      group - the group
      version - the version
      kind - the kind
      clazz - the clazz
    • addModelMap

      public static void addModelMap(String group, String version, String kind, String resourceNamePlural, Class<? extends io.kubernetes.client.common.KubernetesObject> objClass, Class<? extends io.kubernetes.client.common.KubernetesListObject> objListClass)
      Registering concrete model classes by its group, version and kind (e.g. "apps", "v1", "Deployment")
      Parameters:
      group - the group
      version - the version
      kind - the kind
      resourceNamePlural - the resource name plural
      objClass - the clazz
    • addModelMap

      public static void addModelMap(String group, String version, String kind, String resourceNamePlural, Boolean isNamespacedResource, Class<? extends io.kubernetes.client.common.KubernetesObject> objClass)
      Registering concrete model classes by its group, version, kind and isNamespaced (e.g. "apps", "v1", "Deployment", true).
      Parameters:
      group - the group
      version - the version
      kind - the kind
      resourceNamePlural - the resource name plural
      isNamespacedResource - the is namespaced resource
      objClass - the clazz
    • addModelMap

      public static void addModelMap(String group, String version, String kind, String resourceNamePlural, Boolean isNamespacedResource, Class<? extends io.kubernetes.client.common.KubernetesObject> objClass, Class<? extends io.kubernetes.client.common.KubernetesListObject> objListClass)
    • getApiTypeClass

      public static Class<?> getApiTypeClass(String apiGroupVersion, String kind)
      Gets the model classes by given apiGroupVersion (e.g. "apps/v1") and kind (e.g. "Deployment").
      Parameters:
      apiGroupVersion - the api version
      kind - the kind
      Returns:
      the api type class
    • getApiTypeClass

      public static Class<?> getApiTypeClass(String group, String version, String kind)
      Gets the model classes by given group, version and kind (e.g. "apps", ""v1", "Deployment").
      Parameters:
      group - the group
      version - the version
      kind - the kind
      Returns:
      the api type class
    • getGroupVersionKindByClass

      public static GroupVersionKind getGroupVersionKindByClass(Class<?> clazz)
      Gets the GVK by the given model class.
      Parameters:
      clazz - the clazz
      Returns:
      the group version kind by class
    • getGroupVersionResourceByClass

      public static GroupVersionResource getGroupVersionResourceByClass(Class<?> clazz)
      Gets the GVK by the given model class.
      Parameters:
      clazz - the clazz
      Returns:
      the group version kind by class
    • refresh

      public static Set<Discovery.APIResource> refresh(Discovery discovery) throws io.kubernetes.client.openapi.ApiException
      Refreshes the model mapping by syncing up w/the api discovery info from the kubernetes apiserver. These mapping will be cached for DEFAULT_DISCOVERY_REFRESH_INTERVAL.
      Parameters:
      discovery - the discovery
      Returns:
      the set
      Throws:
      io.kubernetes.client.openapi.ApiException - the api exception
    • refresh

      public static Set<Discovery.APIResource> refresh(Discovery discovery, Duration refreshInterval) throws io.kubernetes.client.openapi.ApiException
      Refreshes the model mapping by syncing up w/the api discovery info from the kubernetes apiserver.

      Note: if model mappings can be incomplete if this method is never called.

      Parameters:
      discovery - the discovery
      Returns:
      the api-discovery set
      Throws:
      io.kubernetes.client.openapi.ApiException - the api exception
    • isApiDiscoveryRefreshed

      public static boolean isApiDiscoveryRefreshed()
    • preBuiltGetApiTypeClass

      public static Class<?> preBuiltGetApiTypeClass(String group, String version, String kind)
    • preBuiltGetGroupVersionKindByClass

      public static GroupVersionKind preBuiltGetGroupVersionKindByClass(Class<?> clazz)
    • isNamespaced

      public static Boolean isNamespaced(Class<?> clazz)
      Checks whether the class is connected with a namespaced kubernetes resource.
      Parameters:
      clazz - the clazz
      Returns:
      the boolean
    • groupVersionKindFromApiVersionAndKind

      public static GroupVersionKind groupVersionKindFromApiVersionAndKind(String apiVersion, String kind)
      Find GroupVersionKind from fields in a Kubernetes Resource
      Parameters:
      apiVersion - The apiVersion field from the object
      kind - The kind for the object
      Returns:
      the GroupVersionKind
    • findApiResourceByGroupVersionKind

      public static Discovery.APIResource findApiResourceByGroupVersionKind(GroupVersionKind gvk)