Package org.jdrupes.vmoperator.common
Class K8sGenericStub<O extends io.kubernetes.client.common.KubernetesObject,L extends io.kubernetes.client.common.KubernetesListObject>
java.lang.Object
org.jdrupes.vmoperator.common.K8sGenericStub<O,L>
- Type Parameters:
O
- the generic typeL
- the generic type
- Direct Known Subclasses:
K8sDynamicStubBase
,K8sV1ConfigMapStub
,K8sV1DeploymentStub
,K8sV1PodStub
,K8sV1PvcStub
,K8sV1SecretStub
,K8sV1ServiceStub
,K8sV1StatefulSetStub
public class K8sGenericStub<O extends io.kubernetes.client.common.KubernetesObject,L extends io.kubernetes.client.common.KubernetesListObject>
extends Object
A stub for namespaced custom objects.
This stub provides the functions common to all Kubernetes objects, but uses variables for all types. This class should be used as base class only.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
K8sGenericStub.GenericSupplier<O extends io.kubernetes.client.common.KubernetesObject,
L extends io.kubernetes.client.common.KubernetesListObject, R extends K8sGenericStub<O, L>> A supplier for generic stubs. -
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic io.kubernetes.client.Discovery.APIResource
apiResource
(K8sClient client, io.kubernetes.client.apimachinery.GroupVersionKind gvk) Api resource.apply
(io.kubernetes.client.util.generic.dynamic.DynamicKubernetesObject def) Apply the given definition.io.kubernetes.client.Discovery.APIResource
context()
Gets the context.static <O extends io.kubernetes.client.common.KubernetesObject,
L extends io.kubernetes.client.common.KubernetesListObject, R extends K8sGenericStub<O, L>>
Rcreate
(Class<O> objectClass, Class<L> objectListClass, K8sClient client, io.kubernetes.client.Discovery.APIResource context, O model, K8sGenericStub.GenericSupplier<O, L, R> provider) Get a namespaced object stub for a newly created object.void
delete()
Delete the Kubernetes object.group()
Gets the group.kind()
Gets the kind.static <O extends io.kubernetes.client.common.KubernetesObject,
L extends io.kubernetes.client.common.KubernetesListObject, R extends K8sGenericStub<O, L>>
Collection<R> list
(Class<O> objectClass, Class<L> objectListClass, K8sClient client, io.kubernetes.client.Discovery.APIResource context, String namespace, io.kubernetes.client.util.generic.options.ListOptions options, K8sGenericStub.GenericSupplier<O, L, R> provider) Get the stubs for the objects in the given namespace that match the criteria from the given options.model()
Retrieves and returns the current state of the object.name()
Gets the name.Gets the namespace.Patch the object using default options.patch
(String patchType, io.kubernetes.client.custom.V1Patch patch, io.kubernetes.client.util.generic.options.PatchOptions options) Patch the object.plural()
Gets the plural.toString()
io.kubernetes.client.util.generic.KubernetesApiResponse
<O> Update the object.io.kubernetes.client.util.generic.KubernetesApiResponse
<O> Update the object.updateStatus
(Function<O, Object> status) Updates the status.updateStatus
(O object, Function<O, Object> status) Updates the object’s status, retrying up to 16 times if there is a conflict.updateStatus
(O object, Function<O, Object> status, int retries) Updates the object’s status, retrying for the given number of times if the update fails due to a conflict.version()
Gets the version.
-
Field Details
-
client
-
context
-
namespace
-
name
-
-
Constructor Details
-
K8sGenericStub
protected K8sGenericStub(Class<O> objectClass, Class<L> objectListClass, K8sClient client, io.kubernetes.client.Discovery.APIResource context, String namespace, String name) Instantiates a new stub for the object specified.If the object exists in the context specified, the version (see
version()
is bound to the existing object’s version. Else the stub is dangling with the version set to the context’s preferred version.- Parameters:
objectClass
- the object classobjectListClass
- the object list classclient
- the clientcontext
- the contextnamespace
- the namespacename
- the name
-
-
Method Details
-
context
Gets the context.- Returns:
- the context
-
group
Gets the group.- Returns:
- the group
-
version
Gets the version.- Returns:
- the version
-
kind
Gets the kind.- Returns:
- the kind
-
plural
Gets the plural.- Returns:
- the plural
-
namespace
Gets the namespace.- Returns:
- the namespace
-
name
Gets the name.- Returns:
- the name
-
delete
Delete the Kubernetes object.- Throws:
io.kubernetes.client.openapi.ApiException
- the API exception
-
model
Retrieves and returns the current state of the object.- Returns:
- the object’s state
- Throws:
io.kubernetes.client.openapi.ApiException
- the api exception
-
updateStatus
public Optional<O> updateStatus(O object, Function<O, Object> status, int retries) throws io.kubernetes.client.openapi.ApiExceptionUpdates the object’s status, retrying for the given number of times if the update fails due to a conflict.- Parameters:
object
- the current state of the object (passed tostatus
)status
- function that returns the new statusretries
- the retries- Returns:
- the updated model or empty if not successful
- Throws:
io.kubernetes.client.openapi.ApiException
- the api exception
-
updateStatus
public Optional<O> updateStatus(O object, Function<O, Object> status) throws io.kubernetes.client.openapi.ApiExceptionUpdates the object’s status, retrying up to 16 times if there is a conflict.- Parameters:
object
- the current state of the object (passed tostatus
)status
- function that returns the new status- Returns:
- the updated model or empty if not successful
- Throws:
io.kubernetes.client.openapi.ApiException
- the api exception
-
updateStatus
public Optional<O> updateStatus(Function<O, Object> status) throws io.kubernetes.client.openapi.ApiExceptionUpdates the status.- Parameters:
status
- the status- Returns:
- the kubernetes api response the updated model or empty if not successful
- Throws:
io.kubernetes.client.openapi.ApiException
- the api exception
-
patch
public Optional<O> patch(String patchType, io.kubernetes.client.custom.V1Patch patch, io.kubernetes.client.util.generic.options.PatchOptions options) throws io.kubernetes.client.openapi.ApiException Patch the object.- Parameters:
patchType
- the patch typepatch
- the patchoptions
- the options- Returns:
- the kubernetes api response if successful
- Throws:
io.kubernetes.client.openapi.ApiException
- the api exception
-
patch
public Optional<O> patch(String patchType, io.kubernetes.client.custom.V1Patch patch) throws io.kubernetes.client.openapi.ApiException Patch the object using default options.- Parameters:
patchType
- the patch typepatch
- the patch- Returns:
- the kubernetes api response if successful
- Throws:
io.kubernetes.client.openapi.ApiException
- the api exception
-
apply
public Optional<O> apply(io.kubernetes.client.util.generic.dynamic.DynamicKubernetesObject def) throws io.kubernetes.client.openapi.ApiException Apply the given definition.- Parameters:
def
- the def- Returns:
- the kubernetes api response if successful
- Throws:
io.kubernetes.client.openapi.ApiException
- the api exception
-
update
public io.kubernetes.client.util.generic.KubernetesApiResponse<O> update(O object) throws io.kubernetes.client.openapi.ApiException Update the object.- Parameters:
object
- the object- Returns:
- the kubernetes api response
- Throws:
io.kubernetes.client.openapi.ApiException
- the api exception
-
update
public io.kubernetes.client.util.generic.KubernetesApiResponse<O> update(O object, io.kubernetes.client.util.generic.options.UpdateOptions options) throws io.kubernetes.client.openapi.ApiException Update the object.- Parameters:
object
- the objectoptions
- the options- Returns:
- the kubernetes api response
- Throws:
io.kubernetes.client.openapi.ApiException
- the api exception
-
toString
-
create
public static <O extends io.kubernetes.client.common.KubernetesObject,L extends io.kubernetes.client.common.KubernetesListObject, R createR extends K8sGenericStub<O, L>> (Class<O> objectClass, Class<L> objectListClass, K8sClient client, io.kubernetes.client.Discovery.APIResource context, O model, K8sGenericStub.GenericSupplier<O, L, throws io.kubernetes.client.openapi.ApiExceptionR> provider) Get a namespaced object stub for a newly created object.- Type Parameters:
O
- the object typeL
- the object list typeR
- the stub type- Parameters:
objectClass
- the object classobjectListClass
- the object list classclient
- the clientcontext
- the contextmodel
- the modelprovider
- the provider- Returns:
- the stub if the object exists
- Throws:
io.kubernetes.client.openapi.ApiException
- the api exception
-
list
public static <O extends io.kubernetes.client.common.KubernetesObject,L extends io.kubernetes.client.common.KubernetesListObject, Collection<R> listR extends K8sGenericStub<O, L>> (Class<O> objectClass, Class<L> objectListClass, K8sClient client, io.kubernetes.client.Discovery.APIResource context, String namespace, io.kubernetes.client.util.generic.options.ListOptions options, K8sGenericStub.GenericSupplier<O, L, throws io.kubernetes.client.openapi.ApiExceptionR> provider) Get the stubs for the objects in the given namespace that match the criteria from the given options.- Type Parameters:
O
- the object typeL
- the object list typeR
- the stub type- Parameters:
objectClass
- the object classobjectListClass
- the object list classclient
- the clientcontext
- the contextnamespace
- the namespaceoptions
- the optionsprovider
- the provider- Returns:
- the collection
- Throws:
io.kubernetes.client.openapi.ApiException
- the api exception
-
apiResource
public static io.kubernetes.client.Discovery.APIResource apiResource(K8sClient client, io.kubernetes.client.apimachinery.GroupVersionKind gvk) throws io.kubernetes.client.openapi.ApiException Api resource.- Parameters:
client
- the clientgvk
- the gvk- Returns:
- the API resource
- Throws:
io.kubernetes.client.openapi.ApiException
- the api exception
-