Skip to content

Commit 8a80575

Browse files
committed
minor logic and performance fixes
1 parent f3ca308 commit 8a80575

File tree

3 files changed

+51
-37
lines changed

3 files changed

+51
-37
lines changed

src/KubernetesPfSenseController/Plugin/DNSResourceTrait.php

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -139,27 +139,44 @@ public function doAction()
139139
*/
140140
public function shouldTriggerFromWatchUpdate($event, $oldItem, $item, $stateKey, $options = [])
141141
{
142-
// will be NULL for ADDED and DELETED
143-
if ($oldItem === null) {
144-
return true;
145-
}
146-
$oldResourceHosts = [];
147-
$newResourceHosts = [];
142+
if ($stateKey == "resources") {
143+
// will be NULL for ADDED and DELETED
144+
if ($oldItem === null) {
145+
$tmpResourceHosts = [];
146+
switch ($event['type']) {
147+
case "ADDED":
148+
case "DELETED":
149+
$this->buildResourceHosts($tmpResourceHosts, $item);
150+
if (count($tmpResourceHosts) > 0) {
151+
return true;
152+
}
153+
break;
154+
}
148155

149-
$this->buildResourceHosts($oldResourceHosts, $oldItem);
150-
$this->buildResourceHosts($newResourceHosts, $item);
156+
return false;
157+
}
151158

152-
foreach ($oldResourceHosts as $host => $value) {
153-
$oldResourceHosts[$host] = ['ip' => $value['ip']];
154-
}
159+
$oldResourceHosts = [];
160+
$newResourceHosts = [];
155161

156-
foreach ($newResourceHosts as $host => $value) {
157-
$newResourceHosts[$host] = ['ip' => $value['ip']];
158-
}
162+
$this->buildResourceHosts($oldResourceHosts, $oldItem);
163+
$this->buildResourceHosts($newResourceHosts, $item);
159164

160-
if (md5(json_encode($oldResourceHosts)) != md5(json_encode($newResourceHosts))) {
161-
return true;
165+
foreach ($oldResourceHosts as $host => $value) {
166+
$oldResourceHosts[$host] = ['ip' => $value['ip']];
167+
}
168+
169+
foreach ($newResourceHosts as $host => $value) {
170+
$newResourceHosts[$host] = ['ip' => $value['ip']];
171+
}
172+
173+
if (md5(json_encode($oldResourceHosts)) != md5(json_encode($newResourceHosts))) {
174+
return true;
175+
}
176+
177+
return false;
162178
}
179+
163180
return false;
164181
}
165182
}

src/KubernetesPfSenseController/Plugin/HAProxyDeclarative.php

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -275,28 +275,25 @@ public function shouldTriggerFromWatchUpdate($event, $oldItem, $item, $stateKey,
275275
return true;
276276
}
277277

278-
// various triggers from updates
279-
if ($oldItem !== null) {
280-
// type changes
281-
if ($oldItem['spec']['type'] !== $item['spec']['type']) {
282-
return true;
283-
}
284-
285-
// ip changes for LoadBalancer services
286-
if ($oldItem['spec']['type'] == "LoadBalancer" && $item['spec']['type'] == "LoadBalancer") {
287-
if ($oldItem['status']['loadBalancer']['ingress'][0]['ip'] != $item['status']['loadBalancer']['ingress'][0]['ip']) {
288-
return true;
289-
}
290-
}
278+
// type changes
279+
if ($oldItem['spec']['type'] !== $item['spec']['type']) {
280+
return true;
281+
}
291282

292-
// port changes
293-
$oldPortHash = md5(json_encode($oldItem['spec']['ports']));
294-
$newPortHash = md5(json_encode($item['spec']['ports']));
295-
if ($oldPortHash != $newPortHash) {
283+
// ip changes for LoadBalancer services
284+
if ($oldItem['spec']['type'] == "LoadBalancer" && $item['spec']['type'] == "LoadBalancer") {
285+
if ($oldItem['status']['loadBalancer']['ingress'][0]['ip'] != $item['status']['loadBalancer']['ingress'][0]['ip']) {
296286
return true;
297287
}
298288
}
299289

290+
// port changes
291+
$oldPortHash = md5(json_encode($oldItem['spec']['ports']));
292+
$newPortHash = md5(json_encode($item['spec']['ports']));
293+
if ($oldPortHash != $newPortHash) {
294+
return true;
295+
}
296+
300297
return false;
301298
break;
302299
}

src/KubernetesPfSenseController/Plugin/MetalLB.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,18 +174,18 @@ private function doActionGeneric()
174174
'groupname' => (string) $template['groupname'],
175175
];
176176
$template = array_merge($defaults, $template);
177-
$template = array_map(function($v){
177+
$template = array_map(function ($v) {
178178
return $v ?: '';
179-
},$template);
179+
}, $template);
180180
break;
181181
case 'frr':
182182
$defaults = [
183183
"sendcommunity" => "disabled",
184184
];
185185
$template = array_merge($defaults, $template);
186-
$template = array_map(function($v){
186+
$template = array_map(function ($v) {
187187
return $v ?: '';
188-
},$template);
188+
}, $template);
189189
break;
190190
}
191191

0 commit comments

Comments
 (0)