Skip to content

Commit

Permalink
fix: issues with vlan underlay gateway
Browse files Browse the repository at this point in the history
  • Loading branch information
oilbeater committed Sep 17, 2020
1 parent a301495 commit ab736d8
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 7 deletions.
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ kind-init:
ip_family=ipv4 ha=false j2 yamls/kind.yaml.j2 -o yamls/kind.yaml
kind create cluster --config yamls/kind.yaml --name kube-ovn
kubectl get no -o wide
docker exec kube-ovn-control-plane ip link add link eth0 mac1 type macvlan
docker exec kube-ovn-worker ip link add link eth0 mac1 type macvlan

kind-install:
kind load docker-image --name kube-ovn ${REGISTRY}/kube-ovn:${RELEASE_TAG}
Expand Down
5 changes: 5 additions & 0 deletions pkg/controller/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package controller

import (
"flag"
"fmt"
"os"

clientset "github.com/alauda/kube-ovn/pkg/client/clientset/versioned"
Expand Down Expand Up @@ -143,6 +144,10 @@ func ParseFlags() (*Configuration, error) {
PodNamespace: os.Getenv("KUBE_NAMESPACE"),
}

if config.NetworkType == util.NetworkTypeVlan && config.DefaultHostInterface == "" {
return nil, fmt.Errorf("no host nic for vlan")
}

if config.DefaultGateway == "" {
gw, err := util.FirstSubnetIP(config.DefaultCIDR)
if err != nil {
Expand Down
3 changes: 3 additions & 0 deletions pkg/controller/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ func (c *Controller) initDefaultLogicalSwitch() error {
}
if c.config.NetworkType == util.NetworkTypeVlan {
defaultSubnet.Spec.Vlan = c.config.DefaultVlanName
if c.config.DefaultVlanID == 0 {
defaultSubnet.Spec.UnderlayGateway = true
}
}

_, err = c.config.KubeOvnClient.KubeovnV1().Subnets().Create(&defaultSubnet)
Expand Down
22 changes: 15 additions & 7 deletions pkg/controller/subnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"reflect"
"strconv"
"strings"
"time"

v1 "k8s.io/api/core/v1"
k8serrors "k8s.io/apimachinery/pkg/api/errors"
Expand Down Expand Up @@ -283,6 +284,9 @@ func formatSubnet(subnet *kubeovnv1.Subnet, c *Controller) error {

if c.config.NetworkType == util.NetworkTypeVlan && subnet.Spec.Vlan == "" {
subnet.Spec.Vlan = c.config.DefaultVlanName
if c.config.DefaultVlanID == 0 {
subnet.Spec.UnderlayGateway = true
}
changed = true
}

Expand Down Expand Up @@ -310,6 +314,8 @@ func (c *Controller) handleSubnetFinalizer(subnet *kubeovnv1.Subnet) (bool, erro
klog.Errorf("failed to add finalizer to subnet %s, %v", subnet.Name, err)
return false, err
}
// wait local cache ready
time.Sleep(1 * time.Second)
return false, nil
}

Expand Down Expand Up @@ -417,13 +423,15 @@ func (c *Controller) handleAddOrUpdateSubnet(key string) error {
klog.Errorf("failed to list nodes %v", err)
return err
}
for _, node := range nodes {
for _, addr := range node.Status.Addresses {
if addr.Type == v1.NodeInternalIP && util.CIDRContainIP(subnet.Spec.CIDRBlock, addr.Address) {
err = fmt.Errorf("subnet %s cidr %s conflict with node %s address %s", subnet.Name, subnet.Spec.CIDRBlock, node.Name, addr.Address)
klog.Error(err)
c.patchSubnetStatus(subnet, "ValidateLogicalSwitchFailed", err.Error())
return err
if subnet.Spec.Vlan != "" && !subnet.Spec.UnderlayGateway {
for _, node := range nodes {
for _, addr := range node.Status.Addresses {
if addr.Type == v1.NodeInternalIP && util.CIDRContainIP(subnet.Spec.CIDRBlock, addr.Address) {
err = fmt.Errorf("subnet %s cidr %s conflict with node %s address %s", subnet.Name, subnet.Spec.CIDRBlock, node.Name, addr.Address)
klog.Error(err)
c.patchSubnetStatus(subnet, "ValidateLogicalSwitchFailed", err.Error())
return err
}
}
}
}
Expand Down

0 comments on commit ab736d8

Please sign in to comment.