diff --git a/src/Core/Job/AbstractJob.php b/src/Core/Job/AbstractJob.php new file mode 100644 index 0000000..24e2204 --- /dev/null +++ b/src/Core/Job/AbstractJob.php @@ -0,0 +1,88 @@ +specProcessor = $specProcessor; + } + + /** + * @param ManifestInterface|JobInterface $manifest + * @param AppInterface $app + * + * @return Job + */ + protected function makeResource(ManifestInterface $manifest, AppInterface $app): Job + { + $job = new Job(); + + $labelSelector = new LabelSelectorConfigurator($job->spec()->selector()); + $manifest->labelSelector($labelSelector); + + $app->metadataHelper()->configureMeta($manifest, $job); + $this->specProcessor->process($manifest, $job->spec()->template(), $app); + + $spec = $job->spec(); + foreach ($spec->selector()->matchLabels()->all() as $name => $value) { + $job->metadata()->labels()->add($name, $value); + $job->spec()->template()->metadata()->labels()->add($name, $value); + } + + $backoffLimit = $manifest->backoffLimit(); + $activeDeadlineSeconds = $manifest->activeDeadlineSeconds(); + $ttlSecondsAfterFinished = $manifest->ttlSecondsAfterFinished(); + $completions = $manifest->completions(); + $manualSelector = $manifest->manualSelector(); + $parallelism = $manifest->parallelism(); + if (null !== $backoffLimit) { + $spec->setBackoffLimit($backoffLimit); + } + if (null !== $activeDeadlineSeconds) { + $spec->setActiveDeadlineSeconds($activeDeadlineSeconds); + } + if (null !== $ttlSecondsAfterFinished) { + $spec->setTtlSecondsAfterFinished($ttlSecondsAfterFinished); + } + if (null !== $completions) { + $spec->setCompletions($completions); + } + if (null !== $manualSelector) { + $spec->setManualSelector($manualSelector); + } + if (null !== $parallelism) { + $spec->setParallelism($parallelism); + } + $manifest->configureJob($job); + + return $job; + } + + protected function supportsClass(): string + { + return JobInterface::class; + } +}