Skip to content

Commit

Permalink
Introduce new Environment classes
Browse files Browse the repository at this point in the history
  • Loading branch information
jhoxhaa committed Dec 17, 2024
1 parent 15770d8 commit 467667f
Show file tree
Hide file tree
Showing 22 changed files with 603 additions and 9 deletions.
3 changes: 2 additions & 1 deletion library/Kubernetes/Web/CronJobDetail.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ protected function assemble(): void
$this->translate('Last Schedule Time') => $lastScheduleTime
])),
new Labels($this->cronJob->label),
new Annotations($this->cronJob->annotation)
new Annotations($this->cronJob->annotation),
new CronJobEnvironment($this->cronJob),
);

if (Auth::getInstance()->hasPermission(Auth::SHOW_JOBS)) {
Expand Down
46 changes: 46 additions & 0 deletions library/Kubernetes/Web/CronJobEnvironment.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

/* Icinga for Kubernetes Web | (c) 2024 Icinga GmbH | AGPLv3 */

namespace Icinga\Module\Kubernetes\Web;

use Icinga\Module\Kubernetes\Model\CronJob;
use ipl\Html\Attributes;
use ipl\Html\HtmlDocument;
use ipl\Html\HtmlElement;
use ipl\Html\Text;
use ipl\Html\ValidHtml;
use ipl\Stdlib\Filter;
use Ramsey\Uuid\Uuid;

class CronJobEnvironment implements ValidHtml
{
private CronJob $cronJob;

public function __construct($cronJob)
{
$this->cronJob = $cronJob;
}

public function render(): ValidHtml
{
$childrenFilter = Filter::all(
Filter::equal('namespace', $this->cronJob->namespace),
Filter::equal('job.owner.owner_uuid', Uuid::fromBytes($this->cronJob->uuid)->toString()),
);

$jobs = $this->cronJob->job
->filter($childrenFilter)
->limit(3);

return (new HtmlDocument())
->addHtml(
new HtmlElement(
'h2',
Attributes::create(['class' => 'environment-widget-title']),
Text::create(t('Environment'))
),
new Environment($this->cronJob, null, $jobs, null, $childrenFilter)
);
}
}
3 changes: 2 additions & 1 deletion library/Kubernetes/Web/DaemonSetDetail.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ protected function assemble(): void
])),
new Labels($this->daemonSet->label),
new Annotations($this->daemonSet->annotation),
new ConditionTable($this->daemonSet, (new DaemonSetCondition())->getColumnDefinitions())
new ConditionTable($this->daemonSet, (new DaemonSetCondition())->getColumnDefinitions()),
new DaemonSetEnvironment($this->daemonSet),
);

if (Auth::getInstance()->hasPermission(Auth::SHOW_PODS)) {
Expand Down
48 changes: 48 additions & 0 deletions library/Kubernetes/Web/DaemonSetEnvironment.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

/* Icinga for Kubernetes Web | (c) 2024 Icinga GmbH | AGPLv3 */

namespace Icinga\Module\Kubernetes\Web;

use Icinga\Module\Kubernetes\Common\Database;
use Icinga\Module\Kubernetes\Model\DaemonSet;
use Icinga\Module\Kubernetes\Model\Pod;
use ipl\Html\Attributes;
use ipl\Html\HtmlDocument;
use ipl\Html\HtmlElement;
use ipl\Html\Text;
use ipl\Html\ValidHtml;
use ipl\Stdlib\Filter;
use Ramsey\Uuid\Uuid;

class DaemonSetEnvironment implements ValidHtml
{
private DaemonSet $daemonSet;

public function __construct($daemonSet)
{
$this->daemonSet = $daemonSet;
}

public function render(): ValidHtml
{
$childrenFilter = Filter::all(
Filter::equal('namespace', $this->daemonSet->namespace),
Filter::equal('pod.owner.owner_uuid', Uuid::fromBytes($this->daemonSet->uuid)->toString())
);

$pods = Pod::on(Database::connection())
->filter($childrenFilter)
->limit(3);

return (new HtmlDocument())
->addHtml(
new HtmlElement(
'h2',
Attributes::create(['class' => 'environment-widget-title']),
Text::create(t('Environment'))
),
new Environment($this->daemonSet, null, $pods, null, $childrenFilter)
);
}
}
3 changes: 2 additions & 1 deletion library/Kubernetes/Web/DeploymentDetail.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ protected function assemble(): void
])),
new Labels($this->deployment->label),
new Annotations($this->deployment->annotation),
new DeploymentConditions($this->deployment)
new DeploymentConditions($this->deployment),
new DeploymentEnvironment($this->deployment),
);

