Search in sources :

Example 1 with CoreV1Api

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);
}
Also used : V1ObjectMeta(io.kubernetes.client.openapi.models.V1ObjectMeta) V1Namespace(io.kubernetes.client.openapi.models.V1Namespace) CoreV1Api(io.kubernetes.client.openapi.apis.CoreV1Api) ApiException(io.kubernetes.client.openapi.ApiException) SneakyThrows(lombok.SneakyThrows)

Example 2 with CoreV1Api

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));
    });
}
Also used : V1PodList(io.kubernetes.client.openapi.models.V1PodList) PodLogs(io.kubernetes.client.PodLogs) TypeToken(com.google.gson.reflect.TypeToken) SneakyThrows(lombok.SneakyThrows) Retry(io.pravega.common.util.Retry) V1beta1CustomResourceDefinition(io.kubernetes.client.openapi.models.V1beta1CustomResourceDefinition) Cleanup(lombok.Cleanup) V1PodList(io.kubernetes.client.openapi.models.V1PodList) V1PodStatus(io.kubernetes.client.openapi.models.V1PodStatus) TestFrameworkException(io.pravega.test.system.framework.TestFrameworkException) ApiextensionsV1beta1Api(io.kubernetes.client.openapi.apis.ApiextensionsV1beta1Api) Futures.exceptionallyExpecting(io.pravega.common.concurrent.Futures.exceptionallyExpecting) V1beta1ClusterRole(io.kubernetes.client.openapi.models.V1beta1ClusterRole) V1Patch(io.kubernetes.client.custom.V1Patch) Configuration(io.kubernetes.client.openapi.Configuration) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Duration(java.time.Duration) Map(java.util.Map) V1beta1ClusterRoleBinding(io.kubernetes.client.openapi.models.V1beta1ClusterRoleBinding) V1ServiceAccount(io.kubernetes.client.openapi.models.V1ServiceAccount) V1DeleteOptions(io.kubernetes.client.openapi.models.V1DeleteOptions) ImmutableMap(com.google.common.collect.ImmutableMap) Predicate(java.util.function.Predicate) V1Secret(io.kubernetes.client.openapi.models.V1Secret) CONFLICT(javax.ws.rs.core.Response.Status.CONFLICT) NOT_FOUND(javax.ws.rs.core.Response.Status.NOT_FOUND) RbacAuthorizationV1beta1Api(io.kubernetes.client.openapi.apis.RbacAuthorizationV1beta1Api) V1Status(io.kubernetes.client.openapi.models.V1Status) Collectors(java.util.stream.Collectors) List(java.util.List) Slf4j(lombok.extern.slf4j.Slf4j) Optional(java.util.Optional) ApiCallback(io.kubernetes.client.openapi.ApiCallback) PatchUtils(io.kubernetes.client.util.PatchUtils) Futures(io.pravega.common.concurrent.Futures) V1Deployment(io.kubernetes.client.openapi.models.V1Deployment) Exceptions(io.pravega.common.Exceptions) Watch(io.kubernetes.client.util.Watch) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) CompletableFuture(java.util.concurrent.CompletableFuture) AppsV1Api(io.kubernetes.client.openapi.apis.AppsV1Api) ApiClient(io.kubernetes.client.openapi.ApiClient) ApiException(io.kubernetes.client.openapi.ApiException) V1ConfigMap(io.kubernetes.client.openapi.models.V1ConfigMap) V1ContainerStateTerminated(io.kubernetes.client.openapi.models.V1ContainerStateTerminated) V1ObjectMeta(io.kubernetes.client.openapi.models.V1ObjectMeta) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) V1ContainerStatus(io.kubernetes.client.openapi.models.V1ContainerStatus) V1Namespace(io.kubernetes.client.openapi.models.V1Namespace) V1beta1Role(io.kubernetes.client.openapi.models.V1beta1Role) JsonSyntaxException(com.google.gson.JsonSyntaxException) Files(java.nio.file.Files) CustomObjectsApi(io.kubernetes.client.openapi.apis.CustomObjectsApi) IOException(java.io.IOException) CoreV1Api(io.kubernetes.client.openapi.apis.CoreV1Api) Config(io.kubernetes.client.util.Config) TimeUnit(java.util.concurrent.TimeUnit) ConnectionFailed(io.pravega.test.system.framework.TestFrameworkException.Type.ConnectionFailed) Paths(java.nio.file.Paths) V1ContainerState(io.kubernetes.client.openapi.models.V1ContainerState) ExecutorServiceHelpers(io.pravega.common.concurrent.ExecutorServiceHelpers) V1beta1RoleBinding(io.kubernetes.client.openapi.models.V1beta1RoleBinding) SECONDS(java.util.concurrent.TimeUnit.SECONDS) V1Pod(io.kubernetes.client.openapi.models.V1Pod) InputStream(java.io.InputStream) V1Pod(io.kubernetes.client.openapi.models.V1Pod) CoreV1Api(io.kubernetes.client.openapi.apis.CoreV1Api) SneakyThrows(lombok.SneakyThrows)

Example 3 with CoreV1Api

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();
}
Also used : V1Status(io.kubernetes.client.openapi.models.V1Status) CoreV1Api(io.kubernetes.client.openapi.apis.CoreV1Api) SneakyThrows(lombok.SneakyThrows)

Example 4 with CoreV1Api

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();
}
Also used : V1Status(io.kubernetes.client.openapi.models.V1Status) CoreV1Api(io.kubernetes.client.openapi.apis.CoreV1Api) SneakyThrows(lombok.SneakyThrows)

Example 5 with CoreV1Api

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);
}
Also used : V1ServiceAccount(io.kubernetes.client.openapi.models.V1ServiceAccount) CoreV1Api(io.kubernetes.client.openapi.apis.CoreV1Api) SneakyThrows(lombok.SneakyThrows)

Aggregations

CoreV1Api (io.kubernetes.client.openapi.apis.CoreV1Api)48 V1Pod (io.kubernetes.client.openapi.models.V1Pod)18 ApiClient (io.kubernetes.client.openapi.ApiClient)16 Test (org.junit.Test)16 ApiException (io.kubernetes.client.openapi.ApiException)13 V1PodList (io.kubernetes.client.openapi.models.V1PodList)13 SneakyThrows (lombok.SneakyThrows)12 IOException (java.io.IOException)11 V1Namespace (io.kubernetes.client.openapi.models.V1Namespace)10 V1ObjectMeta (io.kubernetes.client.openapi.models.V1ObjectMeta)10 CallGeneratorParams (io.kubernetes.client.util.CallGeneratorParams)9 Watch (io.kubernetes.client.util.Watch)9 SharedInformerFactory (io.kubernetes.client.informer.SharedInformerFactory)8 JSON (io.kubernetes.client.openapi.JSON)6 V1Status (io.kubernetes.client.openapi.models.V1Status)6 OkHttpClient (okhttp3.OkHttpClient)6 V1Patch (io.kubernetes.client.custom.V1Patch)5 V1ConfigMap (io.kubernetes.client.openapi.models.V1ConfigMap)5 V1ListMeta (io.kubernetes.client.openapi.models.V1ListMeta)5 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)5