Search in sources :

Example 1 with PersistentVolumeClaim

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

the class KubernetesPersistentVolumesClaimsProducer method doListPersistentVolumesClaimsByLabels.

protected void doListPersistentVolumesClaimsByLabels(Exchange exchange, String operation) throws Exception {
    PersistentVolumeClaimList pvcList = null;
    Map<String, String> labels = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_PERSISTENT_VOLUMES_CLAIMS_LABELS, Map.class);
    String namespaceName = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_NAMESPACE_NAME, String.class);
    if (!ObjectHelper.isEmpty(namespaceName)) {
        NonNamespaceOperation<PersistentVolumeClaim, PersistentVolumeClaimList, DoneablePersistentVolumeClaim, Resource<PersistentVolumeClaim, DoneablePersistentVolumeClaim>> pvcs = getEndpoint().getKubernetesClient().persistentVolumeClaims().inNamespace(namespaceName);
        for (Map.Entry<String, String> entry : labels.entrySet()) {
            pvcs.withLabel(entry.getKey(), entry.getValue());
        }
        pvcList = pvcs.list();
    } else {
        MixedOperation<PersistentVolumeClaim, PersistentVolumeClaimList, DoneablePersistentVolumeClaim, Resource<PersistentVolumeClaim, DoneablePersistentVolumeClaim>> pvcs = getEndpoint().getKubernetesClient().persistentVolumeClaims();
        for (Map.Entry<String, String> entry : labels.entrySet()) {
            pvcs.withLabel(entry.getKey(), entry.getValue());
        }
        pvcList = pvcs.list();
    }
    MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(), true);
    exchange.getOut().setBody(pvcList.getItems());
}
Also used : PersistentVolumeClaimList(io.fabric8.kubernetes.api.model.PersistentVolumeClaimList) Resource(io.fabric8.kubernetes.client.dsl.Resource) DoneablePersistentVolumeClaim(io.fabric8.kubernetes.api.model.DoneablePersistentVolumeClaim) PersistentVolumeClaim(io.fabric8.kubernetes.api.model.PersistentVolumeClaim) DoneablePersistentVolumeClaim(io.fabric8.kubernetes.api.model.DoneablePersistentVolumeClaim) Map(java.util.Map)

Example 2 with PersistentVolumeClaim

use of io.fabric8.kubernetes.api.model.PersistentVolumeClaim in project curiostack by curioswitch.

the class DeployDevDbPodTask method exec.

