Skip to content

Commit

Permalink
Merge pull request #15 from Icinga/persistent-volume-claims
Browse files Browse the repository at this point in the history
Persistent volume claims
  • Loading branch information
lippserd authored Jun 19, 2023
2 parents f7f278f + f7ed2bd commit 98abc4a
Show file tree
Hide file tree
Showing 12 changed files with 515 additions and 0 deletions.
34 changes: 34 additions & 0 deletions application/controllers/PersistentvolumeclaimController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

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

namespace Icinga\Module\Kubernetes\Controllers;

use Icinga\Module\Kubernetes\Common\Database;
use Icinga\Module\Kubernetes\Model\PersistentVolumeClaim;
use Icinga\Module\Kubernetes\Web\PersistentVolumeClaimDetail;
use ipl\Stdlib\Filter;
use ipl\Web\Compat\CompatController;

class PersistentvolumeclaimController extends CompatController
{
public function indexAction(): void
{
$id = $this->params->getRequired('id');

$query = PersistentVolumeClaim::on(Database::connection())
->filter(Filter::all(
Filter::equal('pvc.id', $id),
));

/** @var PersistentVolumeClaim $pvc */
$pvc = $query->first();
if ($pvc === null) {
$this->httpNotFound($this->translate('Persistent Volume Claim not found'));
}

$this->addTitleTab("Persistent Volume Claim $pvc->namespace/$pvc->name");

$this->addContent(new PersistentVolumeClaimDetail($pvc));
}
}
93 changes: 93 additions & 0 deletions application/controllers/PersistentvolumeclaimsController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<?php

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

namespace Icinga\Module\Kubernetes\Controllers;

use Icinga\Module\Kubernetes\Common\Database;
use Icinga\Module\Kubernetes\Model\PersistentVolumeClaim;
use Icinga\Module\Kubernetes\Model\Pod;
use Icinga\Module\Kubernetes\TBD\ObjectSuggestions;
use Icinga\Module\Kubernetes\Web\Controller;
use Icinga\Module\Kubernetes\Web\PersistentVolumeClaimList;
use Icinga\Module\Kubernetes\Web\PodList;
use ipl\Web\Compat\SearchControls;
use ipl\Web\Control\LimitControl;
use ipl\Web\Control\SortControl;

class PersistentvolumeclaimsController extends Controller
{
use SearchControls;

public function indexAction(): void
{
$this->addTitleTab($this->translate('Persistent Volume Claims'));

$pvcs = PersistentVolumeClaim::on(Database::connection());

$limitControl = $this->createLimitControl();
$sortControl = $this->createSortControl(
$pvcs,
[
'pvc.name' => $this->translate('Name'),
'pvc.created' => $this->translate('Created')
]
);

$paginationControl = $this->createPaginationControl($pvcs);
$searchBar = $this->createSearchBar($pvcs, [
$limitControl->getLimitParam(),
$sortControl->getSortParam(),
]);

if ($searchBar->hasBeenSent() && ! $searchBar->isValid()) {
if ($searchBar->hasBeenSubmitted()) {
$filter = $this->getFilter();
} else {
$this->addControl($searchBar);
$this->sendMultipartUpdate();

return;
}
} else {
$filter = $searchBar->getFilter();
}

$pvcs->filter($filter);

$this->addControl($paginationControl);
$this->addControl($sortControl);
$this->addControl($limitControl);
$this->addControl($searchBar);

$this->addContent(new PersistentVolumeClaimList($pvcs));

if (! $searchBar->hasBeenSubmitted() && $searchBar->hasBeenSent()) {
$this->sendMultipartUpdate();
}
}

public function completeAction(): void
{
$suggestions = new ObjectSuggestions();
$suggestions->setModel(PersistentVolumeClaim::class);
$suggestions->forRequest($this->getServerRequest());
$this->getDocument()->add($suggestions);
}

public function searchEditorAction(): void
{
$editor = $this->createSearchEditor(PersistentVolumeClaim::on(Database::connection()), [
LimitControl::DEFAULT_LIMIT_PARAM,
SortControl::DEFAULT_SORT_PARAM,
]);

$this->getDocument()->add($editor);
$this->setTitle(t('Adjust Filter'));
}

protected function getPageSize($default)
{
return parent::getPageSize($default ?? 50);
}
}
9 changes: 9 additions & 0 deletions configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,15 @@
]
);

$section->add(
N_('Persistent Volume Claims'),
[
'description' => $this->translate('Persistent Volume Claims'),
'url' => 'kubernetes/persistentvolumeclaims',
'priority' => $i++
]
);

