-
Notifications
You must be signed in to change notification settings - Fork 450
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Do not Recreate Logical_Router_Port when Vpc recreated (#1570)
* fix issue 1569 * rename some local variable
- Loading branch information
Showing
6 changed files
with
183 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package ovs | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/ovn-org/libovsdb/client" | ||
|
||
"github.com/kubeovn/kube-ovn/pkg/ovsdb/ovnnb" | ||
) | ||
|
||
func (c OvnClient) GetLogicalRouter(name string, ignoreNotFound bool) (*ovnnb.LogicalRouter, error) { | ||
predicate := func(model *ovnnb.LogicalRouter) bool { | ||
return model.Name == name | ||
} | ||
// Logical_Router has no indexes defined in the schema | ||
var result []*ovnnb.LogicalRouter | ||
if err := c.ovnNbClient.WhereCache(predicate).List(context.TODO(), &result); err != nil || len(result) == 0 { | ||
if ignoreNotFound && (err == client.ErrNotFound || len(result) == 0) { | ||
return nil, nil | ||
} | ||
return nil, fmt.Errorf("failed to get logical router %s: %v", name, err) | ||
} | ||
|
||
return result[0], nil | ||
} | ||
|
||
func (c OvnClient) LogicalRouterExists(name string) (bool, error) { | ||
lr, err := c.GetLogicalRouter(name, true) | ||
return lr != nil, err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package ovs | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/ovn-org/libovsdb/client" | ||
"github.com/ovn-org/libovsdb/model" | ||
"github.com/ovn-org/libovsdb/ovsdb" | ||
|
||
ovsclient "github.com/kubeovn/kube-ovn/pkg/ovsdb/client" | ||
"github.com/kubeovn/kube-ovn/pkg/ovsdb/ovnnb" | ||
"github.com/kubeovn/kube-ovn/pkg/util" | ||
) | ||
|
||
func (c OvnClient) GetLogicalRouterPort(name string, ignoreNotFound bool) (*ovnnb.LogicalRouterPort, error) { | ||
lrp := &ovnnb.LogicalRouterPort{Name: name} | ||
if err := c.ovnNbClient.Get(context.TODO(), lrp); err != nil { | ||
if ignoreNotFound && err == client.ErrNotFound { | ||
return nil, nil | ||
} | ||
return nil, fmt.Errorf("failed to get logical router port %s: %v", name, err) | ||
} | ||
|
||
return lrp, nil | ||
} | ||
|
||
func (c OvnClient) AddLogicalRouterPort(lr, name, mac, networks string) error { | ||
router, err := c.GetLogicalRouter(lr, false) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if mac == "" { | ||
mac = util.GenerateMac() | ||
} | ||
|
||
var ops []ovsdb.Operation | ||
|
||
lrp := &ovnnb.LogicalRouterPort{ | ||
UUID: ovsclient.NamedUUID(), | ||
Name: name, | ||
MAC: mac, | ||
Networks: strings.Split(networks, ","), | ||
ExternalIDs: map[string]string{"vendor": util.CniTypeName}, | ||
} | ||
|
||
// ensure there is no port in the same name, before we create it in the transaction | ||
waitOp := ConstructWaitForNameNotExistsOperation(name, "Logical_Router_Port") | ||
ops = append(ops, waitOp) | ||
|
||
createOps, err := c.ovnNbClient.Create(lrp) | ||
if err != nil { | ||
return err | ||
} | ||
ops = append(ops, createOps...) | ||
|
||
mutationOps, err := c.ovnNbClient. | ||
Where(router). | ||
Mutate(router, | ||
model.Mutation{ | ||
Field: &router.Ports, | ||
Mutator: ovsdb.MutateOperationInsert, | ||
Value: []string{lrp.UUID}, | ||
}, | ||
) | ||
if err != nil { | ||
return err | ||
} | ||
ops = append(ops, mutationOps...) | ||
|
||
if err := Transact(c.ovnNbClient, "lrp-add", ops, c.ovnNbClient.Timeout); err != nil { | ||
return fmt.Errorf("failed to create logical router port %s: %v", name, err) | ||
} | ||
return nil | ||
} | ||
|
||
func (c OvnClient) LogicalRouterPortExists(name string) (bool, error) { | ||
lrp, err := c.GetLogicalRouterPort(name, true) | ||
return lrp != nil, err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters