Skip to content

Return comma separated list of LB IPs not just first #28

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/KubernetesPfSenseController/Plugin/DNSIngresses.php
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}
}

Expand Down
7 changes: 7 additions & 0 deletions src/KubernetesPfSenseController/Plugin/DNSResourceTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There was a bug here if the hosts config is empty, it returns an empty string; so fixed that here and on unbound

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']);
}

Expand All @@ -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'] = [];
}
Expand Down
9 changes: 7 additions & 2 deletions src/KubernetesPfSenseController/Plugin/KubernetesUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']
);
}

/**
Expand Down