Search in sources :

Example 6 with Controller

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

the class KubernetesClientUtil method resizeApp.

public static void resizeApp(KubernetesClient kubernetes, String namespace, Set<HasMetadata> entities, int replicas, Logger log) {
    for (HasMetadata entity : entities) {
        String name = getName(entity);
        Scaleable<?> scalable = null;
        if (entity instanceof Deployment) {
            scalable = kubernetes.extensions().deployments().inNamespace(namespace).withName(name);
        } else if (entity instanceof ReplicaSet) {
            scalable = kubernetes.extensions().replicaSets().inNamespace(namespace).withName(name);
        } else if (entity instanceof ReplicationController) {
            scalable = kubernetes.replicationControllers().inNamespace(namespace).withName(name);
        } else if (entity instanceof DeploymentConfig) {
            OpenShiftClient openshiftClient = new Controller(kubernetes).getOpenShiftClientOrNull();
            if (openshiftClient == null) {
                log.warn("Ignoring DeploymentConfig %s as not connected to an OpenShift cluster", name);
                continue;
            }
            scalable = openshiftClient.deploymentConfigs().inNamespace(namespace).withName(name);
        }
        if (scalable != null) {
            log.info("Scaling " + getKind(entity) + " " + namespace + "/" + name + " to replicas: " + replicas);
            scalable.scale(replicas, true);
        }
    }
}
Also used : HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) ReplicationController(io.fabric8.kubernetes.api.model.ReplicationController) OpenShiftClient(io.fabric8.openshift.client.OpenShiftClient) Deployment(io.fabric8.kubernetes.api.model.extensions.Deployment) DeploymentConfig(io.fabric8.openshift.api.model.DeploymentConfig) Controller(io.fabric8.kubernetes.api.Controller) ReplicationController(io.fabric8.kubernetes.api.model.ReplicationController) ReplicaSet(io.fabric8.kubernetes.api.model.extensions.ReplicaSet)

Example 7 with Controller

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

the class KubernetesClientUtil method deleteEntities.

public static void deleteEntities(KubernetesClient kubernetes, String namespace, Set<HasMetadata> entities, String s2iBuildNameSuffix, Logger log) {
    List<HasMetadata> list = new ArrayList<>(entities);
    // For OpenShift cluster, also delete s2i buildconfig
    OpenShiftClient openshiftClient = new Controller(kubernetes).getOpenShiftClientOrNull();
    if (openshiftClient != null) {
        for (HasMetadata entity : list) {
            if ("ImageStream".equals(getKind(entity))) {
                ImageName imageName = new ImageName(entity.getMetadata().getName());
                String buildName = getS2IBuildName(imageName, s2iBuildNameSuffix);
                log.info("Deleting resource BuildConfig " + namespace + "/" + buildName);
                openshiftClient.buildConfigs().inNamespace(namespace).withName(buildName).delete();
            }
        }
    }
    // lets delete in reverse order
    Collections.reverse(list);
    for (HasMetadata entity : list) {
        log.info("Deleting resource " + getKind(entity) + " " + namespace + "/" + getName(entity));
        kubernetes.resource(entity).inNamespace(namespace).cascading(true).delete();
    }
}
Also used : ImageName(io.fabric8.maven.docker.util.ImageName) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) OpenShiftClient(io.fabric8.openshift.client.OpenShiftClient) ArrayList(java.util.ArrayList) Controller(io.fabric8.kubernetes.api.Controller) ReplicationController(io.fabric8.kubernetes.api.model.ReplicationController)

Example 8 with Controller

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

the class DaemonSetHandlerTest method daemonTemplateHandlerWithoutControllerTest.

@Test(expected = IllegalArgumentException.class)
public void daemonTemplateHandlerWithoutControllerTest() {
    // without controller name
    ContainerHandler containerHandler = new ContainerHandler(project, envVarHandler, probeHandler);
    PodTemplateHandler podTemplateHandler = new PodTemplateHandler(containerHandler);
    DaemonSetHandler daemonSetHandler = new DaemonSetHandler(podTemplateHandler);
    // without controller name
    ResourceConfig config = new ResourceConfig.Builder().imagePullPolicy("IfNotPresent").withServiceAccount("test-account").volumes(volumes1).build();
    daemonSetHandler.getDaemonSet(config, images);
}
Also used : ResourceConfig(io.fabric8.maven.core.config.ResourceConfig) Test(org.junit.Test)

Example 9 with Controller

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

the class DeploymentHandlerTest method deploymentTemplateHandlerWithoutControllerTest.

@Test(expected = IllegalArgumentException.class)
public void deploymentTemplateHandlerWithoutControllerTest() {
    // without controller name
    ContainerHandler containerHandler = new ContainerHandler(project, envVarHandler, probeHandler);
    PodTemplateHandler podTemplateHandler = new PodTemplateHandler(containerHandler);
    DeploymentHandler deploymentHandler = new DeploymentHandler(podTemplateHandler);
    // without controller name
    ResourceConfig config = new ResourceConfig.Builder().imagePullPolicy("IfNotPresent").withServiceAccount("test-account").withReplicas(5).volumes(volumes1).build();
    deploymentHandler.getDeployment(config, images);
}
Also used : ResourceConfig(io.fabric8.maven.core.config.ResourceConfig) Test(org.junit.Test)

Example 10 with Controller

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

the class JobHandlerTest method daemonTemplateHandlerWithoutControllerTest.

@Test(expected = IllegalArgumentException.class)
public void daemonTemplateHandlerWithoutControllerTest() {
    // without controller name
    ContainerHandler containerHandler = new ContainerHandler(project, envVarHandler, probeHandler);
    PodTemplateHandler podTemplateHandler = new PodTemplateHandler(containerHandler);
    JobHandler jobHandler = new JobHandler(podTemplateHandler);
    // without controller name
    ResourceConfig config = new ResourceConfig.Builder().imagePullPolicy("IfNotPresent").withServiceAccount("test-account").volumes(volumes1).build();
    jobHandler.getJob(config, images);
}
Also used : ResourceConfig(io.fabric8.maven.core.config.ResourceConfig) Test(org.junit.Test)

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