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