Search in sources :

Example 56 with ReplicaSet

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

the class ReplicaSetTest method testGetLogMultiContainer.

@Test
void testGetLogMultiContainer() {
    ReplicaSet replicaSet = createReplicaSetBuilder().build();
    server.expect().get().withPath("/apis/apps/v1/namespaces/ns1/replicasets/replicaset1").andReturn(HttpURLConnection.HTTP_OK, replicaSet).times(3);
    server.expect().get().withPath("/api/v1/namespaces/ns1/pods?labelSelector=" + Utils.toUrlEncoded("app=nginx")).andReturn(HttpURLConnection.HTTP_OK, getReplicaSetPodList(replicaSet)).once();
    server.expect().get().withPath("/api/v1/namespaces/ns1/pods/pod1/log?pretty=true&container=c1").andReturn(HttpURLConnection.HTTP_OK, "testlog").once();
    // When
    String log = client.apps().replicaSets().inNamespace("ns1").withName("replicaset1").inContainer("c1").getLog(true);
    // Then
    assertNotNull(log);
    assertEquals("testlog", log);
}
Also used : ReplicaSet(io.fabric8.kubernetes.api.model.apps.ReplicaSet) Test(org.junit.jupiter.api.Test)

Example 57 with ReplicaSet

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

the class ReplicaSetTest method testScale.

@Test
void testScale() {
    server.expect().withPath("/apis/apps/v1/namespaces/test/replicasets/repl1").andReturn(200, new ReplicaSetBuilder().withNewMetadata().withName("repl1").withResourceVersion("1").endMetadata().withNewSpec().withReplicas(5).endSpec().withNewStatus().withReplicas(1).endStatus().build()).always();
    ReplicaSet repl = client.apps().replicaSets().withName("repl1").scale(5);
    assertNotNull(repl);
    assertNotNull(repl.getSpec());
    assertEquals(5, repl.getSpec().getReplicas().intValue());
    assertEquals(1, repl.getStatus().getReplicas().intValue());
}
Also used : ReplicaSetBuilder(io.fabric8.kubernetes.api.model.apps.ReplicaSetBuilder) ReplicaSet(io.fabric8.kubernetes.api.model.apps.ReplicaSet) Test(org.junit.jupiter.api.Test)

Example 58 with ReplicaSet

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

the class ReplicaSetTest method testRolloutUpdateSingleImage.

@Test
@DisplayName("Should update image based in single argument")
void testRolloutUpdateSingleImage() throws InterruptedException {
    // Given
    String imageToUpdate = "nginx:latest";
    server.expect().get().withPath("/apis/apps/v1/namespaces/ns1/replicasets/replicaset1").andReturn(HttpURLConnection.HTTP_OK, createReplicaSetBuilder().build()).times(3);
    server.expect().patch().withPath("/apis/apps/v1/namespaces/ns1/replicasets/replicaset1").andReturn(HttpURLConnection.HTTP_OK, createReplicaSetBuilder().editSpec().editTemplate().editSpec().editContainer(0).withImage(imageToUpdate).endContainer().endSpec().endTemplate().endSpec().build()).times(2);
    // When
    ReplicaSet replicationController = client.apps().replicaSets().inNamespace("ns1").withName("replicaset1").rolling().updateImage(imageToUpdate);
    // Then
    assertNotNull(replicationController);
    assertEquals(imageToUpdate, replicationController.getSpec().getTemplate().getSpec().getContainers().get(0).getImage());
    int requestCount = server.getRequestCount();
    assertTrue(server.getLastRequest().getBody().readUtf8().contains(imageToUpdate));
}
Also used : ReplicaSet(io.fabric8.kubernetes.api.model.apps.ReplicaSet) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 59 with ReplicaSet

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

the class ReplicaSetTest method testGet.

@Test
void testGet() {
    server.expect().withPath("/apis/apps/v1/namespaces/test/replicasets/repl1").andReturn(200, new ReplicaSetBuilder().build()).once();
    server.expect().withPath("/apis/apps/v1/namespaces/ns1/replicasets/repl2").andReturn(200, new ReplicaSetBuilder().build()).once();
    ReplicaSet repl1 = client.apps().replicaSets().withName("repl1").get();
    assertNotNull(repl1);
    repl1 = client.apps().replicaSets().withName("repl2").get();
    assertNull(repl1);
    repl1 = client.apps().replicaSets().inNamespace("ns1").withName("repl2").get();
    assertNotNull(repl1);
}
Also used : ReplicaSetBuilder(io.fabric8.kubernetes.api.model.apps.ReplicaSetBuilder) ReplicaSet(io.fabric8.kubernetes.api.model.apps.ReplicaSet) Test(org.junit.jupiter.api.Test)

Example 60 with ReplicaSet

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

the class ReplicaSetV1beta1Test method testCreateOrReplace.

@Test
void testCreateOrReplace() {
    ReplicaSet oldReplicaSet = new ReplicaSetBuilder().withApiVersion("extensions/v1beta1").withNewMetadata().withName("test-replicaset").endMetadata().build();
    ReplicaSet newReplicaSet = new ReplicaSetBuilder().withApiVersion("extensions/v1beta1").withNewMetadata().withName("test-deployment").withAnnotations(Collections.singletonMap("newAnnotation", "test")).endMetadata().build();
    server.expect().post().withPath("/apis/extensions/v1beta1/namespaces/test/replicasets").andReturn(HttpURLConnection.HTTP_CONFLICT, oldReplicaSet).once();
    server.expect().get().withPath("/apis/extensions/v1beta1/namespaces/test/replicasets/test-deployment").andReturn(HttpURLConnection.HTTP_OK, oldReplicaSet).times(2);
    server.expect().put().withPath("/apis/extensions/v1beta1/namespaces/test/replicasets/test-deployment").andReturn(HttpURLConnection.HTTP_OK, newReplicaSet).once();
    ReplicaSet result = client.extensions().replicaSets().inNamespace("test").createOrReplace(newReplicaSet);
    assertNotNull(result);
    assertEquals(newReplicaSet, result);
}
Also used : ReplicaSetBuilder(io.fabric8.kubernetes.api.model.extensions.ReplicaSetBuilder) ReplicaSet(io.fabric8.kubernetes.api.model.extensions.ReplicaSet) Test(org.junit.jupiter.api.Test)

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