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