From 1f6e394379fc4727b71ebcf369996ced977c07ed Mon Sep 17 00:00:00 2001 From: karmab Date: Wed, 23 Oct 2024 11:32:37 +0200 Subject: [PATCH] openshift: use smarter logic to get coredns ip --- kvirt/cluster/openshift/99-forcedns | 3 ++- kvirt/providers/kvm/__init__.py | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/kvirt/cluster/openshift/99-forcedns b/kvirt/cluster/openshift/99-forcedns index 0b48accea..02b5c2260 100644 --- a/kvirt/cluster/openshift/99-forcedns +++ b/kvirt/cluster/openshift/99-forcedns @@ -7,7 +7,8 @@ fi if [ "$2" = "dhcp4-change" ] || [ "$2" = "dhcp6-change" ] || [ "$2" = "up" ] || [ "$2" = "connectivity-change" ]; then sleep 2 - IP=$(/bin/hostname -I | awk '{print $1}') + NIC={{ "$(ip -6 r | grep -v lo | head -1 | grep -oP '(?<=dev )[^ ]*')" if ipv6 else "$(ip r | grep default | head -1 | grep -oP '(?<=dev )[^ ]*')" }} + IP={{ "$(ip -o -f inet6 addr show $NIC | head -1 | grep -oP '(?<=inet6 )[^ ]*' | cut -d '/' -f 1)" if ipv6 else "$(ip -o -f inet addr show $NIC | head -1 | grep -oP '(?<=inet )[^ ]*' | cut -d '/' -f 1)" }} if [ "$IP" != "" ] ; then grep -q $IP /etc/resolv.conf if [ "$?" != "0" ] ; then diff --git a/kvirt/providers/kvm/__init__.py b/kvirt/providers/kvm/__init__.py index 49797b078..c028f7759 100644 --- a/kvirt/providers/kvm/__init__.py +++ b/kvirt/providers/kvm/__init__.py @@ -686,7 +686,7 @@ def create(self, name, virttype=None, profile='kvirt', flavor=None, plan='kvirt' nic = nets[index].get('nic', 'ens3') if needs_ignition and ip is not None and netmask is not None and gateway is not None: nameservers = [nameserver] if isinstance(nameserver, str) else nameserver - nameservers = ' '.join([f"nameserver={nameserver}" for name in nameservers]) + nameservers = ' '.join([f"nameserver={name}" for name in nameservers]) warning("Injecting static networking via cmdline") cmdline = f'ip={ip}::{gateway}:{netmask}::{nic}:none {nameservers}' del nets[index]['ip']