@TaskAction
public void exec() {
    ImmutableDatabaseExtension config = getProject().getExtensions().getByType(DatabaseExtension.class);
    PersistentVolumeClaim volumeClaim = new PersistentVolumeClaimBuilder().withMetadata(new ObjectMetaBuilder().withName(config.devDbPodName() + "-pvc").withNamespace(config.devDbPodNamespace()).build()).withSpec(new PersistentVolumeClaimSpecBuilder().withAccessModes("ReadWriteOnce").withResources(new ResourceRequirementsBuilder().withRequests(ImmutableMap.of("storage", new Quantity("5Gi"))).build()).build()).build();
    Pod pod = new PodBuilder().withMetadata(new ObjectMetaBuilder().withName(config.devDbPodName()).withLabels(ImmutableMap.of("name", config.devDbPodName())).withNamespace(config.devDbPodNamespace()).build()).withSpec(new PodSpecBuilder().withContainers(new ContainerBuilder().withResources(new ResourceRequirementsBuilder().withLimits(ImmutableMap.of("cpu", new Quantity("0.1"), "memory", new Quantity("512Mi"))).build()).withImage(config.devDockerImageTag()).withName(config.devDbPodName()).withImagePullPolicy("Always").withPorts(new ContainerPortBuilder().withContainerPort(3306).withName("mysql").build()).withVolumeMounts(new VolumeMountBuilder().withName(config.devDbPodName() + "-data").withMountPath("/var/lib/mysql").build()).withArgs("--ignore-db-dir=lost+found").build()).withVolumes(new VolumeBuilder().withName(config.devDbPodName() + "-data").withPersistentVolumeClaim(new PersistentVolumeClaimVolumeSourceBuilder().withClaimName(volumeClaim.getMetadata().getName()).build()).build()).build()).build();
    Service service = new ServiceBuilder().withMetadata(new ObjectMetaBuilder().withName(config.devDbPodName()).withNamespace(config.devDbPodNamespace()).build()).withSpec(new ServiceSpecBuilder().withPorts(new ServicePortBuilder().withPort(3306).withTargetPort(new IntOrString(3306)).build()).withSelector(ImmutableMap.of("name", config.devDbPodName())).withType("LoadBalancer").withLoadBalancerSourceRanges(config.devDbIpRestrictions()).build()).build();
    KubernetesClient client = new DefaultKubernetesClient();
    try {
        client.resource(volumeClaim).createOrReplace();
    } catch (Exception e) {
    // TODO(choko): Find a better way to idempotently setup.
    // Ignore
    }
    try {
        client.resourceList(pod).createOrReplace();
    } catch (Exception e) {
    // TODO(choko): Find a better way to idempotently setup.
    // Ignore
    }
    client.resource(service).createOrReplace();
}
Also used : PodSpecBuilder(io.fabric8.kubernetes.api.model.PodSpecBuilder) DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) ImmutableDatabaseExtension(org.curioswitch.gradle.plugins.gcloud.ImmutableDatabaseExtension) Pod(io.fabric8.kubernetes.api.model.Pod) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) ResourceRequirementsBuilder(io.fabric8.kubernetes.api.model.ResourceRequirementsBuilder) PodBuilder(io.fabric8.kubernetes.api.model.PodBuilder) PersistentVolumeClaimBuilder(io.fabric8.kubernetes.api.model.PersistentVolumeClaimBuilder) Quantity(io.fabric8.kubernetes.api.model.Quantity) Service(io.fabric8.kubernetes.api.model.Service) PersistentVolumeClaimVolumeSourceBuilder(io.fabric8.kubernetes.api.model.PersistentVolumeClaimVolumeSourceBuilder) ObjectMetaBuilder(io.fabric8.kubernetes.api.model.ObjectMetaBuilder) VolumeMountBuilder(io.fabric8.kubernetes.api.model.VolumeMountBuilder) VolumeBuilder(io.fabric8.kubernetes.api.model.VolumeBuilder) ServiceBuilder(io.fabric8.kubernetes.api.model.ServiceBuilder) ServiceSpecBuilder(io.fabric8.kubernetes.api.model.ServiceSpecBuilder) ContainerBuilder(io.fabric8.kubernetes.api.model.ContainerBuilder) ServicePortBuilder(io.fabric8.kubernetes.api.model.ServicePortBuilder) ContainerPortBuilder(io.fabric8.kubernetes.api.model.ContainerPortBuilder) PersistentVolumeClaimSpecBuilder(io.fabric8.kubernetes.api.model.PersistentVolumeClaimSpecBuilder) PersistentVolumeClaim(io.fabric8.kubernetes.api.model.PersistentVolumeClaim) DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient) TaskAction(org.gradle.api.tasks.TaskAction)

Example 3 with PersistentVolumeClaim

use of io.fabric8.kubernetes.api.model.PersistentVolumeClaim in project jointware by isdream.

the class KubernetesKeyValueStyleGeneratorTest method testKubernetesWithAllKind.

