Skip to content

Commit

Permalink
fix: ipv6 related issues
Browse files Browse the repository at this point in the history
  • Loading branch information
oilbeater committed May 8, 2020
1 parent c0fc0d5 commit 2dd13b2
Show file tree
Hide file tree
Showing 11 changed files with 41 additions and 26 deletions.
4 changes: 2 additions & 2 deletions dist/images/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,10 @@ spec:
type: string
JSONPath: .spec.gatewayType
- name: Used
type: integer
type: number
JSONPath: .status.usingIPs
- name: Available
type: integer
type: number
JSONPath: .status.availableIPs
validation:
openAPIV3Schema:
Expand Down
20 changes: 11 additions & 9 deletions dist/images/start-db.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ DB_SB_PORT=${DB_SB_PORT:-6642}

function gen_conn_str {
t=$(echo -n "${NODE_IPS}" | sed 's/[[:space:]]//g' | sed 's/,/ /g')
x=$(for i in ${t}; do echo -n "tcp:$i:$1",; done| sed 's/,$//')
x=$(for i in ${t}; do echo -n "tcp:[$i]:$1",; done| sed 's/,$//')
echo "$x"
}

Expand Down Expand Up @@ -57,14 +57,16 @@ else
/usr/share/ovn/scripts/ovn-ctl \
--db-nb-create-insecure-remote=yes \
--db-sb-create-insecure-remote=yes \
--db-nb-cluster-local-addr="${POD_IP}" \
--db-sb-cluster-local-addr="${POD_IP}" \
--db-nb-cluster-local-addr="[${POD_IP}]" \
--db-sb-cluster-local-addr="[${POD_IP}]" \
--db-nb-addr=[::] \
--db-sb-addr=[::] \
--ovn-northd-nb-db=$(gen_conn_str 6641) \
--ovn-northd-sb-db=$(gen_conn_str 6642) \
start_northd
ovn-nbctl set-connection ptcp:"${DB_NB_PORT}":0.0.0.0
ovn-nbctl set-connection ptcp:"${DB_NB_PORT}":[::]
ovn-nbctl set Connection . inactivity_probe=0
ovn-sbctl set-connection ptcp:"${DB_SB_PORT}":0.0.0.0
ovn-sbctl set-connection ptcp:"${DB_SB_PORT}":[::]
ovn-sbctl set Connection . inactivity_probe=0
else
while ! nc -z "${nb_leader_ip}" "${DB_NB_PORT}" >/dev/null;
Expand All @@ -82,10 +84,10 @@ else
/usr/share/ovn/scripts/ovn-ctl \
--db-nb-create-insecure-remote=yes \
--db-sb-create-insecure-remote=yes \
--db-nb-cluster-local-addr="${POD_IP}" \
--db-sb-cluster-local-addr="${POD_IP}" \
--db-nb-cluster-remote-addr="${nb_leader_ip}" \
--db-sb-cluster-remote-addr="${sb_leader_ip}" \
--db-nb-cluster-local-addr="[${POD_IP}]" \
--db-sb-cluster-local-addr="[${POD_IP}]" \
--db-nb-cluster-remote-addr="[${nb_leader_ip}]" \
--db-sb-cluster-remote-addr="[${sb_leader_ip}]" \
--ovn-northd-nb-db=$(gen_conn_str 6641) \
--ovn-northd-sb-db=$(gen_conn_str 6642) \
start_northd
Expand Down
2 changes: 1 addition & 1 deletion dist/images/start-ovs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ fi
/usr/share/ovn/scripts/ovn-ctl restart_controller

