Search in sources :

Example 1 with Controller

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

the class KubernetesReplicationControllersProducer method doScaleReplicationController.

protected void doScaleReplicationController(Exchange exchange, String operation) throws Exception {
    String rcName = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_REPLICATION_CONTROLLER_NAME, String.class);
    String namespaceName = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_NAMESPACE_NAME, String.class);
    Integer replicasNumber = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_REPLICATION_CONTROLLER_REPLICAS, Integer.class);
    if (ObjectHelper.isEmpty(rcName)) {
        LOG.error("Scale a specific replication controller require specify a replication controller name");
        throw new IllegalArgumentException("Scale a specific replication controller require specify a replication controller name");
    }
    if (ObjectHelper.isEmpty(namespaceName)) {
        LOG.error("Scale a specific replication controller require specify a namespace name");
        throw new IllegalArgumentException("Scale a specific replication controller require specify a namespace name");
    }
    if (ObjectHelper.isEmpty(replicasNumber)) {
        LOG.error("Scale a specific replication controller require specify a replicas number");
        throw new IllegalArgumentException("Scale a specific replication controller require specify a replicas number");
    }
    ReplicationController rcScaled = getEndpoint().getKubernetesClient().replicationControllers().inNamespace(namespaceName).withName(rcName).scale(replicasNumber, true);
    MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(), true);
    exchange.getOut().setBody(rcScaled.getStatus().getReplicas());
}
Also used : DoneableReplicationController(io.fabric8.kubernetes.api.model.DoneableReplicationController) ReplicationController(io.fabric8.kubernetes.api.model.ReplicationController)

Example 2 with Controller

use of io.fabric8.kubernetes.api.Controller in project fabric8 by jboss-fuse.

the class Fabric8Container method start.

@Override
public void start() throws LifecycleException {
    // lets kill any containers that are running before we start
    FabricAssertions.killJavaAndDockerProcesses();
    fabricControllerManager = createFabricControllerManager();
    Fabric8ContainerConfiguration config = configuration.get();
    config.configure(fabricControllerManager);
    try {
        FabricController fabricController = FabricAssertions.assertFabricCreate(fabricControllerManager);
        controller.set(fabricController);
    } catch (Exception e) {
        throw new LifecycleException("Failed to create fabric: " + e, e);
    }
    System.out.println("Created a controller " + controller.get());
}
Also used : LifecycleException(org.jboss.arquillian.container.spi.client.container.LifecycleException) FabricController(io.fabric8.testkit.FabricController) LifecycleException(org.jboss.arquillian.container.spi.client.container.LifecycleException) DeploymentException(org.jboss.arquillian.container.spi.client.container.DeploymentException)

Example 3 with Controller

use of io.fabric8.kubernetes.api.Controller in project ephemerals by LivePersonInc.

the class KubernetesDeploymentHandler method deploy.

@Override
public DeploymentEndpoints deploy(Deployment deployment) {
    // Create service on KubernetesServiceBuilder cluster
    Service service = kubernetesDeploymentStrategy.service(deployment);
    kubernetesClient.services().inNamespace(kubernetesClient.getNamespace()).create(service);
    // Create pods and replication controller
    ReplicationController replicationController = kubernetesDeploymentStrategy.replicationController(deployment);
    kubernetesClient.replicationControllers().inNamespace(kubernetesClient.getNamespace()).create(replicationController);
    // Wait for deployment to finish by polling KubernetesServiceBuilder and waiting for 'FINISHED' status
    KubernetesDeploymentStatusWaiter deploymentStatusWaiter = new KubernetesDeploymentStatusWaiter(kubernetesClient, deployment, DeploymentStatus.FINISHED);
    try {
        deploymentStatusWaiter.start();
    } catch (TimeoutException e) {
        throw new DeploymentException(e);
    }
    DeploymentEndpoints endpoints = new DeploymentEndpoints();
    for (DeploymentPort deploymentPort : deployment.getDeploymentUnit().getPorts()) {
        KubernetesDeploymentEndpointWaiter kubernetesDeploymentEndpointWaiter = new KubernetesDeploymentEndpointWaiter(kubernetesClient, deployment, deploymentPort);
        try {
            kubernetesDeploymentEndpointWaiter.start();
            endpoints.add(kubernetesDeploymentEndpointWaiter.getEndpoint());
        } catch (TimeoutException e) {
            throw new DeploymentException(e);
        }
    }
    return endpoints;
}
Also used : KubernetesDeploymentStatusWaiter(com.liveperson.ephemerals.provider.kubernetes.wait.KubernetesDeploymentStatusWaiter) ReplicationController(io.fabric8.kubernetes.api.model.ReplicationController) KubernetesDeploymentEndpointWaiter(com.liveperson.ephemerals.provider.kubernetes.wait.KubernetesDeploymentEndpointWaiter) Service(io.fabric8.kubernetes.api.model.Service) TimeoutException(java.util.concurrent.TimeoutException)

