Search in sources :

Example 11 with ScalableResource

use of io.fabric8.kubernetes.client.dsl.ScalableResource in project jointware by isdream.

the class KubernetesAPIExample method main.

/**
 * @param args
 */
public static void main(String[] args) {
    DefaultKubernetesClient client = createClient();
    client.pods();
    client.extensions().deployments();
    client.replicationControllers();
    client.secrets();
    MixedOperation<Deployment, DeploymentList, DoneableDeployment, ScalableResource<Deployment, DoneableDeployment>> deployment = client.extensions().deployments();
    System.out.println(deployment.list().getItems());
}
Also used : DoneableDeployment(io.fabric8.kubernetes.api.model.extensions.DoneableDeployment) ScalableResource(io.fabric8.kubernetes.client.dsl.ScalableResource) DeploymentList(io.fabric8.kubernetes.api.model.extensions.DeploymentList) Deployment(io.fabric8.kubernetes.api.model.extensions.Deployment) DoneableDeployment(io.fabric8.kubernetes.api.model.extensions.DoneableDeployment) DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient)

Example 12 with ScalableResource

use of io.fabric8.kubernetes.client.dsl.ScalableResource in project che-server by eclipse-che.

the class KubernetesDeployments method doDeleteDeployment.

protected CompletableFuture<Void> doDeleteDeployment(String deploymentName) throws InfrastructureException {
    // Try to get pod name if it exists (it may not, if e.g. workspace config refers to
    // nonexistent service account).
    String podName;
    try {
        podName = getPodName(deploymentName);
    } catch (InfrastructureException e) {
        // Not an error, just means the Deployment has failed to create a pod.
        podName = null;
    }
    Watch toCloseOnException = null;
    try {
        ScalableResource<Deployment> deploymentResource = clientFactory.create(workspaceId).apps().deployments().inNamespace(namespace).withName(deploymentName);
        if (deploymentResource.get() == null) {
            throw new InfrastructureException(format("No deployment found to delete for name %s", deploymentName));
        }
        final CompletableFuture<Void> deleteFuture = new CompletableFuture<>();
        final Watch watch;
        // Deployment we are deleting.
        if (!Strings.isNullOrEmpty(podName)) {
            PodResource<Pod> podResource = clientFactory.create(workspaceId).pods().inNamespace(namespace).withName(podName);
            watch = podResource.watch(new DeleteWatcher<>(deleteFuture));
            toCloseOnException = watch;
        } else {
            watch = deploymentResource.watch(new DeleteWatcher<Deployment>(deleteFuture));
            toCloseOnException = watch;
        }
        Boolean deleteSucceeded = deploymentResource.withPropagationPolicy(BACKGROUND).delete();
        if (deleteSucceeded == null || !deleteSucceeded) {
            deleteFuture.complete(null);
        }
        return deleteFuture.whenComplete((v, e) -> {
            if (e != null) {
                LOG.warn("Failed to remove deployment {} cause {}", deploymentName, e.getMessage());
            }
            watch.close();
        });
    } catch (KubernetesClientException e) {
        if (toCloseOnException != null) {
            toCloseOnException.close();
        }
        throw new KubernetesInfrastructureException(e);
    } catch (Exception e) {
        if (toCloseOnException != null) {
            toCloseOnException.close();
        }
        throw e;
    }
}
Also used : Pod(io.fabric8.kubernetes.api.model.Pod) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) KubernetesInfrastructureException(org.eclipse.che.workspace.infrastructure.kubernetes.KubernetesInfrastructureException) TimeoutException(java.util.concurrent.TimeoutException) KubernetesInfrastructureException(org.eclipse.che.workspace.infrastructure.kubernetes.KubernetesInfrastructureException) ParseException(java.text.ParseException) KubernetesClientException(io.fabric8.kubernetes.client.KubernetesClientException) InfrastructureException(org.eclipse.che.api.workspace.server.spi.InfrastructureException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) WatcherException(io.fabric8.kubernetes.client.WatcherException) ExecutionException(java.util.concurrent.ExecutionException) CompletableFuture(java.util.concurrent.CompletableFuture) ExecWatch(io.fabric8.kubernetes.client.dsl.ExecWatch) Watch(io.fabric8.kubernetes.client.Watch) KubernetesInfrastructureException(org.eclipse.che.workspace.infrastructure.kubernetes.KubernetesInfrastructureException) InfrastructureException(org.eclipse.che.api.workspace.server.spi.InfrastructureException) KubernetesClientException(io.fabric8.kubernetes.client.KubernetesClientException)

Example 13 with ScalableResource

use of io.fabric8.kubernetes.client.dsl.ScalableResource in project devspaces-images by redhat-developer.

the class KubernetesDeployments method doDeleteDeployment.

