Skip to content

Commit

Permalink
Add Icinga states to replica set
Browse files Browse the repository at this point in the history
  • Loading branch information
jhoxhaa committed May 23, 2024
1 parent 1ee1c87 commit ec7e60d
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 21 deletions.
12 changes: 12 additions & 0 deletions library/Kubernetes/Model/ReplicaSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ class ReplicaSet extends Model
{
use Translation;

public const STATE_OK = "ok";

public const STATE_WARNING = "warning";

public const STATE_CRITICAL = "critical";

public const STATE_UNKNOWN = "unknown";

public function createBehaviors(Behaviors $behaviors)
{
$behaviors->add(new Binary([
Expand Down Expand Up @@ -64,6 +72,8 @@ public function getColumnDefinitions()
'fully_labeled_replicas' => $this->translate('Fully Labeled Replicas'),
'ready_replicas' => $this->translate('Ready Replicas'),
'available_replicas' => $this->translate('Available Replicas'),
'icinga_state' => $this->translate('Icinga State'),
'icinga_state_reason' => $this->translate('Icinga State Reason'),
'created' => $this->translate('Created At')
];
}
Expand All @@ -81,6 +91,8 @@ public function getColumns()
'fully_labeled_replicas',
'ready_replicas',
'available_replicas',
'icinga_state',
'icinga_state_reason',
'created'
];
}
Expand Down
20 changes: 13 additions & 7 deletions library/Kubernetes/Web/ReplicaSetDetail.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ protected function assemble()
$this->translate('Actual Replicas') => $this->replicaSet->actual_replicas,
$this->translate('Fully Labeled Replicas') => $this->replicaSet->fully_labeled_replicas,
$this->translate('Ready Replicas') => $this->replicaSet->ready_replicas,
$this->translate('Available Replicas') => $this->replicaSet->available_replicas
$this->translate('Available Replicas') => $this->replicaSet->available_replicas,
$this->translate('Icinga State') => $this->replicaSet->icinga_state,
$this->translate('Icinga State Reason') => $this->replicaSet->icinga_state_reason
])),
new Labels($this->replicaSet->label),
new ConditionTable($this->replicaSet, (new ReplicaSetCondition())->getColumnDefinitions()),
Expand All @@ -52,12 +54,16 @@ protected function assemble()
'section',
null,
new HtmlElement('h2', null, new Text($this->translate('Events'))),
new EventList(Event::on(Database::connection())
->filter(Filter::all(
Filter::equal('reference_kind', 'ReplicaSet'),
Filter::equal('reference_namespace', $this->replicaSet->namespace),
Filter::equal('reference_name', $this->replicaSet->name)
)))
new EventList(
Event::on(Database::connection())
->filter(
Filter::all(
Filter::equal('reference_kind', 'ReplicaSet'),
Filter::equal('reference_namespace', $this->replicaSet->namespace),
Filter::equal('reference_name', $this->replicaSet->name)
)
)
)
)
);
}
Expand Down
30 changes: 16 additions & 14 deletions library/Kubernetes/Web/ReplicaSetListItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
use Icinga\Module\Kubernetes\Common\BaseListItem;
use Icinga\Module\Kubernetes\Common\Health;
use Icinga\Module\Kubernetes\Common\Links;
use Icinga\Module\Kubernetes\Model\ReplicaSet;
use ipl\Html\Attributes;
use ipl\Html\BaseHtmlElement;
use ipl\Html\Html;
use ipl\Html\HtmlElement;
use ipl\Html\HtmlString;
use ipl\I18n\Translation;
use ipl\Web\Widget\Icon;
use ipl\Web\Widget\Link;
Expand Down Expand Up @@ -61,34 +63,34 @@ protected function assembleMain(BaseHtmlElement $main): void

protected function assembleTitle(BaseHtmlElement $title): void
{
[, $healthState] = $this->getState();
$content = Html::sprintf(
$this->translate('%s is %s', '<replica_set> is <health>'),
new Link($this->item->name, Links::replicaSet($this->item), ['class' => 'subject']),
Html::tag('span', null, $this->getHealth())
Html::tag('span', null, $healthState)
);

$title->addHtml($content);
}

protected function assembleVisual(BaseHtmlElement $visual): void
{
$health = $this->getHealth();
$visual->addHtml(new Icon(Health::icon($health), ['class' => ['health-' . $health]]));
[$icingaState,] = $this->getState();
$stateBall = new StateBall($icingaState, StateBall::SIZE_MEDIUM);
$visual->addHtml($stateBall);
}

protected function getHealth(): string
protected function getState(): array
{
if ($this->item->desired_replicas < 1) {
return Health::UNDECIDABLE;
}

switch (true) {
case $this->item->available_replicas < 1:
return Health::UNHEALTHY;
case $this->item->available_replicas < $this->item->desired_replicas:
return Health::DEGRADED;
switch ($this->item->icinga_state) {
case ReplicaSet::STATE_WARNING:
return ['warning', Health::DEGRADED];
case ReplicaSet::STATE_CRITICAL:
return ['critical', Health::UNHEALTHY];
case ReplicaSet::STATE_UNKNOWN:
return ['unknown', Health::UNDECIDABLE];
default:
return Health::HEALTHY;
return ['ok', Health::HEALTHY];
}
}
}

0 comments on commit ec7e60d

Please sign in to comment.