Search in sources :

Example 6 with ReplicaSetList

use of io.fabric8.kubernetes.api.model.apps.ReplicaSetList in project nivio by dedica-team.

the class CreateItemsTest method getReplicaSetItems.

@Test
void getReplicaSetItems() {
    var replicaSet = new ReplicaSetBuilder().withNewMetadata().withName("replicaSet").withLabels(Map.of("testLabelKey", "testLabelValue")).withOwnerReferences(new OwnerReferenceBuilder().withUid("testOwnerUid").build()).withNamespace("test").endMetadata().withNewSpec().withReplicas(1).endSpec().withNewStatus().addNewCondition().withType("testType").withStatus("testStatus").endCondition().withReadyReplicas(1).endStatus().build();
    kubernetesClient.apps().replicaSets().create(replicaSet);
    var replicaSetList = CreateItems.getReplicaSetItems(kubernetesClient);
    assertThat(replicaSetList).isNotNull();
    assertThat(replicaSetList.size()).isOne();
    assertThat(replicaSetList.get(0).getItemAdapter().getLabels()).containsExactly(entry("testLabelKey", "testLabelValue"));
    assertThat(replicaSetList.get(0).getItemAdapter().getOwnerReferences().size()).isOne();
    assertThat(replicaSetList.get(0).getItemAdapter().getOwnerReferences().get(0).getUid()).isEqualTo("testOwnerUid");
    assertThat(replicaSetList.get(0).getClass()).isEqualTo(K8sItem.class);
    assertThat(replicaSetList.get(0).getType()).isEqualTo(ItemType.REPLICASET);
    var testDetails = replicaSetList.get(0).getDetails();
    testDetails.remove("creation");
    assertThat(testDetails).isEqualTo(Map.of(InputFormatHandlerKubernetes.LABEL_PREFIX + ".replicacondition.replicas", "1;1", "name", "replicaSet", "namespace", "test"));
}
Also used : ReplicaSetBuilder(io.fabric8.kubernetes.api.model.apps.ReplicaSetBuilder) Test(org.junit.jupiter.api.Test)

Example 7 with ReplicaSetList

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

the class ReplicaSetTest method testList.

@Test
void testList() {
    server.expect().withPath("/apis/apps/v1/namespaces/test/replicasets").andReturn(200, new ReplicaSetListBuilder().build()).once();
    server.expect().withPath("/apis/apps/v1/namespaces/ns1/replicasets").andReturn(200, new ReplicaSetListBuilder().addNewItem().and().addNewItem().and().build()).once();
    ReplicaSetList replicaSetList = client.apps().replicaSets().list();
    assertNotNull(replicaSetList);
    assertEquals(0, replicaSetList.getItems().size());
    replicaSetList = client.apps().replicaSets().inNamespace("ns1").list();
    assertNotNull(replicaSetList);
    assertEquals(2, replicaSetList.getItems().size());
}
Also used : ReplicaSetListBuilder(io.fabric8.kubernetes.api.model.apps.ReplicaSetListBuilder) ReplicaSetList(io.fabric8.kubernetes.api.model.apps.ReplicaSetList) Test(org.junit.jupiter.api.Test)

Example 8 with ReplicaSetList

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

the class ResourceIT method testDeleteExistingWithoutOrphanDeletion.