protected CompletableFuture<Void> doDeleteDeployment(String deploymentName) throws InfrastructureException {
    // Try to get pod name if it exists (it may not, if e.g. workspace config refers to
    // nonexistent service account).
    String podName;
    try {
        podName = getPodName(deploymentName);
    } catch (InfrastructureException e) {
        // Not an error, just means the Deployment has failed to create a pod.
        podName = null;
    }
    Watch toCloseOnException = null;
    try {
        ScalableResource<Deployment> deploymentResource = clientFactory.create(workspaceId).apps().deployments().inNamespace(namespace).withName(deploymentName);
        if (deploymentResource.get() == null) {
            throw new InfrastructureException(format("No deployment found to delete for name %s", deploymentName));
        }
        final CompletableFuture<Void> deleteFuture = new CompletableFuture<>();
        final Watch watch;
        // Deployment we are deleting.
        if (!Strings.isNullOrEmpty(podName)) {
            PodResource<Pod> podResource = clientFactory.create(workspaceId).pods().inNamespace(namespace).withName(podName);
            watch = podResource.watch(new DeleteWatcher<>(deleteFuture));
            toCloseOnException = watch;
        } else {
            watch = deploymentResource.watch(new DeleteWatcher<Deployment>(deleteFuture));
            toCloseOnException = watch;
        }
        Boolean deleteSucceeded = deploymentResource.withPropagationPolicy(BACKGROUND).delete();
        if (deleteSucceeded == null || !deleteSucceeded) {
            deleteFuture.complete(null);
        }
        return deleteFuture.whenComplete((v, e) -> {
            if (e != null) {
                LOG.warn("Failed to remove deployment {} cause {}", deploymentName, e.getMessage());
            }
            watch.close();
        });
    } catch (KubernetesClientException e) {
        if (toCloseOnException != null) {
            toCloseOnException.close();
        }
        throw new KubernetesInfrastructureException(e);
    } catch (Exception e) {
        if (toCloseOnException != null) {
            toCloseOnException.close();
        }
        throw e;
    }
}
Also used : Pod(io.fabric8.kubernetes.api.model.Pod) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) KubernetesInfrastructureException(org.eclipse.che.workspace.infrastructure.kubernetes.KubernetesInfrastructureException) TimeoutException(java.util.concurrent.TimeoutException) KubernetesInfrastructureException(org.eclipse.che.workspace.infrastructure.kubernetes.KubernetesInfrastructureException) ParseException(java.text.ParseException) KubernetesClientException(io.fabric8.kubernetes.client.KubernetesClientException) InfrastructureException(org.eclipse.che.api.workspace.server.spi.InfrastructureException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) WatcherException(io.fabric8.kubernetes.client.WatcherException) ExecutionException(java.util.concurrent.ExecutionException) CompletableFuture(java.util.concurrent.CompletableFuture) ExecWatch(io.fabric8.kubernetes.client.dsl.ExecWatch) Watch(io.fabric8.kubernetes.client.Watch) KubernetesInfrastructureException(org.eclipse.che.workspace.infrastructure.kubernetes.KubernetesInfrastructureException) InfrastructureException(org.eclipse.che.api.workspace.server.spi.InfrastructureException) KubernetesClientException(io.fabric8.kubernetes.client.KubernetesClientException)

Aggregations

ScalableResource (io.fabric8.kubernetes.client.dsl.ScalableResource)9 Deployment (io.fabric8.kubernetes.api.model.extensions.Deployment)8 Service (io.fabric8.kubernetes.api.model.Service)7 NonNamespaceOperation (io.fabric8.kubernetes.client.dsl.NonNamespaceOperation)6 OpenShiftClient (io.fabric8.openshift.client.OpenShiftClient)6 Test (org.junit.Test)6 API (org.wso2.carbon.apimgt.core.models.API)6 ContainerBasedGatewayException (org.wso2.carbon.apimgt.core.exception.ContainerBasedGatewayException)4 Pod (io.fabric8.kubernetes.api.model.Pod)3 DeploymentList (io.fabric8.kubernetes.api.model.extensions.DeploymentList)3 DoneableDeployment (io.fabric8.kubernetes.api.model.extensions.DoneableDeployment)3 Ingress (io.fabric8.kubernetes.api.model.extensions.Ingress)3 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)2 Deployment (io.fabric8.kubernetes.api.model.apps.Deployment)2 KubernetesClientException (io.fabric8.kubernetes.client.KubernetesClientException)2 Watch (io.fabric8.kubernetes.client.Watch)2 WatcherException (io.fabric8.kubernetes.client.WatcherException)2 ExecWatch (io.fabric8.kubernetes.client.dsl.ExecWatch)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 ParseException (java.text.ParseException)2