Search in sources :

Example 26 with ReplicaSet

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

the class ReplicaSetOperationsImpl method updateImage.

@Override
public ReplicaSet updateImage(Map<String, String> containerToImageMap) {
    ReplicaSet replicationController = get();
    if (replicationController == null) {
        throw new KubernetesClientException("Existing replica set doesn't exist");
    }
    if (replicationController.getSpec().getTemplate().getSpec().getContainers().isEmpty()) {
        throw new KubernetesClientException("Pod has no containers!");
    }
    List<Container> containers = replicationController.getSpec().getTemplate().getSpec().getContainers();
    for (Container container : containers) {
        if (containerToImageMap.containsKey(container.getName())) {
            container.setImage(containerToImageMap.get(container.getName()));
        }
    }
    replicationController.getSpec().getTemplate().getSpec().setContainers(containers);
    return sendPatchedObject(get(), replicationController);
}
Also used : Container(io.fabric8.kubernetes.api.model.Container) ReplicaSet(io.fabric8.kubernetes.api.model.apps.ReplicaSet) KubernetesClientException(io.fabric8.kubernetes.client.KubernetesClientException)

Example 27 with ReplicaSet

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

the class ReplicaSetOperationsImpl method updateImage.

@Override
public ReplicaSet updateImage(Map<String, String> containerToImageMap) {
    ReplicaSet replicationController = get();
    if (replicationController == null) {
        throw new KubernetesClientException("Existing replica set doesn't exist");
    }
    if (replicationController.getSpec().getTemplate().getSpec().getContainers().isEmpty()) {
        throw new KubernetesClientException("Pod has no containers!");
    }
    List<Container> containers = replicationController.getSpec().getTemplate().getSpec().getContainers();
    for (Container container : containers) {
        if (containerToImageMap.containsKey(container.getName())) {
            container.setImage(containerToImageMap.get(container.getName()));
        }
    }
    replicationController.getSpec().getTemplate().getSpec().setContainers(containers);
    return sendPatchedObject(get(), replicationController);
}
Also used : Container(io.fabric8.kubernetes.api.model.Container) ReplicaSet(io.fabric8.kubernetes.api.model.extensions.ReplicaSet) KubernetesClientException(io.fabric8.kubernetes.client.KubernetesClientException)

Example 28 with ReplicaSet

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

the class ReplicaSetOperationsImpl method updateImage.

@Override
public ReplicaSet updateImage(String image) {
    ReplicaSet oldRC = get();
    if (oldRC == null) {
        throw new KubernetesClientException("Existing replication controller doesn't exist");
    }
    if (oldRC.getSpec().getTemplate().getSpec().getContainers().size() > 1) {
        throw new KubernetesClientException("Image update is not supported for multicontainer pods");
    }
    if (oldRC.getSpec().getTemplate().getSpec().getContainers().isEmpty()) {
        throw new KubernetesClientException("Pod has no containers!");
    }
    Container container = oldRC.getSpec().getTemplate().getSpec().getContainers().iterator().next();
    return updateImage(Collections.singletonMap(container.getName(), image));
}
Also used : Container(io.fabric8.kubernetes.api.model.Container) ReplicaSet(io.fabric8.kubernetes.api.model.extensions.ReplicaSet) KubernetesClientException(io.fabric8.kubernetes.client.KubernetesClientException)

Example 29 with ReplicaSet

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

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

the class DeleteIT method testDeleteResource.

@Test
public void testDeleteResource() {
    // Given
    String name = "deleteit-resource";
    // When
    ReplicaSet replicaSet = client.apps().replicaSets().inNamespace(session.getNamespace()).withName(name).get();
    Boolean isDeleted = client.resource(replicaSet).inNamespace(session.getNamespace()).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)

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 ReplicaSet (io.fabric8.kubernetes.api.model.extensions.ReplicaSet)17 ReplicaSetBuilder (io.fabric8.kubernetes.api.model.apps.ReplicaSetBuilder)16 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)14 OpenShiftClient (io.fabric8.openshift.client.OpenShiftClient)14 Test (org.junit.jupiter.api.Test)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