diff --git a/controllers/ovndbcluster_controller.go b/controllers/ovndbcluster_controller.go index 156c5deb..485f6a61 100644 --- a/controllers/ovndbcluster_controller.go +++ b/controllers/ovndbcluster_controller.go @@ -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) @@ -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 } @@ -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 } @@ -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") diff --git a/templates/ovncontroller/bin/functions b/templates/ovncontroller/bin/functions index 094f92b0..b6d8f721 100755 --- a/templates/ovncontroller/bin/functions +++ b/templates/ovncontroller/bin/functions @@ -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} diff --git a/templates/ovndbcluster/bin/settings.sh b/templates/ovndbcluster/bin/settings.sh index 627cb6fb..97e4b4c7 100755 --- a/templates/ovndbcluster/bin/settings.sh +++ b/templates/ovndbcluster/bin/settings.sh @@ -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 diff --git a/templates/ovndbcluster/bin/setup.sh b/templates/ovndbcluster/bin/setup.sh index e1844eb1..48542e1f 100755 --- a/templates/ovndbcluster/bin/setup.sh +++ b/templates/ovndbcluster/bin/setup.sh @@ -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 @@ -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