use of io.fabric8.kubernetes.api.model.ResourceQuota in project camel by apache.
the class KubernetesResourcesQuotaProducer method doGetResourceQuota.
protected void doGetResourceQuota(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);
if (ObjectHelper.isEmpty(rqName)) {
LOG.error("Get a specific Resource Quota require specify a Resource Quota name");
throw new IllegalArgumentException("Get a specific Resource Quota require specify a Resource Quota name");
}
if (ObjectHelper.isEmpty(namespaceName)) {
LOG.error("Get a specific Resource Quota require specify a namespace name");
throw new IllegalArgumentException("Get a specific Resource Quota require specify a namespace name");
}
rq = getEndpoint().getKubernetesClient().resourceQuotas().inNamespace(namespaceName).withName(rqName).get();
MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(), true);
exchange.getOut().setBody(rq);
}
use of io.fabric8.kubernetes.api.model.ResourceQuota 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());
}
use of io.fabric8.kubernetes.api.model.ResourceQuota 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);
}
use of io.fabric8.kubernetes.api.model.ResourceQuota 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.ResourceQuota in project camel by apache.
the class KubernetesResourcesQuotaProducer method doListResourceQuotasByLabels.
protected void doListResourceQuotasByLabels(Exchange exchange, String operation) throws Exception {
ResourceQuotaList resList = null;
Map<String, String> labels = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_RESOURCES_QUOTA_LABELS, Map.class);
String namespaceName = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_NAMESPACE_NAME, String.class);
if (!ObjectHelper.isEmpty(namespaceName)) {
NonNamespaceOperation<ResourceQuota, ResourceQuotaList, DoneableResourceQuota, Resource<ResourceQuota, DoneableResourceQuota>> resQuota;
resQuota = getEndpoint().getKubernetesClient().resourceQuotas().inNamespace(namespaceName);
for (Map.Entry<String, String> entry : labels.entrySet()) {
resQuota.withLabel(entry.getKey(), entry.getValue());
}
resList = resQuota.list();
} else {
MixedOperation<ResourceQuota, ResourceQuotaList, DoneableResourceQuota, Resource<ResourceQuota, DoneableResourceQuota>> resQuota;
resQuota = getEndpoint().getKubernetesClient().resourceQuotas();
for (Map.Entry<String, String> entry : labels.entrySet()) {
resQuota.withLabel(entry.getKey(), entry.getValue());
}
resList = resQuota.list();
}
MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(), true);
exchange.getOut().setBody(resList.getItems());
}
Aggregations