Skip to content

Commit

Permalink
feat: in vlan mode if physical gateway exists, no need to create a vi…
Browse files Browse the repository at this point in the history
…rtual one
  • Loading branch information
oilbeater committed May 20, 2020
1 parent d13e945 commit 6c89a04
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 19 deletions.
1 change: 1 addition & 0 deletions docs/vlan.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ spec:
gatewayType: distributed
natOutgoing: true
vlan: product
underlayGateway: true # If the gateway exist in physical switch please set underlayGateway to true, otherwise kube-ovn will create a virtual one
namespaces:
- product
```
Expand Down
3 changes: 2 additions & 1 deletion pkg/apis/kubeovn/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ type SubnetSpec struct {
Private bool `json:"private"`
AllowSubnets []string `json:"allowSubnets,omitempty"`

Vlan string `json:"vlan,omitempty"`
Vlan string `json:"vlan,omitempty"`
UnderlayGateway bool `json:"underlayGateway"`
}

// ConditionType encodes information on the condition
Expand Down
26 changes: 14 additions & 12 deletions pkg/controller/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -439,19 +439,21 @@ func (c *Controller) handleUpdatePod(key string) error {
return err
}

if subnet.Spec.GatewayType == kubeovnv1.GWDistributedType {
node, err := c.nodesLister.Get(pod.Spec.NodeName)
if err != nil {
klog.Errorf("get node %s failed %v", pod.Spec.NodeName, err)
return err
}
nodeTunlIPAddr, err := getNodeTunlIP(node)
if err != nil {
return err
}
if !subnet.Spec.UnderlayGateway {
if subnet.Spec.GatewayType == kubeovnv1.GWDistributedType {
node, err := c.nodesLister.Get(pod.Spec.NodeName)
if err != nil {
klog.Errorf("get node %s failed %v", pod.Spec.NodeName, err)
return err
}
nodeTunlIPAddr, err := getNodeTunlIP(node)
if err != nil {
return err
}

if err := c.ovnClient.AddStaticRoute(ovs.PolicySrcIP, podIP, nodeTunlIPAddr.String(), c.config.ClusterRouter); err != nil {
return errors.Annotate(err, "add static route failed")
if err := c.ovnClient.AddStaticRoute(ovs.PolicySrcIP, podIP, nodeTunlIPAddr.String(), c.config.ClusterRouter); err != nil {
return errors.Annotate(err, "add static route failed")
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/subnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ func (c *Controller) handleAddOrUpdateSubnet(key string) error {
if !exist {
subnet.Status.EnsureStandardConditions()
// If multiple namespace use same ls name, only first one will success
if err := c.ovnClient.CreateLogicalSwitch(subnet.Name, subnet.Spec.Protocol, subnet.Spec.CIDRBlock, subnet.Spec.Gateway, subnet.Spec.ExcludeIps); err != nil {
if err := c.ovnClient.CreateLogicalSwitch(subnet.Name, subnet.Spec.Protocol, subnet.Spec.CIDRBlock, subnet.Spec.Gateway, subnet.Spec.ExcludeIps, subnet.Spec.UnderlayGateway); err != nil {
c.patchSubnetStatus(subnet, "CreateLogicalSwitchFailed", err.Error())
return err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/daemon/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ func (c *Controller) reconcileRouters() error {
}
cidrs := make([]string, 0, len(subnets))
for _, subnet := range subnets {
if !subnet.Status.IsReady() {
if !subnet.Status.IsReady() || subnet.Spec.UnderlayGateway {
continue
}
if _, ipNet, err := net.ParseCIDR(subnet.Spec.CIDRBlock); err != nil {
Expand Down
10 changes: 6 additions & 4 deletions pkg/ovs/ovn-nbctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func (c Client) SetLogicalSwitchConfig(ls, protocol, subnet, gateway string, exc
}

// CreateLogicalSwitch create logical switch in ovn, connect it to router and apply tcp/udp lb rules
func (c Client) CreateLogicalSwitch(ls, protocol, subnet, gateway string, excludeIps []string) error {
func (c Client) CreateLogicalSwitch(ls, protocol, subnet, gateway string, excludeIps []string, underlayGateway bool) error {
var err error
switch protocol {
case kubeovnv1.ProtocolIPv4:
Expand All @@ -107,9 +107,11 @@ func (c Client) CreateLogicalSwitch(ls, protocol, subnet, gateway string, exclud
mac := util.GenerateMac()
mask := strings.Split(subnet, "/")[1]
klog.Infof("create route port for switch %s", ls)
if err := c.createRouterPort(ls, c.ClusterRouter, gateway+"/"+mask, mac); err != nil {
klog.Errorf("failed to connect switch %s to router, %v", ls, err)
return err
if !underlayGateway {
if err := c.createRouterPort(ls, c.ClusterRouter, gateway+"/"+mask, mac); err != nil {
klog.Errorf("failed to connect switch %s to router, %v", ls, err)
return err
}
}
if ls != c.NodeSwitch {
// DO NOT add ovn dns/lb to node switch
Expand Down

0 comments on commit 6c89a04

Please sign in to comment.