Search in sources :

Example 66 with ReplicaSet

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

the class DeleteIT method testDeleteResourceCascading.

@Test
public void testDeleteResourceCascading() {
    // Given
    String name = "deleteit-resource-cascading";
    // When
    ReplicaSet replicaSet = client.apps().replicaSets().inNamespace(session.getNamespace()).withName(name).get();
    Boolean isDeleted = client.resource(replicaSet).inNamespace(session.getNamespace()).cascading(true).delete();
    // Then
    assertTrue(isDeleted);
    DeleteEntity<ReplicaSet> deleteEntity = new DeleteEntity<>(ReplicaSet.class, client, name, session.getNamespace());
    await().atMost(30, TimeUnit.SECONDS).until(deleteEntity);
}
Also used : DeleteEntity(io.fabric8.commons.DeleteEntity) ReplicaSet(io.fabric8.kubernetes.api.model.apps.ReplicaSet) Test(org.junit.Test)

Example 67 with ReplicaSet

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

the class DeploymentOperationsImpl method undo.

@Override
public Deployment undo() {
    List<ReplicaSet> replicaSets = getReplicaSetListForDeployment(get()).getItems();
    // Sort list of replicaSets based on revision annotation
    replicaSets.sort((o1, o2) -> {
        String revisionO1 = o1.getMetadata().getAnnotations().get(DEPLOYMENT_KUBERNETES_IO_REVISION);
        String revisionO2 = o2.getMetadata().getAnnotations().get(DEPLOYMENT_KUBERNETES_IO_REVISION);
        return Integer.parseInt(revisionO2) - Integer.parseInt(revisionO1);
    });
    ReplicaSet latestReplicaSet = replicaSets.get(0);
    ReplicaSet previousRevisionReplicaSet = replicaSets.get(1);
    Deployment deployment = get();
    deployment.getMetadata().getAnnotations().put(DEPLOYMENT_KUBERNETES_IO_REVISION, latestReplicaSet.getMetadata().getAnnotations().get(DEPLOYMENT_KUBERNETES_IO_REVISION));
    deployment.getSpec().setTemplate(previousRevisionReplicaSet.getSpec().getTemplate());
    return sendPatchedObject(get(), deployment);
}
Also used : Deployment(io.fabric8.kubernetes.api.model.extensions.Deployment) ReplicaSet(io.fabric8.kubernetes.api.model.extensions.ReplicaSet)

Example 68 with ReplicaSet

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

Example 69 with ReplicaSet

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

the class Readiness method isReplicaSetReady.

public static boolean isReplicaSetReady(ReplicaSet r) {
    Utils.checkNotNull(r, "ReplicationController can't be null.");
    ReplicaSetSpec spec = r.getSpec();
    ReplicaSetStatus status = r.getStatus();
    if (status == null || status.getReadyReplicas() == null) {
        return false;
    }
    // Can be true in testing, so handle it to make test writing easier.
    if (spec == null || spec.getReplicas() == null) {
        return false;
    }
    return spec.getReplicas().intValue() == status.getReadyReplicas();
}
Also used : ReplicaSetSpec(io.fabric8.kubernetes.api.model.apps.ReplicaSetSpec) ReplicaSetStatus(io.fabric8.kubernetes.api.model.apps.ReplicaSetStatus)

Example 70 with ReplicaSet

use of io.fabric8.kubernetes.api.model.apps.ReplicaSet in project che-server by eclipse-che.

the class ContainerSearchTest method setup.

