Skip to content

Commit

Permalink
Remove excess code
Browse files Browse the repository at this point in the history
  • Loading branch information
fanriming authored and oilbeater committed Feb 14, 2022
1 parent 273eb84 commit 9c5556c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 17 deletions.
2 changes: 1 addition & 1 deletion pkg/controller/subnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,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, vpc.Status.Router, subnet.Spec.Protocol, subnet.Spec.CIDRBlock, subnet.Spec.Gateway, subnet.Spec.ExcludeIps, needRouter); err != nil {
if err := c.ovnClient.CreateLogicalSwitch(subnet.Name, vpc.Status.Router, subnet.Spec.CIDRBlock, subnet.Spec.Gateway, needRouter); err != nil {
c.patchSubnetStatus(subnet, "CreateLogicalSwitchFailed", err.Error())
return err
}
Expand Down
21 changes: 5 additions & 16 deletions pkg/ovs/ovn-nbctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -390,29 +390,18 @@ func (c Client) SetLogicalSwitchConfig(ls, lr, protocol, subnet, gateway string,
}

// CreateLogicalSwitch create logical switch in ovn, connect it to router and apply tcp/udp lb rules
func (c Client) CreateLogicalSwitch(ls, lr, protocol, subnet, gateway string, excludeIps []string, needRouter bool) error {
var err error
switch protocol {
case kubeovnv1.ProtocolIPv4:
_, err = c.ovnNbCommand(MayExist, "ls-add", ls, "--",
"set", "logical_switch", ls, fmt.Sprintf("external_ids:vendor=%s", util.CniTypeName))
case kubeovnv1.ProtocolIPv6:
_, err = c.ovnNbCommand(MayExist, "ls-add", ls, "--",
"set", "logical_switch", ls, fmt.Sprintf("external_ids:vendor=%s", util.CniTypeName))
case kubeovnv1.ProtocolDual:
// gateway is not an official column, which is used for private
_, err = c.ovnNbCommand(MayExist, "ls-add", ls, "--",
"set", "logical_switch", ls, fmt.Sprintf("external_ids:vendor=%s", util.CniTypeName))
}
func (c Client) CreateLogicalSwitch(ls, lr, subnet, gateway string, needRouter bool) error {
_, err := c.ovnNbCommand(MayExist, "ls-add", ls, "--",
"set", "logical_switch", ls, fmt.Sprintf("external_ids:vendor=%s", util.CniTypeName))

if err != nil {
klog.Errorf("create switch %s failed: %v", ls, err)
return err
}

ip := util.GetIpAddrWithMask(gateway, subnet)
mac := util.GenerateMac()
if needRouter {
ip := util.GetIpAddrWithMask(gateway, subnet)
mac := util.GenerateMac()
if err := c.createRouterPort(ls, lr, ip, mac); err != nil {
klog.Errorf("failed to connect switch %s to router, %v", ls, err)
return err
Expand Down

0 comments on commit 9c5556c

Please sign in to comment.