# Set remote ovn-sb for ovn-controller to connect to
ovs-vsctl set open . external-ids:ovn-remote=tcp:"${OVN_SB_SERVICE_HOST}":"${OVN_SB_SERVICE_PORT}"
ovs-vsctl set open . external-ids:ovn-remote=tcp:"[${OVN_SB_SERVICE_HOST}]":"${OVN_SB_SERVICE_PORT}"
ovs-vsctl set open . external-ids:ovn-remote-probe-interval=10000
ovs-vsctl set open . external-ids:ovn-openflow-probe-interval=180
ovs-vsctl set open . external-ids:ovn-encap-type=geneve
Expand Down
6 changes: 3 additions & 3 deletions pkg/apis/kubeovn/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,9 @@ type SubnetStatus struct {
// +patchStrategy=merge
Conditions []SubnetCondition `json:"conditions,omitempty" patchStrategy:"merge" patchMergeKey:"type"`

AvailableIPs uint64 `json:"availableIPs"`
UsingIPs uint64 `json:"usingIPs"`
ActivateGateway string `json:"activateGateway"`
AvailableIPs float64 `json:"availableIPs"`
UsingIPs float64 `json:"usingIPs"`
ActivateGateway string `json:"activateGateway"`
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
Expand Down
4 changes: 4 additions & 0 deletions pkg/client/informers/externalversions/generic.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions pkg/controller/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func (c *Controller) handleUpdateEndpoint(key string) error {
}

for _, port := range svc.Spec.Ports {
vip := fmt.Sprintf("%s:%d", clusterIP, port.Port)
vip := fmt.Sprintf("[%s]:%d", clusterIP, port.Port)
backends := getServicePortBackends(ep, port, clusterIP)
if port.Protocol == v1.ProtocolTCP {
// for performance reason delete lb with no backends
Expand Down Expand Up @@ -168,7 +168,7 @@ func getServicePortBackends(endpoints *v1.Endpoints, servicePort v1.ServicePort,

for _, address := range subset.Addresses {
if util.CheckProtocol(serviceIP) == util.CheckProtocol(address.IP) {
backends = append(backends, fmt.Sprintf("%s:%d", address.IP, targetPort))
backends = append(backends, fmt.Sprintf("[%s]:%d", address.IP, targetPort))
}
}
}
Expand Down
1 change: 0 additions & 1 deletion pkg/controller/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ func (c *Controller) initDefaultLogicalSwitch() error {
NatOutgoing: true,
GatewayType: kubeovnv1.GWDistributedType,
Protocol: util.CheckProtocol(c.config.DefaultCIDR),
Vlan: c.config.DefaultVlanName,
},
}
if c.config.NetworkType == util.NetworkTypeVlan {
Expand Down
4 changes: 2 additions & 2 deletions pkg/controller/subnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -991,8 +991,8 @@ func calcSubnetStatusIP(subnet *kubeovnv1.Subnet, c *Controller) error {
for _, podUsedIP := range podUsedIPs.Items {
toSubIPs = append(toSubIPs, podUsedIP.Spec.IPAddress)
}
availableIPs := util.AddressCount(cidr) - uint64(len(util.UniqString(toSubIPs)))
usingIPs := uint64(len(podUsedIPs.Items))
availableIPs := util.AddressCount(cidr) - float64(len(util.UniqString(toSubIPs)))
usingIPs := float64(len(podUsedIPs.Items))
subnet.Status.AvailableIPs = availableIPs
subnet.Status.UsingIPs = usingIPs
bytes, err := subnet.Status.Bytes()
Expand Down
10 changes: 8 additions & 2 deletions pkg/daemon/ovs.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,14 @@ func configureContainerNic(nicName, ipAddr, gateway string, macAddr net.Hardware
// For docker version >=17.x the "none" network will disable ipv6 by default.
// We have to enable ipv6 here to add v6 address and gateway.
// See https://github.com/containernetworking/cni/issues/531
if _, err = sysctl.Sysctl("net.ipv6.conf.all.disable_ipv6", "0"); err != nil {
return fmt.Errorf("failed to enable ipv6 on all nic %v", err)
value, err := sysctl.Sysctl("net.ipv6.conf.all.disable_ipv6")
if err != nil {
return fmt.Errorf("failed to get sysctl net.ipv6.conf.all.disable_ipv6 %v", err)
}
if value != "0" {
if _, err = sysctl.Sysctl("net.ipv6.conf.all.disable_ipv6", "0"); err != nil {
return fmt.Errorf("failed to enable ipv6 on all nic %v", err)
}
}
}

Expand Down
8 changes: 6 additions & 2 deletions pkg/util/net.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package util

import (
"fmt"
"math"
"math/big"
"math/rand"
"net"
Expand Down Expand Up @@ -91,7 +92,10 @@ func CheckProtocol(address string) string {
return kubeovnv1.ProtocolIPv6
}

func AddressCount(network *net.IPNet) uint64 {
func AddressCount(network *net.IPNet) float64 {
prefixLen, bits := network.Mask.Size()
return 1 << (uint64(bits) - uint64(prefixLen))
if bits-prefixLen < 2 {
return 0
}
return math.Pow(2, float64(bits-prefixLen)) - 2
}
4 changes: 2 additions & 2 deletions yamls/crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ spec:
type: string
JSONPath: .spec.gatewayType
- name: Used
type: integer
type: number
JSONPath: .status.usingIPs
- name: Available
type: integer
type: number
JSONPath: .status.availableIPs
validation:
openAPIV3Schema:
Expand Down

0 comments on commit 2dd13b2

Please sign in to comment.