Search in sources :

Example 11 with Deletable

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

the class AsyncStoragePodInterceptorTest method shouldDoDeletePodIfWorkspaceWithEmptyAttributes.

@Test
public void shouldDoDeletePodIfWorkspaceWithEmptyAttributes() throws InfrastructureException {
    when(identity.getWorkspaceId()).thenReturn(WORKSPACE_ID);
    when(identity.getInfrastructureNamespace()).thenReturn(NAMESPACE);
    when(clientFactory.create(WORKSPACE_ID)).thenReturn(kubernetesClient);
    when(kubernetesEnvironment.getAttributes()).thenReturn(emptyMap());
    when(kubernetesClient.pods()).thenReturn(mixedOperationPod);
    when(mixedOperationPod.inNamespace(NAMESPACE)).thenReturn(namespacePodOperation);
    when(namespacePodOperation.withName(ASYNC_STORAGE)).thenReturn(podResource);
    when(podResource.get()).thenReturn(null);
    when(kubernetesClient.apps()).thenReturn(apps);
    when(apps.deployments()).thenReturn(mixedOperation);
    when(mixedOperation.inNamespace(NAMESPACE)).thenReturn(namespaceOperation);
    when(namespaceOperation.withName(ASYNC_STORAGE)).thenReturn(deploymentResource);
    ObjectMeta meta = new ObjectMeta();
    meta.setName(ASYNC_STORAGE);
    Deployment deployment = new Deployment();
    deployment.setMetadata(meta);
    when(deploymentResource.get()).thenReturn(deployment);
    when(deploymentResource.withPropagationPolicy(BACKGROUND)).thenReturn(deletable);
    Watch watch = mock(Watch.class);
    when(deploymentResource.watch(any())).thenReturn(watch);
    asyncStoragePodInterceptor.intercept(kubernetesEnvironment, identity);
    verify(deletable).delete();
    verify(watch).close();
}
Also used : ObjectMeta(io.fabric8.kubernetes.api.model.ObjectMeta) Watch(io.fabric8.kubernetes.client.Watch) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) Test(org.testng.annotations.Test)

Example 12 with Deletable

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

the class AsyncStoragePodInterceptorTest method shouldDoDeletePodIfWorkspaceConfigureToPersistentStorage.

@Test
public void shouldDoDeletePodIfWorkspaceConfigureToPersistentStorage() throws InfrastructureException {
    when(identity.getWorkspaceId()).thenReturn(WORKSPACE_ID);
    when(identity.getInfrastructureNamespace()).thenReturn(NAMESPACE);
    when(clientFactory.create(WORKSPACE_ID)).thenReturn(kubernetesClient);
    when(kubernetesEnvironment.getAttributes()).thenReturn(ImmutableMap.of(PERSIST_VOLUMES_ATTRIBUTE, "true"));
    when(kubernetesClient.pods()).thenReturn(mixedOperationPod);
    when(mixedOperationPod.inNamespace(NAMESPACE)).thenReturn(namespacePodOperation);
    when(namespacePodOperation.withName(ASYNC_STORAGE)).thenReturn(podResource);
    when(podResource.get()).thenReturn(null);
    when(kubernetesClient.apps()).thenReturn(apps);
    when(apps.deployments()).thenReturn(mixedOperation);
    when(mixedOperation.inNamespace(NAMESPACE)).thenReturn(namespaceOperation);
    when(namespaceOperation.withName(ASYNC_STORAGE)).thenReturn(deploymentResource);
    ObjectMeta meta = new ObjectMeta();
    meta.setName(ASYNC_STORAGE);
    Deployment deployment = new Deployment();
    deployment.setMetadata(meta);
    when(deploymentResource.get()).thenReturn(deployment);
    when(deploymentResource.withPropagationPolicy(BACKGROUND)).thenReturn(deletable);
    Watch watch = mock(Watch.class);
    when(deploymentResource.watch(any())).thenReturn(watch);
    asyncStoragePodInterceptor.intercept(kubernetesEnvironment, identity);
    verify(deletable).delete();
    verify(watch).close();
}
Also used : ObjectMeta(io.fabric8.kubernetes.api.model.ObjectMeta) Watch(io.fabric8.kubernetes.client.Watch) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) Test(org.testng.annotations.Test)

