use of io.fabric8.kubernetes.api.model.PersistentVolumeClaimSpec in project camel by apache.
the class KubernetesPersistentVolumesClaimsProducerTest method createListAndDeletePersistentVolumeClaim.
@Test
public void createListAndDeletePersistentVolumeClaim() throws Exception {
if (ObjectHelper.isEmpty(authToken)) {
return;
}
Exchange ex = template.request("direct:create", new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
exchange.getIn().setHeader(KubernetesConstants.KUBERNETES_NAMESPACE_NAME, "default");
exchange.getIn().setHeader(KubernetesConstants.KUBERNETES_PERSISTENT_VOLUME_CLAIM_NAME, "test");
Map<String, String> labels = new HashMap<String, String>();
labels.put("this", "rocks");
exchange.getIn().setHeader(KubernetesConstants.KUBERNETES_PERSISTENT_VOLUMES_CLAIMS_LABELS, labels);
PersistentVolumeClaimSpec pvcSpec = new PersistentVolumeClaimSpec();
ResourceRequirements rr = new ResourceRequirements();
Map<String, Quantity> mp = new HashMap<String, Quantity>();
mp.put("storage", new Quantity("100"));
rr.setLimits(mp);
Map<String, Quantity> req = new HashMap<String, Quantity>();
req.put("storage", new Quantity("100"));
rr.setRequests(req);
pvcSpec.setResources(rr);
pvcSpec.setVolumeName("vol001");
List<String> access = new ArrayList<String>();
access.add("ReadWriteOnce");
pvcSpec.setAccessModes(access);
exchange.getIn().setHeader(KubernetesConstants.KUBERNETES_PERSISTENT_VOLUME_CLAIM_SPEC, pvcSpec);
}
});
PersistentVolumeClaim pvc = ex.getOut().getBody(PersistentVolumeClaim.class);
assertEquals(pvc.getMetadata().getName(), "test");
ex = template.request("direct:listByLabels", new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
exchange.getIn().setHeader(KubernetesConstants.KUBERNETES_NAMESPACE_NAME, "default");
Map<String, String> labels = new HashMap<String, String>();
labels.put("this", "rocks");
exchange.getIn().setHeader(KubernetesConstants.KUBERNETES_PERSISTENT_VOLUMES_CLAIMS_LABELS, labels);
}
});
List<PersistentVolumeClaim> result = ex.getOut().getBody(List.class);
boolean pvcExists = false;
Iterator<PersistentVolumeClaim> it = result.iterator();
while (it.hasNext()) {
PersistentVolumeClaim pvcLocal = it.next();
if ("test".equalsIgnoreCase(pvcLocal.getMetadata().getName())) {
pvcExists = true;
}
}
assertTrue(pvcExists);
ex = template.request("direct:delete", new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
exchange.getIn().setHeader(KubernetesConstants.KUBERNETES_NAMESPACE_NAME, "default");
exchange.getIn().setHeader(KubernetesConstants.KUBERNETES_PERSISTENT_VOLUME_CLAIM_NAME, "test");
}
});
boolean pvcDeleted = ex.getOut().getBody(Boolean.class);
assertTrue(pvcDeleted);
}
use of io.fabric8.kubernetes.api.model.PersistentVolumeClaimSpec in project camel by apache.
the class KubernetesPersistentVolumesClaimsProducer method doCreatePersistentVolumeClaim.
protected void doCreatePersistentVolumeClaim(Exchange exchange, String operation) throws Exception {
PersistentVolumeClaim pvc = null;
String pvcName = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_PERSISTENT_VOLUME_CLAIM_NAME, String.class);
String namespaceName = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_NAMESPACE_NAME, String.class);
PersistentVolumeClaimSpec pvcSpec = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_PERSISTENT_VOLUME_CLAIM_SPEC, PersistentVolumeClaimSpec.class);
if (ObjectHelper.isEmpty(pvcName)) {
LOG.error("Create a specific Persistent Volume Claim require specify a Persistent Volume Claim name");
throw new IllegalArgumentException("Create a specific Persistent Volume Claim require specify a Persistent Volume Claim name");
}
if (ObjectHelper.isEmpty(namespaceName)) {
LOG.error("Create a specific Persistent Volume Claim require specify a namespace name");
throw new IllegalArgumentException("Create a specific Persistent Volume Claim require specify a namespace name");
}
if (ObjectHelper.isEmpty(pvcSpec)) {
LOG.error("Create a specific Persistent Volume Claim require specify a Persistent Volume Claim spec bean");
throw new IllegalArgumentException("Create a specific Persistent Volume Claim require specify a Persistent Volume Claim spec bean");
}
Map<String, String> labels = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_PERSISTENT_VOLUMES_CLAIMS_LABELS, Map.class);
PersistentVolumeClaim pvcCreating = new PersistentVolumeClaimBuilder().withNewMetadata().withName(pvcName).withLabels(labels).endMetadata().withSpec(pvcSpec).build();
pvc = getEndpoint().getKubernetesClient().persistentVolumeClaims().inNamespace(namespaceName).create(pvcCreating);
MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(), true);
exchange.getOut().setBody(pvc);
}
Aggregations