Search in sources :

Example 6 with Resource

use of io.fabric8.support.api.Resource in project camel by apache.

the class KubernetesConfigMapsProducer method doListConfigMapsByLabels.

protected void doListConfigMapsByLabels(Exchange exchange, String operation) throws Exception {
    ConfigMapList configMapsList = null;
    Map<String, String> labels = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_CONFIGMAPS_LABELS, Map.class);
    NonNamespaceOperation<ConfigMap, ConfigMapList, DoneableConfigMap, Resource<ConfigMap, DoneableConfigMap>> configMaps = getEndpoint().getKubernetesClient().configMaps();
    for (Map.Entry<String, String> entry : labels.entrySet()) {
        configMaps.withLabel(entry.getKey(), entry.getValue());
    }
    configMapsList = configMaps.list();
    MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(), true);
    exchange.getOut().setBody(configMapsList.getItems());
}
Also used : ConfigMapList(io.fabric8.kubernetes.api.model.ConfigMapList) DoneableConfigMap(io.fabric8.kubernetes.api.model.DoneableConfigMap) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) Resource(io.fabric8.kubernetes.client.dsl.Resource) HashMap(java.util.HashMap) DoneableConfigMap(io.fabric8.kubernetes.api.model.DoneableConfigMap) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) Map(java.util.Map) DoneableConfigMap(io.fabric8.kubernetes.api.model.DoneableConfigMap)

Example 7 with Resource

use of io.fabric8.support.api.Resource 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 8 with Resource

use of io.fabric8.support.api.Resource in project camel by apache.

the class KubernetesSecretsProducer method doListSecretsByLabels.

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

Example 9 with Resource

use of io.fabric8.support.api.Resource in project carbon-apimgt by wso2.

the class KubernetesGatewayImpl method createDeploymentResource.

/**
 * Create a deployment in cms
 *
 * @param deploymentTemplate Deployment template as a String
 * @param deploymentName     Name of the deployment
 * @throws ContainerBasedGatewayException if failed to create a deployment
 */
private void createDeploymentResource(String deploymentTemplate, String deploymentName) throws ContainerBasedGatewayException {
    HasMetadata resource = getResourcesFromTemplate(deploymentTemplate);
    try {
        if (resource instanceof Deployment) {
            // check whether there are existing service already
            if (client.extensions().deployments().inNamespace(namespace).withName(deploymentName).get() == null) {
                log.debug("Deploying in CMS type: {} and the Deployment resource definition: {} ", cmsType, deploymentTemplate);
                Deployment deployment = (Deployment) resource;
                Deployment result = client.extensions().deployments().inNamespace(namespace).create(deployment);
                log.info("Created Deployment : " + result.getMetadata().getName() + " in Namespace : " + result.getMetadata().getNamespace() + " in " + cmsType);
            } else {
                log.info("There exist a deployment with the same name in " + cmsType + ". Deployment name : " + deploymentName);
            }
        } else {
            throw new ContainerBasedGatewayException("Loaded Resource is not a Deployment in " + cmsType + "! " + resource, ExceptionCodes.LOADED_RESOURCE_DEFINITION_IS_NOT_VALID);
        }
    } catch (KubernetesClientException e) {
        throw new ContainerBasedGatewayException("Error while creating container based gateway deployment in " + cmsType + "!", e, ExceptionCodes.DEDICATED_CONTAINER_GATEWAY_CREATION_FAILED);
    }
}
Also used : HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) Deployment(io.fabric8.kubernetes.api.model.extensions.Deployment) ContainerBasedGatewayException(org.wso2.carbon.apimgt.core.exception.ContainerBasedGatewayException) KubernetesClientException(io.fabric8.kubernetes.client.KubernetesClientException)

Example 10 with Resource

use of io.fabric8.support.api.Resource in project carbon-apimgt by wso2.

the class KubernetesGatewayImpl method createIngressResource.

/**
 * Create an Ingress resource in cms
 *
 * @param ingressTemplate Ingress template as a String
 * @param ingressName     Name of the ingress
 * @throws ContainerBasedGatewayException if failed to create a service
 */
private void createIngressResource(String ingressTemplate, String ingressName) throws ContainerBasedGatewayException {
    HasMetadata resource = getResourcesFromTemplate(ingressTemplate);
    try {
        if (resource instanceof Ingress) {
            // check whether there are existing service already
            if (client.extensions().ingresses().inNamespace(namespace).withName(ingressName).get() == null) {
                log.debug("Deploying in CMS type: {} and the Ingress resource definition: {} ", cmsType, ingressTemplate);
                Ingress ingress = (Ingress) resource;
                Ingress result = client.extensions().ingresses().inNamespace(namespace).create(ingress);
                log.info("Created Ingress : " + result.getMetadata().getName() + " in Namespace : " + result.getMetadata().getNamespace() + " in " + cmsType);
            } else {
                log.info("There exist an ingress with the same name in " + cmsType + ". Ingress name : " + ingressName);
            }
        } else {
            throw new ContainerBasedGatewayException("Loaded Resource is not a Service in " + cmsType + "! " + resource, ExceptionCodes.LOADED_RESOURCE_DEFINITION_IS_NOT_VALID);
        }
    } catch (KubernetesClientException e) {
        throw new ContainerBasedGatewayException("Error while creating container based gateway ingress in " + cmsType + "!", e, ExceptionCodes.DEDICATED_CONTAINER_GATEWAY_CREATION_FAILED);
    }
}
Also used : HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) Ingress(io.fabric8.kubernetes.api.model.extensions.Ingress) ContainerBasedGatewayException(org.wso2.carbon.apimgt.core.exception.ContainerBasedGatewayException) KubernetesClientException(io.fabric8.kubernetes.client.KubernetesClientException)

Aggregations

HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)25 Resource (io.fabric8.kubernetes.client.dsl.Resource)25 Map (java.util.Map)20 Test (org.junit.Test)20 IOException (java.io.IOException)19 HashMap (java.util.HashMap)16 Deployment (io.fabric8.kubernetes.api.model.extensions.Deployment)14 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)14 MixedOperation (io.fabric8.kubernetes.client.dsl.MixedOperation)14 Resource (org.osgi.resource.Resource)14 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)13 NonNamespaceOperation (io.fabric8.kubernetes.client.dsl.NonNamespaceOperation)13 ArrayList (java.util.ArrayList)13 Async (io.vertx.ext.unit.Async)12 File (java.io.File)10 ReplicationController (io.fabric8.kubernetes.api.model.ReplicationController)9 Service (io.fabric8.kubernetes.api.model.Service)9 KubernetesClientException (io.fabric8.kubernetes.client.KubernetesClientException)9 DeploymentConfig (io.fabric8.openshift.api.model.DeploymentConfig)8 Bundle (org.osgi.framework.Bundle)7