protected static void testKubernetesWithAllKind() throws Exception {
    info(KUBERNETES_KIND, KubernetesDocumentKeyValueStyleGenerator.class.getName(), new ServiceAccount());
    info(KUBERNETES_KIND, KubernetesDocumentKeyValueStyleGenerator.class.getName(), new ThirdPartyResource());
    info(KUBERNETES_KIND, KubernetesDocumentKeyValueStyleGenerator.class.getName(), new ResourceQuota());
    info(KUBERNETES_KIND, KubernetesDocumentKeyValueStyleGenerator.class.getName(), new Node());
    info(KUBERNETES_KIND, KubernetesDocumentKeyValueStyleGenerator.class.getName(), new ConfigMap());
    info(KUBERNETES_KIND, KubernetesDocumentKeyValueStyleGenerator.class.getName(), new NetworkPolicy());
    info(KUBERNETES_KIND, KubernetesDocumentKeyValueStyleGenerator.class.getName(), new CustomResourceDefinition());
    info(KUBERNETES_KIND, KubernetesDocumentKeyValueStyleGenerator.class.getName(), new Ingress());
    info(KUBERNETES_KIND, KubernetesDocumentKeyValueStyleGenerator.class.getName(), new Service());
    info(KUBERNETES_KIND, KubernetesDocumentKeyValueStyleGenerator.class.getName(), new Namespace());
    info(KUBERNETES_KIND, KubernetesDocumentKeyValueStyleGenerator.class.getName(), new Secret());
    info(KUBERNETES_KIND, KubernetesDocumentKeyValueStyleGenerator.class.getName(), new LimitRange());
    info(KUBERNETES_KIND, KubernetesDocumentKeyValueStyleGenerator.class.getName(), new Event());
    info(KUBERNETES_KIND, KubernetesDocumentKeyValueStyleGenerator.class.getName(), new PersistentVolume());
    info(KUBERNETES_KIND, KubernetesDocumentKeyValueStyleGenerator.class.getName(), new StatefulSet());
    info(KUBERNETES_KIND, KubernetesDocumentKeyValueStyleGenerator.class.getName(), new PersistentVolumeClaim());
    info(KUBERNETES_KIND, KubernetesDocumentKeyValueStyleGenerator.class.getName(), new DaemonSet());
    info(KUBERNETES_KIND, KubernetesDocumentKeyValueStyleGenerator.class.getName(), new HorizontalPodAutoscaler());
    info(KUBERNETES_KIND, KubernetesDocumentKeyValueStyleGenerator.class.getName(), new Pod());
    info(KUBERNETES_KIND, KubernetesDocumentKeyValueStyleGenerator.class.getName(), new ReplicaSet());
    info(KUBERNETES_KIND, KubernetesDocumentKeyValueStyleGenerator.class.getName(), new Job());
    info(KUBERNETES_KIND, KubernetesDocumentKeyValueStyleGenerator.class.getName(), new ReplicationController());
    info(KUBERNETES_KIND, KubernetesDocumentKeyValueStyleGenerator.class.getName(), new Deployment());
}
Also used : ServiceAccount(io.fabric8.kubernetes.api.model.ServiceAccount) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) Pod(io.fabric8.kubernetes.api.model.Pod) ThirdPartyResource(io.fabric8.kubernetes.api.model.extensions.ThirdPartyResource) NetworkPolicy(io.fabric8.kubernetes.api.model.extensions.NetworkPolicy) CustomResourceDefinition(io.fabric8.kubernetes.api.model.apiextensions.CustomResourceDefinition) Node(io.fabric8.kubernetes.api.model.Node) Ingress(io.fabric8.kubernetes.api.model.extensions.Ingress) Service(io.fabric8.kubernetes.api.model.Service) Deployment(io.fabric8.kubernetes.api.model.extensions.Deployment) Namespace(io.fabric8.kubernetes.api.model.Namespace) Secret(io.fabric8.kubernetes.api.model.Secret) LimitRange(io.fabric8.kubernetes.api.model.LimitRange) ResourceQuota(io.fabric8.kubernetes.api.model.ResourceQuota) ReplicationController(io.fabric8.kubernetes.api.model.ReplicationController) HorizontalPodAutoscaler(io.fabric8.kubernetes.api.model.HorizontalPodAutoscaler) Event(io.fabric8.kubernetes.api.model.Event) PersistentVolumeClaim(io.fabric8.kubernetes.api.model.PersistentVolumeClaim) DaemonSet(io.fabric8.kubernetes.api.model.extensions.DaemonSet) PersistentVolume(io.fabric8.kubernetes.api.model.PersistentVolume) StatefulSet(io.fabric8.kubernetes.api.model.extensions.StatefulSet) Job(io.fabric8.kubernetes.api.model.Job) KubernetesDocumentKeyValueStyleGenerator(com.github.isdream.chameleon.docs.KubernetesDocumentKeyValueStyleGenerator) ReplicaSet(io.fabric8.kubernetes.api.model.extensions.ReplicaSet)

Example 4 with PersistentVolumeClaim