$this->provideConfigTab(
'database',
[
Expand Down
6 changes: 6 additions & 0 deletions library/Kubernetes/Common/Icons.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ abstract class Icons

public const POD_FAILED = 'circle-triangle';

public const PVC_PENDING = 'spinner';

public const PVC_BOUND = 'link';

public const PVC_LOST = 'file-circle-exclamation';

public const DEPLOYMENT_HEALTHY = 'circle-check';

public const DEPLOYMENT_UNHEALTHY = 'exclamation-triangle';
Expand Down
6 changes: 6 additions & 0 deletions library/Kubernetes/Common/Links.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Icinga\Module\Kubernetes\Model\Pod;
use Icinga\Module\Kubernetes\Model\ReplicaSet;
use Icinga\Module\Kubernetes\Model\StatefulSet;
use Icinga\Module\Kubernetes\Model\PersistentVolumeClaim;
use ipl\Web\Url;

abstract class Links
Expand Down Expand Up @@ -61,4 +62,9 @@ public static function event(Event $event): Url
{
return Url::fromPath('kubernetes/event', ['id' => bin2hex($event->id)]);
}

public static function pvc(PersistentVolumeClaim $persistentVolumeClaim): Url
{
return Url::fromPath('kubernetes/persistentvolumeclaim', ['id' => bin2hex($persistentVolumeClaim->id)]);
}
}
4 changes: 4 additions & 0 deletions library/Kubernetes/Model/Label.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ public function createRelations(Relations $relations)
$relations
->belongsToMany('pod', Pod::class)
->through('pod_label');

$relations
->belongsToMany('pvc', PersistentVolumeClaim::class)
->through('pvc_label');
//
// $relations->belongsToMany('contact', Contact::class)
// ->through('incident_contact');
Expand Down
95 changes: 95 additions & 0 deletions library/Kubernetes/Model/PersistentVolumeClaim.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
<?php

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

namespace Icinga\Module\Kubernetes\Model;

use ipl\Orm\Behavior\Binary;
use ipl\Orm\Behavior\MillisecondTimestamp;
use ipl\Orm\Behaviors;
use ipl\Orm\Model;
use ipl\Orm\Relations;

class PersistentVolumeClaim extends Model
{
public const PHASE_PENDING = 'pending';

public const PHASE_BOUND = 'bound';

public const PHASE_LOST = 'failed';

public function getTableName()
{
return 'pvc';
}

public function getKeyName()
{
return 'id';
}

public function getColumns()
{
return [
'namespace',
'name',
'uid',
'resource_version',
'desired_access_modes',
'actual_access_modes',
'minimum_capacity',
'actual_capacity',
'phase',
'volume_name',
'volume_mode',
'storage_class',
'created'
];
}

public function getColumnDefinitions()
{
return [
'namespace' => t('Namespace'),
'name' => t('Name'),
'phase' => t('Phase'),
'created' => t('Created At')
];
}

public function getSearchColumns()
{
return ['name'];
}

public function getDefaultSort()
{
return ['namespace', 'created desc'];
}

public function createBehaviors(Behaviors $behaviors)
{
$behaviors->add(
new Binary([
'id'
])
);
$behaviors->add(
new MillisecondTimestamp([
'created'
])
);
}

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

$relations
->belongsToMany('label', Label::class)
->through('pvc_label');

$relations
->belongsTo('pod', Pod::class);
}
}
73 changes: 73 additions & 0 deletions library/Kubernetes/Model/PersistentVolumeClaimCondition.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php

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

namespace Icinga\Module\Kubernetes\Model;

use ipl\Orm\Behavior\Binary;
use ipl\Orm\Behavior\MillisecondTimestamp;
use ipl\Orm\Behaviors;
use ipl\Orm\Model;
use ipl\Orm\Relations;

class PersistentVolumeClaimCondition extends Model
{
public function getTableName()
{
return 'pvc_condition';
}

public function getKeyName()
{
return ['pvc_id', 'type'];
}

public function getColumns()
{
return [
'status',
'last_probe',
'last_transition',
'message',
'reason'
];
}

public function getColumnDefinitions()
{
return [
'type' => t('Type'),
'status' => t('Status'),
'last_probe' => t('Last Probe'),
'last_transition' => t('Last Transition'),
'message' => t('Message'),
'reason' => t('Reason')
];
}

public function getDefaultSort()
{
return ['last_transition desc'];
}

public function createBehaviors(Behaviors $behaviors)
{
$behaviors->add(
new Binary([
'pvc_id'
])
);
$behaviors->add(
new MillisecondTimestamp([
'last_probe',
'last_transition'
])
);
}

public function createRelations(Relations $relations)
{
$relations
->belongsTo('pvc', PersistentVolumeClaim::class);
}
}
36 changes: 36 additions & 0 deletions library/Kubernetes/TBD/AccessModes.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

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

namespace Icinga\Module\Kubernetes\TBD;

class AccessModes
{
public const READ_WRITE_ONCE = 1 << 0;

public const READ_ONLY_MANY = 1 << 1;

public const READ_WRITE_MANY = 1 << 2;

public const READ_WRITE_ONCE_POD = 1 << 3;

public static $names = [
self::READ_WRITE_ONCE => 'ReadWriteOnce',
self::READ_ONLY_MANY => 'ReadOnlyMany',
self::READ_WRITE_MANY => 'ReadWriteMany',
self::READ_WRITE_ONCE_POD => 'ReadWriteOncePod'
];

public static function asNames(int $bitmask): array
{
$names = [];

foreach (static::$names as $flag => $name) {
if ($bitmask & $flag) {
$names[] = $name;
}
}

return $names;
}
}
Loading

0 comments on commit 98abc4a

Please sign in to comment.