Java Code Examples for io.fabric8.kubernetes.api.model.PersistentVolumeClaim#setStatus()
The following examples show how to use
io.fabric8.kubernetes.api.model.PersistentVolumeClaim#setStatus() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: VolumeResizingTest.java From strimzi-kafka-operator with Apache License 2.0 | 4 votes |
@Test public void testVolumesBoundExpandableStorageClass() { Kafka kafka = getKafkaCrd(); KafkaCluster kafkaCluster = KafkaCluster.fromCrd(kafka, VERSIONS); ResourceOperatorSupplier supplier = ResourceUtils.supplierWithMocks(false); // Mock the PVC Operator PvcOperator mockPvcOps = supplier.pvcOperations; List<PersistentVolumeClaim> realPvcs = kafkaCluster.generatePersistentVolumeClaims(kafka.getSpec().getKafka().getStorage()); for (PersistentVolumeClaim pvc : realPvcs) { pvc.getSpec().getResources().getRequests().put("storage", new Quantity("10Gi")); pvc.setStatus(new PersistentVolumeClaimStatusBuilder() .withPhase("Bound") .withCapacity(pvc.getSpec().getResources().getRequests()) .build()); } when(mockPvcOps.getAsync(eq(namespace), ArgumentMatchers.startsWith("data-"))) .thenAnswer(invocation -> { String pvcName = invocation.getArgument(1); return Future.succeededFuture(realPvcs.stream().filter(pvc -> pvcName.equals(pvc.getMetadata().getName())).findFirst().orElse(null)); }); ArgumentCaptor<PersistentVolumeClaim> pvcCaptor = ArgumentCaptor.forClass(PersistentVolumeClaim.class); when(mockPvcOps.reconcile(anyString(), anyString(), pvcCaptor.capture())).thenReturn(Future.succeededFuture()); // Mock the StorageClass Operator StorageClassOperator mockSco = supplier.storageClassOperations; when(mockSco.getAsync(eq("mysc"))) .thenAnswer(invocation -> { StorageClass sc = new StorageClassBuilder() .withNewMetadata() .withName("mysc") .endMetadata() .withAllowVolumeExpansion(true) .build(); return Future.succeededFuture(sc); }); MockKafkaAssemblyOperator kao = new MockKafkaAssemblyOperator(vertx, new PlatformFeaturesAvailability(false, kubernetesVersion), certManager, passwordGenerator, supplier, config); kao.resizeVolumes(new Reconciliation("test-trigger", Kafka.RESOURCE_KIND, namespace, clusterName), kafka, kafkaCluster.generatePersistentVolumeClaims(kafka.getSpec().getKafka().getStorage()), kafkaCluster).onComplete(res -> { assertThat(res.succeeded(), is(true)); assertThat(pvcCaptor.getAllValues().size(), is(3)); assertThat(pvcCaptor.getAllValues(), is(kafkaCluster.generatePersistentVolumeClaims(kafka.getSpec().getKafka().getStorage()))); }); }
Example 2
Source File: VolumeResizingTest.java From strimzi-kafka-operator with Apache License 2.0 | 4 votes |
@Test public void testVolumesBoundNonExpandableStorageClass() { Kafka kafka = getKafkaCrd(); KafkaCluster kafkaCluster = KafkaCluster.fromCrd(kafka, VERSIONS); ResourceOperatorSupplier supplier = ResourceUtils.supplierWithMocks(false); // Mock the PVC Operator PvcOperator mockPvcOps = supplier.pvcOperations; List<PersistentVolumeClaim> realPvcs = kafkaCluster.generatePersistentVolumeClaims(kafka.getSpec().getKafka().getStorage()); for (PersistentVolumeClaim pvc : realPvcs) { pvc.getSpec().getResources().getRequests().put("storage", new Quantity("10Gi")); pvc.setStatus(new PersistentVolumeClaimStatusBuilder() .withPhase("Bound") .withCapacity(pvc.getSpec().getResources().getRequests()) .build()); } when(mockPvcOps.getAsync(eq(namespace), ArgumentMatchers.startsWith("data-"))) .thenAnswer(invocation -> { String pvcName = invocation.getArgument(1); return Future.succeededFuture(realPvcs.stream().filter(pvc -> pvcName.equals(pvc.getMetadata().getName())).findFirst().orElse(null)); }); ArgumentCaptor<PersistentVolumeClaim> pvcCaptor = ArgumentCaptor.forClass(PersistentVolumeClaim.class); when(mockPvcOps.reconcile(anyString(), anyString(), pvcCaptor.capture())).thenReturn(Future.succeededFuture()); // Mock the StorageClass Operator StorageClassOperator mockSco = supplier.storageClassOperations; when(mockSco.getAsync(eq("mysc"))) .thenAnswer(invocation -> { StorageClass sc = new StorageClassBuilder() .withNewMetadata() .withName("mysc") .endMetadata() .withAllowVolumeExpansion(false) .build(); return Future.succeededFuture(sc); }); MockKafkaAssemblyOperator kao = new MockKafkaAssemblyOperator(vertx, new PlatformFeaturesAvailability(false, kubernetesVersion), certManager, passwordGenerator, supplier, config); kao.resizeVolumes(new Reconciliation("test-trigger", Kafka.RESOURCE_KIND, namespace, clusterName), kafka, kafkaCluster.generatePersistentVolumeClaims(kafka.getSpec().getKafka().getStorage()), kafkaCluster).onComplete(res -> { assertThat(res.succeeded(), is(true)); // Resizing is not supported, we do not reconcile assertThat(pvcCaptor.getAllValues().size(), is(0)); }); }
Example 3
Source File: VolumeResizingTest.java From strimzi-kafka-operator with Apache License 2.0 | 4 votes |
@Test public void testVolumesResizing() { Kafka kafka = getKafkaCrd(); KafkaCluster kafkaCluster = KafkaCluster.fromCrd(kafka, VERSIONS); ResourceOperatorSupplier supplier = ResourceUtils.supplierWithMocks(false); // Mock the PVC Operator PvcOperator mockPvcOps = supplier.pvcOperations; List<PersistentVolumeClaim> realPvcs = kafkaCluster.generatePersistentVolumeClaims(kafka.getSpec().getKafka().getStorage()); for (PersistentVolumeClaim pvc : realPvcs) { pvc.setStatus(new PersistentVolumeClaimStatusBuilder() .withPhase("Bound") .withConditions(new PersistentVolumeClaimConditionBuilder() .withStatus("True") .withType("Resizing") .build()) .withCapacity(singletonMap("storage", new Quantity("10Gi"))) .build()); } when(mockPvcOps.getAsync(eq(namespace), ArgumentMatchers.startsWith("data-"))) .thenAnswer(invocation -> { String pvcName = invocation.getArgument(1); return Future.succeededFuture(realPvcs.stream().filter(pvc -> pvcName.equals(pvc.getMetadata().getName())).findFirst().orElse(null)); }); ArgumentCaptor<PersistentVolumeClaim> pvcCaptor = ArgumentCaptor.forClass(PersistentVolumeClaim.class); when(mockPvcOps.reconcile(anyString(), anyString(), pvcCaptor.capture())).thenReturn(Future.succeededFuture()); // Mock the StorageClass Operator StorageClassOperator mockSco = supplier.storageClassOperations; when(mockSco.getAsync(eq("mysc"))) .thenAnswer(invocation -> { StorageClass sc = new StorageClassBuilder() .withNewMetadata() .withName("mysc") .endMetadata() .withAllowVolumeExpansion(true) .build(); return Future.succeededFuture(sc); }); MockKafkaAssemblyOperator kao = new MockKafkaAssemblyOperator(vertx, new PlatformFeaturesAvailability(false, kubernetesVersion), certManager, passwordGenerator, supplier, config); kao.resizeVolumes(new Reconciliation("test-trigger", Kafka.RESOURCE_KIND, namespace, clusterName), kafka, kafkaCluster.generatePersistentVolumeClaims(kafka.getSpec().getKafka().getStorage()), kafkaCluster).onComplete(res -> { assertThat(res.succeeded(), is(true)); // The volumes are resizing => no reconciliation assertThat(pvcCaptor.getAllValues().size(), is(0)); }); }
Example 4
Source File: VolumeResizingTest.java From strimzi-kafka-operator with Apache License 2.0 | 4 votes |
@Test public void testVolumesWaitingForRestart() { Kafka kafka = getKafkaCrd(); KafkaCluster kafkaCluster = KafkaCluster.fromCrd(kafka, VERSIONS); ResourceOperatorSupplier supplier = ResourceUtils.supplierWithMocks(false); // Mock the PVC Operator PvcOperator mockPvcOps = supplier.pvcOperations; List<PersistentVolumeClaim> realPvcs = kafkaCluster.generatePersistentVolumeClaims(kafka.getSpec().getKafka().getStorage()); for (PersistentVolumeClaim pvc : realPvcs) { pvc.setStatus(new PersistentVolumeClaimStatusBuilder() .withPhase("Bound") .withConditions(new PersistentVolumeClaimConditionBuilder() .withStatus("True") .withType("FileSystemResizePending") .build()) .withCapacity(singletonMap("storage", new Quantity("10Gi"))) .build()); } when(mockPvcOps.getAsync(eq(namespace), ArgumentMatchers.startsWith("data-"))) .thenAnswer(invocation -> { String pvcName = invocation.getArgument(1); return Future.succeededFuture(realPvcs.stream().filter(pvc -> pvcName.equals(pvc.getMetadata().getName())).findFirst().orElse(null)); }); ArgumentCaptor<PersistentVolumeClaim> pvcCaptor = ArgumentCaptor.forClass(PersistentVolumeClaim.class); when(mockPvcOps.reconcile(anyString(), anyString(), pvcCaptor.capture())).thenReturn(Future.succeededFuture()); // Mock the StorageClass Operator StorageClassOperator mockSco = supplier.storageClassOperations; when(mockSco.getAsync(eq("mysc"))) .thenAnswer(invocation -> { StorageClass sc = new StorageClassBuilder() .withNewMetadata() .withName("mysc") .endMetadata() .withAllowVolumeExpansion(true) .build(); return Future.succeededFuture(sc); }); MockKafkaAssemblyOperator kao = new MockKafkaAssemblyOperator(vertx, new PlatformFeaturesAvailability(false, kubernetesVersion), certManager, passwordGenerator, supplier, config); kao.resizeVolumes(new Reconciliation("test-trigger", Kafka.RESOURCE_KIND, namespace, clusterName), kafka, kafkaCluster.generatePersistentVolumeClaims(kafka.getSpec().getKafka().getStorage()), kafkaCluster).onComplete(res -> { assertThat(res.succeeded(), is(true)); // The volumes are waiting for pod restart => no reconciliation assertThat(pvcCaptor.getAllValues().size(), is(0)); for (int i = 0; i < kafkaCluster.getReplicas(); i++) { assertThat(res.result().fsResizingRestartRequest.contains(kafkaCluster.getPodName(i)), is(true)); } }); }
Example 5
Source File: VolumeResizingTest.java From strimzi-kafka-operator with Apache License 2.0 | 4 votes |
@Test public void testVolumesResized() { Kafka kafka = getKafkaCrd(); KafkaCluster kafkaCluster = KafkaCluster.fromCrd(kafka, VERSIONS); ResourceOperatorSupplier supplier = ResourceUtils.supplierWithMocks(false); // Mock the PVC Operator PvcOperator mockPvcOps = supplier.pvcOperations; List<PersistentVolumeClaim> realPvcs = kafkaCluster.generatePersistentVolumeClaims(kafka.getSpec().getKafka().getStorage()); for (PersistentVolumeClaim pvc : realPvcs) { pvc.setStatus(new PersistentVolumeClaimStatusBuilder() .withPhase("Bound") .withCapacity(singletonMap("storage", new Quantity("20Gi"))) .build()); } when(mockPvcOps.getAsync(eq(namespace), ArgumentMatchers.startsWith("data-"))) .thenAnswer(invocation -> { String pvcName = invocation.getArgument(1); return Future.succeededFuture(realPvcs.stream().filter(pvc -> pvcName.equals(pvc.getMetadata().getName())).findFirst().orElse(null)); }); ArgumentCaptor<PersistentVolumeClaim> pvcCaptor = ArgumentCaptor.forClass(PersistentVolumeClaim.class); when(mockPvcOps.reconcile(anyString(), anyString(), pvcCaptor.capture())).thenReturn(Future.succeededFuture()); // Mock the StorageClass Operator StorageClassOperator mockSco = supplier.storageClassOperations; when(mockSco.getAsync(eq("mysc"))) .thenAnswer(invocation -> { StorageClass sc = new StorageClassBuilder() .withNewMetadata() .withName("mysc") .endMetadata() .withAllowVolumeExpansion(true) .build(); return Future.succeededFuture(sc); }); MockKafkaAssemblyOperator kao = new MockKafkaAssemblyOperator(vertx, new PlatformFeaturesAvailability(false, kubernetesVersion), certManager, passwordGenerator, supplier, config); kao.resizeVolumes(new Reconciliation("test-trigger", Kafka.RESOURCE_KIND, namespace, clusterName), kafka, kafkaCluster.generatePersistentVolumeClaims(kafka.getSpec().getKafka().getStorage()), kafkaCluster).onComplete(res -> { assertThat(res.succeeded(), is(true)); assertThat(pvcCaptor.getAllValues().size(), is(3)); assertThat(pvcCaptor.getAllValues(), is(kafkaCluster.generatePersistentVolumeClaims(kafka.getSpec().getKafka().getStorage()))); }); }