Search in sources :

Example 51 with ReplicaSet

use of io.fabric8.kubernetes.api.model.apps.ReplicaSet 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 = KubernetesHelper.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 = OpenshiftHelper.asOpenShiftClient(kubernetes);
            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 " + KubernetesHelper.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.apps.Deployment) DeploymentConfig(io.fabric8.openshift.api.model.DeploymentConfig) ReplicaSet(io.fabric8.kubernetes.api.model.apps.ReplicaSet)

Example 52 with ReplicaSet

use of io.fabric8.kubernetes.api.model.apps.ReplicaSet in project fabric8-maven-plugin by fabric8io.

the class DebugEnricher method enableDebug.

private boolean enableDebug(HasMetadata entity) {
    if (entity instanceof Deployment) {
        Deployment resource = (Deployment) entity;
        DeploymentSpec spec = resource.getSpec();
        if (spec != null) {
            return enableDebugging(entity, spec.getTemplate());
        }
    } else if (entity instanceof ReplicaSet) {
        ReplicaSet resource = (ReplicaSet) entity;
        ReplicaSetSpec spec = resource.getSpec();
        if (spec != null) {
            return enableDebugging(entity, spec.getTemplate());
        }
    } else if (entity instanceof ReplicationController) {
        ReplicationController resource = (ReplicationController) entity;
        ReplicationControllerSpec spec = resource.getSpec();
        if (spec != null) {
            return enableDebugging(entity, spec.getTemplate());
        }
    } else if (entity instanceof DeploymentConfig) {
        DeploymentConfig resource = (DeploymentConfig) entity;
        DeploymentConfigSpec spec = resource.getSpec();
        if (spec != null) {
            return enableDebugging(entity, spec.getTemplate());
        }
    }
    return false;
}
Also used : DeploymentSpec(io.fabric8.kubernetes.api.model.apps.DeploymentSpec) ReplicaSetSpec(io.fabric8.kubernetes.api.model.apps.ReplicaSetSpec) ReplicationController(io.fabric8.kubernetes.api.model.ReplicationController) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) DeploymentConfig(io.fabric8.openshift.api.model.DeploymentConfig) DeploymentConfigSpec(io.fabric8.openshift.api.model.DeploymentConfigSpec) ReplicaSet(io.fabric8.kubernetes.api.model.apps.ReplicaSet) ReplicationControllerSpec(io.fabric8.kubernetes.api.model.ReplicationControllerSpec)

Example 53 with ReplicaSet

use of io.fabric8.kubernetes.api.model.apps.ReplicaSet in project kubernetes-client by fabric8io.

the class DeploymentTest method testDelete.

@Test
void testDelete() {
    Deployment deployment1 = new DeploymentBuilder().withNewMetadata().withName("deployment1").addToLabels("key1", "value1").withResourceVersion("1").withGeneration(1L).endMetadata().withNewSpec().withNewSelector().addToMatchLabels("key1", "value1").endSelector().withReplicas(0).endSpec().withNewStatus().withReplicas(1).withObservedGeneration(1L).endStatus().build();
    ReplicaSet replicaSet1 = new ReplicaSetBuilder().withNewMetadata().withName("rs1").addToLabels("key1", "value1").withResourceVersion("1").withGeneration(1L).endMetadata().withNewSpec().withNewSelector().addToMatchLabels("key1", "value1").endSelector().withReplicas(0).endSpec().withNewStatus().withReplicas(1).withObservedGeneration(1L).endStatus().build();
    Deployment deployment2 = new DeploymentBuilder().withNewMetadata().withName("deployment2").addToLabels("key2", "value2").withResourceVersion("1").withGeneration(1L).endMetadata().withNewSpec().withNewSelector().addToMatchLabels("key2", "value2").endSelector().withReplicas(0).endSpec().withNewStatus().withReplicas(1).withObservedGeneration(1L).endStatus().build();
    server.expect().withPath("/apis/apps/v1/namespaces/test/deployments/deployment1").andReturn(200, deployment1).once();
    server.expect().withPath("/apis/apps/v1/namespaces/test/deployments/deployment1").andReturn(200, new DeploymentBuilder(deployment1).editSpec().withReplicas(0).endSpec().build()).times(5);
    server.expect().withPath("/apis/apps/v1/namespaces/test/replicasets?labelSelector=key1%3Dvalue1").andReturn(200, new ReplicaSetListBuilder().addToItems(replicaSet1).build()).once();
    server.expect().withPath("/apis/apps/v1/namespaces/test/replicasets/rs1").andReturn(200, replicaSet1).once();
    server.expect().withPath("/apis/apps/v1/namespaces/ns1/deployments/deployment2").andReturn(200, deployment2).once();
    server.expect().withPath("/apis/apps/v1/namespaces/ns1/deployments/deployment2").andReturn(200, new DeploymentBuilder(deployment2).editSpec().withReplicas(0).endSpec().build()).times(5);
    Boolean deleted = client.apps().deployments().withName("deployment1").delete();
    assertTrue(deleted);
    deleted = client.apps().deployments().withName("deployment2").delete();
    assertFalse(deleted);
    deleted = client.apps().deployments().inNamespace("ns1").withName("deployment2").delete();
    assertTrue(deleted);
}
Also used : ReplicaSetBuilder(io.fabric8.kubernetes.api.model.apps.ReplicaSetBuilder) ReplicaSetListBuilder(io.fabric8.kubernetes.api.model.apps.ReplicaSetListBuilder) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) ReplicaSet(io.fabric8.kubernetes.api.model.apps.ReplicaSet) DeploymentBuilder(io.fabric8.kubernetes.api.model.apps.DeploymentBuilder) Test(org.junit.jupiter.api.Test)

