Search in sources :

Example 1 with ReplicaSetListBuilder

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

the class ReplicaSetTest method testUpdate.

@Disabled
@Test
void testUpdate() {
    ReplicaSet repl1 = new ReplicaSetBuilder().withNewMetadata().withName("repl1").withNamespace("test").endMetadata().withNewSpec().withReplicas(1).withNewTemplate().withNewMetadata().withLabels(new HashMap<String, String>()).endMetadata().withNewSpec().addNewContainer().withImage("img1").endContainer().endSpec().endTemplate().endSpec().withNewStatus().withReplicas(1).endStatus().build();
    server.expect().withPath("/apis/apps/v1/namespaces/test/replicasets/repl1").andReturn(200, repl1).once();
    server.expect().put().withPath("/apis/apps/v1/namespaces/test/replicasets/repl1").andReturn(200, repl1).once();
    server.expect().get().withPath("/apis/apps/v1/namespaces/test/replicasets").andReturn(200, new ReplicaSetListBuilder().withItems(repl1).build()).once();
    server.expect().post().withPath("/apis/apps/v1/namespaces/test/replicasets").andReturn(201, repl1).once();
    server.expect().withPath("/apis/apps/v1/namespaces/test/pods").andReturn(200, new KubernetesListBuilder().build()).once();
    repl1 = client.apps().replicaSets().withName("repl1").rolling().withTimeout(5, TimeUnit.MINUTES).updateImage("");
    assertNotNull(repl1);
}
Also used : ReplicaSetBuilder(io.fabric8.kubernetes.api.model.apps.ReplicaSetBuilder) KubernetesListBuilder(io.fabric8.kubernetes.api.model.KubernetesListBuilder) ReplicaSetListBuilder(io.fabric8.kubernetes.api.model.apps.ReplicaSetListBuilder) ReplicaSet(io.fabric8.kubernetes.api.model.apps.ReplicaSet) Test(org.junit.jupiter.api.Test) Disabled(org.junit.jupiter.api.Disabled)

Example 2 with ReplicaSetListBuilder

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

the class ReplicaSetTest method testScaleAndWait.

@Test
void testScaleAndWait() {
    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()).once();
    ReplicaSet scaled = new ReplicaSetBuilder().withNewMetadata().withName("repl1").withResourceVersion("1").endMetadata().withNewSpec().withReplicas(5).endSpec().withNewStatus().withReplicas(5).endStatus().build();
    // patch
    server.expect().withPath("/apis/apps/v1/namespaces/test/replicasets/repl1").andReturn(200, scaled).once();
    // list for waiting
    server.expect().withPath("/apis/apps/v1/namespaces/test/replicasets?fieldSelector=metadata.name%3Drepl1").andReturn(200, new ReplicaSetListBuilder().withItems(scaled).withMetadata(new ListMetaBuilder().build()).build()).always();
    ReplicaSet repl = client.apps().replicaSets().withName("repl1").scale(5, true);
    assertNotNull(repl);
    assertNotNull(repl.getSpec());
    assertEquals(5, repl.getSpec().getReplicas().intValue());
    assertEquals(5, repl.getStatus().getReplicas().intValue());
}
Also used : ReplicaSetBuilder(io.fabric8.kubernetes.api.model.apps.ReplicaSetBuilder) ListMetaBuilder(io.fabric8.kubernetes.api.model.ListMetaBuilder) ReplicaSetListBuilder(io.fabric8.kubernetes.api.model.apps.ReplicaSetListBuilder) ReplicaSet(io.fabric8.kubernetes.api.model.apps.ReplicaSet) Test(org.junit.jupiter.api.Test)

Example 3 with ReplicaSetListBuilder

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

the class DeploymentTest method testRolloutUndo.

