use of io.kubernetes.client.openapi.apis.CustomObjectsApi in project pravega by pravega.
the class K8sClient method deleteCustomObject.
/**
* Delete Custom Object for a given resource group.
* @param customResourceGroup Custom resource group.
* @param version Version.
* @param namespace Namespace.
* @param plural Plural of the CRD.
* @param name Name of the object.
* @return Future which completes once the delete request is accepted.
*/
@SneakyThrows(ApiException.class)
public CompletableFuture<Object> deleteCustomObject(String customResourceGroup, String version, String namespace, String plural, String name) {
CustomObjectsApi api = new CustomObjectsApi();
V1DeleteOptions options = new V1DeleteOptions();
options.setOrphanDependents(false);
K8AsyncCallback<Object> callback = new K8AsyncCallback<>("getCustomObject-" + customResourceGroup);
api.deleteNamespacedCustomObjectAsync(customResourceGroup, version, namespace, plural, name, 0, false, null, options, callback);
return callback.getFuture();
}
use of io.kubernetes.client.openapi.apis.CustomObjectsApi in project pravega by pravega.
the class K8sClient method createAndUpdateCustomObject.
/**
* This is used to update a custom object. This is useful to modify the custom object configuration, number of
* instances is one type of configuration. If the object does not exist then a new object is created.
* @param customResourceGroup Custom resource group.
* @param version version.
* @param namespace Namespace.
* @param plural Plural of the CRD.
* @param request Actual request.
* @return A Future representing the status of create/update.
*/
@SuppressWarnings("unchecked")
public CompletableFuture<Object> createAndUpdateCustomObject(String customResourceGroup, String version, String namespace, String plural, Map<String, Object> request) {
CustomObjectsApi api = new CustomObjectsApi();
// Fetch the name of the custom object.
String name = ((Map<String, String>) request.get("metadata")).get("name");
return getCustomObject(customResourceGroup, version, namespace, plural, name).thenCompose(o -> {
log.info("Instance {} of custom resource {} exists, update it with the new request", name, customResourceGroup);
try {
// patch object
K8AsyncCallback<Object> cb1 = new K8AsyncCallback<>("patchCustomObject");
PatchUtils.patch(CustomObjectsApi.class, () -> api.patchNamespacedCustomObjectCall(customResourceGroup, version, namespace, plural, name, request, cb1), V1Patch.PATCH_FORMAT_JSON_MERGE_PATCH);
return cb1.getFuture();
} catch (ApiException e) {
throw Exceptions.sneakyThrow(e);
}
}).exceptionally(t -> {
log.warn("Exception while trying to fetch instance {} of custom resource {}, try to create it. Details: {}", name, customResourceGroup, t.getMessage());
try {
// create object
K8AsyncCallback<Object> cb = new K8AsyncCallback<>("createCustomObject");
api.createNamespacedCustomObjectAsync(customResourceGroup, version, namespace, plural, request, PRETTY_PRINT, cb);
return cb.getFuture();
} catch (ApiException e) {
throw Exceptions.sneakyThrow(e);
}
});
}
use of io.kubernetes.client.openapi.apis.CustomObjectsApi in project pravega by pravega.
the class K8sClient method createCustomObject.
/**
* Create a Custom object for a Custom Resource Definition (CRD). This is useful while interacting with operators.
* @param customResourceGroup Custom resource group.
* @param version Version.
* @param namespace Namespace.
* @param plural plural of the CRD.
* @param request Actual request.
* @return Future representing the custom object creation.
*/
@SneakyThrows(ApiException.class)
public CompletableFuture<Object> createCustomObject(String customResourceGroup, String version, String namespace, String plural, Map<String, Object> request) {
CustomObjectsApi api = new CustomObjectsApi();
K8AsyncCallback<Object> callback = new K8AsyncCallback<>("createCustomObject-" + customResourceGroup);
api.createNamespacedCustomObjectAsync(customResourceGroup, version, namespace, plural, request, PRETTY_PRINT, callback);
return callback.getFuture();
}
use of io.kubernetes.client.openapi.apis.CustomObjectsApi in project pravega by pravega.
the class K8sClient method getCustomObject.
/**
* Fetch Custom Object for a given custom resource group.
* @param customResourceGroup Custom resource group.
* @param version Version.
* @param namespace Namespace.
* @param plural Plural of the CRD.
* @param name Name of the object.
* @return A future which returns the details of the object. The future completes exceptionally if the object is not present.
*/
@SneakyThrows(ApiException.class)
public CompletableFuture<Object> getCustomObject(String customResourceGroup, String version, String namespace, String plural, String name) {
CustomObjectsApi api = new CustomObjectsApi();
K8AsyncCallback<Object> callback = new K8AsyncCallback<>("getCustomObject-" + customResourceGroup);
api.getNamespacedCustomObjectAsync(customResourceGroup, version, namespace, plural, name, callback);
return callback.getFuture();
}
Aggregations