Search in sources :

Example 1 with ResourceQuota

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);
}
Also used : DoneableResourceQuota(io.fabric8.kubernetes.api.model.DoneableResourceQuota) ResourceQuota(io.fabric8.kubernetes.api.model.ResourceQuota)

Example 2 with ResourceQuota

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());
}
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 3 with ResourceQuota

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);
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) ResourceQuota(io.fabric8.kubernetes.api.model.ResourceQuota) ResourceQuotaSpec(io.fabric8.kubernetes.api.model.ResourceQuotaSpec) Quantity(io.fabric8.kubernetes.api.model.Quantity) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 4 with ResourceQuota

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);
}
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)

Example 5 with ResourceQuota

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());
}
Also used : ResourceQuotaList(io.fabric8.kubernetes.api.model.ResourceQuotaList) DoneableResourceQuota(io.fabric8.kubernetes.api.model.DoneableResourceQuota) ResourceQuota(io.fabric8.kubernetes.api.model.ResourceQuota) Resource(io.fabric8.kubernetes.client.dsl.Resource) DoneableResourceQuota(io.fabric8.kubernetes.api.model.DoneableResourceQuota) Map(java.util.Map)

Aggregations

ResourceQuota (io.fabric8.kubernetes.api.model.ResourceQuota)5 DoneableResourceQuota (io.fabric8.kubernetes.api.model.DoneableResourceQuota)3 ResourceQuotaSpec (io.fabric8.kubernetes.api.model.ResourceQuotaSpec)2 Map (java.util.Map)2 KubernetesDocumentKeyValueStyleGenerator (com.github.isdream.chameleon.docs.KubernetesDocumentKeyValueStyleGenerator)1 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)1 Event (io.fabric8.kubernetes.api.model.Event)1 HorizontalPodAutoscaler (io.fabric8.kubernetes.api.model.HorizontalPodAutoscaler)1 Job (io.fabric8.kubernetes.api.model.Job)1 LimitRange (io.fabric8.kubernetes.api.model.LimitRange)1 Namespace (io.fabric8.kubernetes.api.model.Namespace)1 Node (io.fabric8.kubernetes.api.model.Node)1 PersistentVolume (io.fabric8.kubernetes.api.model.PersistentVolume)1 PersistentVolumeClaim (io.fabric8.kubernetes.api.model.PersistentVolumeClaim)1 Pod (io.fabric8.kubernetes.api.model.Pod)1 Quantity (io.fabric8.kubernetes.api.model.Quantity)1 ReplicationController (io.fabric8.kubernetes.api.model.ReplicationController)1 ResourceQuotaBuilder (io.fabric8.kubernetes.api.model.ResourceQuotaBuilder)1 ResourceQuotaList (io.fabric8.kubernetes.api.model.ResourceQuotaList)1 Secret (io.fabric8.kubernetes.api.model.Secret)1