Skip to content

Commit

Permalink
Moving to PHP 8.0, using new version of dealroadshow/k8s-resources
Browse files Browse the repository at this point in the history
  • Loading branch information
petr-buchyn committed Dec 7, 2020
1 parent 9166f29 commit 6d0c2d6
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 104 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
"minimum-stability": "dev",
"prefer-stable": true,
"require": {
"php": ">=8.0",
"php": "^8.0",
"ext-json": "*",
"symfony/yaml": "^5.1",
"symfony/yaml": "^5.2",
"dealroadshow/k8s-resources": "^1.16 || ^1.17 || ^1.18 || ^1.19",
"symfony/polyfill-php80": "^1.18"
},
Expand Down
44 changes: 30 additions & 14 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 4 additions & 27 deletions src/Core/Container/Lifecycle/Action/ActionConfiguratorTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Dealroadshow\K8S\Data\HTTPGetAction;
use Dealroadshow\K8S\Data\TCPSocketAction;
use Dealroadshow\K8S\ValueObject\IntOrString;

trait ActionConfiguratorTrait
{
Expand All @@ -16,43 +15,21 @@ public function exec(array $command): void
$action->command()->addAll($command);
}

/**
* @param int|string $port
*
* @return HttpGetActionBuilder
*/
public function httpGet($port): HttpGetActionBuilder
public function httpGet(int|string $port): HttpGetActionBuilder
{
$action = new HTTPGetAction($this->getPort($port));
$action = new HTTPGetAction($port);
$this->handler->setHttpGet($action);

return new HttpGetActionBuilder($action);
}

public function tcpSocket($port, string $host = null): void
public function tcpSocket(int|string $port, string $host = null): void
{
$action = new TCPSocketAction($this->getPort($port));
$action = new TCPSocketAction($port);
if (null !== $host) {
$action->setHost($host);
}

$this->handler->setTcpSocket($action);
}

/**
* @param int|string $port
*
* @return IntOrString
*/
private function getPort($port): IntOrString
{
if (is_string($port)) {
return IntOrString::fromString($port);
}
if (is_int($port)) {
return IntOrString::fromInt($port);
}

throw new \TypeError('$port must be an int or a string');
}
}
5 changes: 2 additions & 3 deletions src/Core/Container/Resources/ContainerResourcesField.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Dealroadshow\K8S\Framework\Core\Container\Resources;

use Dealroadshow\K8S\Data\ResourceFieldSelector;
use Dealroadshow\K8S\ValueObject\Quantity;

class ContainerResourcesField
{
Expand All @@ -26,7 +25,7 @@ public function selector(): ResourceFieldSelector
return $this->selector;
}

