io.fabric8.kubernetes.api.model.storage.StorageClass Java Examples
The following examples show how to use
io.fabric8.kubernetes.api.model.storage.StorageClass.
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: KafkaAssemblyOperator.java From strimzi-kafka-operator with Apache License 2.0 | 5 votes |
Future<Void> resizePvc(PersistentVolumeClaim current, PersistentVolumeClaim desired) { Promise<Void> resultPromise = Promise.promise(); String storageClassName = current.getSpec().getStorageClassName(); if (storageClassName != null && !storageClassName.isEmpty()) { storageClassOperator.getAsync(storageClassName).onComplete(scRes -> { if (scRes.succeeded()) { StorageClass sc = scRes.result(); if (sc == null) { log.warn("{}: Storage Class {} not found. PVC {} cannot be resized. Reconciliation will proceed without reconciling this PVC.", reconciliation, storageClassName, desired.getMetadata().getName()); resultPromise.complete(); } else if (sc.getAllowVolumeExpansion() == null || !sc.getAllowVolumeExpansion()) { // Resizing not suported in SC => do nothing log.warn("{}: Storage Class {} does not support resizing of volumes. PVC {} cannot be resized. Reconciliation will proceed without reconciling this PVC.", reconciliation, storageClassName, desired.getMetadata().getName()); resultPromise.complete(); } else { // Resizing supported by SC => We can reconcile the PVC to have it resized log.info("{}: Resizing PVC {} from {} to {}.", reconciliation, desired.getMetadata().getName(), current.getStatus().getCapacity().get("storage").getAmount(), desired.getSpec().getResources().getRequests().get("storage").getAmount()); pvcOperations.reconcile(namespace, desired.getMetadata().getName(), desired).onComplete(pvcRes -> { if (pvcRes.succeeded()) { resultPromise.complete(); } else { resultPromise.fail(pvcRes.cause()); } }); } } else { log.error("{}: Storage Class {} not found. PVC {} cannot be resized.", reconciliation, storageClassName, desired.getMetadata().getName(), scRes.cause()); resultPromise.fail(scRes.cause()); } }); } else { log.warn("{}: PVC {} does not use any Storage Class and cannot be resized. Reconciliation will proceed without reconciling this PVC.", reconciliation, desired.getMetadata().getName()); resultPromise.complete(); } return resultPromise.future(); }
Example #2
Source File: NamespaceDeletionRecoveryST.java From strimzi-kafka-operator with Apache License 2.0 | 5 votes |
@BeforeAll void createStorageClass() { kubeClient().getClient().storage().storageClasses().inNamespace(NAMESPACE).withName(storageClassName).delete(); StorageClass storageClass = new StorageClassBuilder() .withNewMetadata() .withName(storageClassName) .endMetadata() .withProvisioner("kubernetes.io/cinder") .withReclaimPolicy("Retain") .build(); kubeClient().getClient().storage().storageClasses().inNamespace(NAMESPACE).createOrReplace(storageClass); }
Example #3
Source File: StorageClassOperatorTest.java From strimzi-kafka-operator with Apache License 2.0 | 5 votes |
@Override protected StorageClass resource() { return new StorageClassBuilder() .withNewMetadata() .withName(RESOURCE_NAME) .withLabels(singletonMap("foo", "bar")) .endMetadata() .withAllowVolumeExpansion(true) .withReclaimPolicy("Delete") .withProvisioner("kubernetes.io/aws-ebs") .withParameters(singletonMap("type", "gp2")) .build(); }
Example #4
Source File: StorageClassOperatorIT.java From strimzi-kafka-operator with Apache License 2.0 | 5 votes |
@Override protected void assertResources(VertxTestContext context, StorageClass expected, StorageClass actual) { context.verify(() -> { assertThat(actual.getMetadata().getName(), is(expected.getMetadata().getName())); assertThat(actual.getMetadata().getLabels(), is(expected.getMetadata().getLabels())); assertThat(actual.getReclaimPolicy(), is(expected.getReclaimPolicy())); assertThat(actual.getProvisioner(), is(expected.getProvisioner())); assertThat(actual.getParameters(), is(expected.getParameters())); }); }
Example #5
Source File: StorageClassOperatorIT.java From strimzi-kafka-operator with Apache License 2.0 | 5 votes |
@Override protected StorageClass getOriginal() { return new StorageClassBuilder() .withNewMetadata() .withName(RESOURCE_NAME) .withLabels(singletonMap("state", "new")) .endMetadata() .withReclaimPolicy("Delete") .withProvisioner("kubernetes.io/aws-ebs") .withParameters(singletonMap("type", "gp2")) .withVolumeBindingMode("Immediate") .build(); }
Example #6
Source File: StorageClassOperatorIT.java From strimzi-kafka-operator with Apache License 2.0 | 5 votes |
@Override protected StorageClass getModified() { // Most of the fields seem to be immutable, we patch only labels return new StorageClassBuilder() .withNewMetadata() .withName(RESOURCE_NAME) .withLabels(singletonMap("state", "modified")) .endMetadata() .withReclaimPolicy("Delete") .withProvisioner("kubernetes.io/aws-ebs") .withParameters(singletonMap("type", "gp2")) .withVolumeBindingMode("Immediate") .build(); }
Example #7
Source File: StorageClassExamples.java From kubernetes-client with Apache License 2.0 | 4 votes |
public static void main(String[] args) { String master = "http://localhost:8080/"; if (args.length == 1) { master = args[0]; } io.fabric8.kubernetes.client.Config config = new io.fabric8.kubernetes.client.ConfigBuilder().withMasterUrl(master).build(); try (final KubernetesClient client = new DefaultKubernetesClient(config)) { //list all storage classes StorageClassList storageClassList = client.storage().storageClasses().list(); logger.info("List of storage classes: {}", storageClassList.toString()); //create new storage class String name = UUID.randomUUID().toString(); ObjectMeta metadata = new ObjectMeta(); metadata.setName(name); Map<String, String> parameters = new HashMap<>(); parameters.put("resturl", "http://192.168.10.100:8080"); parameters.put("restuser", ""); parameters.put("secretNamespace", ""); parameters.put("secretName", ""); parameters.put("key", "value1"); StorageClass storageClass = new StorageClassBuilder().withApiVersion("storage.k8s.io/v1") .withKind("StorageClass") .withMetadata(metadata) .withParameters(parameters) .withProvisioner("k8s.io/minikube-hostpath") .build(); storageClass = client.storage().storageClasses().create(storageClass); logger.info("Newly created storage class details: {}", storageClass.toString()); //list all storage classes storageClassList = client.storage().storageClasses().list(); logger.info("List of storage classes: {}", storageClassList.toString()); //update storage class. add label storageClass = client.storage().storageClasses().withName(name).edit().editMetadata().addToLabels("testLabel", "testLabelValue").endMetadata().done(); //list all storage classes storageClassList = client.storage().storageClasses().list(); logger.info("List of storage classes: {}", storageClassList.toString()); //delete storage class boolean isDeleteSuccessful = client.storage().storageClasses().delete(storageClass); logger.info("Storage Class resource successfully deleted: {}", isDeleteSuccessful); } catch (KubernetesClientException e) { logger.error(e.getMessage(), e); } }
Example #8
Source File: PersistentVolumeClaimExample.java From kubernetes-client with Apache License 2.0 | 4 votes |
public static void main(String[] args) { String master = "https://localhost:8443"; String namespace = "default"; String storageClassName = "my-local-storage"; if (args.length == 1) { master = args[0]; } log("Using master with url ", master); Config config = new ConfigBuilder().withMasterUrl(master).build(); try (final KubernetesClient client = new DefaultKubernetesClient(config)) { try { StorageClass storageClass = client.storage().storageClasses().load(PersistentVolumeClaimExample.class.getResourceAsStream("/test-storage.yml")).get(); client.storage().storageClasses().create(storageClass); log("Creating PersistentVolume object"); PersistentVolume pv = new PersistentVolumeBuilder() .withNewMetadata().withName("test-local-pv").endMetadata() .withNewSpec() .addToCapacity(Collections.singletonMap("storage", new Quantity("500Gi"))) .withAccessModes("ReadWriteOnce") .withPersistentVolumeReclaimPolicy("Retain") .withStorageClassName(storageClassName) .withNewLocal() .withPath("/mnt/disks/vol1") .endLocal() .withNewNodeAffinity() .withNewRequired() .addNewNodeSelectorTerm() .withMatchExpressions(Arrays.asList(new NodeSelectorRequirementBuilder() .withKey("kubernetes.io/hostname") .withOperator("In") .withValues("my-node") .build() )) .endNodeSelectorTerm() .endRequired() .endNodeAffinity() .endSpec() .build(); client.persistentVolumes().create(pv); log("Successfully created PersistentVolume object"); log("Creating PersistentVolumeClaim object"); PersistentVolumeClaim persistentVolumeClaim = new PersistentVolumeClaimBuilder() .withNewMetadata().withName("test-pv-claim").withNamespace(namespace).endMetadata() .withNewSpec() .withStorageClassName(storageClassName) .withAccessModes("ReadWriteOnce") .withNewResources() .addToRequests("storage", new Quantity("500Gi")) .endResources() .endSpec() .build(); client.persistentVolumeClaims().create(persistentVolumeClaim); log("Successfully created PersistentVolumeClaim object"); log("Creating pod"); Pod pod = client.pods().inNamespace(namespace).load(PersistentVolumeClaimExample.class.getResourceAsStream("/test-pv-pod.yml")).get(); client.pods().inNamespace(namespace).create(pod); log("Successfully created pod"); } finally { client.persistentVolumeClaims().inNamespace(namespace).withName("test-pv-claim").delete(); client.persistentVolumes().withName("test-local-pv").delete(); //fixed the name client.pods().inNamespace("default").withName("test-pv-pod").delete(); // you forgot to remove the pod client.storage().storageClasses().withName(storageClassName).delete(); } } catch (KubernetesClientException e) { log("Could not create resource", e.getMessage()); } }
Example #9
Source File: StorageClassIT.java From kubernetes-client with Apache License 2.0 | 4 votes |
@Test public void load() { StorageClass storageClassLoaded = client.storage().storageClasses().load(getClass().getResourceAsStream("/test-storageclass.yml")).get(); assertNotNull(storageClassLoaded); assertEquals("gluster-vol-default", storageClassLoaded.getMetadata().getName()); }
Example #10
Source File: UtilsTest.java From kubernetes-client with Apache License 2.0 | 4 votes |
@Test @DisplayName("Should test whether resource is namespaced or not") void testWhetherNamespacedOrNot() { assertTrue(Utils.isResourceNamespaced(Binding.class)); assertFalse(Utils.isResourceNamespaced(ComponentStatus.class)); assertTrue(Utils.isResourceNamespaced(ConfigMap.class)); assertTrue(Utils.isResourceNamespaced(Endpoints.class)); assertTrue(Utils.isResourceNamespaced(Event.class)); assertTrue(Utils.isResourceNamespaced(LimitRange.class)); assertFalse(Utils.isResourceNamespaced(Namespace.class)); assertFalse(Utils.isResourceNamespaced(Node.class)); assertTrue(Utils.isResourceNamespaced(PersistentVolumeClaim.class)); assertFalse(Utils.isResourceNamespaced(PersistentVolume.class)); assertTrue(Utils.isResourceNamespaced(Pod.class)); assertTrue(Utils.isResourceNamespaced(PodTemplate.class)); assertTrue(Utils.isResourceNamespaced(ReplicationController.class)); assertTrue(Utils.isResourceNamespaced(ResourceQuota.class)); assertTrue(Utils.isResourceNamespaced(Secret.class)); assertTrue(Utils.isResourceNamespaced(ServiceAccount.class)); assertTrue(Utils.isResourceNamespaced(Service.class)); assertFalse(Utils.isResourceNamespaced(MutatingWebhookConfiguration.class)); assertFalse(Utils.isResourceNamespaced(ValidatingWebhookConfiguration.class)); assertFalse(Utils.isResourceNamespaced(CustomResourceDefinition.class)); assertTrue(Utils.isResourceNamespaced(ControllerRevision.class)); assertTrue(Utils.isResourceNamespaced(DaemonSet.class)); assertTrue(Utils.isResourceNamespaced(Deployment.class)); assertTrue(Utils.isResourceNamespaced(ReplicaSet.class)); assertTrue(Utils.isResourceNamespaced(StatefulSet.class)); assertTrue(Utils.isResourceNamespaced(TokenReview.class)); assertTrue(Utils.isResourceNamespaced(LocalSubjectAccessReview.class)); assertTrue(Utils.isResourceNamespaced(SelfSubjectAccessReview.class)); assertTrue(Utils.isResourceNamespaced(SelfSubjectRulesReview.class)); assertTrue(Utils.isResourceNamespaced(SubjectAccessReview.class)); assertTrue(Utils.isResourceNamespaced(HorizontalPodAutoscaler.class)); assertTrue(Utils.isResourceNamespaced(CronJob.class)); assertTrue(Utils.isResourceNamespaced(Job.class)); assertTrue(Utils.isResourceNamespaced(CertificateSigningRequest.class)); assertTrue(Utils.isResourceNamespaced(Lease.class)); assertTrue(Utils.isResourceNamespaced(EndpointSlice.class)); assertTrue(Utils.isResourceNamespaced(Ingress.class)); assertTrue(Utils.isResourceNamespaced(NetworkPolicy.class)); assertTrue(Utils.isResourceNamespaced(PodDisruptionBudget.class)); assertFalse(Utils.isResourceNamespaced(PodSecurityPolicy.class)); assertFalse(Utils.isResourceNamespaced(ClusterRoleBinding.class)); assertFalse(Utils.isResourceNamespaced(ClusterRole.class)); assertTrue(Utils.isResourceNamespaced(RoleBinding.class)); assertTrue(Utils.isResourceNamespaced(Role.class)); assertFalse(Utils.isResourceNamespaced(PriorityClass.class)); assertTrue(Utils.isResourceNamespaced(CSIDriver.class)); assertTrue(Utils.isResourceNamespaced(CSINode.class)); assertFalse(Utils.isResourceNamespaced(StorageClass.class)); assertTrue(Utils.isResourceNamespaced(VolumeAttachment.class)); }
Example #11
Source File: UtilsTest.java From kubernetes-client with Apache License 2.0 | 4 votes |
@Test void testGetPluralFromKind() { // Given Map<String, Class> pluralToKubernetesResourceMap = new HashMap<>(); pluralToKubernetesResourceMap.put("bindings", Binding.class); pluralToKubernetesResourceMap.put("componentstatuses", ComponentStatus.class); pluralToKubernetesResourceMap.put("configmaps", ConfigMap.class); pluralToKubernetesResourceMap.put("endpoints", Endpoints.class); pluralToKubernetesResourceMap.put("events", Event.class); pluralToKubernetesResourceMap.put("limitranges", LimitRange.class); pluralToKubernetesResourceMap.put("namespaces", Namespace.class); pluralToKubernetesResourceMap.put("nodes", Node.class); pluralToKubernetesResourceMap.put("persistentvolumeclaims", PersistentVolumeClaim.class); pluralToKubernetesResourceMap.put("persistentvolumes", PersistentVolume.class); pluralToKubernetesResourceMap.put("pods", Pod.class); pluralToKubernetesResourceMap.put("podtemplates", PodTemplate.class); pluralToKubernetesResourceMap.put("replicationcontrollers", ReplicationController.class); pluralToKubernetesResourceMap.put("resourcequotas", ResourceQuota.class); pluralToKubernetesResourceMap.put("secrets", Secret.class); pluralToKubernetesResourceMap.put("serviceaccounts", ServiceAccount.class); pluralToKubernetesResourceMap.put("services", Service.class); pluralToKubernetesResourceMap.put("mutatingwebhookconfigurations", MutatingWebhookConfiguration.class); pluralToKubernetesResourceMap.put("validatingwebhookconfigurations", ValidatingWebhookConfiguration.class); pluralToKubernetesResourceMap.put("customresourcedefinitions", CustomResourceDefinition.class); pluralToKubernetesResourceMap.put("controllerrevisions", ControllerRevision.class); pluralToKubernetesResourceMap.put("daemonsets", DaemonSet.class); pluralToKubernetesResourceMap.put("deployments", Deployment.class); pluralToKubernetesResourceMap.put("replicasets", ReplicaSet.class); pluralToKubernetesResourceMap.put("statefulsets", StatefulSet.class); pluralToKubernetesResourceMap.put("tokenreviews", TokenReview.class); pluralToKubernetesResourceMap.put("localsubjectaccessreviews", LocalSubjectAccessReview.class); pluralToKubernetesResourceMap.put("selfsubjectaccessreviews", SelfSubjectAccessReview.class); pluralToKubernetesResourceMap.put("selfsubjectrulesreviews", SelfSubjectRulesReview.class); pluralToKubernetesResourceMap.put("subjectaccessreviews", SubjectAccessReview.class); pluralToKubernetesResourceMap.put("horizontalpodautoscalers", HorizontalPodAutoscaler.class); pluralToKubernetesResourceMap.put("cronjobs", CronJob.class); pluralToKubernetesResourceMap.put("jobs", Job.class); pluralToKubernetesResourceMap.put("certificatesigningrequests", CertificateSigningRequest.class); pluralToKubernetesResourceMap.put("leases", Lease.class); pluralToKubernetesResourceMap.put("endpointslices", EndpointSlice.class); pluralToKubernetesResourceMap.put("ingresses", Ingress.class); pluralToKubernetesResourceMap.put("networkpolicies", NetworkPolicy.class); pluralToKubernetesResourceMap.put("poddisruptionbudgets", PodDisruptionBudget.class); pluralToKubernetesResourceMap.put("podsecuritypolicies", PodSecurityPolicy.class); pluralToKubernetesResourceMap.put("clusterrolebindings", ClusterRoleBinding.class); pluralToKubernetesResourceMap.put("clusterroles", ClusterRole.class); pluralToKubernetesResourceMap.put("rolebindings", RoleBinding.class); pluralToKubernetesResourceMap.put("roles", Role.class); pluralToKubernetesResourceMap.put("priorityclasses", PriorityClass.class); pluralToKubernetesResourceMap.put("csidrivers", CSIDriver.class); pluralToKubernetesResourceMap.put("csinodes", CSINode.class); pluralToKubernetesResourceMap.put("storageclasses", StorageClass.class); pluralToKubernetesResourceMap.put("volumeattachments", VolumeAttachment.class); // When & Then pluralToKubernetesResourceMap.forEach((plural, kubernetesResource) -> assertEquals(plural, Utils.getPluralFromKind(kubernetesResource.getSimpleName()))); }
Example #12
Source File: StorageAPIGroupClient.java From kubernetes-client with Apache License 2.0 | 4 votes |
@Override public MixedOperation<StorageClass, StorageClassList, DoneableStorageClass, Resource<StorageClass, DoneableStorageClass>> storageClasses() { return new StorageClassOperationsImpl(httpClient, getConfiguration()); }
Example #13
Source File: StorageSpaceCrudTest.java From kubernetes-client with Apache License 2.0 | 4 votes |
@Test public void testCrud() { KubernetesClient client = server.getClient(); final String name = "test"; ObjectMeta metadata = new ObjectMeta(); metadata.setName(name); Map<String, String> parameters = new HashMap<>(); parameters.put("key", "value"); StorageClass storageClass = new StorageClassBuilder().withApiVersion("storage.k8s.io/v1") .withKind("StorageClass") .withMetadata(metadata) .withParameters(parameters) .withProvisioner("kubernetes.io/aws-ebs") .build(); //test create storageClass = client.storage().storageClasses().create(storageClass); assertNotNull(storageClass); assertEquals(name, storageClass.getMetadata().getName()); //test get StorageClassList storageClassList = client.storage().storageClasses().list(); logger.info(storageClassList.toString()); assertNotNull(storageClassList); assertEquals(1, storageClassList.getItems().size()); assertEquals("kubernetes.io/aws-ebs", storageClassList.getItems().get(0).getProvisioner()); assertEquals("value", storageClassList.getItems().get(0).getParameters().get("key")); assertNull(storageClassList.getItems().get(0).getMetadata().getLabels()); //test update storageClass = client.storage().storageClasses().withName(name).edit().editOrNewMetadata() .addToLabels("key1", "value1") .endMetadata().done(); logger.info("Updated Storage Class: {} ", storageClass.toString()); assertNotNull(storageClass); assertEquals(1, storageClass.getMetadata().getLabels().size()); //test delete boolean result = client.storage().storageClasses().delete(storageClass); assertEquals(true, result); StorageClassList storageClassList2 = client.storage().storageClasses().list(); assertEquals(0, storageClassList2.getItems().size()); }
Example #14
Source File: Kubernetes.java From enmasse with Apache License 2.0 | 4 votes |
public StorageClass getStorageClass(String name) { return client.storage().storageClasses().withName(name).get(); }
Example #15
Source File: StorageClassOperatorIT.java From strimzi-kafka-operator with Apache License 2.0 | 4 votes |
@Override protected AbstractNonNamespacedResourceOperator<KubernetesClient, StorageClass, StorageClassList, DoneableStorageClass, Resource<StorageClass, DoneableStorageClass>> operator() { return new StorageClassOperator(vertx, client, 10_000); }
Example #16
Source File: StorageClassOperatorTest.java From strimzi-kafka-operator with Apache License 2.0 | 4 votes |
@Override protected AbstractNonNamespacedResourceOperator<KubernetesClient, StorageClass, StorageClassList, DoneableStorageClass, Resource<StorageClass, DoneableStorageClass>> createResourceOperations( Vertx vertx, KubernetesClient mockClient) { return new StorageClassOperator(vertx, mockClient, 100); }
Example #17
Source File: StorageClassOperator.java From strimzi-kafka-operator with Apache License 2.0 | 4 votes |
@Override protected MixedOperation<StorageClass, StorageClassList, DoneableStorageClass, Resource<StorageClass, DoneableStorageClass>> operation() { return client.storage().storageClasses(); }
Example #18
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()))); }); }
Example #19
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 #20
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 #21
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 #22
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 #23
Source File: VolumeResizingTest.java From strimzi-kafka-operator with Apache License 2.0 | 4 votes |
@Test public void testNotBoundVolumes() { 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()); 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 #24
Source File: VolumeResizingTest.java From strimzi-kafka-operator with Apache License 2.0 | 4 votes |
@Test public void testNoExistingVolumes() { Kafka kafka = getKafkaCrd(); KafkaCluster kafkaCluster = KafkaCluster.fromCrd(kafka, VERSIONS); ResourceOperatorSupplier supplier = ResourceUtils.supplierWithMocks(false); // Mock the PVC Operator PvcOperator mockPvcOps = supplier.pvcOperations; when(mockPvcOps.getAsync(eq(namespace), ArgumentMatchers.startsWith("data-"))) .thenAnswer(invocation -> { String pvcName = invocation.getArgument(1); return Future.succeededFuture(); }); 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 #25
Source File: StorageAPIGroupDSL.java From kubernetes-client with Apache License 2.0 | votes |
MixedOperation<StorageClass, StorageClassList, DoneableStorageClass, Resource<StorageClass, DoneableStorageClass>> storageClasses();