Search in sources :

Example 1 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.apps.ReplicaSetList) RollableScalableResource(io.fabric8.kubernetes.client.dsl.RollableScalableResource) ArrayList(java.util.ArrayList) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) ReplicaSet(io.fabric8.kubernetes.api.model.apps.ReplicaSet)

Example 2 with ReplicaSetList

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

the class ReplicaSetIT method list.

@Test
public void list() {
    ReplicaSetList replicaSetList = client.apps().replicaSets().inNamespace(session.getNamespace()).list();
    assertThat(replicaSetList).isNotNull();
    assertTrue(replicaSetList.getItems().size() >= 1);
}
Also used : ReplicaSetList(io.fabric8.kubernetes.api.model.apps.ReplicaSetList) Test(org.junit.Test)

Example 3 with ReplicaSetList

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

the class ResourceIT method testDeleteExistingWithOrphanDeletion.

@Test
public void testDeleteExistingWithOrphanDeletion() throws Exception {
    // 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 NOT to match later, meaning the orphan WAS 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.delete();
    resource.waitUntilCondition(Objects::isNull, 30, TimeUnit.SECONDS);
    resource.create();
    final Callable<List<ReplicaSet>> replicaSets = () -> client.apps().replicaSets().inNamespace(session.getNamespace()).withLabel("run", deploymentName).list().getItems().stream().filter(rs -> Utils.isNullOrEmpty(rs.getMetadata().getDeletionTimestamp())).collect(Collectors.toList());
    await().atMost(30, TimeUnit.SECONDS).until(() -> resourceIsReady(deployment).call() && replicaSets.call().size() == 1);
    // check that uid DOES NOT MATCH original, meaning the orphan WAS deleted
    assertNotEquals(replicaSetUid, replicaSets.call().iterator().next().getMetadata().getUid());
    // cleanup
    assertEquals(true, resource.withGracePeriod(0L).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().isEmpty());
}
Also used : ReplicaSet(io.fabric8.kubernetes.api.model.apps.ReplicaSet) DeletionPropagation(io.fabric8.kubernetes.api.model.DeletionPropagation) BeforeClass(org.junit.BeforeClass) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) RunWith(org.junit.runner.RunWith) Session(org.arquillian.cube.kubernetes.api.Session) Callable(java.util.concurrent.Callable) DeploymentSpecBuilder(io.fabric8.kubernetes.api.model.apps.DeploymentSpecBuilder) Resource(io.fabric8.kubernetes.client.dsl.Resource) Utils(io.fabric8.kubernetes.client.utils.Utils) TestCase.assertNotNull(junit.framework.TestCase.assertNotNull) ClusterEntity(io.fabric8.commons.ClusterEntity) PodBuilder(io.fabric8.kubernetes.api.model.PodBuilder) After(org.junit.After) ArquillianResource(org.jboss.arquillian.test.api.ArquillianResource) ContainerBuilder(io.fabric8.kubernetes.api.model.ContainerBuilder) ArquillianConditionalRunner(org.arquillian.cube.requirement.ArquillianConditionalRunner) Service(io.fabric8.kubernetes.api.model.Service) ServiceBuilder(io.fabric8.kubernetes.api.model.ServiceBuilder) ObjectMetaBuilder(io.fabric8.kubernetes.api.model.ObjectMetaBuilder) Before(org.junit.Before) PodTemplateSpecBuilder(io.fabric8.kubernetes.api.model.PodTemplateSpecBuilder) KubernetesList(io.fabric8.kubernetes.api.model.KubernetesList) AfterClass(org.junit.AfterClass) Awaitility.await(org.awaitility.Awaitility.await) KubernetesListBuilder(io.fabric8.kubernetes.api.model.KubernetesListBuilder) ReplicaSetList(io.fabric8.kubernetes.api.model.apps.ReplicaSetList) Pod(io.fabric8.kubernetes.api.model.Pod) Assert.assertTrue(org.junit.Assert.assertTrue) RequiresKubernetes(org.arquillian.cube.kubernetes.impl.requirement.RequiresKubernetes) Test(org.junit.Test) UUID(java.util.UUID) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) PodListBuilder(io.fabric8.kubernetes.api.model.PodListBuilder) Collectors(java.util.stream.Collectors) DeploymentBuilder(io.fabric8.kubernetes.api.model.apps.DeploymentBuilder) Assert.assertNotEquals(org.junit.Assert.assertNotEquals) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) ConfigMapBuilder(io.fabric8.kubernetes.api.model.ConfigMapBuilder) Objects(java.util.Objects) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) Assert(org.junit.Assert) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) ReplicaSetList(io.fabric8.kubernetes.api.model.apps.ReplicaSetList) Objects(java.util.Objects) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) KubernetesList(io.fabric8.kubernetes.api.model.KubernetesList) ReplicaSetList(io.fabric8.kubernetes.api.model.apps.ReplicaSetList) List(java.util.List) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) Test(org.junit.Test)

Example 4 with ReplicaSetList

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

the class DeleteIT method testDeleteWithPropagationPolicyOrphan.

@Test
public void testDeleteWithPropagationPolicyOrphan() {
    // Given
    String name = "deleteit-existent-orphan";
    // When
    Boolean isDeleted = client.apps().deployments().inNamespace(session.getNamespace()).withName(name).withPropagationPolicy(DeletionPropagation.ORPHAN).delete();
    // Then
    ReplicaSetList replicaSetList = client.apps().replicaSets().inNamespace(session.getNamespace()).withLabel("test", name).list();
    assertTrue(isDeleted);
    assertNotNull(replicaSetList);
    assertEquals(1, replicaSetList.getItems().size());
    assertTrue(client.resource(replicaSetList.getItems().get(0)).inNamespace(session.getNamespace()).delete());
}
Also used : ReplicaSetList(io.fabric8.kubernetes.api.model.apps.ReplicaSetList) Test(org.junit.Test)

Example 5 with ReplicaSetList

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

the class DeleteIT method testDeleteResourcePropagationPolicyOrphan.

@Test
public void testDeleteResourcePropagationPolicyOrphan() {
    // Given
    String name = "deleteit-resource-orphan";
    // When
    Deployment deploy = client.apps().deployments().inNamespace(session.getNamespace()).withName(name).get();
    Boolean isDeleted = client.resource(deploy).inNamespace(session.getNamespace()).withPropagationPolicy(DeletionPropagation.ORPHAN).delete();
    // Then
    ReplicaSetList replicaSetList = client.apps().replicaSets().inNamespace(session.getNamespace()).withLabel("test", name).list();
    assertTrue(isDeleted);
    assertNotNull(replicaSetList);
    assertEquals(1, replicaSetList.getItems().size());
    assertTrue(client.resource(replicaSetList.getItems().get(0)).inNamespace(session.getNamespace()).delete());
}
Also used : ReplicaSetList(io.fabric8.kubernetes.api.model.apps.ReplicaSetList) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) Test(org.junit.Test)

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