Example 54 with ReplicaSet

use of io.fabric8.kubernetes.api.model.apps.ReplicaSet in project kubernetes-client by fabric8io.

the class DeploymentTest method testDeploymentGetLog.

@Test
@DisplayName("Should get logs for a Deployment")
void testDeploymentGetLog() {
    // Given
    ReplicaSet replicaSet = createMockReplicaSet("deploy1", "136581bf-82c2-4675-af05-63c55500b378", "deploy1-hk9nf", Collections.singletonMap("app", "nginx"), "3Dc4c8746c-94fd-47a7-ac01-11047c0323b4");
    Pod deployPod = createMockPod("1", "3Dc4c8746c-94fd-47a7-ac01-11047c0323b4", "deploy1-hk9nf", Collections.singletonMap("controller-uid", "3Dc4c8746c-94fd-47a7-ac01-11047c0323b4"));
    server.expect().get().withPath("/apis/apps/v1/namespaces/ns1/deployments/deploy1").andReturn(HttpURLConnection.HTTP_OK, createDeploymentBuilder().build()).always();
    server.expect().get().withPath("/apis/apps/v1/namespaces/ns1/replicasets?labelSelector=app%3Dnginx").andReturn(HttpURLConnection.HTTP_OK, new ReplicaSetListBuilder().withItems(replicaSet).build()).once();
    server.expect().get().withPath("/apis/apps/v1/namespaces/ns1/replicasets/deploy1-hk9nf").andReturn(HttpURLConnection.HTTP_OK, replicaSet).once();
    server.expect().get().withPath("/api/v1/namespaces/ns1/pods?labelSelector=app%3Dnginx").andReturn(HttpURLConnection.HTTP_OK, new PodListBuilder().withItems(deployPod).build()).once();
    server.expect().get().withPath("/api/v1/namespaces/ns1/pods/deploy1-hk9nf/log?pretty=false").andReturn(HttpURLConnection.HTTP_OK, "hello").once();
    // When
    String log = client.apps().deployments().inNamespace("ns1").withName("deploy1").getLog();
    // Then
    assertNotNull(log);
    assertEquals("hello", log);
}
Also used : PodListBuilder(io.fabric8.kubernetes.api.model.PodListBuilder) Pod(io.fabric8.kubernetes.api.model.Pod) ReplicaSetListBuilder(io.fabric8.kubernetes.api.model.apps.ReplicaSetListBuilder) ReplicaSet(io.fabric8.kubernetes.api.model.apps.ReplicaSet) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 55 with ReplicaSet

use of io.fabric8.kubernetes.api.model.apps.ReplicaSet in project kubernetes-client by fabric8io.

the class ReplicaSetOperationsImpl method updateImage.

@Override
public ReplicaSet updateImage(String image) {
    ReplicaSet oldRC = get();
    if (oldRC == null) {
        throw new KubernetesClientException("Existing replication controller doesn't exist");
    }
    if (oldRC.getSpec().getTemplate().getSpec().getContainers().size() > 1) {
        throw new KubernetesClientException("Image update is not supported for multicontainer pods");
    }
    if (oldRC.getSpec().getTemplate().getSpec().getContainers().isEmpty()) {
        throw new KubernetesClientException("Pod has no containers!");
    }
    Container container = oldRC.getSpec().getTemplate().getSpec().getContainers().iterator().next();
    return updateImage(Collections.singletonMap(container.getName(), image));
}
Also used : Container(io.fabric8.kubernetes.api.model.Container) ReplicaSet(io.fabric8.kubernetes.api.model.apps.ReplicaSet) KubernetesClientException(io.fabric8.kubernetes.client.KubernetesClientException)

Aggregations

ReplicaSet (io.fabric8.kubernetes.api.model.apps.ReplicaSet)50 ReplicationController (io.fabric8.kubernetes.api.model.ReplicationController)26 Deployment (io.fabric8.kubernetes.api.model.apps.Deployment)22 DeploymentConfig (io.fabric8.openshift.api.model.DeploymentConfig)22 Test (org.junit.Test)19 ReplicaSetBuilder (io.fabric8.kubernetes.api.model.apps.ReplicaSetBuilder)18 ReplicaSet (io.fabric8.kubernetes.api.model.extensions.ReplicaSet)17 Test (org.junit.jupiter.api.Test)15 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)14 OpenShiftClient (io.fabric8.openshift.client.OpenShiftClient)14 Pod (io.fabric8.kubernetes.api.model.Pod)13 Deployment (io.fabric8.kubernetes.api.model.extensions.Deployment)10 KubernetesListBuilder (io.fabric8.kubernetes.api.model.KubernetesListBuilder)9 ReplicationControllerSpec (io.fabric8.kubernetes.api.model.ReplicationControllerSpec)9 ReplicaSetSpec (io.fabric8.kubernetes.api.model.apps.ReplicaSetSpec)9 DeploymentConfigSpec (io.fabric8.openshift.api.model.DeploymentConfigSpec)9 LabelSelector (io.fabric8.kubernetes.api.model.LabelSelector)8 Container (io.fabric8.kubernetes.api.model.Container)7 DaemonSet (io.fabric8.kubernetes.api.model.apps.DaemonSet)7 DeploymentSpec (io.fabric8.kubernetes.api.model.apps.DeploymentSpec)7