public function setContainerName(?string $containerName): self
public function setContainerName(string|null $containerName): self
{
$this->selector->setContainerName($containerName);

Expand All @@ -35,7 +34,7 @@ public function setContainerName(?string $containerName): self

public function setDivisor(string $divisor): self
{
$this->selector->setDivisor(Quantity::fromString($divisor));
$this->selector->setDivisor($divisor);

return $this;
}
Expand Down
13 changes: 5 additions & 8 deletions src/Core/Container/Resources/ResourcesConfigurator.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

namespace Dealroadshow\K8S\Framework\Core\Container\Resources;

use Dealroadshow\K8S\Data\Collection\QuantityMap;
use Dealroadshow\K8S\Data\Collection\StringOrFloatMap;
use Dealroadshow\K8S\Data\ResourceRequirements;
use Dealroadshow\K8S\ValueObject\Quantity;

class ResourcesConfigurator
{
Expand Down Expand Up @@ -49,18 +48,16 @@ public function limitStorage(Memory $memory): self
return $this->setMemory(self::EPHEMERAL_STORAGE, $memory, $this->resources->limits());
}

private function setCPU(CPU $cpu, QuantityMap $map): self
private function setCPU(CPU $cpu, StringOrFloatMap $map): self
{
$quantity = Quantity::fromString($cpu->toString());
$map->add(self::CPU, $quantity);
$map->add(self::CPU, $cpu->toString());

return $this;
}

private function setMemory(string $key, Memory $memory, QuantityMap $map): self
private function setMemory(string $key, Memory $memory, StringOrFloatMap $map): self
{
$quantity = Quantity::fromString($memory->toString());
$map->add(self::MEMORY, $quantity);
$map->add($key, $memory->toString());

return $this;
}
Expand Down
32 changes: 2 additions & 30 deletions src/Core/Ingress/Configurator/IngressBackendFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Dealroadshow\K8S\Data\IngressBackend;
use Dealroadshow\K8S\Framework\App\AppInterface;
use Dealroadshow\K8S\ValueObject\IntOrString;

class IngressBackendFactory
{
Expand All @@ -15,15 +14,8 @@ public function __construct(AppInterface $app)
$this->app = $app;
}

/**
* @param string $serviceName
* @param int|string $servicePort
*
* @return IngressBackend
*/
public function fromServiceNameAndPort(string $serviceName, $servicePort): IngressBackend
public function fromServiceNameAndPort(string $serviceName, int|string $servicePort): IngressBackend
{
$servicePort = $this->getPort($servicePort);
$backend = new IngressBackend($serviceName, $servicePort);
$backend
->setServiceName($serviceName)
Expand All @@ -32,30 +24,10 @@ public function fromServiceNameAndPort(string $serviceName, $servicePort): Ingre
return $backend;
}

/**
* @param string $serviceClass
* @param int|string $servicePort
*
* @return IngressBackend
*/
public function fromServiceClassAndPort(string $serviceClass, $servicePort): IngressBackend
public function fromServiceClassAndPort(string $serviceClass, int|string $servicePort): IngressBackend
{
$serviceName = $this->app->namesHelper()->byServiceClass($serviceClass);

return $this->fromServiceNameAndPort($serviceName, $servicePort);
}

private function getPort($servicePort): IntOrString
{
// TODO change this to int|string typehint when PHP 8.0 is released
if (is_int($servicePort)) {
$servicePort = IntOrString::fromInt($servicePort);
} elseif (is_string($servicePort)) {
$servicePort = IntOrString::fromString($servicePort);
} else {
throw new \TypeError('$servicePort must be an int or a string');
}

return $servicePort;
}
}
4 changes: 1 addition & 3 deletions src/Core/Pod/Volume/Builder/EmptyDirVolumeBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use Dealroadshow\K8S\Data\EmptyDirVolumeSource;
use Dealroadshow\K8S\Data\Volume;
use Dealroadshow\K8S\Framework\Core\Container\Resources\Memory;
use Dealroadshow\K8S\ValueObject\Quantity;

class EmptyDirVolumeBuilder extends AbstractVolumeBuilder
{
Expand All @@ -32,8 +31,7 @@ public function useRAM(): self

public function setSizeLimit(Memory $memory): self
{
$limit = Quantity::fromString($memory->toString());
$this->source->setSizeLimit($limit);
$this->source->setSizeLimit($memory->toString());

return $this;
}
Expand Down
18 changes: 1 addition & 17 deletions src/Core/Service/Configurator/ServicePortsConfigurator.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Dealroadshow\K8S\Data\Collection\ServicePortList;
use Dealroadshow\K8S\Data\ServicePort;
use Dealroadshow\K8S\ValueObject\IntOrString;

class ServicePortsConfigurator
{
Expand All @@ -15,23 +14,8 @@ public function __construct(ServicePortList $ports)
$this->ports = $ports;
}

/**
* @param int $servicePort
* @param int|string $targetPort
*
* @return ServicePortConfigurator
*/
public function add(int $servicePort, $targetPort)
public function add(int $servicePort, int|string $targetPort): ServicePortConfigurator
{
// TODO change this to int|string typehint when PHP 8.0 is released
if (is_int($targetPort)) {
$targetPort = IntOrString::fromInt($targetPort);
} elseif (is_string($targetPort)) {
$targetPort = IntOrString::fromString($targetPort);
} else {
throw new \TypeError('$targetPort must be an int or a string');
}

$port = new ServicePort($servicePort);
$port->setTargetPort($targetPort);
$this->ports->add($port);
Expand Down

0 comments on commit 6d0c2d6

Please sign in to comment.