if (Auth::getInstance()->hasPermission(Auth::SHOW_REPLICA_SETS)) {
Expand Down
48 changes: 48 additions & 0 deletions library/Kubernetes/Web/DeploymentEnvironment.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

/* Icinga for Kubernetes Web | (c) 2024 Icinga GmbH | AGPLv3 */

namespace Icinga\Module\Kubernetes\Web;

use Icinga\Module\Kubernetes\Common\Database;
use Icinga\Module\Kubernetes\Model\Deployment;
use Icinga\Module\Kubernetes\Model\ReplicaSet;
use ipl\Html\Attributes;
use ipl\Html\HtmlDocument;
use ipl\Html\HtmlElement;
use ipl\Html\Text;
use ipl\Html\ValidHtml;
use ipl\Stdlib\Filter;
use Ramsey\Uuid\Uuid;

class DeploymentEnvironment implements ValidHtml
{
private Deployment $deployment;

public function __construct($deployment)
{
$this->deployment = $deployment;
}

public function render(): ValidHtml
{
$childrenFilter = Filter::all(
Filter::equal('namespace', $this->deployment->namespace),
Filter::equal('replica_set.owner.owner_uuid', Uuid::fromBytes($this->deployment->uuid)->toString())
);

$replicaSets = ReplicaSet::on(Database::connection())
->filter($childrenFilter)
->limit(3);

return (new HtmlDocument())
->addHtml(
new HtmlElement(
'h2',
Attributes::create(['class' => 'environment-widget-title']),
Text::create(t('Environment'))
),
new Environment($this->deployment, null, $replicaSets, $childrenFilter)
);
}
}
3 changes: 2 additions & 1 deletion library/Kubernetes/Web/IngressDetail.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ protected function assemble(): void
$this->addHtml(
new Details(new ResourceDetails($this->ingress)),
new Labels($this->ingress->label),
new Annotations($this->ingress->annotation)
new Annotations($this->ingress->annotation),
new IngressEnvironment($this->ingress)
);

$backendServices = IngressBackendService::on(Database::connection())
Expand Down
52 changes: 52 additions & 0 deletions library/Kubernetes/Web/IngressEnvironment.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

/* Icinga for Kubernetes Web | (c) 2024 Icinga GmbH | AGPLv3 */

namespace Icinga\Module\Kubernetes\Web;

use Icinga\Module\Kubernetes\Common\Database;
use Icinga\Module\Kubernetes\Model\Ingress;
use Icinga\Module\Kubernetes\Model\Service;
use ipl\Html\Attributes;
use ipl\Html\HtmlDocument;
use ipl\Html\HtmlElement;
use ipl\Html\Text;
use ipl\Html\ValidHtml;
use ipl\Stdlib\Filter;

class IngressEnvironment implements ValidHtml
{
private Ingress $ingress;

public function __construct($ingress)
{
$this->ingress = $ingress;
}

public function render(): ValidHtml
{
$services = Service::on(Database::connection())
->filter(Filter::equal('namespace', $this->ingress->namespace));

$filters = [];
foreach ($this->ingress->backend_service as $backendService) {
$filters[] = Filter::all(
Filter::equal('service.name', $backendService->service_name),
Filter::equal('service.port.port', $backendService->service_port_number)
);
}

$services->filter(Filter::any(...$filters))
->limit(3);

return (new HtmlDocument())
->addHtml(
new HtmlElement(
'h2',
Attributes::create(['class' => 'environment-widget-title']),
Text::create(t('Environment'))
),
new Environment($this->ingress, null, $services, null, Filter::any(...$filters))
);
}
}
3 changes: 2 additions & 1 deletion library/Kubernetes/Web/JobDetail.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ protected function assemble(): void
])),
new Labels($this->job->label),
new Annotations($this->job->annotation),
new JobConditions($this->job)
new JobConditions($this->job),
new JobEnvironment($this->job),
);

