diff --git a/src/Core/Deployment/AbstractDeployment.php b/src/Core/Deployment/AbstractDeployment.php index 36cea34..266912e 100644 --- a/src/Core/Deployment/AbstractDeployment.php +++ b/src/Core/Deployment/AbstractDeployment.php @@ -2,8 +2,10 @@ namespace Dealroadshow\K8S\Framework\Core\Deployment; +use Dealroadshow\K8S\API\Apps\Deployment; use Dealroadshow\K8S\Data\Collection\StringMap; use Dealroadshow\K8S\Data\PodSpec; +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; @@ -20,6 +22,10 @@ public function initContainers(PodContainers $containers): void { } + public function configureMeta(MetadataConfigurator $meta): void + { + } + public function imagePullSecrets(ImagePullSecretsConfigurator $secrets): void { } @@ -40,4 +46,23 @@ public function restartPolicy(): ?RestartPolicy public function configurePodSpec(PodSpec $spec): void { } + + public function replicas(): int + { + return 1; + } + + public function minReadySeconds(): ?int + { + return null; + } + + public function progressDeadlineSeconds(): ?int + { + return null; + } + + public function configureDeployment(Deployment $deployment): void + { + } } diff --git a/src/Core/Deployment/DeploymentInterface.php b/src/Core/Deployment/DeploymentInterface.php index 49762e0..a472ca3 100644 --- a/src/Core/Deployment/DeploymentInterface.php +++ b/src/Core/Deployment/DeploymentInterface.php @@ -2,6 +2,7 @@ namespace Dealroadshow\K8S\Framework\Core\Deployment; +use Dealroadshow\K8S\API\Apps\Deployment; use Dealroadshow\K8S\Framework\Core\LabelSelector\LabelSelectorConfigurator; use Dealroadshow\K8S\Framework\Core\ManifestInterface; use Dealroadshow\K8S\Framework\Core\Pod\PodTemplateSpecInterface; @@ -9,4 +10,8 @@ interface DeploymentInterface extends PodTemplateSpecInterface, ManifestInterface { public function labelSelector(LabelSelectorConfigurator $selector): void; + public function replicas(): ?int; + public function minReadySeconds(): ?int; + public function progressDeadlineSeconds(): ?int; + public function configureDeployment(Deployment $deployment): void; } diff --git a/src/ResourceMaker/DeploymentMaker.php b/src/ResourceMaker/DeploymentMaker.php index 3bcc267..d7eecf2 100644 --- a/src/ResourceMaker/DeploymentMaker.php +++ b/src/ResourceMaker/DeploymentMaker.php @@ -34,11 +34,26 @@ public function makeResource(ManifestInterface $manifest, AppInterface $app): De $app->metadataHelper()->configureMeta($manifest, $deployment); $this->specProcessor->process($manifest, $deployment->spec()->template(), $app); - foreach ($deployment->spec()->selector()->matchLabels()->all() as $name => $value) { + $spec = $deployment->spec(); + foreach ($spec->selector()->matchLabels()->all() as $name => $value) { $deployment->metadata()->labels()->add($name, $value); $deployment->spec()->template()->metadata()->labels()->add($name, $value); } + $replicas = $manifest->replicas(); + $minReadySeconds = $manifest->minReadySeconds(); + $progressDeadlineSeconds = $manifest->progressDeadlineSeconds(); + if (null !== $replicas) { + $spec->setReplicas($replicas); + } + if (null !== $minReadySeconds) { + $spec->setMinReadySeconds($minReadySeconds); + } + if (null !== $progressDeadlineSeconds) { + $spec->setProgressDeadlineSeconds($progressDeadlineSeconds); + } + $manifest->configureDeployment($deployment); + return $deployment; }