use of io.fabric8.kubernetes.api.model.PersistentVolumeClaim in project kubernetes by ballerinax.

the class PersistentVolumeClaimHandler method generate.

@Override
public String generate() throws KubernetesPluginException {
    Quantity quantity = new QuantityBuilder().withAmount(volumeClaimModel.getVolumeClaimSize()).build();
    Map<String, Quantity> requests = new HashMap<>();
    requests.put("storage", quantity);
    PersistentVolumeClaim secret = new PersistentVolumeClaimBuilder().withNewMetadata().withName(volumeClaimModel.getName()).endMetadata().withNewSpec().withAccessModes(volumeClaimModel.getAccessMode()).withNewResources().withRequests(requests).endResources().endSpec().build();
    try {
        return SerializationUtils.dumpWithoutRuntimeStateAsYaml(secret);
    } catch (JsonProcessingException e) {
        String errorMessage = "Error while parsing yaml file for volume claim: " + volumeClaimModel.getName();
        throw new KubernetesPluginException(errorMessage, e);
    }
}
Also used : QuantityBuilder(io.fabric8.kubernetes.api.model.QuantityBuilder) HashMap(java.util.HashMap) Quantity(io.fabric8.kubernetes.api.model.Quantity) PersistentVolumeClaimBuilder(io.fabric8.kubernetes.api.model.PersistentVolumeClaimBuilder) PersistentVolumeClaim(io.fabric8.kubernetes.api.model.PersistentVolumeClaim) KubernetesPluginException(org.ballerinax.kubernetes.exceptions.KubernetesPluginException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 5 with PersistentVolumeClaim

use of io.fabric8.kubernetes.api.model.PersistentVolumeClaim in project strimzi by strimzi.

the class AbstractModel method createPersistentVolumeClaim.

protected PersistentVolumeClaim createPersistentVolumeClaim(String name) {
    Map<String, Quantity> requests = new HashMap<>();
    requests.put("storage", storage.size());
    PersistentVolumeClaim pvc = new PersistentVolumeClaimBuilder().withNewMetadata().withName(name).endMetadata().withNewSpec().withAccessModes("ReadWriteOnce").withNewResources().withRequests(requests).endResources().withStorageClassName(storage.storageClass()).withSelector(storage.selector()).endSpec().build();
    return pvc;
}
Also used : HashMap(java.util.HashMap) Quantity(io.fabric8.kubernetes.api.model.Quantity) PersistentVolumeClaimBuilder(io.fabric8.kubernetes.api.model.PersistentVolumeClaimBuilder) PersistentVolumeClaim(io.fabric8.kubernetes.api.model.PersistentVolumeClaim)

Aggregations

PersistentVolumeClaim (io.fabric8.kubernetes.api.model.PersistentVolumeClaim)12 PersistentVolumeClaimBuilder (io.fabric8.kubernetes.api.model.PersistentVolumeClaimBuilder)5 StatefulSet (io.fabric8.kubernetes.api.model.extensions.StatefulSet)5 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)4 DoneablePersistentVolumeClaim (io.fabric8.kubernetes.api.model.DoneablePersistentVolumeClaim)4 Pod (io.fabric8.kubernetes.api.model.Pod)4 Quantity (io.fabric8.kubernetes.api.model.Quantity)4 Service (io.fabric8.kubernetes.api.model.Service)4 HashMap (java.util.HashMap)4 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)3 Deployment (io.fabric8.kubernetes.api.model.extensions.Deployment)3 KubernetesClientException (io.fabric8.kubernetes.client.KubernetesClientException)3 OpenShiftNotAvailableException (io.fabric8.openshift.client.OpenShiftNotAvailableException)3 FileNotFoundException (java.io.FileNotFoundException)3 IOException (java.io.IOException)3 Container (io.fabric8.kubernetes.api.model.Container)2 ContainerBuilder (io.fabric8.kubernetes.api.model.ContainerBuilder)2 Namespace (io.fabric8.kubernetes.api.model.Namespace)2 PersistentVolumeClaimList (io.fabric8.kubernetes.api.model.PersistentVolumeClaimList)2 PersistentVolumeClaimSpec (io.fabric8.kubernetes.api.model.PersistentVolumeClaimSpec)2