use of io.kubernetes.client.openapi.apis.CoreV1Api in project pravega by pravega.
the class K8sClient method createNamespace.
/**
* Method used to create a namespace. This blocks until the namespace is created.
* @param namespace Namespace to be created.
* @return V1Namespace.
*/
@SneakyThrows(ApiException.class)
public V1Namespace createNamespace(final String namespace) {
CoreV1Api api = new CoreV1Api();
try {
V1Namespace existing = api.readNamespace(namespace, PRETTY_PRINT, Boolean.FALSE, Boolean.FALSE);
if (existing != null) {
log.info("Namespace {} already exists, ignoring namespace create operation.", namespace);
return existing;
}
} catch (ApiException ignore) {
// ignore exception and proceed with Namespace creation.
}
V1Namespace body = new V1Namespace();
// Set the required api version and kind of resource
body.setApiVersion("v1");
body.setKind("Namespace");
// Setup the standard object metadata
V1ObjectMeta meta = new V1ObjectMeta();
meta.setName(namespace);
body.setMetadata(meta);
return api.createNamespace(body, PRETTY_PRINT, DRY_RUN, FIELD_MANAGER);
}
use of io.kubernetes.client.openapi.apis.CoreV1Api in project pravega by pravega.
the class K8sClient method getStatusOfPod.
/**
* Method used to fetch the status of a Pod. V1PodStatus also helps to indicate the container status.
* @param namespace Namespace.
* @param podName Name of the pod.
* @return A future representing the status of the pod.
*/
@SneakyThrows(ApiException.class)
public CompletableFuture<V1PodStatus> getStatusOfPod(final String namespace, final String podName) {
CoreV1Api api = new CoreV1Api();
K8AsyncCallback<V1PodList> callback = new K8AsyncCallback<>("listPods");
api.listNamespacedPodAsync(namespace, PRETTY_PRINT, ALLOW_WATCH_BOOKMARKS, null, null, "POD_NAME=" + podName, null, null, null, false, callback);
return callback.getFuture().thenApply(v1PodList -> {
Optional<V1Pod> vpod = v1PodList.getItems().stream().filter(v1Pod -> v1Pod.getMetadata().getName().equals(podName) && v1Pod.getMetadata().getNamespace().equals(namespace)).findFirst();
return vpod.map(V1Pod::getStatus).orElseThrow(() -> new RuntimeException("pod not found" + podName));
});
}
use of io.kubernetes.client.openapi.apis.CoreV1Api in project pravega by pravega.
the class K8sClient method deleteConfigMap.
/**
* Method to delete V1ConfigMap.
* @param name Name of the ConfigMap.
* @param namespace Namespace on which the pod(s) reside.
* @return Future representing the V1ConfigMap.
*/
@SneakyThrows(ApiException.class)
public CompletableFuture<V1Status> deleteConfigMap(String name, String namespace) {
CoreV1Api api = new CoreV1Api();
K8AsyncCallback<V1Status> callback = new K8AsyncCallback<>("deleteNamespacedConfigMap-" + name);
api.deleteNamespacedConfigMapAsync(name, namespace, PRETTY_PRINT, null, 0, false, null, null, callback);
return callback.getFuture();
}
use of io.kubernetes.client.openapi.apis.CoreV1Api in project pravega by pravega.
the class K8sClient method deleteSecret.
/**
* Method to delete V1Secret.
* @param name Name of the Secret.
* @param namespace Namespace on which the pod(s) reside.
* @return Future representing the V1Secret.
*/
@SneakyThrows(ApiException.class)
public CompletableFuture<V1Status> deleteSecret(String name, String namespace) {
CoreV1Api api = new CoreV1Api();
K8AsyncCallback<V1Status> callback = new K8AsyncCallback<>("deleteNamespacedSecret-" + name);
api.deleteNamespacedSecretAsync(name, namespace, PRETTY_PRINT, null, 0, false, null, null, callback);
return callback.getFuture();
}
use of io.kubernetes.client.openapi.apis.CoreV1Api in project pravega by pravega.
the class K8sClient method createServiceAccount.
/**
* Create a service account.
* @param namespace The namespace.
* @param account Service Account.
* @return A future indicating the status of create service account operation.
*/
@SneakyThrows(ApiException.class)
public CompletableFuture<V1ServiceAccount> createServiceAccount(String namespace, V1ServiceAccount account) {
CoreV1Api api = new CoreV1Api();
K8AsyncCallback<V1ServiceAccount> callback = new K8AsyncCallback<>("createServiceAccount-" + account.getMetadata().getName());
api.createNamespacedServiceAccountAsync(namespace, account, PRETTY_PRINT, DRY_RUN, FIELD_MANAGER, callback);
return exceptionallyExpecting(callback.getFuture(), isConflict, null);
}
Aggregations