Skip to content

Commit a35e0d0

Browse files
authored
Merge pull request #12 from Icinga/add-labels
Add labels to resources
2 parents 6e82772 + 965a372 commit a35e0d0

16 files changed

+124
-32
lines changed

library/Kubernetes/Model/DaemonSet.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ public function createRelations(Relations $relations)
5757
->belongsToMany('pods', Pod::class)
5858
->through('pod_owner');
5959

60+
$relations
61+
->belongsToMany('label', Label::class)
62+
->through('daemon_set_label');
63+
6064
$relations->hasMany('condition', DaemonSetCondition::class);
6165
}
6266
}

library/Kubernetes/Model/Deployment.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ public function createRelations(Relations $relations)
6262
->belongsToMany('replica_sets', ReplicaSet::class)
6363
->through('replica_set_owner');
6464

65+
$relations
66+
->belongsToMany('label', Label::class)
67+
->through('deployment_label');
68+
6569
$relations->hasMany('condition', DeploymentCondition::class);
6670
}
6771
}

library/Kubernetes/Model/Label.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,30 @@ public function createRelations(Relations $relations)
6969
$relations
7070
->belongsToMany('pvc', PersistentVolumeClaim::class)
7171
->through('pvc_label');
72+
73+
$relations
74+
->belongsToMany('deployment', Deployment::class)
75+
->through('deployment_label');
76+
77+
$relations
78+
->belongsToMany('replica_set', ReplicaSet::class)
79+
->through('replica_set_label');
80+
81+
$relations
82+
->belongsToMany('daemon_set', DaemonSet::class)
83+
->through('daemon_set_label');
84+
85+
$relations
86+
->belongsToMany('stateful_set', StatefulSet::class)
87+
->through('stateful_set_label');
88+
89+
$relations
90+
->belongsToMany('namespace', NamespaceModel::class)
91+
->through('namespace_label');
92+
93+
$relations
94+
->belongsToMany('node', Node::class)
95+
->through('node_label');
7296
//
7397
// $relations->belongsToMany('contact', Contact::class)
7498
// ->through('incident_contact');

library/Kubernetes/Model/NamespaceModel.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,5 +67,8 @@ public function createBehaviors(Behaviors $behaviors)
6767

6868
public function createRelations(Relations $relations)
6969
{
70+
$relations
71+
->belongsToMany('label', Label::class)
72+
->through('namespace_label');
7073
}
7174
}

library/Kubernetes/Model/Node.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,11 @@ public function createRelations(Relations $relations)
8989
->hasMany('pod', Pod::class)
9090
->setCandidateKey('name')
9191
->setForeignKey('node_name');
92+
93+
$relations
94+
->belongsToMany('label', Label::class)
95+
->through('node_label');
96+
9297
//
9398
// $relations->belongsToMany('contact', Contact::class)
9499
// ->through('incident_contact');

library/Kubernetes/Model/ReplicaSet.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ public function createRelations(Relations $relations)
6565
->setCandidateKey('id')
6666
->setForeignKey('replica_set_id');
6767

68+
$relations
69+
->belongsToMany('label', Label::class)
70+
->through('replica_set_label');
71+
6872
$relations->hasMany('condition', ReplicaSetCondition::class);
6973
}
7074
}

library/Kubernetes/Model/StatefulSet.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ public function createRelations(Relations $relations)
6363
->belongsToMany('pods', Pod::class)
6464
->through('pod_owner');
6565

66+
$relations
67+
->belongsToMany('label', Label::class)
68+
->through('stateful_set_label');
69+
6670
$relations->hasMany('condition', StatefulSetCondition::class);
6771
}
6872
}

library/Kubernetes/Web/DaemonSetDetail.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Icinga\Module\Kubernetes\Common\Database;
66
use Icinga\Module\Kubernetes\Model\DaemonSet;
77
use Icinga\Module\Kubernetes\Model\Event;
8+
use Icinga\Module\Kubernetes\Model\Label;
89
use Icinga\Module\Kubernetes\Model\ReplicaSet;
910
use Icinga\Module\Kubernetes\Model\ReplicaSetCondition;
1011
use ipl\Html\Attributes;
@@ -13,6 +14,7 @@
1314
use ipl\Html\Text;
1415
use ipl\Stdlib\Filter;
1516
use ipl\Stdlib\Str;
17+
use ipl\Web\Widget\HorizontalKeyValue;
1618
use ipl\Web\Widget\TimeAgo;
1719

1820
class DaemonSetDetail extends BaseHtmlElement
@@ -49,7 +51,10 @@ protected function assemble()
4951
t('Created') => new TimeAgo($this->daemonSet->created->getTimestamp())
5052
]));
5153

52-
$this->addHtml(new ConditionTable($this->daemonSet, (new ReplicaSetCondition())->getColumnDefinitions()));
54+
$this->addHtml(
55+
new Labels($this->daemonSet->label),
56+
new ConditionTable($this->daemonSet, (new ReplicaSetCondition())->getColumnDefinitions())
57+
);
5358

5459
$this->addHtml(new HtmlElement(
5560
'section',

library/Kubernetes/Web/DeploymentDetail.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@
66

77
use Icinga\Module\Kubernetes\Model\Deployment;
88
use Icinga\Module\Kubernetes\Model\DeploymentCondition;
9+
use Icinga\Module\Kubernetes\Model\Label;
910
use ipl\Html\Attributes;
1011
use ipl\Html\BaseHtmlElement;
1112
use ipl\Html\HtmlElement;
1213
use ipl\Html\Text;
1314
use ipl\Stdlib\Str;
15+
use ipl\Web\Widget\HorizontalKeyValue;
1416
use ipl\Web\Widget\TimeAgo;
1517

1618
class DeploymentDetail extends BaseHtmlElement
@@ -46,7 +48,10 @@ protected function assemble()
4648
t('Created') => new TimeAgo($this->deployment->created->getTimestamp())
4749
]));
4850

49-
$this->addHtml(new ConditionTable($this->deployment, (new DeploymentCondition())->getColumnDefinitions()));
51+
$this->addHtml(
52+
new Labels($this->deployment->label),
53+
new ConditionTable($this->deployment, (new DeploymentCondition())->getColumnDefinitions())
54+
);
5055

5156
$this->addHtml(new HtmlElement(
5257
'section',

library/Kubernetes/Web/Labels.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
/* Icinga Kubernetes Web | (c) 2023 Icinga GmbH | GPLv2 */
4+
5+
namespace Icinga\Module\Kubernetes\Web;
6+
7+
use ipl\Html\BaseHtmlElement;
8+
use ipl\Html\HtmlElement;
9+
use ipl\Html\Text;
10+
use ipl\Web\Widget\HorizontalKeyValue;
11+
12+
class Labels extends BaseHtmlElement
13+
{
14+
protected $tag = 'section';
15+
16+
protected $defaultAttributes = ['class' => 'labels'];
17+
18+
/** @var iterable<Labels> */
19+
protected $labels;
20+
21+
public function __construct(iterable $labels)
22+
{
23+
$this->labels = $labels;
24+
}
25+
26+
protected function assemble()
27+
{
28+
$this->addHtml(new HtmlElement('h2', null, new Text(t('Labels'))));
29+
30+
foreach ($this->labels as $label) {
31+
$this->addHtml(new HorizontalKeyValue($label->name, $label->value));
32+
}
33+
}
34+
}

0 commit comments

Comments
 (0)