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

Add PodUID to the OVSDB #311

Merged
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
15 changes: 8 additions & 7 deletions pkg/ovsdb/ovsdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,13 +158,13 @@ func (ovsd *OvsDriver) ovsdbTransact(ops []ovsdb.Operation) ([]ovsdb.OperationRe
// **************** OVS driver API ********************

// CreatePort Create an internal port in OVS
func (ovsd *OvsBridgeDriver) CreatePort(intfName, contNetnsPath, contIfaceName, ovnPortName string, ofportRequest uint, vlanTag uint, trunks []uint, portType string, intfType string) error {
func (ovsd *OvsBridgeDriver) CreatePort(intfName, contNetnsPath, contIfaceName, ovnPortName string, ofportRequest uint, vlanTag uint, trunks []uint, portType string, intfType string, contPodUid string) error {
intfUUID, intfOp, err := createInterfaceOperation(intfName, ofportRequest, ovnPortName, intfType)
if err != nil {
return err
}

portUUID, portOp, err := createPortOperation(intfName, contNetnsPath, contIfaceName, vlanTag, trunks, portType, intfUUID)
portUUID, portOp, err := createPortOperation(intfName, contNetnsPath, contIfaceName, vlanTag, trunks, portType, intfUUID, contPodUid)
if err != nil {
return err
}
Expand Down Expand Up @@ -658,7 +658,7 @@ func (ovsd *OvsDriver) GetOvsPortForContIface(contIface, contNetnsPath string) (
return "", false, err
}

condition := ovsdb.NewCondition("external_ids", ovsdb.ConditionEqual, ovsmap)
condition := ovsdb.NewCondition("external_ids", ovsdb.ConditionIncludes, ovsmap)
colums := []string{"name", "external_ids"}
port, err := ovsd.findByCondition("Port", condition, colums)
if err != nil {
Expand Down Expand Up @@ -853,7 +853,7 @@ func createInterfaceOperation(intfName string, ofportRequest uint, ovnPortName s
return intfUUID, &intfOp, nil
}

func createPortOperation(intfName, contNetnsPath, contIfaceName string, vlanTag uint, trunks []uint, portType string, intfUUID ovsdb.UUID) (ovsdb.UUID, *ovsdb.Operation, error) {
func createPortOperation(intfName, contNetnsPath, contIfaceName string, vlanTag uint, trunks []uint, portType string, intfUUID ovsdb.UUID, contPodUid string) (ovsdb.UUID, *ovsdb.Operation, error) {
portUUIDStr := intfName
portUUID := ovsdb.UUID{GoUUID: portUUIDStr}

Expand All @@ -877,9 +877,10 @@ func createPortOperation(intfName, contNetnsPath, contIfaceName string, vlanTag
}

oMap, err := ovsdb.NewOvsMap(map[string]string{
"contNetns": contNetnsPath,
"contIface": contIfaceName,
"owner": ovsPortOwner,
"contPodUid": contPodUid,
"contNetns": contNetnsPath,
"contIface": contIfaceName,
"owner": ovsPortOwner,
})
if err != nil {
return ovsdb.UUID{}, nil, err
Expand Down
13 changes: 8 additions & 5 deletions pkg/plugin/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,9 @@ import (
// EnvArgs args containing common, desired mac and ovs port name
type EnvArgs struct {
cnitypes.CommonArgs
MAC cnitypes.UnmarshallableString `json:"mac,omitempty"`
OvnPort cnitypes.UnmarshallableString `json:"ovnPort,omitempty"`
MAC cnitypes.UnmarshallableString `json:"mac,omitempty"`
OvnPort cnitypes.UnmarshallableString `json:"ovnPort,omitempty"`
K8S_POD_UID cnitypes.UnmarshallableString
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is no assurance runtime will provide this value (altohugh for k8s we do get this information passed down by the runtime)

so in case this arg is not provided should we store an empty value ? or just avoid adding this key to external-ids ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While I do not believe it is critical, I would prefer not to have an empty value inside the external_id section of the port. Ideally, the field should be added conditionally only if the runtime provides a value for it.

}

func init() {
Expand Down Expand Up @@ -168,8 +169,8 @@ func getBridgeName(driver *ovsdb.OvsDriver, bridgeName, ovnPort, deviceID string
return "", fmt.Errorf("failed to get bridge name")
}

func attachIfaceToBridge(ovsDriver *ovsdb.OvsBridgeDriver, hostIfaceName string, contIfaceName string, ofportRequest uint, vlanTag uint, trunks []uint, portType string, intfType string, contNetnsPath string, ovnPortName string) error {
err := ovsDriver.CreatePort(hostIfaceName, contNetnsPath, contIfaceName, ovnPortName, ofportRequest, vlanTag, trunks, portType, intfType)
func attachIfaceToBridge(ovsDriver *ovsdb.OvsBridgeDriver, hostIfaceName string, contIfaceName string, ofportRequest uint, vlanTag uint, trunks []uint, portType string, intfType string, contNetnsPath string, ovnPortName string, contPodUid string) error {
err := ovsDriver.CreatePort(hostIfaceName, contNetnsPath, contIfaceName, ovnPortName, ofportRequest, vlanTag, trunks, portType, intfType, contPodUid)
if err != nil {
return err
}
Expand Down Expand Up @@ -247,9 +248,11 @@ func CmdAdd(args *skel.CmdArgs) error {

var mac string
var ovnPort string
var contPodUid string
if envArgs != nil {
mac = string(envArgs.MAC)
ovnPort = string(envArgs.OvnPort)
contPodUid = string(envArgs.K8S_POD_UID)
}

netconf, err := config.LoadConf(args.StdinData)
Expand Down Expand Up @@ -329,7 +332,7 @@ func CmdAdd(args *skel.CmdArgs) error {
}
}

if err = attachIfaceToBridge(ovsBridgeDriver, hostIface.Name, contIface.Name, netconf.OfportRequest, vlanTagNum, trunks, portType, netconf.InterfaceType, args.Netns, ovnPort); err != nil {
if err = attachIfaceToBridge(ovsBridgeDriver, hostIface.Name, contIface.Name, netconf.OfportRequest, vlanTagNum, trunks, portType, netconf.InterfaceType, args.Netns, ovnPort, contPodUid); err != nil {
return err
}
defer func() {
Expand Down
Loading