Example 4 with Controller

use of io.fabric8.kubernetes.api.Controller in project ephemerals by LivePersonInc.

the class KubernetesDeploymentHandler method destroy.

@Override
public void destroy(Deployment deployment) {
    List<ReplicationController> apps = kubernetesClient.replicationControllers().withLabel(DEPLOYMENT_LABEL_KEY, deployment.getId()).list().getItems();
    for (ReplicationController rc : apps) {
        String deploymentId = rc.getMetadata().getName();
        logger.info("Deleting service, replication controller and pods for deployment: {}", deploymentId);
        Service svc = kubernetesClient.services().withName(deploymentId).get();
        if (svc.getSpec().getType().equals(KubernetesServiceType.LOAD_BALANCER.getValue())) {
            KubernetesLoadBalancerWaiter kubernetesLoadBalancerWaiter = new KubernetesLoadBalancerWaiter(kubernetesClient, deployment);
            try {
                kubernetesLoadBalancerWaiter.start();
            } catch (TimeoutException e) {
                throw new DeploymentException(e);
            }
        }
        Boolean svcDeleted = kubernetesClient.services().withName(deploymentId).delete();
        logger.info("Deleted service for deployment: {} {}", deploymentId, svcDeleted);
        Boolean rcDeleted = kubernetesClient.replicationControllers().withName(deploymentId).delete();
        logger.info("Deleted replication controller for deployment: {} {}", deploymentId, rcDeleted);
        Map<String, String> selector = new HashMap<>();
        selector.put(DEPLOYMENT_LABEL_KEY, deploymentId);
        Boolean podDeleted = kubernetesClient.pods().withLabels(selector).delete();
        logger.info("Deleted pods for deployment: {} {}", deploymentId, podDeleted);
    }
}
Also used : HashMap(java.util.HashMap) ReplicationController(io.fabric8.kubernetes.api.model.ReplicationController) Service(io.fabric8.kubernetes.api.model.Service) KubernetesLoadBalancerWaiter(com.liveperson.ephemerals.provider.kubernetes.wait.KubernetesLoadBalancerWaiter) TimeoutException(java.util.concurrent.TimeoutException)

Example 5 with Controller

use of io.fabric8.kubernetes.api.Controller in project fabric8-maven-plugin by fabric8io.

the class DefaultControllerEnricherTest method setupExpectations.

protected void setupExpectations(final BuildImageConfiguration buildConfig, final TreeMap controllerConfig) {
    new Expectations() {

        {
            project.getArtifactId();
            result = "fmp-controller-test";
            project.getBuild().getOutputDirectory();
            result = Files.createTempDir().getAbsolutePath();
            context.getProject();
            result = project;
            context.getConfig();
            result = new ProcessorConfig(null, null, Collections.singletonMap("fmp-controller", controllerConfig));
            imageConfiguration.getBuildConfiguration();
            result = buildConfig;
            imageConfiguration.getName();
            result = "helloworld";
            context.getImages();
            result = Arrays.asList(imageConfiguration);
        }
    };
}
Also used : Expectations(mockit.Expectations) ProcessorConfig(io.fabric8.maven.core.config.ProcessorConfig)

Aggregations

Test (org.junit.Test)23 ReplicationController (io.fabric8.kubernetes.api.model.ReplicationController)16 Controller (io.fabric8.kubernetes.api.Controller)13 ResourceConfig (io.fabric8.maven.core.config.ResourceConfig)12 OpenShiftClient (io.fabric8.openshift.client.OpenShiftClient)12 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)9 Deployment (io.fabric8.kubernetes.api.model.extensions.Deployment)8 DefaultKubernetesClient (io.fabric8.kubernetes.client.DefaultKubernetesClient)8 KubernetesClientException (io.fabric8.kubernetes.client.KubernetesClientException)8 Async (io.vertx.ext.unit.Async)8 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)7 Service (io.fabric8.kubernetes.api.model.Service)6 File (java.io.File)6 IOException (java.io.IOException)6 ArrayList (java.util.ArrayList)6 HashMap (java.util.HashMap)6 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)5 ReplicaSet (io.fabric8.kubernetes.api.model.extensions.ReplicaSet)5 DeploymentConfig (io.fabric8.openshift.api.model.DeploymentConfig)5 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)4