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