Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
lippserd committed Jan 12, 2024
1 parent 66e8cf5 commit 7c95854
Show file tree
Hide file tree
Showing 7 changed files with 119 additions and 38 deletions.
7 changes: 7 additions & 0 deletions library/Kubernetes/Common/Icons.php
Expand Up @@ -4,6 +4,8 @@

namespace Icinga\Module\Kubernetes\Common;

use ipl\Web\Widget\Icon;

abstract class Icons
{
public const BUG = 'bug';
Expand Down Expand Up @@ -117,4 +119,9 @@ abstract class Icons
public const USER = 'user';

public const USER_MANAGER = 'user-tie';

public static function ready(bool $ready): Icon
{
return new Icon($ready ? 'check' : 'xmark');
}
}
13 changes: 10 additions & 3 deletions library/Kubernetes/Model/Endpoint.php
Expand Up @@ -6,6 +6,7 @@

use ipl\I18n\Translation;
use ipl\Orm\Behavior\Binary;
use ipl\Orm\Behavior\BoolCast;
use ipl\Orm\Behaviors;
use ipl\Orm\Model;
use ipl\Orm\Relations;
Expand All @@ -19,6 +20,12 @@ public function createBehaviors(Behaviors $behaviors)
$behaviors->add(new Binary([
'id'
]));

$behaviors->add(new BoolCast([
'ready',
'serving',
'terminating'
]));
}

public function createRelations(Relations $relations)
Expand All @@ -29,15 +36,15 @@ public function createRelations(Relations $relations)
public function getColumnDefinitions()
{
return [
'host_name' => $this->translate('Host Name'),
'node_name' => $this->translate('Node Name'),
'host_name' => $this->translate('Host Name'),
'port_name' => $this->translate('Port Name'),
'ready' => $this->translate('Ready'),
'serving' => $this->translate('Serving'),
'terminating' => $this->translate('Terminating'),
'address' => $this->translate('Address'),
'protocol' => $this->translate('Protocol'),
'port' => $this->translate('Port'),
'port_name' => $this->translate('Port Name'),
'protocol' => $this->translate('Protocol'),
'app_protocol' => $this->translate('App Protocol')
];
}
Expand Down
10 changes: 8 additions & 2 deletions library/Kubernetes/Model/Service.php
Expand Up @@ -6,6 +6,7 @@

use ipl\I18n\Translation;
use ipl\Orm\Behavior\Binary;
use ipl\Orm\Behavior\BoolCast;
use ipl\Orm\Behavior\MillisecondTimestamp;
use ipl\Orm\Behaviors;
use ipl\Orm\Model;
Expand All @@ -21,16 +22,21 @@ public function createBehaviors(Behaviors $behaviors)
'id'
]));

$behaviors->add(new BoolCast([
'publish_not_ready_addresses',
'allocate_load_balancer_node_ports'
]));

$behaviors->add(new MillisecondTimestamp([
'created'
]));
}