@BeforeMethod
public void setup() {
    // These are all the object types that can be contained in a KubernetesList which can contain a
    // container:
    // Pod, PodTemplate, DaemonSet, Deployment, Job, ReplicaSet, ReplicationController, StatefulSet,
    // CronJob, DeploymentConfig, Template
    Container container1 = new ContainerBuilder().withName("container1").build();
    Container container2 = new ContainerBuilder().withName("container2").build();
    Container container3 = new ContainerBuilder().withName("container3").build();
    Container container4 = new ContainerBuilder().withName("container4").build();
    Container container5 = new ContainerBuilder().withName("container5").build();
    Container container6 = new ContainerBuilder().withName("container6").build();
    Container container7 = new ContainerBuilder().withName("container7").build();
    Container container8 = new ContainerBuilder().withName("container8").build();
    Container container9 = new ContainerBuilder().withName("container9").build();
    Container container10 = new ContainerBuilder().withName("container10").build();
    Container container11 = new ContainerBuilder().withName("container11").build();
    Container container12 = new ContainerBuilder().withName("container12").build();
    Pod podWithName = new PodBuilder().withNewMetadata().withName("podWithName").addToLabels("app", "che").endMetadata().withNewSpec().withContainers(container1).endSpec().build();
    Pod podWithGenerateName = new PodBuilder().withNewMetadata().withGenerateName("podWithGenerateName").endMetadata().withNewSpec().withContainers(container2).endSpec().build();
    PodTemplate podTemplate = new PodTemplateBuilder().withNewMetadata().withName("podTemplate").addToLabels("app", "che").endMetadata().withNewTemplate().withNewSpec().withContainers(container3).endSpec().endTemplate().build();
    DaemonSet daemonSet = new DaemonSetBuilder().withNewMetadata().withName("daemonSet").endMetadata().withNewSpec().withNewTemplate().withNewSpec().withContainers(container4).endSpec().endTemplate().endSpec().build();
    Deployment deployment = new DeploymentBuilder().withNewMetadata().withName("deployment").addToLabels("app", "che").endMetadata().withNewSpec().withNewTemplate().withNewMetadata().withName("podWithName").endMetadata().withNewSpec().withContainers(container5).endSpec().endTemplate().endSpec().build();
    Job job = new JobBuilder().withNewMetadata().withName("job").endMetadata().withNewSpec().withNewTemplate().withNewSpec().withContainers(container6).endSpec().endTemplate().endSpec().build();
    ReplicaSet replicaSet = new ReplicaSetBuilder().withNewMetadata().withName("replicaSet").addToLabels("app", "che").endMetadata().withNewSpec().withNewTemplate().withNewSpec().withContainers(container7).endSpec().endTemplate().endSpec().build();
    ReplicationController replicationController = new ReplicationControllerBuilder().withNewMetadata().withName("replicationController").endMetadata().withNewSpec().withNewTemplate().withNewSpec().withContainers(container8).endSpec().endTemplate().endSpec().build();
    StatefulSet statefulSet = new StatefulSetBuilder().withNewMetadata().withName("statefulSet").addToLabels("app", "che").endMetadata().withNewSpec().withNewTemplate().withNewSpec().withContainers(container9).endSpec().endTemplate().endSpec().build();
    CronJob cronJob = new CronJobBuilder().withNewMetadata().withName("cronJob").endMetadata().withNewSpec().withNewJobTemplate().withNewSpec().withNewTemplate().withNewSpec().withContainers(container10).endSpec().endTemplate().endSpec().endJobTemplate().endSpec().build();
    DeploymentConfig deploymentConfig = new DeploymentConfigBuilder().withNewMetadata().withName("deploymentConfig").addToLabels("app", "che").endMetadata().withNewSpec().withNewTemplate().withNewSpec().withContainers(container11).endSpec().endTemplate().endSpec().build();
    Template template = new TemplateBuilder().addToObjects(new DeploymentBuilder().withNewMetadata().withName("deploymentWithName").endMetadata().withNewSpec().withNewTemplate().withNewMetadata().withName("podWithName").endMetadata().withNewSpec().withContainers(container12).endSpec().endTemplate().endSpec().build()).build();
    // Pod, PodTemplate, DaemonSet, Deployment, Job, ReplicaSet, ReplicationController, StatefulSet,
    // CronJob, DeploymentConfig, Template
    testList = asList(podWithName, podWithGenerateName, podTemplate, daemonSet, deployment, job, replicaSet, replicationController, statefulSet, cronJob, deploymentConfig, template);
}
Also used : ReplicaSetBuilder(io.fabric8.kubernetes.api.model.apps.ReplicaSetBuilder) PodTemplateBuilder(io.fabric8.kubernetes.api.model.PodTemplateBuilder) Pod(io.fabric8.kubernetes.api.model.Pod) ReplicationControllerBuilder(io.fabric8.kubernetes.api.model.ReplicationControllerBuilder) PodBuilder(io.fabric8.kubernetes.api.model.PodBuilder) TemplateBuilder(io.fabric8.openshift.api.model.TemplateBuilder) PodTemplateBuilder(io.fabric8.kubernetes.api.model.PodTemplateBuilder) CronJobBuilder(io.fabric8.kubernetes.api.model.batch.v1.CronJobBuilder) JobBuilder(io.fabric8.kubernetes.api.model.batch.v1.JobBuilder) DeploymentConfigBuilder(io.fabric8.openshift.api.model.DeploymentConfigBuilder) Deployment(io.fabric8.kubernetes.api.model.apps.Deployment) CronJobBuilder(io.fabric8.kubernetes.api.model.batch.v1.CronJobBuilder) StatefulSetBuilder(io.fabric8.kubernetes.api.model.apps.StatefulSetBuilder) PodTemplate(io.fabric8.kubernetes.api.model.PodTemplate) Template(io.fabric8.openshift.api.model.Template) DaemonSetBuilder(io.fabric8.kubernetes.api.model.apps.DaemonSetBuilder) Container(io.fabric8.kubernetes.api.model.Container) ContainerBuilder(io.fabric8.kubernetes.api.model.ContainerBuilder) CronJob(io.fabric8.kubernetes.api.model.batch.v1.CronJob) ReplicationController(io.fabric8.kubernetes.api.model.ReplicationController) DaemonSet(io.fabric8.kubernetes.api.model.apps.DaemonSet) CronJob(io.fabric8.kubernetes.api.model.batch.v1.CronJob) Job(io.fabric8.kubernetes.api.model.batch.v1.Job) StatefulSet(io.fabric8.kubernetes.api.model.apps.StatefulSet) DeploymentConfig(io.fabric8.openshift.api.model.DeploymentConfig) ReplicaSet(io.fabric8.kubernetes.api.model.apps.ReplicaSet) DeploymentBuilder(io.fabric8.kubernetes.api.model.apps.DeploymentBuilder) PodTemplate(io.fabric8.kubernetes.api.model.PodTemplate) BeforeMethod(org.testng.annotations.BeforeMethod)

