Skip to content

Commit

Permalink
add external vpc switch
Browse files Browse the repository at this point in the history
  • Loading branch information
fanriming committed Aug 18, 2021
1 parent f12e5ee commit 7724990
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
7 changes: 5 additions & 2 deletions pkg/controller/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,9 @@ type Configuration struct {
DefaultVlanName string
DefaultVlanID int

EnableLb bool
EnableNP bool
EnableLb bool
EnableNP bool
EnableExternalVpc bool
}

// ParseFlags parses cmd args then init kubeclient and conf
Expand Down Expand Up @@ -95,6 +96,7 @@ func ParseFlags() (*Configuration, error) {
argPodNicType = pflag.String("pod-nic-type", "veth-pair", "The default pod network nic implementation type, default: veth-pair")
argEnableLb = pflag.Bool("enable-lb", true, "Enable load balancer, default: true")
argEnableNP = pflag.Bool("enable-np", true, "Enable network policy support, default: true")
argEnableExternalVpc = pflag.Bool("enable-external-vpc", true, "Enable external vpc support, default: true")
)

klogFlags := flag.NewFlagSet("klog", flag.ExitOnError)
Expand Down Expand Up @@ -144,6 +146,7 @@ func ParseFlags() (*Configuration, error) {
PodNicType: *argPodNicType,
EnableLb: *argEnableLb,
EnableNP: *argEnableNP,
EnableExternalVpc: *argEnableExternalVpc,
}

if config.NetworkType == util.NetworkTypeVlan && config.DefaultHostInterface == "" {
Expand Down
8 changes: 5 additions & 3 deletions pkg/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -557,9 +557,11 @@ func (c *Controller) startWorkers(stopCh <-chan struct{}) {
}
}, 6*time.Minute, stopCh)

go wait.Until(func() {
c.syncExternalVpc()
}, 5*time.Second, stopCh)
if c.config.EnableExternalVpc {
go wait.Until(func() {
c.syncExternalVpc()
}, 5*time.Second, stopCh)
}

go wait.Until(c.resyncSubnetMetrics, 30*time.Second, stopCh)
go wait.Until(c.CheckGatewayReady, 5*time.Second, stopCh)
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/gc.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ func (c *Controller) markAndCleanLSP() error {
for _, node := range nodes {
ipNames = append(ipNames, fmt.Sprintf("node-%s", node.Name))
}
lsps, err := c.ovnClient.ListLogicalSwitchPort()
lsps, err := c.ovnClient.ListLogicalSwitchPort(c.config.EnableExternalVpc)
if err != nil {
klog.Errorf("failed to list logical switch port, %v", err)
return err
Expand Down
8 changes: 6 additions & 2 deletions pkg/ovs/ovn-nbctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -515,8 +515,12 @@ func (c Client) LogicalSwitchExists(logicalSwitch string, args ...string) (bool,
return false, nil
}

func (c Client) ListLogicalSwitchPort() ([]string, error) {
output, err := c.ovnNbCommand("--format=csv", "--data=bare", "--no-heading", "--columns=name", "find", "logical_switch_port", "type=\"\"", fmt.Sprintf("external_ids:vendor=%s", util.CniTypeName))
func (c Client) ListLogicalSwitchPort(needVendorFilter bool) ([]string, error) {
cmdArg := []string{"--format=csv", "--data=bare", "--no-heading", "--columns=name", "find", "logical_switch_port", "type=\"\""}
if needVendorFilter {
cmdArg = append(cmdArg, fmt.Sprintf("external_ids:vendor=%s", util.CniTypeName))
}
output, err := c.ovnNbCommand(cmdArg...)
if err != nil {
klog.Errorf("failed to list logical switch port, %v", err)
return nil, err
Expand Down

0 comments on commit 7724990

Please sign in to comment.