Skip to content

Commit

Permalink
feat: lsp forwarding external Layer-2 packets (#1487)
Browse files Browse the repository at this point in the history
  • Loading branch information
fanriming committed Apr 26, 2022
1 parent d4d700e commit d631f8f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
7 changes: 7 additions & 0 deletions pkg/controller/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,13 @@ func (c *Controller) handleAddPod(key string) error {
return err
}

if pod.Annotations[fmt.Sprintf(util.Layer2ForwardAnnotationTemplate, podNet.ProviderName)] == "true" {
if err := c.ovnClient.EnablePortLayer2forward(subnet.Name, portName); err != nil {
c.recorder.Eventf(pod, v1.EventTypeWarning, "EnablePortLayer2forwardFailed", err.Error())
return err
}
}

if portSecurity {
sgNames := strings.Split(securityGroupAnnotation, ",")
for _, sgName := range sgNames {
Expand Down
9 changes: 9 additions & 0 deletions pkg/ovs/ovn-nbctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,15 @@ func (c Client) ListVirtualPort(ls string) ([]string, error) {
return result, nil
}

// EnablePortLayer2forward set logical switch port addresses as 'unknown'
func (c Client) EnablePortLayer2forward(ls, port string) error {
if _, err := c.ovnNbCommand("lsp-set-addresses", port, "unknown"); err != nil {
klog.Errorf("enable port %s layer2 forward failed: %v", port, err)
return err
}
return nil
}

// CreatePort create logical switch port in ovn
func (c Client) CreatePort(ls, port, ip, mac, pod, namespace string, portSecurity bool, securityGroups string, vips string, liveMigration bool, enableDHCP bool, dhcpOptions *DHCPOptionsUUIDs) error {
var ovnCommand []string
Expand Down
9 changes: 5 additions & 4 deletions pkg/util/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@ const (
LogicalRouterAnnotation = "ovn.kubernetes.io/logical_router"
VpcAnnotation = "ovn.kubernetes.io/vpc"

PortSecurityAnnotationTemplate = "%s.kubernetes.io/port_security"
PortVipAnnotationTemplate = "%s.kubernetes.io/port_vips"
PortSecurityAnnotation = "ovn.kubernetes.io/port_security"
NorthGatewayAnnotation = "ovn.kubernetes.io/north_gateway"
Layer2ForwardAnnotationTemplate = "%s.kubernetes.io/layer2_forward"
PortSecurityAnnotationTemplate = "%s.kubernetes.io/port_security"
PortVipAnnotationTemplate = "%s.kubernetes.io/port_vips"
PortSecurityAnnotation = "ovn.kubernetes.io/port_security"
NorthGatewayAnnotation = "ovn.kubernetes.io/north_gateway"

AllocatedAnnotationSuffix = ".kubernetes.io/allocated"
AllocatedAnnotationTemplate = "%s.kubernetes.io/allocated"
Expand Down

0 comments on commit d631f8f

Please sign in to comment.