Skip to content

Commit

Permalink
Middleware (#6)
Browse files Browse the repository at this point in the history
* MiddlewareInterface
  • Loading branch information
bpasfinsight authored Oct 21, 2020
1 parent 8d907ec commit 22e2de2
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
26 changes: 25 additions & 1 deletion src/Core/Container/ContainerMaker.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,30 @@
use Dealroadshow\K8S\Data\Container;
use Dealroadshow\K8S\Framework\App\AppInterface;
use Dealroadshow\K8S\Framework\Core\Container\Env\EnvConfigurator;
use Dealroadshow\K8S\Framework\Core\Container\Image\Image;
use Dealroadshow\K8S\Framework\Core\Container\Lifecycle\LifecycleConfigurator;
use Dealroadshow\K8S\Framework\Core\Container\Lifecycle\Probes\ProbesConfigurator;
use Dealroadshow\K8S\Framework\Core\Container\Ports\PortsConfigurator;
use Dealroadshow\K8S\Framework\Core\Container\Resources\ResourcesConfigurator;
use Dealroadshow\K8S\Framework\Core\Container\Security\SecurityContextConfigurator;
use Dealroadshow\K8S\Framework\Core\Container\VolumeMount\VolumeMountsConfigurator;
use Dealroadshow\K8S\Framework\Middleware\ContainerImageMiddlewareInterface;

class ContainerMaker
{
/**
* @var ContainerImageMiddlewareInterface[]|iterable
*/
private iterable $middlewares;

/**
* @param ContainerImageMiddlewareInterface[] $middlewares
*/
public function __construct(iterable $middlewares)
{
$this->middlewares = $middlewares;
}

public function make(ContainerInterface $builder, VolumeList $volumes, AppInterface $app): Container
{
$container = new Container($builder->name());
Expand Down Expand Up @@ -44,7 +59,9 @@ public function make(ContainerInterface $builder, VolumeList $volumes, AppInterf
);
$builder->probes($probes);

$container->setImage($builder->image()->fullName());
$image = $builder->image();
$this->applyMiddlewares($image, $app);
$container->setImage($image->fullName());
$pullPolicy = $builder->imagePullPolicy();
if (null !== $pullPolicy) {
$container->setImagePullPolicy($pullPolicy->toString());
Expand All @@ -62,4 +79,11 @@ public function make(ContainerInterface $builder, VolumeList $volumes, AppInterf

return $container;
}

private function applyMiddlewares(Image $image, AppInterface $app)
{
foreach ($this->middlewares as $middleware) {
$middleware->apply($image, $app);
}
}
}
2 changes: 1 addition & 1 deletion src/Core/ManifestProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class ManifestProcessor
private iterable $makers;

/**
* @param ResourceMakerInterface[]|iterable
* @param ResourceMakerInterface[] $makers
*/
public function __construct(iterable $makers)
{
Expand Down
12 changes: 12 additions & 0 deletions src/Middleware/ContainerImageMiddlewareInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

namespace Dealroadshow\K8S\Framework\Middleware;

use Dealroadshow\K8S\Framework\App\AppInterface;
use Dealroadshow\K8S\Framework\Core\Container\Image\Image;

interface ContainerImageMiddlewareInterface
{
public function apply(Image $image, AppInterface $app): void;
public function priority(): int;
}

0 comments on commit 22e2de2

Please sign in to comment.