use of bio.terra.testrunner.common.utils.KubernetesClientUtils in project terra-workspace-manager by DataBiosphere.
the class DeleteInitialPods method disrupt.
@Override
public void disrupt(List<TestUserSpecification> testUsers) throws Exception {
// give user journey threads time to get started before disruption
TimeUnit.SECONDS.sleep(SECONDS_TO_WAIT_BEFORE_STARTING_DISRUPT);
logger.info("Starting disruption - all initially created api pods will be deleted, one by one.");
String componentLabelKey = // e.g. "app.kubernetes.io/component";
KubernetesClientUtils.getComponentLabel();
String componentLabelVal = // e.g. "workspacemanager";
KubernetesClientUtils.getApiComponentLabel();
V1Deployment workspacemanagerDeployment = KubernetesClientUtils.getApiDeployment();
if (workspacemanagerDeployment == null) {
throw new RuntimeException("WorkspaceManager deployment not found.");
}
// TODO (QA-1421): refactor this out into a method of the Test Runner KubernetesClientUtils
// class.
List<String> podsToDelete = KubernetesClientUtils.listPods().stream().filter(pod -> pod.getMetadata().getLabels().containsKey(componentLabelKey) && pod.getMetadata().getLabels().get(componentLabelKey).equals(componentLabelVal)).map(pod -> pod.getMetadata().getName()).collect(Collectors.toList());
// delete original pods, and give them a chance to recover
for (String podName : podsToDelete) {
logger.debug("delete pod: {}", podName);
workspacemanagerDeployment = KubernetesClientUtils.getApiDeployment();
if (workspacemanagerDeployment != null) {
KubernetesClientUtils.printApiPods(workspacemanagerDeployment);
KubernetesClientUtils.deletePod(podName);
Calendar startWaiting = Calendar.getInstance();
logger.debug("start waiting for pod to recover at time {}", LocalDateTime.ofInstant(startWaiting.toInstant(), startWaiting.getTimeZone().toZoneId()));
TimeUnit.SECONDS.sleep(TIME_TO_WAIT);
KubernetesClientUtils.waitForReplicaSetSizeChange(workspacemanagerDeployment, podsToDelete.size());
Calendar endWaiting = Calendar.getInstance();
logger.debug("end waiting for pod to recover at time {}", LocalDateTime.ofInstant(endWaiting.toInstant(), endWaiting.getTimeZone().toZoneId()));
logger.debug("pod recovers in {} ms", endWaiting.getTimeInMillis() - startWaiting.getTimeInMillis());
}
}
logger.debug("original pods:");
podsToDelete.forEach(p -> logger.debug(p));
KubernetesClientUtils.printApiPods(workspacemanagerDeployment);
}
Aggregations