From da9d444d2913114aad95047091d759809a5287b1 Mon Sep 17 00:00:00 2001 From: Pasechnik Bogdan Date: Tue, 13 Oct 2020 14:17:40 +0300 Subject: [PATCH 1/3] job maker --- src/Core/Job/AbstractJob.php | 83 ++++++++++++++++++++++++++++++++++ src/Core/Job/JobInterface.php | 18 ++++++++ src/ResourceMaker/JobMaker.php | 72 +++++++++++++++++++++++++++++ 3 files changed, 173 insertions(+) create mode 100644 src/Core/Job/AbstractJob.php create mode 100644 src/Core/Job/JobInterface.php create mode 100644 src/ResourceMaker/JobMaker.php diff --git a/src/Core/Job/AbstractJob.php b/src/Core/Job/AbstractJob.php new file mode 100644 index 0000000..e300dc5 --- /dev/null +++ b/src/Core/Job/AbstractJob.php @@ -0,0 +1,83 @@ +specProcessor = $specProcessor; + } + + /** + * @param ManifestInterface|JobInterface $manifest + * @param AppInterface $app + * + * @return Job + */ + protected function makeResource(ManifestInterface $manifest, AppInterface $app): Job + { + $job = new Job(); + + $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; + } +} \ No newline at end of file From 7c857bddad403dccfc79b053928216bb29788736 Mon Sep 17 00:00:00 2001 From: Pasechnik Bogdan Date: Tue, 13 Oct 2020 18:27:52 +0300 Subject: [PATCH 2/3] job maker --- src/Core/Job/AbstractJob.php | 5 +++++ src/Core/Job/JobInterface.php | 2 ++ src/ResourceMaker/JobMaker.php | 4 ++++ 3 files changed, 11 insertions(+) diff --git a/src/Core/Job/AbstractJob.php b/src/Core/Job/AbstractJob.php index e300dc5..24e2204 100644 --- a/src/Core/Job/AbstractJob.php +++ b/src/Core/Job/AbstractJob.php @@ -5,6 +5,7 @@ use Dealroadshow\K8S\API\Batch\Job; use Dealroadshow\K8S\Data\Collection\StringMap; use Dealroadshow\K8S\Data\PodSpec; +use Dealroadshow\K8S\Framework\Core\LabelSelector\LabelSelectorConfigurator; use Dealroadshow\K8S\Framework\Core\MetadataConfigurator; use Dealroadshow\K8S\Framework\Core\Pod\Affinity\AffinityConfigurator; use Dealroadshow\K8S\Framework\Core\Pod\Containers\PodContainers; @@ -14,6 +15,10 @@ abstract class AbstractJob implements JobInterface { + public function labelSelector(LabelSelectorConfigurator $selector): void + { + } + public function backoffLimit(): ?int { return null; diff --git a/src/Core/Job/JobInterface.php b/src/Core/Job/JobInterface.php index daf60bb..1bb0267 100644 --- a/src/Core/Job/JobInterface.php +++ b/src/Core/Job/JobInterface.php @@ -3,11 +3,13 @@ namespace Dealroadshow\K8S\Framework\Core\Job; use Dealroadshow\K8S\API\Batch\Job; +use Dealroadshow\K8S\Framework\Core\LabelSelector\LabelSelectorConfigurator; use Dealroadshow\K8S\Framework\Core\ManifestInterface; use Dealroadshow\K8S\Framework\Core\Pod\PodTemplateSpecInterface; interface JobInterface extends PodTemplateSpecInterface, ManifestInterface { + public function labelSelector(LabelSelectorConfigurator $selector): void; public function backoffLimit(): ?int; public function activeDeadlineSeconds(): ?int; public function ttlSecondsAfterFinished(): ?int; diff --git a/src/ResourceMaker/JobMaker.php b/src/ResourceMaker/JobMaker.php index 98fbe7b..7221fde 100644 --- a/src/ResourceMaker/JobMaker.php +++ b/src/ResourceMaker/JobMaker.php @@ -5,6 +5,7 @@ use Dealroadshow\K8S\API\Batch\Job; use Dealroadshow\K8S\Framework\App\AppInterface; use Dealroadshow\K8S\Framework\Core\Job\JobInterface; +use Dealroadshow\K8S\Framework\Core\LabelSelector\LabelSelectorConfigurator; use Dealroadshow\K8S\Framework\Core\ManifestInterface; use Dealroadshow\K8S\Framework\Core\Pod\PodTemplateSpecProcessor; @@ -27,6 +28,9 @@ protected function makeResource(ManifestInterface $manifest, AppInterface $app): { $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); From f952abdd5776e08da423fd8ae55e11a1514e82a9 Mon Sep 17 00:00:00 2001 From: Pasechnik Bogdan Date: Tue, 13 Oct 2020 19:22:34 +0300 Subject: [PATCH 3/3] job maker --- src/Core/Job/JobInterface.php | 2 +- src/ResourceMaker/JobMaker.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Core/Job/JobInterface.php b/src/Core/Job/JobInterface.php index 1bb0267..3e92462 100644 --- a/src/Core/Job/JobInterface.php +++ b/src/Core/Job/JobInterface.php @@ -17,4 +17,4 @@ public function completions(): ?int; public function manualSelector(): ?bool; public function parallelism(): ?int; public function configureJob(Job $job): void; -} \ No newline at end of file +} diff --git a/src/ResourceMaker/JobMaker.php b/src/ResourceMaker/JobMaker.php index 7221fde..b0828d1 100644 --- a/src/ResourceMaker/JobMaker.php +++ b/src/ResourceMaker/JobMaker.php @@ -73,4 +73,4 @@ protected function supportsClass(): string { return JobInterface::class; } -} \ No newline at end of file +}