Search in sources :

Example 1 with DoneablePersistentVolume

use of io.fabric8.kubernetes.api.model.DoneablePersistentVolume in project camel by apache.

the class KubernetesPersistentVolumesProducer method doListPersistentVolumesByLabels.

protected void doListPersistentVolumesByLabels(Exchange exchange, String operation) throws Exception {
    PersistentVolumeList pvList = null;
    Map<String, String> labels = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_PERSISTENT_VOLUMES_LABELS, Map.class);
    NonNamespaceOperation<PersistentVolume, PersistentVolumeList, DoneablePersistentVolume, Resource<PersistentVolume, DoneablePersistentVolume>> pvs;
    pvs = getEndpoint().getKubernetesClient().persistentVolumes();
    for (Map.Entry<String, String> entry : labels.entrySet()) {
        pvs.withLabel(entry.getKey(), entry.getValue());
    }
    pvList = pvs.list();
    MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(), true);
    exchange.getOut().setBody(pvList.getItems());
}
Also used : Resource(io.fabric8.kubernetes.client.dsl.Resource) DoneablePersistentVolume(io.fabric8.kubernetes.api.model.DoneablePersistentVolume) PersistentVolume(io.fabric8.kubernetes.api.model.PersistentVolume) DoneablePersistentVolume(io.fabric8.kubernetes.api.model.DoneablePersistentVolume) Map(java.util.Map) PersistentVolumeList(io.fabric8.kubernetes.api.model.PersistentVolumeList)

Example 2 with DoneablePersistentVolume

use of io.fabric8.kubernetes.api.model.DoneablePersistentVolume in project syndesis-qe by syndesisio.

the class OperatorValidationSteps method createPv.

@Given("create test persistent volumes with {string} storage class name")
public void createPv(String className) {
    // Create 3 PVs, two with higher capacity that will be used by meta and prometheus, because the binding of PV is FCFS,
    // so they theoretically can steal the test-pv from db
    // These volumes won't work, but they will be available to bind
    Map<String, Quantity> capacity = new HashMap<>();
    capacity.put("storage", new Quantity("3Gi"));
    if (!"".equals(className) && OpenShiftUtils.getInstance().storage().storageClasses().withName(className).get() == null) {
        log.info("Creating storage class " + className);
        OpenShiftUtils.getInstance().storage().storageClasses().createOrReplaceWithNew().withNewMetadata().withName(className).endMetadata().withProvisioner("kubernetes.io/cinder").done();
    }
    PersistentVolumeFluent.SpecNested<DoneablePersistentVolume> pv = OpenShiftUtils.getInstance().persistentVolumes().createOrReplaceWithNew().withNewMetadata().withName(TEST_PV_NAME).withLabels(TestUtils.map("operator", "test")).endMetadata().withNewSpec().withAccessModes("ReadOnlyMany", "ReadWriteOnce", "ReadWriteMany").withCapacity(capacity).withNewNfs().withNewServer("testServer").withNewPath("/testPath").endNfs();
    // The default storage class for OCP3 is empty, for OCP4 is "standard", so if the className is empty, we should use the default one
    if ("".equals(className)) {
        if (!OpenShiftUtils.isOpenshift3()) {
            if (OpenShiftUtils.isOSD()) {
                pv.withStorageClassName("gp2");
            } else {
                pv.withStorageClassName("standard");
            }
        }
    } else {
        pv.withStorageClassName(className);
    }
    pv.endSpec().done();
    capacity.put("storage", new Quantity("5Gi"));
    for (int i = 1; i < 3; i++) {
        pv = OpenShiftUtils.getInstance().persistentVolumes().createOrReplaceWithNew().withNewMetadata().withName(TEST_PV_NAME + "-" + i).endMetadata().withNewSpec().withAccessModes("ReadWriteOnce").withCapacity(capacity).withNewNfs().withNewServer("testServer").withNewPath("/testPath").endNfs();
        if (!OpenShiftUtils.isOpenshift3()) {
            // This should always be the default value despite the actual value of className - that is used only in "test-pv" intentionally
            if (OpenShiftUtils.isOSD()) {
                pv.withStorageClassName("gp2");
            } else {
                pv.withStorageClassName("standard");
            }
        }
        pv.endSpec().done();
    }
}
Also used : HashMap(java.util.HashMap) Quantity(io.fabric8.kubernetes.api.model.Quantity) DoneablePersistentVolume(io.fabric8.kubernetes.api.model.DoneablePersistentVolume) IntegrationsEndpoint(io.syndesis.qe.endpoint.IntegrationsEndpoint) PersistentVolumeFluent(io.fabric8.kubernetes.api.model.PersistentVolumeFluent) Given(io.cucumber.java.en.Given)

Aggregations

DoneablePersistentVolume (io.fabric8.kubernetes.api.model.DoneablePersistentVolume)2 Given (io.cucumber.java.en.Given)1 PersistentVolume (io.fabric8.kubernetes.api.model.PersistentVolume)1 PersistentVolumeFluent (io.fabric8.kubernetes.api.model.PersistentVolumeFluent)1 PersistentVolumeList (io.fabric8.kubernetes.api.model.PersistentVolumeList)1 Quantity (io.fabric8.kubernetes.api.model.Quantity)1 Resource (io.fabric8.kubernetes.client.dsl.Resource)1 IntegrationsEndpoint (io.syndesis.qe.endpoint.IntegrationsEndpoint)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1