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 3ca3d8f..1b81828 100644 --- a/src/KubernetesPfSenseController/Plugin/KubernetesUtils.php +++ b/src/KubernetesPfSenseController/Plugin/KubernetesUtils.php @@ -197,14 +197,19 @@ 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 array_map( + function ($lbIngress) { + return $lbIngress['ip']; + }, + $ingress['status']['loadBalancer']['ingress'] + ); } /**