Skip to content

Commit

Permalink
Merge pull request #241 from rabi/ipv6
Browse files Browse the repository at this point in the history
Make the scripts ipv6 compatible
  • Loading branch information
openshift-merge-bot[bot] committed Mar 7, 2024
2 parents 67e8aec + 8f8860c commit 3abd273
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 12 deletions.
12 changes: 4 additions & 8 deletions controllers/ovndbcluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ func (r *OVNDBClusterReconciler) reconcileNormal(ctx context.Context, instance *
return ctrl.Result{}, nil
}

func getPodIPv4InNetwork(ovnPod corev1.Pod, namespace string, networkAttachment string) (string, error) {
func getPodIPInNetwork(ovnPod corev1.Pod, namespace string, networkAttachment string) (string, error) {
netStat, err := nad.GetNetworkStatusFromAnnotation(ovnPod.Annotations)
if err != nil {
err = fmt.Errorf("Error while getting the Network Status for pod %s: %v", ovnPod.Name, err)
Expand All @@ -493,14 +493,12 @@ func getPodIPv4InNetwork(ovnPod corev1.Pod, namespace string, networkAttachment
for _, v := range netStat {
if v.Name == namespace+"/"+networkAttachment {
for _, ip := range v.IPs {
if !strings.Contains(ip, ":") {
return ip, nil
}
return ip, nil
}
}
}
// If this is reached it means that no IP was found, construct error and return
err = fmt.Errorf("Error while getting IPv4 address from pod %s in network %s, IP is empty", ovnPod.Name, networkAttachment)
err = fmt.Errorf("Error while getting IP address from pod %s in network %s, IP is empty", ovnPod.Name, networkAttachment)
return "", err
}

Expand Down Expand Up @@ -632,8 +630,7 @@ func (r *OVNDBClusterReconciler) reconcileServices(
return ctrl.Result{}, err
}

// Currently only IPv4 is supported
dnsIP, err := getPodIPv4InNetwork(ovnPod, instance.Namespace, instance.Spec.NetworkAttachment)
dnsIP, err := getPodIPInNetwork(ovnPod, instance.Namespace, instance.Spec.NetworkAttachment)
if err != nil {
return ctrl.Result{}, err
}
Expand All @@ -654,7 +651,6 @@ func (r *OVNDBClusterReconciler) reconcileServices(
}
}
// dbAddress will contain ovsdbserver-(nb|sb).openstack.svc or empty
// IPv6 is not handled
instance.Status.DBAddress = ovndbcluster.GetDBAddress(svc, serviceName, instance.Namespace)

Log.Info("Reconciled OVN DB Cluster Service successfully")
Expand Down
2 changes: 1 addition & 1 deletion templates/ovncontroller/bin/functions
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

# Configs are obtained from ENV variables.
OvnBridge=${OvnBridge:-"br-int"}
OvnRemote=${OvnRemote:-"tcp:127.0.0.1:6642"}
OvnRemote=${OvnRemote:-"tcp:localhost:6642"}
OvnEncapType=${OvnEncapType:-"geneve"}
OvnAvailabilityZones=${OvnAvailabilityZones:-""}
EnableChassisAsGateway=${EnableChassisAsGateway:-true}
Expand Down
11 changes: 10 additions & 1 deletion templates/ovndbcluster/bin/settings.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,17 @@ if [[ "$(hostname)" == "{{ .SERVICE_NAME }}-0" ]]; then
sleep 1
done

PODNAME=$(hostname -f | cut -d. -f1,2)
PODIPV6=$(grep "${PODNAME}" /etc/hosts | grep ':' | cut -d$'\t' -f1)

if [[ "" = "${PODIPV6}" ]]; then
DB_ADDR="0.0.0.0"
else
DB_ADDR="[::]"
fi

while [ "$(ovn-${DB_TYPE}ctl --no-leader-only get connection . inactivity_probe)" != "{{ .OVN_INACTIVITY_PROBE }}" ]; do
ovn-${DB_TYPE}ctl --no-leader-only --inactivity-probe={{ .OVN_INACTIVITY_PROBE }} set-connection ptcp:${DB_PORT}:0.0.0.0
ovn-${DB_TYPE}ctl --no-leader-only --inactivity-probe={{ .OVN_INACTIVITY_PROBE }} set-connection ptcp:${DB_PORT}:${DB_ADDR}
done
ovn-${DB_TYPE}ctl --no-leader-only list connection
fi
15 changes: 13 additions & 2 deletions templates/ovndbcluster/bin/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,23 @@ DB_NAME="OVN_Northbound"
if [[ "${DB_TYPE}" == "sb" ]]; then
DB_NAME="OVN_Southbound"
fi

PODNAME=$(hostname -f | cut -d. -f1,2)
PODIPV6=$(grep "${PODNAME}" /etc/hosts | grep ':' | cut -d$'\t' -f1)

if [[ "" = "${PODIPV6}" ]]; then
DB_ADDR="0.0.0.0"
else
DB_ADDR="[::]"
fi

if [[ "$(hostname)" != "{{ .SERVICE_NAME }}-0" ]]; then
rm -f /etc/ovn/ovn${DB_TYPE}_db.db
#ovsdb-tool join-cluster /etc/ovn/ovn${DB_TYPE}_db.db ${DB_NAME} tcp:$(hostname).{{ .SERVICE_NAME }}.${NAMESPACE}.svc.cluster.local:${RAFT_PORT} tcp:{{ .SERVICE_NAME }}-0.{{ .SERVICE_NAME }}.${NAMESPACE}.svc.cluster.local:${RAFT_PORT}
OPTS="--db-${DB_TYPE}-cluster-remote-proto=tcp --db-${DB_TYPE}-cluster-remote-addr={{ .SERVICE_NAME }}-0.{{ .SERVICE_NAME }}.${NAMESPACE}.svc.cluster.local --db-${DB_TYPE}-cluster-remote-port=${RAFT_PORT}"
OPTS="--db-${DB_TYPE}-cluster-remote-proto=tcp --db-${DB_TYPE}-cluster-remote-addr={{ .SERVICE_NAME }}-0.{{ .SERVICE_NAME }}.${NAMESPACE}.svc.cluster.local --db-${DB_TYPE}-cluster-remote-port=${RAFT_PORT} --db-${DB_TYPE}-addr=${DB_ADDR}"
fi


# call to ovn-ctl directly instead of start-${DB_TYPE}-db-server to pass
# extra_args after --
set /usr/share/ovn/scripts/ovn-ctl --no-monitor
Expand All @@ -38,7 +49,7 @@ set "$@" --db-${DB_TYPE}-cluster-local-proto=tcp
set "$@" --db-${DB_TYPE}-cluster-local-addr=$(hostname).{{ .SERVICE_NAME }}.${NAMESPACE}.svc.cluster.local
set "$@" --db-${DB_TYPE}-cluster-local-port=${RAFT_PORT}
set "$@" --db-${DB_TYPE}-probe-interval-to-active={{ .OVN_PROBE_INTERVAL_TO_ACTIVE }}
set "$@" --db-${DB_TYPE}-addr=0.0.0.0
set "$@" --db-${DB_TYPE}-addr=${DB_ADDR}
set "$@" --db-${DB_TYPE}-port=${DB_PORT}

# log to console
Expand Down

0 comments on commit 3abd273

Please sign in to comment.