use of io.fabric8.kubernetes.api.model.storage.StorageClass in project strimzi by strimzi.
the class NamespaceDeletionRecoveryIsolatedST method createStorageClass.
@BeforeAll
void createStorageClass() {
kubeClient().getClient().storage().storageClasses().withName(storageClassName).delete();
StorageClass storageClass = new StorageClassBuilder().withNewMetadata().withName(storageClassName).endMetadata().withProvisioner("kubernetes.io/cinder").withReclaimPolicy("Retain").build();
kubeClient().getClient().storage().storageClasses().createOrReplace(storageClass);
}
use of io.fabric8.kubernetes.api.model.storage.StorageClass in project strimzi-kafka-operator by strimzi.
the class AbstractModel method createPersistentVolumeClaim.
/**
* createPersistentVolumeClaim is called uniquely for each ordinal (Broker ID) of a stateful set
*
* @param ordinalId the ordinal of the pod/broker for which the persistent volume claim is being created
* used to retrieve the optional broker storage overrides for each broker
* @param name the name of the persistent volume claim to be created
* @param storage the user supplied configuration of the PersistentClaimStorage
*
* @return PersistentVolumeClaim
*/
protected PersistentVolumeClaim createPersistentVolumeClaim(int ordinalId, String name, PersistentClaimStorage storage) {
Map<String, Quantity> requests = new HashMap<>(1);
requests.put("storage", new Quantity(storage.getSize(), null));
LabelSelector selector = null;
if (storage.getSelector() != null && !storage.getSelector().isEmpty()) {
selector = new LabelSelector(null, storage.getSelector());
}
String storageClass = storage.getStorageClass();
if (storage.getOverrides() != null) {
storageClass = storage.getOverrides().stream().filter(broker -> broker != null && broker.getBroker() != null && broker.getBroker() == ordinalId && broker.getStorageClass() != null).map(PersistentClaimStorageOverride::getStorageClass).findAny().orElse(storageClass);
}
PersistentVolumeClaim pvc = new PersistentVolumeClaimBuilder().withNewMetadata().withName(name).withNamespace(namespace).withLabels(getLabelsWithStrimziName(this.name, templatePersistentVolumeClaimLabels).toMap()).withAnnotations(Util.mergeLabelsOrAnnotations(Collections.singletonMap(ANNO_STRIMZI_IO_DELETE_CLAIM, Boolean.toString(storage.isDeleteClaim())), templatePersistentVolumeClaimAnnotations)).endMetadata().withNewSpec().withAccessModes("ReadWriteOnce").withNewResources().withRequests(requests).endResources().withStorageClassName(storageClass).withSelector(selector).withVolumeMode("Filesystem").endSpec().build();
// if the persistent volume claim has to be deleted when the cluster is un-deployed then set an owner reference of the CR
if (storage.isDeleteClaim()) {
pvc.getMetadata().setOwnerReferences(Collections.singletonList(createOwnerReference()));
}
return pvc;
}
use of io.fabric8.kubernetes.api.model.storage.StorageClass in project strimzi-kafka-operator by strimzi.
the class VolumeResizingTest method testVolumesBoundNonExpandableStorageClass.
@Test
public void testVolumesBoundNonExpandableStorageClass() {
Kafka kafka = getKafkaCrd();
KafkaCluster kafkaCluster = KafkaCluster.fromCrd(Reconciliation.DUMMY_RECONCILIATION, 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(any(), 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));
});
}
use of io.fabric8.kubernetes.api.model.storage.StorageClass in project strimzi-kafka-operator by strimzi.
the class VolumeResizingTest method testNotBoundVolumes.
@Test
public void testNotBoundVolumes() {
Kafka kafka = getKafkaCrd();
KafkaCluster kafkaCluster = KafkaCluster.fromCrd(Reconciliation.DUMMY_RECONCILIATION, kafka, VERSIONS);
ResourceOperatorSupplier supplier = ResourceUtils.supplierWithMocks(false);
// Mock the PVC Operator
PvcOperator mockPvcOps = supplier.pvcOperations;
List<PersistentVolumeClaim> realPvcs = kafkaCluster.generatePersistentVolumeClaims(kafka.getSpec().getKafka().getStorage());
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(any(), 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())));
});
}
use of io.fabric8.kubernetes.api.model.storage.StorageClass in project strimzi-kafka-operator by strimzi.
the class VolumeResizingTest method testVolumesResized.
@Test
public void testVolumesResized() {
Kafka kafka = getKafkaCrd();
KafkaCluster kafkaCluster = KafkaCluster.fromCrd(Reconciliation.DUMMY_RECONCILIATION, 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(any(), 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())));
});
}
Aggregations