Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
jrauh01 committed Dec 30, 2024
1 parent 11f9d5a commit 226a42e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 25 deletions.
8 changes: 5 additions & 3 deletions application/controllers/ConfigController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace Icinga\Module\Kubernetes\Controllers;

use Exception;
use GuzzleHttp\Psr7\ServerRequest;
use Icinga\Application\Config;
use Icinga\Application\Logger;
Expand All @@ -22,6 +21,7 @@
use Icinga\Web\Widget\Tabs;
use ipl\Sql\Connection;
use ipl\Stdlib\Filter;
use ipl\Web\Url;
use LogicException;
use Ramsey\Uuid\Uuid;
use Throwable;
Expand Down Expand Up @@ -81,6 +81,7 @@ public function hasBeenSubmitted(): bool
try {

$form = (new NotificationsConfigForm())
->populate(['cluster_uuid' => $this->getRequest()->get('id')])
->on(
NotificationsConfigForm::ON_SUCCESS,
function (NotificationsConfigForm $form) use ($sourceForm) {
Expand Down Expand Up @@ -157,7 +158,7 @@ function (NotificationsConfigForm $form) use ($sourceForm) {
$this->translate('New configuration has successfully been stored.')
);

$this->redirectNow('__REFRESH__');
$this->redirectNow(Url::fromPath('kubernetes/config/notifications', ['id' => $clusterUuid]));
}
)->handleRequest($this->getServerRequest());

Expand Down Expand Up @@ -188,6 +189,7 @@ function (NotificationsConfigForm $form) use ($sourceForm) {
public function prometheusAction()
{
$form = (new PrometheusConfigForm())
->populate(['cluster_uuid' => $this->getRequest()->get('id')])
->on(PrometheusConfigForm::ON_SUCCESS, function (PrometheusConfigForm $form) {
if ($form->isLocked()) {
$form->addMessage($this->translate('Prometheus configuration is locked.'));
Expand Down Expand Up @@ -228,7 +230,7 @@ public function prometheusAction()
}

Notification::success($this->translate('New configuration has successfully been stored'));
$this->redirectNow('__REFRESH__');
$this->redirectNow(Url::fromPath('kubernetes/config/prometheus', ['id' => $clusterUuid]));
})->handleRequest($this->getServerRequest());

$this->mergeTabs($this->Module()->getConfigTabs()->activate('prometheus'));
Expand Down
7 changes: 6 additions & 1 deletion application/forms/NotificationsConfigForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ public function getClusterUuid(): string
(string) Uuid::fromBytes(Cluster::on(Database::connection())->orderBy('uuid')->first()->uuid);
}

public function getOldClusterUuid(): string
{
return $this->getPopulatedValue('old_cluster_uuid', $this->getClusterUuid());
}

public function getKConfig(string $clusterUuid): array
{
$kconfig = [];
Expand Down Expand Up @@ -112,7 +117,7 @@ protected function assemble(): void
{
$clusterUuid = $this->getClusterUuid();

if ($clusterUuid !== $this->getPopulatedValue('old_cluster_uuid', $clusterUuid)) {
if ($clusterUuid !== $this->getOldClusterUuid()) {
$this->clearPopulatedValue('old_cluster_uuid');
$this->clearPopulatedValue(static::transformKeyForForm(KConfig::NOTIFICATIONS_URL));
$this->clearPopulatedValue(static::transformKeyForForm(KConfig::NOTIFICATIONS_KUBERNETES_WEB_URL));
Expand Down
27 changes: 6 additions & 21 deletions application/forms/PrometheusConfigForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
use Icinga\Module\Kubernetes\Model\Cluster;
use Icinga\Module\Kubernetes\Model\Config as KConfig;
use Icinga\Module\Kubernetes\Web\ClusterForm;
use ipl\Html\Attributes;
use ipl\Html\Html;
use ipl\Stdlib\Filter;
use ipl\Web\Compat\CompatForm;
use Ramsey\Uuid\Uuid;
Expand Down Expand Up @@ -102,7 +100,8 @@ protected function assemble(): void
'label' => $this->translate('URL'),
'required' => true,
'value' => $kconfig[KConfig::PROMETHEUS_URL]->value ?? null,
'disabled' => $kconfig[KConfig::PROMETHEUS_URL]->locked ?? false
'disabled' => $kconfig[KConfig::PROMETHEUS_URL]->locked ?? false,
'ignore' => $kconfig[KConfig::PROMETHEUS_URL]->locked ?? false,
]
);

Expand All @@ -112,7 +111,8 @@ protected function assemble(): void
[
'label' => $this->translate('Username'),
'value' => $kconfig[KConfig::PROMETHEUS_USERNAME]->value ?? null,
'disabled' => $kconfig[KConfig::PROMETHEUS_USERNAME]->locked ?? false
'disabled' => $kconfig[KConfig::PROMETHEUS_USERNAME]->locked ?? false,
'ignore' => $kconfig[KConfig::PROMETHEUS_USERNAME]->locked ?? false,
]
);

Expand All @@ -122,26 +122,11 @@ protected function assemble(): void
[
'label' => $this->translate('Password'),
'value' => $kconfig[KConfig::PROMETHEUS_PASSWORD]->value ?? null,
'disabled' => $kconfig[KConfig::PROMETHEUS_PASSWORD]->locked ?? false
'disabled' => $kconfig[KConfig::PROMETHEUS_PASSWORD]->locked ?? false,
'ignore' => $kconfig[KConfig::PROMETHEUS_PASSWORD]->locked ?? false,
]
);

if ($this->isLocked()) {
$this->addHtml(
Html::tag('div', Attributes::create(['class' => 'control-group']), [
Html::tag(
'div',
new Attributes(['class' => 'control-label-group']),
),
Html::tag(
'p',
null,
'Prometheus configuration is provided via YAML.'
)
])
);
}

$this->addElement(
'submit',
'submit',
Expand Down

0 comments on commit 226a42e

Please sign in to comment.