Aggregations

ReplicaSet (io.fabric8.kubernetes.api.model.apps.ReplicaSet)50 ReplicationController (io.fabric8.kubernetes.api.model.ReplicationController)26 Deployment (io.fabric8.kubernetes.api.model.apps.Deployment)22 DeploymentConfig (io.fabric8.openshift.api.model.DeploymentConfig)22 Test (org.junit.Test)19 ReplicaSetBuilder (io.fabric8.kubernetes.api.model.apps.ReplicaSetBuilder)18 ReplicaSet (io.fabric8.kubernetes.api.model.extensions.ReplicaSet)17 Test (org.junit.jupiter.api.Test)15 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)14 OpenShiftClient (io.fabric8.openshift.client.OpenShiftClient)14 Pod (io.fabric8.kubernetes.api.model.Pod)13 Deployment (io.fabric8.kubernetes.api.model.extensions.Deployment)10 KubernetesListBuilder (io.fabric8.kubernetes.api.model.KubernetesListBuilder)9 ReplicationControllerSpec (io.fabric8.kubernetes.api.model.ReplicationControllerSpec)9 ReplicaSetSpec (io.fabric8.kubernetes.api.model.apps.ReplicaSetSpec)9 DeploymentConfigSpec (io.fabric8.openshift.api.model.DeploymentConfigSpec)9 LabelSelector (io.fabric8.kubernetes.api.model.LabelSelector)8 Container (io.fabric8.kubernetes.api.model.Container)7 DaemonSet (io.fabric8.kubernetes.api.model.apps.DaemonSet)7 DeploymentSpec (io.fabric8.kubernetes.api.model.apps.DeploymentSpec)7