Example 13 with Deletable

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

the class AsyncStoragePodInterceptorTest method shouldDoDeletePodIfWorkspaceWithEmptyAttributes.

@Test
public void shouldDoDeletePodIfWorkspaceWithEmptyAttributes() throws InfrastructureException {
    when(identity.getWorkspaceId()).thenReturn(WORKSPACE_ID);
    when(identity.getInfrastructureNamespace()).thenReturn(NAMESPACE);
    when(clientFactory.create(WORKSPACE_ID)).thenReturn(kubernetesClient);
    when(kubernetesEnvironment.getAttributes()).thenReturn(emptyMap());
    when(kubernetesClient.pods()).thenReturn(mixedOperationPod);
    when(mixedOperationPod.inNamespace(NAMESPACE)).thenReturn(namespacePodOperation);
    when(namespacePodOperation.withName(ASYNC_STORAGE)).thenReturn(podResource);
    when(podResource.get()).thenReturn(null);
    when(kubernetesClient.apps()).thenReturn(apps);
    when(apps.deployments()).thenReturn(mixedOperation);
    when(mixedOperation.inNamespace(NAMESPACE)).thenReturn(namespaceOperation);
    when(namespaceOperation.withName(ASYNC_STORAGE)).thenReturn(deploymentResource);
    ObjectMeta meta = new ObjectMeta();
    meta.setName(ASYNC_STORAGE);
    Deployment deployment = new Deployment();
    deployment.setMetadata(meta);
    when(deploymentResource.get()).thenReturn(deployment);
    when(deploymentResource.withPropagationPolicy(BACKGROUND)).thenReturn(deletable);
    Watch watch = mock(Watch.class);
    when(deploymentResource.watch(any())).thenReturn(watch);
    asyncStoragePodInterceptor.intercept(kubernetesEnvironment, identity);
    verify(deletable).delete();
    verify(watch).close();
}
Also used : ObjectMeta(io.fabric8.kubernetes.api.model.ObjectMeta) Watch(io.fabric8.kubernetes.client.Watch) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) Test(org.testng.annotations.Test)

Aggregations

Watch (io.fabric8.kubernetes.client.Watch)12 StatefulSet (io.fabric8.kubernetes.api.model.apps.StatefulSet)9 Deletable (io.fabric8.kubernetes.client.dsl.Deletable)9 Test (org.junit.jupiter.api.Test)9 DeletionPropagation (io.fabric8.kubernetes.api.model.DeletionPropagation)8 PersistentVolumeClaim (io.fabric8.kubernetes.api.model.PersistentVolumeClaim)8 PersistentVolumeClaimBuilder (io.fabric8.kubernetes.api.model.PersistentVolumeClaimBuilder)8 PodBuilder (io.fabric8.kubernetes.api.model.PodBuilder)8 Quantity (io.fabric8.kubernetes.api.model.Quantity)8 StatefulSetBuilder (io.fabric8.kubernetes.api.model.apps.StatefulSetBuilder)8 StatefulSetList (io.fabric8.kubernetes.api.model.apps.StatefulSetList)8 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)8 Watcher (io.fabric8.kubernetes.client.Watcher)8 AppsAPIGroupDSL (io.fabric8.kubernetes.client.dsl.AppsAPIGroupDSL)8 EditReplacePatchDeletable (io.fabric8.kubernetes.client.dsl.EditReplacePatchDeletable)8 MixedOperation (io.fabric8.kubernetes.client.dsl.MixedOperation)8 NonNamespaceOperation (io.fabric8.kubernetes.client.dsl.NonNamespaceOperation)8 Resource (io.fabric8.kubernetes.client.dsl.Resource)8 RollableScalableResource (io.fabric8.kubernetes.client.dsl.RollableScalableResource)8 Reconciliation (io.strimzi.operator.common.Reconciliation)8