-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from Icinga/persistent-volume-claims
Persistent volume claims
- Loading branch information
Showing
12 changed files
with
515 additions
and
0 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
application/controllers/PersistentvolumeclaimController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
93
application/controllers/PersistentvolumeclaimsController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
73
library/Kubernetes/Model/PersistentVolumeClaimCondition.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
Oops, something went wrong.