io.fabric8.kubernetes.api.model.PersistentVolume Java Examples
The following examples show how to use
io.fabric8.kubernetes.api.model.PersistentVolume.
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: NamespaceDeletionRecoveryST.java From strimzi-kafka-operator with Apache License 2.0 | 5 votes |
private void recreatePvcAndUpdatePv(List<PersistentVolumeClaim> persistentVolumeClaimList) { for (PersistentVolumeClaim pvc : persistentVolumeClaimList) { pvc.getMetadata().setResourceVersion(null); kubeClient().getClient().persistentVolumeClaims().inNamespace(NAMESPACE).create(pvc); PersistentVolume pv = kubeClient().getClient().persistentVolumes().withName(pvc.getSpec().getVolumeName()).get(); pv.getSpec().setClaimRef(null); kubeClient().getClient().persistentVolumes().createOrReplace(pv); } }
Example #2
Source File: PersistentVolumeTest.java From kubernetes-client with Apache License 2.0 | 5 votes |
@Test public void testGet() { server.expect().withPath("/api/v1/persistentvolumes/persistentvolume1").andReturn(200, new PersistentVolumeBuilder().build()).once(); KubernetesClient client = server.getClient(); PersistentVolume persistentVolume = client.persistentVolumes().withName("persistentvolume1").get(); assertNotNull(persistentVolume); }
Example #3
Source File: PersistentVolumeTest.java From kubernetes-client with Apache License 2.0 | 5 votes |
@Test public void testDeleteMulti() { PersistentVolume persistentVolume1 = new PersistentVolumeBuilder().withNewMetadata().withName("persistentvolume1").endMetadata().build(); PersistentVolume persistentVolume2 = new PersistentVolumeBuilder().withNewMetadata().withName("persistentvolume2").endMetadata().build(); server.expect().withPath("/api/v1/persistentvolumes/persistentvolume1").andReturn(200, persistentVolume1).once(); server.expect().withPath("/api/v1/persistentvolumes/persistentvolume2").andReturn(200, persistentVolume2).once(); KubernetesClient client = server.getClient(); Boolean deleted = client.persistentVolumes().delete(persistentVolume1, persistentVolume2); assertTrue(deleted); }
Example #4
Source File: PersistentVolumeTest.java From kubernetes-client with Apache License 2.0 | 5 votes |
@Test public void testBuild() { PersistentVolume persistentVolume = new PersistentVolumeBuilder() .withNewMetadata().withName("persistentvolume").endMetadata() .withNewSpec() .addToCapacity(Collections.singletonMap("storage", new Quantity("500Gi"))) .withAccessModes("ReadWriteOnce") .withPersistentVolumeReclaimPolicy("Retain") .withStorageClassName("local-storage") .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(); server.expect().withPath("/api/v1/persistentvolumes/persistentvolume").andReturn(200, persistentVolume).once(); KubernetesClient client = server.getClient(); persistentVolume = client.persistentVolumes().withName("persistentvolume").get(); assertNotNull(persistentVolume); }
Example #5
Source File: PersistentVolumeTest.java From kubernetes-client with Apache License 2.0 | 4 votes |
@Test public void testLoadFromFile() { KubernetesClient client = server.getClient(); PersistentVolume persistentVolume = client.persistentVolumes().load(getClass().getResourceAsStream("/test-persistentvolume.yml")).get(); assertEquals("pv-test", persistentVolume.getMetadata().getName()); }
Example #6
Source File: AutoAdaptableKubernetesClient.java From kubernetes-client with Apache License 2.0 | 4 votes |
@Override public NonNamespaceOperation<PersistentVolume, PersistentVolumeList, DoneablePersistentVolume, Resource<PersistentVolume, DoneablePersistentVolume>> persistentVolumes() { return delegate.persistentVolumes(); }
Example #7
Source File: DefaultKubernetesClient.java From kubernetes-client with Apache License 2.0 | 4 votes |
@Override public NonNamespaceOperation<PersistentVolume, PersistentVolumeList, DoneablePersistentVolume, Resource<PersistentVolume, DoneablePersistentVolume>> persistentVolumes() { return new PersistentVolumeOperationsImpl(httpClient, getConfiguration()); }
Example #8
Source File: ManagedKubernetesClient.java From kubernetes-client with Apache License 2.0 | 4 votes |
public NonNamespaceOperation<PersistentVolume, PersistentVolumeList, DoneablePersistentVolume, Resource<PersistentVolume, DoneablePersistentVolume>> persistentVolumes() { return delegate.persistentVolumes(); }
Example #9
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 #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: PersistentVolumeExample.java From kubernetes-client with Apache License 2.0 | 4 votes |
public static void main(String args[]) throws InterruptedException { String master = "https://192.168.99.100:8443/"; 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)) { log("Creating persistent volume object"); PersistentVolume pv = new PersistentVolumeBuilder() .withNewMetadata().withName("example-local-pv").endMetadata() .withNewSpec() .addToCapacity(Collections.singletonMap("storage", new Quantity("500Gi"))) .withAccessModes("ReadWriteOnce") .withPersistentVolumeReclaimPolicy("Retain") .withStorageClassName("local-storage") .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 Persistent Volume object"); } catch (KubernetesClientException e) { log("Could not create resource", e.getMessage()); } }
Example #12
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 #13
Source File: KubernetesClient.java From kubernetes-client with Apache License 2.0 | 2 votes |
/** * API entrypoint for PersistentVolume related operations. PersistentVolume (core/v1) * * @return NonNamespaceOperation object for PersistentVolume related operations. */ NonNamespaceOperation<PersistentVolume, PersistentVolumeList, DoneablePersistentVolume, Resource<PersistentVolume, DoneablePersistentVolume>> persistentVolumes();