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