Skip to content
Draft
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
72 changes: 72 additions & 0 deletions bindata/network/ovn-kubernetes/common/008-script-lib.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,75 @@ data:
echo "$(date --iso-8601=seconds) [{$1}] ${2}"
}

# get-first-interface-address() returns the first global address on the
# specified interface for the requested IP family.
#
# Arguments:
# $1 - interface name
# $2 - IP family, either 4 or 6
get-first-interface-address()
{
local interface_name=$1
local family=$2

ip -o -"${family}" addr show dev "${interface_name}" scope global 2>/dev/null | \
awk 'NR == 1 {split($4, addr, "/"); print addr[1]}'
}

# set-encap-ip-flag() resolves --encap-ip from /etc/ovnk/encap_interface
# or from the OVN_ENCAP_IP environment variable.
#
# The host root is also checked through /host so this continues to work on
# node pods that do not mount /etc/ovnk directly into the container.
set-encap-ip-flag()
{
local encap_interface_file="/etc/ovnk/encap_interface"
local encap_interface=""
local encap_ipv4=""
local encap_ipv6=""
local resolved_encap_ips=""

ovn_encap_ip_flag=

if [[ ! -f "${encap_interface_file}" && -f "/host${encap_interface_file}" ]]; then
encap_interface_file="/host${encap_interface_file}"
fi

if [[ -f "${encap_interface_file}" ]]; then
read -r encap_interface < "${encap_interface_file}"
encap_interface="${encap_interface//[[:space:]]/}"
if [[ -z "${encap_interface}" ]]; then
log "encapip" "Ignoring empty encap interface file ${encap_interface_file}"
else
encap_ipv4="$(get-first-interface-address "${encap_interface}" 4)"
encap_ipv6="$(get-first-interface-address "${encap_interface}" 6)"

if [[ -n "${encap_ipv4}" ]]; then
resolved_encap_ips="${encap_ipv4}"
fi
if [[ -n "${encap_ipv6}" ]]; then
if [[ -n "${resolved_encap_ips}" ]]; then
resolved_encap_ips="${resolved_encap_ips},${encap_ipv6}"
else
resolved_encap_ips="${encap_ipv6}"
fi
fi

if [[ -n "${resolved_encap_ips}" ]]; then
log "encapip" "Resolved encap IPs ${resolved_encap_ips} from interface ${encap_interface}"
ovn_encap_ip_flag="--encap-ip=${resolved_encap_ips}"
else
log "encapip" "No global IPv4 or IPv6 address found on interface ${encap_interface}"
fi
fi
fi

if [[ -n "${OVN_ENCAP_IP}" ]]; then
log "encapip" "Using OVN_ENCAP_IP override ${OVN_ENCAP_IP}"
ovn_encap_ip_flag="--encap-ip=${OVN_ENCAP_IP}"
fi
Comment on lines +544 to +547
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Normalize OVN_ENCAP_IP before building the flag.

At Line 544, OVN_ENCAP_IP is used verbatim. Accidental whitespace in env overrides can produce an invalid/split --encap-ip argument at runtime.

Suggested patch
-      if [[ -n "${OVN_ENCAP_IP}" ]]; then
-        log "encapip" "Using OVN_ENCAP_IP override ${OVN_ENCAP_IP}"
-        ovn_encap_ip_flag="--encap-ip=${OVN_ENCAP_IP}"
+      local encap_ip_override="${OVN_ENCAP_IP//[[:space:]]/}"
+      if [[ -n "${encap_ip_override}" ]]; then
+        log "encapip" "Using OVN_ENCAP_IP override ${encap_ip_override}"
+        ovn_encap_ip_flag="--encap-ip=${encap_ip_override}"
       fi
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if [[ -n "${OVN_ENCAP_IP}" ]]; then
log "encapip" "Using OVN_ENCAP_IP override ${OVN_ENCAP_IP}"
ovn_encap_ip_flag="--encap-ip=${OVN_ENCAP_IP}"
fi
local encap_ip_override="${OVN_ENCAP_IP//[[:space:]]/}"
if [[ -n "${encap_ip_override}" ]]; then
log "encapip" "Using OVN_ENCAP_IP override ${encap_ip_override}"
ovn_encap_ip_flag="--encap-ip=${encap_ip_override}"
fi
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@bindata/network/ovn-kubernetes/common/008-script-lib.yaml` around lines 544 -
547, Normalize and trim whitespace from the OVN_ENCAP_IP environment variable
before constructing ovn_encap_ip_flag: create a trimmed value (e.g., strip
leading/trailing whitespace from OVN_ENCAP_IP), check that the trimmed value is
non-empty, then set ovn_encap_ip_flag="--encap-ip=${TRIMMED_OVN_ENCAP_IP}" and
log the trimmed value; update uses of OVN_ENCAP_IP to reference the trimmed
variable so accidental surrounding whitespace won't produce an invalid or split
--encap-ip argument.

}

# cni-bin-copy() detects the host OS and copies the correct shim binary to
# the CNI binary directory.
#
Expand Down Expand Up @@ -708,6 +777,8 @@ data:
ovn_v6_transit_switch_subnet_opt="--cluster-manager-v6-transit-subnet {{.V6TransitSwitchSubnet}}"
fi

set-encap-ip-flag

exec /usr/bin/ovnkube \
${init_ovnkube_controller} \
--init-node "${K8S_NODE}" \
Expand All @@ -718,6 +789,7 @@ data:
${gateway_mode_flags} \
${node_mgmt_port_netdev_flags} \
${ovnkube_node_mode} \
${ovn_encap_ip_flag} \
--metrics-bind-address "127.0.0.1:${metrics_port}" \
--ovn-metrics-bind-address "127.0.0.1:${ovn_metrics_port}" \
--metrics-enable-pprof \
Expand Down