public function createRelations(Relations $relations)
{
$relations->hasMany('service_condition', ServiceCondition::class);
$relations->hasMany('condition', ServiceCondition::class);

$relations->hasMany('service_port', ServicePort::class);
$relations->hasMany('port', ServicePort::class);

$relations
->belongsToMany('selector', Selector::class)
Expand Down
4 changes: 2 additions & 2 deletions library/Kubernetes/Model/ServicePort.php
Expand Up @@ -30,10 +30,10 @@ public function getColumnDefinitions()
{
return [
'name' => $this->translate('Name'),
'protocol' => $this->translate('Protocol'),
'app_protocol' => $this->translate('App Protocol'),
'port' => $this->translate('Port'),
'target_port' => $this->translate('Target Port'),
'protocol' => $this->translate('Protocol'),
'app_protocol' => $this->translate('App Protocol'),
'node_port' => $this->translate('Node Port')
];
}
Expand Down
8 changes: 7 additions & 1 deletion library/Kubernetes/Web/EndpointTable.php
Expand Up @@ -4,6 +4,7 @@

namespace Icinga\Module\Kubernetes\Web;

use Icinga\Module\Kubernetes\Common\Icons;
use ipl\Html\HtmlElement;
use ipl\Html\Table;
use ipl\Html\Text;
Expand Down Expand Up @@ -46,7 +47,12 @@ public function assemble()
foreach ($this->resource as $resource) {
$row = new HtmlElement('tr');
foreach ($this->columnDefinitions as $column => $_) {
$content = Text::create($resource->$column);
$value = $resource->$column;
if (is_bool($value)) {
$content = Icons::ready($value);
} else {
$content = Text::create($value);
}
$row->addHtml(new HtmlElement('td', null, $content));
}
$this->addHtml($row);
Expand Down
61 changes: 61 additions & 0 deletions library/Kubernetes/Web/PortTable.php
@@ -0,0 +1,61 @@
<?php

/* Icinga Kubernetes Web | (c) 2023 Icinga GmbH | GPLv2 */

namespace Icinga\Module\Kubernetes\Web;

use Icinga\Module\Kubernetes\Common\Icons;
use ipl\Html\HtmlElement;
use ipl\Html\Table;
use ipl\Html\Text;
use ipl\I18n\Translation;

class PortTable extends Table
{
use Translation;

protected $columnDefinitions;

protected $defaultAttributes = [
'class' => 'common-table collapsible'
];

protected $resource;

public function __construct($resource, array $columnDefinitions)
{
$this->resource = $resource;
$this->columnDefinitions = $columnDefinitions;
}

public function assemble()
{
$this->addWrapper(
new HtmlElement(
'section',
null,
new HtmlElement('h2', null, new Text($this->translate('Ports')))
)
);

$header = new HtmlElement('tr');
foreach ($this->columnDefinitions as $label) {
$header->addHtml(new HtmlElement('th', null, Text::create($label)));
}
$this->getHeader()->addHtml($header);

foreach ($this->resource as $resource) {
$row = new HtmlElement('tr');
foreach ($this->columnDefinitions as $column => $_) {
$value = $resource->$column;
if (is_bool($value)) {
$content = Icons::ready($value);
} else {
$content = Text::create($value);
}
$row->addHtml(new HtmlElement('td', null, $content));
}
$this->addHtml($row);
}
}
}
54 changes: 24 additions & 30 deletions library/Kubernetes/Web/ServiceDetail.php
Expand Up @@ -5,13 +5,14 @@
namespace Icinga\Module\Kubernetes\Web;

use Icinga\Module\Kubernetes\Common\Database;
use Icinga\Module\Kubernetes\Common\Icons;
use Icinga\Module\Kubernetes\Common\ResourceDetails;
use Icinga\Module\Kubernetes\Model\Endpoint;
use Icinga\Module\Kubernetes\Model\EndpointSlice;
use Icinga\Module\Kubernetes\Model\Pod;
use Icinga\Module\Kubernetes\Model\Service;
use Icinga\Module\Kubernetes\Model\ServicePort;
use ipl\Html\BaseHtmlElement;
use ipl\Html\FormattedString;
use ipl\Html\HtmlElement;
use ipl\Html\Text;
use ipl\I18n\Translation;
Expand Down Expand Up @@ -58,53 +59,46 @@ protected function assemble()
$this->service->external_traffic_policy
)),
$this->translate('Health Check Node Port') => $this->service->health_check_node_port,
$this->translate('Publish Not Ready Addresses') => $this->service->publish_not_ready_addresses,
$this->translate('Publish Not Ready Addresses') => Icons::ready(
$this->service->publish_not_ready_addresses
),
$this->translate('IP Families') => $this->service->ip_families,
$this->translate('IP Family Policy') => ucfirst(Str::camel(
$this->service->ip_family_policy
)),
$this->translate('Allocate Load Balancer Node Ports') =>
$this->service->allocate_load_balancer_node_ports,
$this->translate('Allocate Load Balancer Node Ports') => Icons::ready(
$this->service->allocate_load_balancer_node_ports
),
$this->translate('Load Balancer Class') => $this->service->load_balancer_class,
$this->translate('Internal Traffic Policy') => ucfirst(Str::camel(
$this->service->internal_traffic_policy
))
])),
new Labels($this->service->label),
new InternalEndpointList($this->service->service_port),
new PortTable($this->service->port, (new ServicePort())->getColumnDefinitions()),
new EndpointTable($endpointSlices->endpoint, (new Endpoint())->getColumnDefinitions())
);

$selectors = $this->service->selector->execute();
if ($selectors->valid()) {
$pods = new HtmlElement(
$pods = Pod::on(Database::connection())
->with(['node'])
->filter(Filter::all(
Filter::equal('pod.namespace', $this->service->namespace),
));
foreach ($selectors as $selector) {
$pods->filter(Filter::all(
Filter::equal('pod.label.name', $selector->name),
Filter::equal('pod.label.value', $selector->value)
));
}
$this->addHtml((new PodList(
$pods
))->setWrapper(new HtmlElement(
'section',
null,
new HtmlElement('h2', null, new Text($this->translate('Pods')))
);

foreach ($selectors as $selector) {
$pods->addHtml(
new HtmlElement(
'section',
null,
new HtmlElement(
'h3',
null,
FormattedString::create('%s: %s', $selector->name, $selector->value)
),
new PodList(Pod::on(Database::connection())
->with(['node'])
->filter(Filter::all(
Filter::equal('pod.namespace', $this->service->namespace),
Filter::equal('pod.label.name', $selector->name),
Filter::equal('pod.label.value', $selector->value)
)))
)
);
}

$this->addHtml($pods);
)));
}
}
}

0 comments on commit 7c95854

Please sign in to comment.