Search in sources :

Example 1 with KubernetesExecutorParameters

use of pipelite.stage.parameters.KubernetesExecutorParameters in project pipelite by enasequence.

the class SingleStageKubernetesTestProcessConfiguration method configure.

@Override
protected void configure(ProcessBuilder builder) {
    KubernetesExecutorParameters.KubernetesExecutorParametersBuilder<?, ?> executorParamsBuilder = KubernetesExecutorParameters.builder();
    executorParamsBuilder.namespace(kubernetesTestConfiguration.getNamespace()).timeout(Duration.ofSeconds(180)).maximumRetries(maximumRetries()).immediateRetries(immediateRetries());
    KubernetesExecutorParameters executorParams = executorParamsBuilder.build();
    executorParams.setPermanentErrors(testType().permanentErrors());
    builder.execute(stageName()).withKubernetesExecutor(testType().image(), testType().nextImageArgs(pipelineName(), builder.getProcessId(), stageName()), executorParams);
}
Also used : KubernetesExecutorParameters(pipelite.stage.parameters.KubernetesExecutorParameters)

Example 2 with KubernetesExecutorParameters

use of pipelite.stage.parameters.KubernetesExecutorParameters in project pipelite by enasequence.

the class KubernetesExecutor method submit.

@Override
protected SubmitResult submit(StageExecutorRequest request) {
    KubernetesExecutorParameters executorParams = getExecutorParams();
    context = executorParams.getContext();
    namespace = executorParams.getNamespace() != null ? executorParams.getNamespace() : "default";
    String jobId = createJobId();
    logContext(log.atFine(), request).log("Submitting Kubernetes job " + jobId);
    // Map<String, String> labelMap = new HashMap<>();
    // labelMap.put(..., ...);
    Map<String, Quantity> requestsMap = new HashMap<>();
    requestsMap.put("cpu", executorParams.getMemory());
    requestsMap.put("memory", executorParams.getCpu());
    Map<String, Quantity> limitsMap = new HashMap<>();
    limitsMap.put("cpu", executorParams.getMemoryLimit());
    limitsMap.put("memory", executorParams.getCpuLimit());
    try (KubernetesClient client = kubernetesClient(context)) {
        Job job = new JobBuilder().withApiVersion("batch/v1").withNewMetadata().withName(jobId).endMetadata().withNewSpec().withBackoffLimit(1).withTtlSecondsAfterFinished(KUBERNETES_TTL_SECONDS_AFTER_FINISHED).withNewTemplate().withNewSpec().addNewContainer().withName(jobId).withImage(image).withArgs(imageArgs).withNewResources().withRequests(requestsMap).withLimits(limitsMap).endResources().endContainer().withRestartPolicy("Never").endSpec().endTemplate().endSpec().build();
        RetryTask.DEFAULT.execute(r -> client.batch().v1().jobs().inNamespace(namespace).create(job));
        logContext(log.atInfo(), request).log("Submitted Kubernetes job " + jobId);
    } catch (KubernetesClientException e) {
        throw new PipeliteException("Kubernetes error", e);
    }
    return new SubmitResult(jobId, StageExecutorResult.submitted());
}
Also used : DefaultKubernetesClient(io.fabric8.kubernetes.client.DefaultKubernetesClient) KubernetesClient(io.fabric8.kubernetes.client.KubernetesClient) Quantity(io.fabric8.kubernetes.api.model.Quantity) PipeliteException(pipelite.exception.PipeliteException) KubernetesExecutorParameters(pipelite.stage.parameters.KubernetesExecutorParameters) KubernetesClientException(io.fabric8.kubernetes.client.KubernetesClientException)

Example 3 with KubernetesExecutorParameters

use of pipelite.stage.parameters.KubernetesExecutorParameters in project pipelite by enasequence.

the class KubernetesDescribeJobsCacheTest method test.

@Test
public void test() {
    KubernetesDescribeJobsCache cache = new KubernetesDescribeJobsCache(Mockito.mock(ServiceConfiguration.class), Mockito.mock(InternalErrorService.class));
    KubernetesExecutorParameters namespace1 = KubernetesExecutorParameters.builder().namespace("1").build();
    KubernetesExecutorParameters namespace2 = KubernetesExecutorParameters.builder().namespace("2").build();
    KubernetesExecutor executor1Namespace1 = new KubernetesExecutor();
    KubernetesExecutor executor2Namespace1 = new KubernetesExecutor();
    KubernetesExecutor executor3Namespace2 = new KubernetesExecutor();
    KubernetesExecutor executor4Namespace1 = new KubernetesExecutor();
    executor1Namespace1.setExecutorParams(namespace1);
    executor2Namespace1.setExecutorParams(namespace1);
    executor3Namespace2.setExecutorParams(namespace2);
    executor4Namespace1.setExecutorParams(namespace1);
    assertThat(cache.getCacheContext(executor1Namespace1).getNamespace()).isEqualTo(namespace1.getNamespace());
    assertThat(cache.getCacheContext(executor2Namespace1).getNamespace()).isEqualTo(namespace1.getNamespace());
    assertThat(cache.getCacheContext(executor3Namespace2).getNamespace()).isEqualTo(namespace2.getNamespace());
    assertThat(cache.getCacheContext(executor4Namespace1).getNamespace()).isEqualTo(namespace1.getNamespace());
    DescribeJobs<String, KubernetesDescribeJobsCache.ExecutorContext> describeJobs1 = cache.getDescribeJobs(executor1Namespace1);
    DescribeJobs<String, KubernetesDescribeJobsCache.ExecutorContext> describeJobs2 = cache.getDescribeJobs(executor2Namespace1);
    DescribeJobs<String, KubernetesDescribeJobsCache.ExecutorContext> describeJobs3 = cache.getDescribeJobs(executor3Namespace2);
    DescribeJobs<String, KubernetesDescribeJobsCache.ExecutorContext> describeJobs4 = cache.getDescribeJobs(executor4Namespace1);
    assertThat(describeJobs1 == describeJobs2).isTrue();
    assertThat(describeJobs1 != describeJobs3).isTrue();
    assertThat(describeJobs1 == describeJobs4).isTrue();
}
Also used : ServiceConfiguration(pipelite.configuration.ServiceConfiguration) KubernetesDescribeJobsCache(pipelite.executor.describe.cache.KubernetesDescribeJobsCache) InternalErrorService(pipelite.service.InternalErrorService) KubernetesExecutorParameters(pipelite.stage.parameters.KubernetesExecutorParameters) KubernetesExecutor(pipelite.executor.KubernetesExecutor) Test(org.junit.jupiter.api.Test)

Aggregations

KubernetesExecutorParameters (pipelite.stage.parameters.KubernetesExecutorParameters)3 Quantity (io.fabric8.kubernetes.api.model.Quantity)1 DefaultKubernetesClient (io.fabric8.kubernetes.client.DefaultKubernetesClient)1 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)1 KubernetesClientException (io.fabric8.kubernetes.client.KubernetesClientException)1 Test (org.junit.jupiter.api.Test)1 ServiceConfiguration (pipelite.configuration.ServiceConfiguration)1 PipeliteException (pipelite.exception.PipeliteException)1 KubernetesExecutor (pipelite.executor.KubernetesExecutor)1 KubernetesDescribeJobsCache (pipelite.executor.describe.cache.KubernetesDescribeJobsCache)1 InternalErrorService (pipelite.service.InternalErrorService)1