@Test
@DisplayName("Should undo rollout")
void testRolloutUndo() throws InterruptedException {
    // Given
    ReplicaSet replicaSetRevision1 = new ReplicaSetBuilder().withNewMetadata().addToAnnotations("deployment.kubernetes.io/revision", "1").withName("rs1").endMetadata().withNewSpec().withReplicas(0).withNewSelector().addToMatchLabels("app", "nginx").endSelector().withNewTemplate().withNewMetadata().addToAnnotations("kubectl.kubernetes.io/restartedAt", "2020-06-08T11:52:50.022").addToAnnotations("app", "rs1").addToLabels("app", "nginx").endMetadata().withNewSpec().addNewContainer().withName("nginx").withImage("nginx:perl").addNewPort().withContainerPort(80).endPort().endContainer().endSpec().endTemplate().endSpec().build();
    ReplicaSet replicaSetRevision2 = new ReplicaSetBuilder().withNewMetadata().addToAnnotations("deployment.kubernetes.io/revision", "2").withName("rs2").endMetadata().withNewSpec().withReplicas(1).withNewSelector().addToMatchLabels("app", "nginx").endSelector().withNewTemplate().withNewMetadata().addToAnnotations("kubectl.kubernetes.io/restartedAt", "2020-06-08T11:52:50.022").addToAnnotations("app", "rs2").addToLabels("app", "nginx").endMetadata().withNewSpec().addNewContainer().withName("nginx").withImage("nginx:1.19").addNewPort().withContainerPort(80).endPort().endContainer().endSpec().endTemplate().endSpec().build();
    server.expect().get().withPath("/apis/apps/v1/namespaces/ns1/replicasets?labelSelector=" + Utils.toUrlEncoded("app=nginx")).andReturn(HttpURLConnection.HTTP_OK, new ReplicaSetListBuilder().withItems(replicaSetRevision1, replicaSetRevision2).build()).once();
    server.expect().get().withPath("/apis/apps/v1/namespaces/ns1/deployments/deploy1").andReturn(HttpURLConnection.HTTP_OK, createDeploymentBuilder().build()).times(3);
    server.expect().patch().withPath("/apis/apps/v1/namespaces/ns1/deployments/deploy1").andReturn(HttpURLConnection.HTTP_OK, createDeploymentBuilder().build()).once();
    // When
    Deployment deployment = client.apps().deployments().inNamespace("ns1").withName("deploy1").rolling().undo();
    // Then
    RecordedRequest recordedRequest = server.getLastRequest();
    assertNotNull(deployment);
    assertEquals("PATCH", recordedRequest.getMethod());
    assertTrue(recordedRequest.getBody().readUtf8().contains("\"app\":\"rs1\""));
}
Also used : ReplicaSetBuilder(io.fabric8.kubernetes.api.model.apps.ReplicaSetBuilder) RecordedRequest(okhttp3.mockwebserver.RecordedRequest) ReplicaSetListBuilder(io.fabric8.kubernetes.api.model.apps.ReplicaSetListBuilder) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) ReplicaSet(io.fabric8.kubernetes.api.model.apps.ReplicaSet) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 4 with ReplicaSetListBuilder

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

the class DeploymentTest method testDeploymentGetLogMultiContainer.

@Test
void testDeploymentGetLogMultiContainer() {
    // Given
    ReplicaSet replicaSet = createMockReplicaSet("deploy-multi1", "93b8b619-731a-435a-bcb0-4b0c19f07f2f", "multi-container-deploy-5dfdf5ddfc", Collections.singletonMap("app", "nginx"), "f9ed6d37-9256-44aa-93b0-4af70e046348");
    Pod deployPod = createMockPod("multi-container-deploy-5dfdf5ddfc", "f9ed6d37-9256-44aa-93b0-4af70e046348", "multi-container-deploy-5dfdf5ddfc-r6q4j", Collections.singletonMap("controller-uid", "f9ed6d37-9256-44aa-93b0-4af70e046348"));
    server.expect().get().withPath("/apis/apps/v1/namespaces/ns1/deployments/deploy-multi1").andReturn(HttpURLConnection.HTTP_OK, createDeploymentBuilder().editMetadata().withName("deploy-multi1").withUid("93b8b619-731a-435a-bcb0-4b0c19f07f2f").endMetadata().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/multi-container-deploy-5dfdf5ddfc").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/multi-container-deploy-5dfdf5ddfc-r6q4j/log?pretty=false&container=container1").andReturn(HttpURLConnection.HTTP_OK, "hello").once();
    // When
    String log = client.apps().deployments().inNamespace("ns1").withName("deploy-multi1").inContainer("container1").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)

Example 5 with ReplicaSetListBuilder

use of io.fabric8.kubernetes.api.model.apps.ReplicaSetListBuilder 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)

Aggregations

ReplicaSetListBuilder (io.fabric8.kubernetes.api.model.apps.ReplicaSetListBuilder)7 Test (org.junit.jupiter.api.Test)7 ReplicaSet (io.fabric8.kubernetes.api.model.apps.ReplicaSet)6 ReplicaSetBuilder (io.fabric8.kubernetes.api.model.apps.ReplicaSetBuilder)4 Pod (io.fabric8.kubernetes.api.model.Pod)2 PodListBuilder (io.fabric8.kubernetes.api.model.PodListBuilder)2 Deployment (io.fabric8.kubernetes.api.model.apps.Deployment)2 DisplayName (org.junit.jupiter.api.DisplayName)2 KubernetesListBuilder (io.fabric8.kubernetes.api.model.KubernetesListBuilder)1 ListMetaBuilder (io.fabric8.kubernetes.api.model.ListMetaBuilder)1 DeploymentBuilder (io.fabric8.kubernetes.api.model.apps.DeploymentBuilder)1 ReplicaSetList (io.fabric8.kubernetes.api.model.apps.ReplicaSetList)1 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)1 Disabled (org.junit.jupiter.api.Disabled)1