@Test
public void testDeleteExistingWithoutOrphanDeletion() {
    // Create Deployment
    Resource<Deployment> resource = client.resource(deployment).inNamespace(session.getNamespace());
    resource.createOrReplace();
    await().atMost(30, TimeUnit.SECONDS).until(resourceIsReady(deployment));
    // get uid of underlying replicaset. we expect this to match later, meaning the orphan was not deleted.
    ReplicaSetList replicaSetList = client.apps().replicaSets().inNamespace(session.getNamespace()).withLabel("run", deploymentName).list();
    assertEquals(1, replicaSetList.getItems().size());
    String replicaSetUid = replicaSetList.getItems().get(0).getMetadata().getUid();
    // Recreate deployment
    resource.withPropagationPolicy(DeletionPropagation.ORPHAN).delete();
    resource.waitUntilCondition(Objects::isNull, 30, TimeUnit.SECONDS);
    resource.create();
    await().atMost(30, TimeUnit.SECONDS).until(resourceIsReady(deployment));
    // check that uid matches original, meaning the orphan was not deleted
    replicaSetList = client.apps().replicaSets().inNamespace(session.getNamespace()).withLabel("run", deploymentName).list();
    assertEquals(1, replicaSetList.getItems().size());
    assertEquals(replicaSetUid, replicaSetList.getItems().get(0).getMetadata().getUid());
    // cleanup
    assertEquals(true, resource.delete());
    // Check whether child resources are also deleted
    await().atMost(30, TimeUnit.SECONDS).until(() -> client.apps().replicaSets().inNamespace(session.getNamespace()).withLabel("run", deploymentName).list().getItems().size() == 0);
}
Also used : ReplicaSetList(io.fabric8.kubernetes.api.model.apps.ReplicaSetList) Objects(java.util.Objects) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) Test(org.junit.Test)

Example 9 with ReplicaSetList

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

the class DeploymentOperationsImpl method doGetLog.

private List<RollableScalableResource<ReplicaSet>> doGetLog() {
    List<RollableScalableResource<ReplicaSet>> rcs = new ArrayList<>();
    Deployment deployment = requireFromServer();
    String rcUid = deployment.getMetadata().getUid();
    ReplicaSetOperationsImpl rsOperations = new ReplicaSetOperationsImpl(new RollingOperationContext(rollingOperationContext.getContainerId(), false, 0, null, rollingOperationContext.getLogWaitTimeout()), context.withName(null));
    ReplicaSetList rcList = rsOperations.withLabels(getDeploymentSelectorLabels(deployment)).list();
    for (ReplicaSet rs : rcList.getItems()) {
        OwnerReference ownerReference = KubernetesResourceUtil.getControllerUid(rs);
        if (ownerReference != null && ownerReference.getUid().equals(rcUid)) {
            rcs.add(rsOperations.withName(rs.getMetadata().getName()));
        }
    }
    return rcs;
}
Also used : RollingOperationContext(io.fabric8.kubernetes.client.dsl.internal.RollingOperationContext) OwnerReference(io.fabric8.kubernetes.api.model.OwnerReference) ReplicaSetList(io.fabric8.kubernetes.api.model.extensions.ReplicaSetList) RollableScalableResource(io.fabric8.kubernetes.client.dsl.RollableScalableResource) ArrayList(java.util.ArrayList) Deployment(io.fabric8.kubernetes.api.model.extensions.Deployment) ReplicaSet(io.fabric8.kubernetes.api.model.extensions.ReplicaSet)

Aggregations

ReplicaSetList (io.fabric8.kubernetes.api.model.apps.ReplicaSetList)7 Test (org.junit.Test)5 Deployment (io.fabric8.kubernetes.api.model.apps.Deployment)4 IntOrString (io.fabric8.kubernetes.api.model.IntOrString)2 OwnerReference (io.fabric8.kubernetes.api.model.OwnerReference)2 ReplicaSet (io.fabric8.kubernetes.api.model.apps.ReplicaSet)2 RollableScalableResource (io.fabric8.kubernetes.client.dsl.RollableScalableResource)2 RollingOperationContext (io.fabric8.kubernetes.client.dsl.internal.RollingOperationContext)2 ArrayList (java.util.ArrayList)2 Objects (java.util.Objects)2 ClusterEntity (io.fabric8.commons.ClusterEntity)1 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)1 ConfigMapBuilder (io.fabric8.kubernetes.api.model.ConfigMapBuilder)1 ContainerBuilder (io.fabric8.kubernetes.api.model.ContainerBuilder)1 DeletionPropagation (io.fabric8.kubernetes.api.model.DeletionPropagation)1 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)1 KubernetesList (io.fabric8.kubernetes.api.model.KubernetesList)1 KubernetesListBuilder (io.fabric8.kubernetes.api.model.KubernetesListBuilder)1 ObjectMetaBuilder (io.fabric8.kubernetes.api.model.ObjectMetaBuilder)1 Pod (io.fabric8.kubernetes.api.model.Pod)1