if (Auth::getInstance()->hasPermission(Auth::SHOW_PODS)) {
Expand Down
65 changes: 65 additions & 0 deletions library/Kubernetes/Web/JobEnvironment.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php

/* Icinga for Kubernetes Web | (c) 2024 Icinga GmbH | AGPLv3 */

namespace Icinga\Module\Kubernetes\Web;

use Icinga\Module\Kubernetes\Common\Database;
use Icinga\Module\Kubernetes\Model\CronJob;
use Icinga\Module\Kubernetes\Model\Job;
use Icinga\Module\Kubernetes\Model\JobOwner;
use Icinga\Module\Kubernetes\Model\Pod;
use ipl\Html\Attributes;
use ipl\Html\HtmlDocument;
use ipl\Html\HtmlElement;
use ipl\Html\Text;
use ipl\Html\ValidHtml;
use ipl\Stdlib\Filter;
use Ramsey\Uuid\Uuid;

class JobEnvironment implements ValidHtml
{
private Job $job;

public function __construct($job)
{
$this->job = $job;
}

public function render(): ValidHtml
{
$jobOwner = JobOwner::on(Database::connection())
->filter(Filter::equal('job_uuid', Uuid::fromBytes($this->job->uuid)->toString()))->first();

$parentsFilter = Filter::all();

if ($jobOwner !== null) {
$parentsFilter = Filter::equal('uuid', Uuid::fromBytes($jobOwner->owner_uuid)->toString());

$cronJobs = CronJob::on(Database::connection())
->filter($parentsFilter)
->limit(3);
} else {
$cronJobs = null;
}

$childrenFilter = Filter::all(
Filter::equal('namespace', $this->job->namespace),
Filter::equal('pod.owner.owner_uuid', Uuid::fromBytes($this->job->uuid)->toString())
);

$pods = Pod::on(Database::connection())
->filter($childrenFilter)
->limit(3);

return (new HtmlDocument())
->addHtml(
new HtmlElement(
'h2',
Attributes::create(['class' => 'environment-widget-title']),
Text::create(t('Environment'))
),
new Environment($this->job, $cronJobs, $pods, $parentsFilter, $childrenFilter)
);
}
}
3 changes: 2 additions & 1 deletion library/Kubernetes/Web/PersistentVolumeClaimDetail.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ protected function assemble(): void
])),
new Labels($this->pvc->label),
new Annotations($this->pvc->annotation),
new ConditionTable($this->pvc, (new PersistentVolumeClaimCondition())->getColumnDefinitions())
new ConditionTable($this->pvc, (new PersistentVolumeClaimCondition())->getColumnDefinitions()),
new PersistentVolumeClaimEnvironment($this->pvc),
);

if (Auth::getInstance()->hasPermission(Auth::SHOW_PODS)) {
Expand Down
42 changes: 42 additions & 0 deletions library/Kubernetes/Web/PersistentVolumeClaimEnvironment.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

/* Icinga for Kubernetes Web | (c) 2024 Icinga GmbH | AGPLv3 */

namespace Icinga\Module\Kubernetes\Web;

use Icinga\Module\Kubernetes\Model\PersistentVolumeClaim;
use ipl\Html\Attributes;
use ipl\Html\HtmlDocument;
use ipl\Html\HtmlElement;
use ipl\Html\Text;
use ipl\Html\ValidHtml;
use ipl\Stdlib\Filter;

class PersistentVolumeClaimEnvironment implements ValidHtml
{
private PersistentVolumeClaim $pvc;

public function __construct($pvc)
{
$this->pvc = $pvc;
}

public function render(): ValidHtml
{
$childrenFilter = Filter::equal('pod.pvc.name', $this->pvc->name);

$pods = $this->pvc->pod
->filter($childrenFilter)
->limit(3);

return (new HtmlDocument())
->addHtml(
new HtmlElement(
'h2',
Attributes::create(['class' => 'environment-widget-title']),
Text::create(t('Environment'))
),
new Environment($this->pvc, $this->pvc->persistent_volume, $pods, null, $childrenFilter)
);
}
}
1 change: 1 addition & 0 deletions library/Kubernetes/Web/PersistentVolumeDetail.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ protected function assemble(): void
]),
new Labels($this->persistentVolume->label),
new Annotations($this->persistentVolume->annotation),
new PersistentVolumeEnvironment($this->persistentVolume),
);

if (Auth::getInstance()->hasPermission(Auth::SHOW_PERSISTENT_VOLUME_CLAIMS)) {
Expand Down
Loading

0 comments on commit 467667f

Please sign in to comment.