From 91bea58ee035320200df973d3a69970801bbfcfa Mon Sep 17 00:00:00 2001 From: hailu Date: Fri, 29 Dec 2023 12:09:37 +0800 Subject: [PATCH] feat: getting LISTEN IP for CIDR `CIDR` is easier to manage than `interface` on clusters with different hardware. Change-Id: I1266eb37c1355b95f23efd33856a79f259020017 --- nova/Chart.yaml | 2 +- nova/templates/bin/_nova-compute-init.sh.tpl | 12 +++++++-- .../bin/_nova-console-compute-init.sh.tpl | 12 ++++----- .../bin/_nova-console-proxy-init.sh.tpl | 12 ++++----- nova/templates/bin/_ssh-start.sh.tpl | 8 ++++++ nova/values.yaml | 25 ++++++++++++++----- releasenotes/notes/nova.yaml | 1 + 7 files changed, 51 insertions(+), 21 deletions(-) diff --git a/nova/Chart.yaml b/nova/Chart.yaml index 027777d6af..f9e19b0583 100644 --- a/nova/Chart.yaml +++ b/nova/Chart.yaml @@ -14,7 +14,7 @@ apiVersion: v1 appVersion: v1.0.0 description: OpenStack-Helm Nova name: nova -version: 0.3.30 +version: 0.3.31 home: https://docs.openstack.org/nova/latest/ icon: https://www.openstack.org/themes/openstack/images/project-mascots/Nova/OpenStack_Project_Nova_vertical.png sources: diff --git a/nova/templates/bin/_nova-compute-init.sh.tpl b/nova/templates/bin/_nova-compute-init.sh.tpl index 442e7d6b19..4bc71a393d 100644 --- a/nova/templates/bin/_nova-compute-init.sh.tpl +++ b/nova/templates/bin/_nova-compute-init.sh.tpl @@ -26,7 +26,11 @@ migration_interface="{{- .Values.conf.libvirt.live_migration_interface -}}" if [[ -z $migration_interface ]]; then # search for interface with default routing # If there is not default gateway, exit - migration_interface=$(ip -4 route list 0/0 | awk -F 'dev' '{ print $2; exit }' | awk '{ print $1 }') || exit 1 + migration_network_cidr="{{- .Values.conf.libvirt.live_migration_network_cidr -}}" + if [ -z "${migration_network_cidr}" ] ; then + migration_network_cidr="0/0" + fi + migration_interface=$(ip -4 route list ${migration_network_cidr} | awk -F 'dev' '{ print $2; exit }' | awk '{ print $1 }') || exit 1 fi migration_address=$(ip a s $migration_interface | grep 'inet ' | awk '{print $2}' | awk -F "/" '{print $1}' | head -1) @@ -45,7 +49,11 @@ hypervisor_interface="{{- .Values.conf.hypervisor.host_interface -}}" if [[ -z $hypervisor_interface ]]; then # search for interface with default routing # If there is not default gateway, exit - hypervisor_interface=$(ip -4 route list 0/0 | awk -F 'dev' '{ print $2; exit }' | awk '{ print $1 }') || exit 1 + hypervisor_network_cidr="{{- .Values.conf.hypervisor.host_network_cidr -}}" + if [ -z "${hypervisor_network_cidr}" ] ; then + hypervisor_network_cidr="0/0" + fi + hypervisor_interface=$(ip -4 route list ${hypervisor_network_cidr} | awk -F 'dev' '{ print $2; exit }' | awk '{ print $1 }') || exit 1 fi hypervisor_address=$(ip a s $hypervisor_interface | grep 'inet ' | awk '{print $2}' | awk -F "/" '{print $1}' | head -1) diff --git a/nova/templates/bin/_nova-console-compute-init.sh.tpl b/nova/templates/bin/_nova-console-compute-init.sh.tpl index cb3333052e..b2fb92f0f4 100644 --- a/nova/templates/bin/_nova-console-compute-init.sh.tpl +++ b/nova/templates/bin/_nova-console-compute-init.sh.tpl @@ -21,25 +21,25 @@ console_kind="{{- .Values.console.console_kind -}}" if [ "${console_kind}" == "novnc" ] ; then client_address="{{- .Values.conf.nova.vnc.server_proxyclient_address -}}" client_interface="{{- .Values.console.novnc.compute.vncserver_proxyclient_interface -}}" + client_network_cidr="{{- .Values.console.novnc.compute.vncserver_proxyclient_network_cidr -}}" listen_ip="{{- .Values.conf.nova.vnc.server_listen -}}" elif [ "${console_kind}" == "spice" ] ; then client_address="{{- .Values.conf.nova.spice.server_proxyclient_address -}}" client_interface="{{- .Values.console.spice.compute.server_proxyclient_interface -}}" + client_network_cidr="{{- .Values.console.spice.compute.server_proxyclient_network_cidr -}}" listen_ip="{{- .Values.conf.nova.spice.server_listen -}}" fi if [ -z "${client_address}" ] ; then if [ -z "${client_interface}" ] ; then - if [ -x "$(command -v route)" ] ; then - # search for interface with default routing, if multiple default routes exist then select the one with the lowest metric. - client_interface=$(route -n | awk '/^0.0.0.0/ { print $5 " " $NF }' | sort | awk '{ print $NF; exit }') - else - client_interface=$(ip r | grep default | awk '{print $5}') + if [ -z "${client_network_cidr}" ] ; then + client_network_cidr="0/0" fi + client_interface=$(ip -4 route list ${client_network_cidr} | awk -F 'dev' '{ print $2; exit }' | awk '{ print $1 }') || exit 1 fi # determine client ip dynamically based on interface provided - client_address=$(ip a s $client_interface | grep 'inet ' | awk '{print $2}' | awk -F "/" '{print $1}' | head -n 1) + client_address=$(ip a s $client_interface | grep 'inet ' | awk '{print $2}' | awk -F "/" '{print $1}' | head -1) fi if [ -z "${listen_ip}" ] ; then diff --git a/nova/templates/bin/_nova-console-proxy-init.sh.tpl b/nova/templates/bin/_nova-console-proxy-init.sh.tpl index f3522c9c2b..4eedda9e94 100644 --- a/nova/templates/bin/_nova-console-proxy-init.sh.tpl +++ b/nova/templates/bin/_nova-console-proxy-init.sh.tpl @@ -21,25 +21,25 @@ console_kind="{{- .Values.console.console_kind -}}" if [ "${console_kind}" == "novnc" ] ; then client_address="{{- .Values.conf.nova.vnc.server_proxyclient_address -}}" client_interface="{{- .Values.console.novnc.vncproxy.vncserver_proxyclient_interface -}}" + client_network_cidr="{{- .Values.console.novnc.vncproxy.vncserver_proxyclient_network_cidr -}}" listen_ip="{{- .Values.conf.nova.vnc.server_listen -}}" elif [ "${console_kind}" == "spice" ] ; then client_address="{{- .Values.conf.nova.spice.server_proxyclient_address -}}" client_interface="{{- .Values.console.spice.proxy.server_proxyclient_interface -}}" + client_network_cidr="{{- .Values.console.spice.proxy.server_proxyclient_network_cidr -}}" listen_ip="{{- .Values.conf.nova.spice.server_listen -}}" fi if [ -z "${client_address}" ] ; then if [ -z "${client_interface}" ] ; then - if [ -x "$(command -v route)" ] ; then - # search for interface with default routing, if multiple default routes exist then select the one with the lowest metric. - client_interface=$(route -n | awk '/^0.0.0.0/ { print $5 " " $NF }' | sort | awk '{ print $NF; exit }') - else - client_interface=$(ip r | grep default | awk '{print $5}') + if [ -z "${client_network_cidr}" ] ; then + client_network_cidr="0/0" fi + client_interface=$(ip -4 route list ${client_network_cidr} | awk -F 'dev' '{ print $2; exit }' | awk '{ print $1 }') || exit 1 fi # determine client ip dynamically based on interface provided - client_address=$(ip a s $client_interface | grep 'inet ' | awk '{print $2}' | awk -F "/" '{print $1}' | head -n 1) + client_address=$(ip a s $client_interface | grep 'inet ' | awk '{print $2}' | awk -F "/" '{print $1}' | head -1) fi if [ -z "${listen_ip}" ] ; then diff --git a/nova/templates/bin/_ssh-start.sh.tpl b/nova/templates/bin/_ssh-start.sh.tpl index 562da442d5..feca575bc8 100644 --- a/nova/templates/bin/_ssh-start.sh.tpl +++ b/nova/templates/bin/_ssh-start.sh.tpl @@ -26,7 +26,15 @@ done IFS='' subnet_address="{{- .Values.network.ssh.from_subnet -}}" + +if [ -z "${subnet_address}" ] ; then + subnet_address="0.0.0.0/0" +fi +listen_interface=$(ip -4 route list ${subnet_address} | awk -F 'dev' '{ print $2; exit }' | awk '{ print $1 }') || exit 1 +listen_address=$(ip a s $listen_interface | grep 'inet ' | awk '{print $2}' | awk -F "/" '{print $1}' | head -1) + cat > /tmp/sshd_config_extend <