use of io.fabric8.kubernetes.api.model.ResourceQuotaSpec 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);
}
use of io.fabric8.kubernetes.api.model.ResourceQuotaSpec in project camel by apache.
the class KubernetesResourcesQuotaProducerTest method createAndDeleteResourceQuota.
@Test
public void createAndDeleteResourceQuota() 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_RESOURCES_QUOTA_NAME, "test");
Map<String, String> labels = new HashMap<String, String>();
labels.put("this", "rocks");
exchange.getIn().setHeader(KubernetesConstants.KUBERNETES_RESOURCES_QUOTA_LABELS, labels);
ResourceQuotaSpec rsSpec = new ResourceQuotaSpec();
Map<String, Quantity> mp = new HashMap<String, Quantity>();
mp.put("pods", new Quantity("100"));
rsSpec.setHard(mp);
exchange.getIn().setHeader(KubernetesConstants.KUBERNETES_RESOURCE_QUOTA_SPEC, rsSpec);
}
});
ResourceQuota rs = ex.getOut().getBody(ResourceQuota.class);
assertEquals(rs.getMetadata().getName(), "test");
ex = template.request("direct:get", new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
exchange.getIn().setHeader(KubernetesConstants.KUBERNETES_NAMESPACE_NAME, "default");
exchange.getIn().setHeader(KubernetesConstants.KUBERNETES_RESOURCES_QUOTA_NAME, "test");
}
});
ResourceQuota rsGet = ex.getOut().getBody(ResourceQuota.class);
assertEquals(rsGet.getMetadata().getName(), "test");
assertEquals(rsGet.getSpec().getHard().get("pods"), new Quantity("100"));
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_RESOURCES_QUOTA_NAME, "test");
}
});
boolean rqDeleted = ex.getOut().getBody(Boolean.class);
assertTrue(rqDeleted);
}
Aggregations