use of io.fabric8.kubernetes.client.dsl.Deletable in project strimzi by strimzi.
the class StatefulSetOperatorTest method testInternalReplace.
@Test
public void testInternalReplace(VertxTestContext context) {
StatefulSet sts1 = new StatefulSetBuilder().withNewMetadata().withNamespace(AbstractResourceOperatorTest.NAMESPACE).withName(AbstractResourceOperatorTest.RESOURCE_NAME).endMetadata().withNewSpec().withReplicas(3).withNewTemplate().withNewMetadata().endMetadata().endTemplate().endSpec().build();
Map<String, Quantity> requests = new HashMap<>();
requests.put("storage", new Quantity("100Gi"));
PersistentVolumeClaim pvc = new PersistentVolumeClaimBuilder().withNewMetadata().withName("data").endMetadata().withNewSpec().withAccessModes("ReadWriteOnce").withNewResources().withRequests(requests).endResources().withStorageClassName("gp2").endSpec().build();
StatefulSet sts2 = new StatefulSetBuilder().withNewMetadata().withNamespace(AbstractResourceOperatorTest.NAMESPACE).withName(AbstractResourceOperatorTest.RESOURCE_NAME).endMetadata().withNewSpec().withReplicas(3).withNewTemplate().withNewMetadata().endMetadata().endTemplate().withVolumeClaimTemplates(pvc).endSpec().build();
Deletable mockDeletable = mock(Deletable.class);
when(mockDeletable.delete()).thenReturn(Boolean.TRUE);
Resource mockERPD = mock(resourceType());
when(mockERPD.withPropagationPolicy(any(DeletionPropagation.class))).thenReturn(mockDeletable);
when(mockERPD.withGracePeriod(anyLong())).thenReturn(mockDeletable);
Resource mockResource = mock(resourceType());
when(mockResource.get()).thenReturn(sts1);
when(mockResource.withPropagationPolicy(eq(DeletionPropagation.ORPHAN))).thenReturn(mockERPD);
when(mockResource.create(any(StatefulSet.class))).thenReturn(sts1);
PodOperator podOperator = mock(PodOperator.class);
when(podOperator.waitFor(any(), anyString(), anyString(), anyLong(), anyLong(), any(BiPredicate.class))).thenReturn(Future.succeededFuture());
when(podOperator.readiness(any(), anyString(), anyString(), anyLong(), anyLong())).thenReturn(Future.succeededFuture());
when(podOperator.reconcile(any(), anyString(), anyString(), any())).thenReturn(Future.succeededFuture());
when(podOperator.getAsync(anyString(), anyString())).thenReturn(Future.succeededFuture(new PodBuilder().withNewMetadata().withName("my-pod-0").endMetadata().build()));
PvcOperator pvcOperator = mock(PvcOperator.class);
when(pvcOperator.reconcile(any(), anyString(), anyString(), any())).thenReturn(Future.succeededFuture());
NonNamespaceOperation mockNameable = mock(NonNamespaceOperation.class);
when(mockNameable.withName(matches(RESOURCE_NAME))).thenReturn(mockResource);
MixedOperation mockCms = mock(MixedOperation.class);
when(mockCms.inNamespace(matches(NAMESPACE))).thenReturn(mockNameable);
KubernetesClient mockClient = mock(KubernetesClient.class);
mocker(mockClient, mockCms);
StatefulSetOperator op = new StatefulSetOperator(AbstractResourceOperatorTest.vertx, mockClient, 5_000L, podOperator, pvcOperator) {
@Override
protected boolean shouldIncrementGeneration(Reconciliation reconciliation, StatefulSetDiff diff) {
return true;
}
@Override
public Future<Void> waitFor(Reconciliation reconciliation, String namespace, String name, String logState, long pollIntervalMs, final long timeoutMs, BiPredicate<String, String> predicate) {
return Future.succeededFuture();
}
};
Checkpoint async = context.checkpoint();
op.reconcile(new Reconciliation("test", "kind", "namespace", "name"), sts1.getMetadata().getNamespace(), sts1.getMetadata().getName(), sts2).onComplete(context.succeeding(rrState -> {
verify(mockDeletable).delete();
async.flag();
}));
}
use of io.fabric8.kubernetes.client.dsl.Deletable in project strimzi by strimzi.
the class StatefulSetOperatorTest method testCascadingDeleteAsync.
@Test
public void testCascadingDeleteAsync(VertxTestContext context) {
Deletable mockDeletable = mock(Deletable.class);
when(mockDeletable.delete()).thenReturn(Boolean.TRUE);
Resource mockERPD = mock(resourceType());
when(mockERPD.withPropagationPolicy(any(DeletionPropagation.class))).thenReturn(mockDeletable);
when(mockERPD.withGracePeriod(anyLong())).thenReturn(mockDeletable);
RollableScalableResource mockRSR = mock(RollableScalableResource.class);
ArgumentCaptor<DeletionPropagation> cascadingCaptor = ArgumentCaptor.forClass(DeletionPropagation.class);
when(mockRSR.withPropagationPolicy(cascadingCaptor.capture())).thenReturn(mockERPD);
ArgumentCaptor<Watcher> watcherCaptor = ArgumentCaptor.forClass(Watcher.class);
when(mockRSR.watch(watcherCaptor.capture())).thenReturn(mock(Watch.class));
NonNamespaceOperation mockNameable = mock(NonNamespaceOperation.class);
when(mockNameable.withName(matches(RESOURCE_NAME))).thenReturn(mockRSR);
MixedOperation mockCms = mock(MixedOperation.class);
when(mockCms.inNamespace(matches(NAMESPACE))).thenReturn(mockNameable);
PodOperator podOperator = mock(PodOperator.class);
PvcOperator pvcOperator = mock(PvcOperator.class);
KubernetesClient mockClient = mock(KubernetesClient.class);
mocker(mockClient, mockCms);
StatefulSetOperator op = new StatefulSetOperator(AbstractResourceOperatorTest.vertx, mockClient, 5_000L, podOperator, pvcOperator) {
@Override
protected boolean shouldIncrementGeneration(Reconciliation reconciliation, StatefulSetDiff diff) {
return true;
}
};
Checkpoint async = context.checkpoint();
op.deleteAsync(new Reconciliation("test", "kind", "namespace", "name"), NAMESPACE, RESOURCE_NAME, true).onComplete(context.succeeding(v -> context.verify(() -> {
assertThat(cascadingCaptor.getValue(), is(DeletionPropagation.FOREGROUND));
async.flag();
})));
}
use of io.fabric8.kubernetes.client.dsl.Deletable in project strimzi-kafka-operator by strimzi.
the class StatefulSetOperatorTest method testDeleteAsyncFailing.
@Test
public void testDeleteAsyncFailing(VertxTestContext context) {
Deletable mockDeletable = mock(Deletable.class);
when(mockDeletable.delete()).thenThrow(new MockitoException("Something failed"));
Resource mockERPD = mock(resourceType());
when(mockERPD.withPropagationPolicy(any(DeletionPropagation.class))).thenReturn(mockDeletable);
when(mockERPD.withGracePeriod(anyLong())).thenReturn(mockDeletable);
RollableScalableResource mockRSR = mock(RollableScalableResource.class);
when(mockRSR.withPropagationPolicy(any(DeletionPropagation.class))).thenReturn(mockERPD);
when(mockRSR.watch(any())).thenReturn(mock(Watch.class));
NonNamespaceOperation mockNameable = mock(NonNamespaceOperation.class);
when(mockNameable.withName(matches(RESOURCE_NAME))).thenReturn(mockRSR);
MixedOperation mockCms = mock(MixedOperation.class);
when(mockCms.inNamespace(matches(NAMESPACE))).thenReturn(mockNameable);
PodOperator podOperator = mock(PodOperator.class);
PvcOperator pvcOperator = mock(PvcOperator.class);
KubernetesClient mockClient = mock(KubernetesClient.class);
mocker(mockClient, mockCms);
StatefulSetOperator op = new StatefulSetOperator(AbstractResourceOperatorTest.vertx, mockClient, 5_000L, podOperator, pvcOperator) {
@Override
protected boolean shouldIncrementGeneration(Reconciliation reconciliation, StatefulSetDiff diff) {
return true;
}
};
Checkpoint async = context.checkpoint();
op.deleteAsync(new Reconciliation("test", "kind", "namespace", "name"), NAMESPACE, RESOURCE_NAME, false).onComplete(context.failing(e -> context.verify(() -> {
assertThat(e, instanceOf(MockitoException.class));
assertThat(e.getMessage(), is("Something failed"));
async.flag();
})));
}
use of io.fabric8.kubernetes.client.dsl.Deletable in project strimzi-kafka-operator by strimzi.
the class StatefulSetOperatorTest method testInternalReplace.
@Test
public void testInternalReplace(VertxTestContext context) {
StatefulSet sts1 = new StatefulSetBuilder().withNewMetadata().withNamespace(AbstractResourceOperatorTest.NAMESPACE).withName(AbstractResourceOperatorTest.RESOURCE_NAME).endMetadata().withNewSpec().withReplicas(3).withNewTemplate().withNewMetadata().endMetadata().endTemplate().endSpec().build();
Map<String, Quantity> requests = new HashMap<>();
requests.put("storage", new Quantity("100Gi"));
PersistentVolumeClaim pvc = new PersistentVolumeClaimBuilder().withNewMetadata().withName("data").endMetadata().withNewSpec().withAccessModes("ReadWriteOnce").withNewResources().withRequests(requests).endResources().withStorageClassName("gp2").endSpec().build();
StatefulSet sts2 = new StatefulSetBuilder().withNewMetadata().withNamespace(AbstractResourceOperatorTest.NAMESPACE).withName(AbstractResourceOperatorTest.RESOURCE_NAME).endMetadata().withNewSpec().withReplicas(3).withNewTemplate().withNewMetadata().endMetadata().endTemplate().withVolumeClaimTemplates(pvc).endSpec().build();
Deletable mockDeletable = mock(Deletable.class);
when(mockDeletable.delete()).thenReturn(Boolean.TRUE);
Resource mockERPD = mock(resourceType());
when(mockERPD.withPropagationPolicy(any(DeletionPropagation.class))).thenReturn(mockDeletable);
when(mockERPD.withGracePeriod(anyLong())).thenReturn(mockDeletable);
Resource mockResource = mock(resourceType());
when(mockResource.get()).thenReturn(sts1);
when(mockResource.withPropagationPolicy(eq(DeletionPropagation.ORPHAN))).thenReturn(mockERPD);
when(mockResource.create(any(StatefulSet.class))).thenReturn(sts1);
PodOperator podOperator = mock(PodOperator.class);
when(podOperator.waitFor(any(), anyString(), anyString(), anyLong(), anyLong(), any(BiPredicate.class))).thenReturn(Future.succeededFuture());
when(podOperator.readiness(any(), anyString(), anyString(), anyLong(), anyLong())).thenReturn(Future.succeededFuture());
when(podOperator.reconcile(any(), anyString(), anyString(), any())).thenReturn(Future.succeededFuture());
when(podOperator.getAsync(anyString(), anyString())).thenReturn(Future.succeededFuture(new PodBuilder().withNewMetadata().withName("my-pod-0").endMetadata().build()));
PvcOperator pvcOperator = mock(PvcOperator.class);
when(pvcOperator.reconcile(any(), anyString(), anyString(), any())).thenReturn(Future.succeededFuture());
NonNamespaceOperation mockNameable = mock(NonNamespaceOperation.class);
when(mockNameable.withName(matches(RESOURCE_NAME))).thenReturn(mockResource);
MixedOperation mockCms = mock(MixedOperation.class);
when(mockCms.inNamespace(matches(NAMESPACE))).thenReturn(mockNameable);
KubernetesClient mockClient = mock(KubernetesClient.class);
mocker(mockClient, mockCms);
StatefulSetOperator op = new StatefulSetOperator(AbstractResourceOperatorTest.vertx, mockClient, 5_000L, podOperator, pvcOperator) {
@Override
protected boolean shouldIncrementGeneration(Reconciliation reconciliation, StatefulSetDiff diff) {
return true;
}
@Override
public Future<Void> waitFor(Reconciliation reconciliation, String namespace, String name, String logState, long pollIntervalMs, final long timeoutMs, BiPredicate<String, String> predicate) {
return Future.succeededFuture();
}
};
Checkpoint async = context.checkpoint();
op.reconcile(new Reconciliation("test", "kind", "namespace", "name"), sts1.getMetadata().getNamespace(), sts1.getMetadata().getName(), sts2).onComplete(context.succeeding(rrState -> {
verify(mockDeletable).delete();
async.flag();
}));
}
use of io.fabric8.kubernetes.client.dsl.Deletable in project strimzi-kafka-operator by strimzi.
the class StatefulSetOperatorTest method testCascadingDeleteAsync.
@Test
public void testCascadingDeleteAsync(VertxTestContext context) {
Deletable mockDeletable = mock(Deletable.class);
when(mockDeletable.delete()).thenReturn(Boolean.TRUE);
Resource mockERPD = mock(resourceType());
when(mockERPD.withPropagationPolicy(any(DeletionPropagation.class))).thenReturn(mockDeletable);
when(mockERPD.withGracePeriod(anyLong())).thenReturn(mockDeletable);
RollableScalableResource mockRSR = mock(RollableScalableResource.class);
ArgumentCaptor<DeletionPropagation> cascadingCaptor = ArgumentCaptor.forClass(DeletionPropagation.class);
when(mockRSR.withPropagationPolicy(cascadingCaptor.capture())).thenReturn(mockERPD);
ArgumentCaptor<Watcher> watcherCaptor = ArgumentCaptor.forClass(Watcher.class);
when(mockRSR.watch(watcherCaptor.capture())).thenReturn(mock(Watch.class));
NonNamespaceOperation mockNameable = mock(NonNamespaceOperation.class);
when(mockNameable.withName(matches(RESOURCE_NAME))).thenReturn(mockRSR);
MixedOperation mockCms = mock(MixedOperation.class);
when(mockCms.inNamespace(matches(NAMESPACE))).thenReturn(mockNameable);
PodOperator podOperator = mock(PodOperator.class);
PvcOperator pvcOperator = mock(PvcOperator.class);
KubernetesClient mockClient = mock(KubernetesClient.class);
mocker(mockClient, mockCms);
StatefulSetOperator op = new StatefulSetOperator(AbstractResourceOperatorTest.vertx, mockClient, 5_000L, podOperator, pvcOperator) {
@Override
protected boolean shouldIncrementGeneration(Reconciliation reconciliation, StatefulSetDiff diff) {
return true;
}
};
Checkpoint async = context.checkpoint();
op.deleteAsync(new Reconciliation("test", "kind", "namespace", "name"), NAMESPACE, RESOURCE_NAME, true).onComplete(context.succeeding(v -> context.verify(() -> {
assertThat(cascadingCaptor.getValue(), is(DeletionPropagation.FOREGROUND));
async.flag();
})));
}
Aggregations