Search in sources :

Example 1 with KubernetesClientUtils

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);
}
Also used : V1Deployment(io.kubernetes.client.openapi.models.V1Deployment) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) DisruptiveScript(bio.terra.testrunner.runner.DisruptiveScript) Calendar(java.util.Calendar) Logger(org.slf4j.Logger) TestUserSpecification(bio.terra.testrunner.runner.config.TestUserSpecification) LocalDateTime(java.time.LocalDateTime) LoggerFactory(org.slf4j.LoggerFactory) KubernetesClientUtils(bio.terra.testrunner.common.utils.KubernetesClientUtils) Collectors(java.util.stream.Collectors) V1Deployment(io.kubernetes.client.openapi.models.V1Deployment) Calendar(java.util.Calendar)

Aggregations

KubernetesClientUtils (bio.terra.testrunner.common.utils.KubernetesClientUtils)1 DisruptiveScript (bio.terra.testrunner.runner.DisruptiveScript)1 TestUserSpecification (bio.terra.testrunner.runner.config.TestUserSpecification)1 V1Deployment (io.kubernetes.client.openapi.models.V1Deployment)1 LocalDateTime (java.time.LocalDateTime)1 Calendar (java.util.Calendar)1 List (java.util.List)1 TimeUnit (java.util.concurrent.TimeUnit)1 Collectors (java.util.stream.Collectors)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1