Search in sources :

Example 1 with ResourceQuotaBuilder

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

the class KubernetesResourcesQuotaProducer method doCreateResourceQuota.

protected void doCreateResourceQuota(Exchange exchange, String operation) throws Exception {
    ResourceQuota rq = null;
    String rqName = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_RESOURCES_QUOTA_NAME, String.class);
    String namespaceName = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_NAMESPACE_NAME, String.class);
    ResourceQuotaSpec rqSpec = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_RESOURCE_QUOTA_SPEC, ResourceQuotaSpec.class);
    if (ObjectHelper.isEmpty(rqName)) {
        LOG.error("Create a specific resource quota require specify a resource quota name");
        throw new IllegalArgumentException("Create a specific resource quota require specify a resource quota name");
    }
    if (ObjectHelper.isEmpty(namespaceName)) {
        LOG.error("Create a specific resource quota require specify a namespace name");
        throw new IllegalArgumentException("Create a specific resource quota require specify a namespace name");
    }
    if (ObjectHelper.isEmpty(rqSpec)) {
        LOG.error("Create a specific resource quota require specify a resource quota spec bean");
        throw new IllegalArgumentException("Create a specific resource quota require specify a resource quota spec bean");
    }
    Map<String, String> labels = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_RESOURCES_QUOTA_LABELS, Map.class);
    ResourceQuota rqCreating = new ResourceQuotaBuilder().withNewMetadata().withName(rqName).withLabels(labels).endMetadata().withSpec(rqSpec).build();
    rq = getEndpoint().getKubernetesClient().resourceQuotas().inNamespace(namespaceName).create(rqCreating);
    MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(), true);
    exchange.getOut().setBody(rq);
}
Also used : DoneableResourceQuota(io.fabric8.kubernetes.api.model.DoneableResourceQuota) ResourceQuota(io.fabric8.kubernetes.api.model.ResourceQuota) ResourceQuotaSpec(io.fabric8.kubernetes.api.model.ResourceQuotaSpec) ResourceQuotaBuilder(io.fabric8.kubernetes.api.model.ResourceQuotaBuilder)

Aggregations

DoneableResourceQuota (io.fabric8.kubernetes.api.model.DoneableResourceQuota)1 ResourceQuota (io.fabric8.kubernetes.api.model.ResourceQuota)1 ResourceQuotaBuilder (io.fabric8.kubernetes.api.model.ResourceQuotaBuilder)1 ResourceQuotaSpec (io.fabric8.kubernetes.api.model.ResourceQuotaSpec)1