Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More ovsdb porting of OVN functions #586

Merged
merged 4 commits into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions internal/server/network/driver_ovn.go
Original file line number Diff line number Diff line change
Expand Up @@ -2064,7 +2064,7 @@ func (n *ovn) setup(update bool) error {
}

if !update {
revert.Add(func() { _ = n.state.OVNNB.ChassisGroupDelete(n.getChassisGroupName()) })
revert.Add(func() { _ = n.state.OVNNB.DeleteChassisGroup(context.TODO(), n.getChassisGroupName()) })
}

// Create logical router.
Expand Down Expand Up @@ -2758,7 +2758,7 @@ func (n *ovn) Delete(clientType request.ClientType) error {
}

// Must be done after logical router removal.
err = n.state.OVNNB.ChassisGroupDelete(n.getChassisGroupName())
err = n.state.OVNNB.DeleteChassisGroup(context.TODO(), n.getChassisGroupName())
if err != nil {
return err
}
Expand Down
5 changes: 5 additions & 0 deletions internal/server/network/ovn/ovn_icnb_actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ func (o *ICNB) DeleteTransitSwitch(ctx context.Context, name string, force bool)

err := o.client.Get(ctx, &transitSwitch)
if err != nil {
// Already exists.
if err == ErrNotFound {
return nil
}

return err
}

Expand Down
41 changes: 29 additions & 12 deletions internal/server/network/ovn/ovn_nb_actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ type OVNSwitchPortOpts struct {
Parent OVNSwitchPort // Optional, if set a nested port is created.
VLAN uint16 // Optional, use with Parent to request a specific VLAN for nested port.
Location string // Optional, use to indicate the name of the server this port is bound to.
RouterPort string // Optional, the name of the associated logical router port.
RouterPort OVNRouterPort // Optional, the name of the associated logical router port.
}

// OVNACLRule represents an ACL rule that can be added to a logical switch or port group.
Expand Down Expand Up @@ -1223,7 +1223,7 @@ func (o *NB) CreateLogicalSwitchPort(ctx context.Context, switchName OVNSwitch,
if opts.RouterPort != "" {
logicalSwitchPort.Type = "router"
logicalSwitchPort.Addresses = []string{"router"}
logicalSwitchPort.Options = map[string]string{"router-port": opts.RouterPort}
logicalSwitchPort.Options = map[string]string{"router-port": string(opts.RouterPort)}
} else {
ipStr := make([]string, 0, len(opts.IPs))
for _, ip := range opts.IPs {
Expand Down Expand Up @@ -1694,20 +1694,37 @@ func (o *NB) CreateChassisGroup(ctx context.Context, haChassisGroupName OVNChass
return nil
}

// ChassisGroupDelete deletes an HA chassis group.
func (o *NB) ChassisGroupDelete(haChassisGroupName OVNChassisGroup) error {
// ovn-nbctl doesn't provide an "--if-exists" option for removing chassis groups.
existing, err := o.nbctl("--no-headings", "--data=bare", "--colum=name", "find", "ha_chassis_group", fmt.Sprintf("name=%s", string(haChassisGroupName)))
// DeleteChassisGroup deletes an HA chassis group.
func (o *NB) DeleteChassisGroup(ctx context.Context, haChassisGroupName OVNChassisGroup) error {
// Get the current chassis group.
haChassisGroup := ovnNB.HAChassisGroup{
Name: string(haChassisGroupName),
}

err := o.client.Get(ctx, &haChassisGroup)
if err != nil {
// Already gone.
if err == ErrNotFound {
return nil
}

return err
}

// Remove chassis group if exists.
if strings.TrimSpace(existing) != "" {
_, err := o.nbctl("ha-chassis-group-del", string(haChassisGroupName))
if err != nil {
return err
}
// Delete the chassis group.
deleteOps, err := o.client.Where(&haChassisGroup).Delete()
if err != nil {
return err
}

resp, err := o.client.Transact(ctx, deleteOps...)
if err != nil {
return err
}

_, err = ovsdb.CheckOperationResults(resp, deleteOps)
if err != nil {
return err
}

return nil
Expand Down
Loading