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());
}
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;
}
}
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;
}
}
Aggregations