Skip to content

Commit

Permalink
Few more methods on DeploymentInterface
Browse files Browse the repository at this point in the history
  • Loading branch information
petr-buchyn committed Oct 7, 2020
1 parent b89ffb3 commit b7fa438
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
25 changes: 25 additions & 0 deletions src/Core/Deployment/AbstractDeployment.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -20,6 +22,10 @@ public function initContainers(PodContainers $containers): void
{
}

public function configureMeta(MetadataConfigurator $meta): void
{
}

public function imagePullSecrets(ImagePullSecretsConfigurator $secrets): void
{
}
Expand All @@ -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
{
}
}
5 changes: 5 additions & 0 deletions src/Core/Deployment/DeploymentInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@

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;

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;
}
17 changes: 16 additions & 1 deletion src/ResourceMaker/DeploymentMaker.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit b7fa438

Please sign in to comment.