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