From 5d010446075fbc9175daf8ba69192cbc03a69b0e Mon Sep 17 00:00:00 2001 From: Nathaniel Moseley <677609+FinalDoom@users.noreply.github.com> Date: Mon, 2 Dec 2024 13:54:20 -0700 Subject: [PATCH 1/2] Return comma separated list of LB IPs not just first (cherry picked from commit 156de9bcb2b9251738405bbe0664e17971c61065) --- .../Plugin/KubernetesUtils.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/KubernetesPfSenseController/Plugin/KubernetesUtils.php b/src/KubernetesPfSenseController/Plugin/KubernetesUtils.php index 3ca3d8f..390098a 100644 --- a/src/KubernetesPfSenseController/Plugin/KubernetesUtils.php +++ b/src/KubernetesPfSenseController/Plugin/KubernetesUtils.php @@ -197,14 +197,22 @@ public static function getServiceIp($service) } /** - * Get IP address of an ingress resource + * Get list of IP addresses of an ingress resource as comma-separated string * * @param $ingress * @return mixed */ public static function getIngressIp($ingress) { - return $ingress['status']['loadBalancer']['ingress'][0]['ip']; + return implode( + ',', + array_map( + function ($lbIngress) { + return $lbIngress['ip']; + }, + $ingress['status']['loadBalancer']['ingress']; + ) + ); } /** From 1b890bbd63feb2002c18f4935f12d19c50132e1f Mon Sep 17 00:00:00 2001 From: Nathaniel Moseley <677609+FinalDoom@users.noreply.github.com> Date: Mon, 2 Dec 2024 17:04:26 -0700 Subject: [PATCH 2/2] Fix single IP for dnsmasq --- .../Plugin/DNSIngresses.php | 10 ++++++---- .../Plugin/DNSResourceTrait.php | 7 +++++++ .../Plugin/KubernetesUtils.php | 13 +++++-------- 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/src/KubernetesPfSenseController/Plugin/DNSIngresses.php b/src/KubernetesPfSenseController/Plugin/DNSIngresses.php index b6089ee..15b94f5 100644 --- a/src/KubernetesPfSenseController/Plugin/DNSIngresses.php +++ b/src/KubernetesPfSenseController/Plugin/DNSIngresses.php @@ -126,17 +126,19 @@ public function buildResourceHosts(&$resourceHosts, $ingress) return; } - $ip = KubernetesUtils::getIngressIp($ingress); - if (empty($ip)) { + $ips = KubernetesUtils::getIngressIp($ingress); + if (empty($ips)) { return; } foreach ($ingress['spec']['rules'] as $rule) { if ($this->shouldCreateHost($rule['host'])) { $resourceHosts[$rule['host']] = [ - 'ip' => $ip, + 'ip' => implode(',', $ips), 'resource' => $ingress, ]; - } + } else { +var_dump("what"); +} } } diff --git a/src/KubernetesPfSenseController/Plugin/DNSResourceTrait.php b/src/KubernetesPfSenseController/Plugin/DNSResourceTrait.php index 4711d8a..e3c31a3 100644 --- a/src/KubernetesPfSenseController/Plugin/DNSResourceTrait.php +++ b/src/KubernetesPfSenseController/Plugin/DNSResourceTrait.php @@ -69,10 +69,14 @@ public function doAction() if ($dnsmasqEnabled) { $dnsmasqConfig = PfSenseConfigBlock::getRootConfigBlock($this->getController()->getRegistryItem('pfSenseClient'), 'dnsmasq'); + if (!isset($dnsmasqConfig->data) || !is_array($dnsmasqConfig->data)) { + $dnsmasqConfig->data = []; + } if (!isset($dnsmasqConfig->data['hosts']) || !is_array($dnsmasqConfig->data['hosts'])) { $dnsmasqConfig->data['hosts'] = []; } foreach ($hosts as $host) { + $host['ip'] = explode(',', $host['ip'], 2)[0]; Utils::putListItemMultiKey($dnsmasqConfig->data['hosts'], $host, ['host', 'domain']); } @@ -87,6 +91,9 @@ public function doAction() if ($unboundEnabled) { $unboundConfig = PfSenseConfigBlock::getRootConfigBlock($this->getController()->getRegistryItem('pfSenseClient'), 'unbound'); + if (!isset($unboundConfig->data) || !is_array($unboundConfig->data)) { + $unboundConfig->data = []; + } if (!isset($unboundConfig->data['hosts']) || !is_array($unboundConfig->data['hosts'])) { $unboundConfig->data['hosts'] = []; } diff --git a/src/KubernetesPfSenseController/Plugin/KubernetesUtils.php b/src/KubernetesPfSenseController/Plugin/KubernetesUtils.php index 390098a..1b81828 100644 --- a/src/KubernetesPfSenseController/Plugin/KubernetesUtils.php +++ b/src/KubernetesPfSenseController/Plugin/KubernetesUtils.php @@ -204,14 +204,11 @@ public static function getServiceIp($service) */ public static function getIngressIp($ingress) { - return implode( - ',', - array_map( - function ($lbIngress) { - return $lbIngress['ip']; - }, - $ingress['status']['loadBalancer']['ingress']; - ) + return array_map( + function ($lbIngress) { + return $lbIngress['ip']; + }, + $ingress['status']['loadBalancer']['ingress'] ); }