-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from dealroadshow/job_maker
job maker
- Loading branch information
Showing
3 changed files
with
184 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
<?php | ||
|
||
namespace Dealroadshow\K8S\Framework\Core\Job; | ||
|
||
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; | ||
use Dealroadshow\K8S\Framework\Core\Pod\ImagePullSecrets\ImagePullSecretsConfigurator; | ||
use Dealroadshow\K8S\Framework\Core\Pod\Policy\RestartPolicy; | ||
use Dealroadshow\K8S\Framework\Core\Pod\Volume\VolumesConfigurator; | ||
|
||
abstract class AbstractJob implements JobInterface | ||
{ | ||
public function labelSelector(LabelSelectorConfigurator $selector): void | ||
{ | ||
} | ||
|
||
public function backoffLimit(): ?int | ||
{ | ||
return null; | ||
} | ||
|
||
public function activeDeadlineSeconds(): ?int | ||
{ | ||
return null; | ||
} | ||
|
||
public function ttlSecondsAfterFinished(): ?int | ||
{ | ||
return null; | ||
} | ||
|
||
public function completions(): ?int | ||
{ | ||
return null; | ||
} | ||
|
||
public function manualSelector(): ?bool | ||
{ | ||
return null; | ||
} | ||
|
||
public function parallelism(): ?int | ||
{ | ||
return null; | ||
} | ||
|
||
public function configureMeta(MetadataConfigurator $meta): void | ||
{ | ||
} | ||
|
||
public function affinity(AffinityConfigurator $affinity): void | ||
{ | ||
} | ||
|
||
public function initContainers(PodContainers $containers): void | ||
{ | ||
} | ||
|
||
public function imagePullSecrets(ImagePullSecretsConfigurator $secrets): void | ||
{ | ||
} | ||
|
||
public function nodeSelector(StringMap $nodeSelector): void | ||
{ | ||
} | ||
|
||
public function volumes(VolumesConfigurator $volumes): void | ||
{ | ||
} | ||
|
||
public function restartPolicy(): ?RestartPolicy | ||
{ | ||
return null; | ||
} | ||
|
||
public function configurePodSpec(PodSpec $spec): void | ||
{ | ||
} | ||
|
||
public function configureJob(Job $job): void | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
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; | ||
public function completions(): ?int; | ||
public function manualSelector(): ?bool; | ||
public function parallelism(): ?int; | ||
public function configureJob(Job $job): void; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
<?php | ||
|
||
namespace Dealroadshow\K8S\Framework\ResourceMaker; | ||
|
||
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; | ||
|
||
class JobMaker extends AbstractResourceMaker | ||
{ | ||
private PodTemplateSpecProcessor $specProcessor; | ||
|
||
public function __construct(PodTemplateSpecProcessor $specProcessor) | ||
{ | ||
$this->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; | ||
} | ||
} |