Skip to content

Commit

Permalink
Move dummyLinkExists into createDummyLink
Browse files Browse the repository at this point in the history
Signed-off-by: Arko Dasgupta <arko.dasgupta@docker.com>
  • Loading branch information
Arko Dasgupta committed Jul 25, 2019
1 parent 4c5094c commit ea744fb
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 39 deletions.
28 changes: 9 additions & 19 deletions drivers/ipvlan/ipvlan_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,16 +97,11 @@ func (d *driver) createNetwork(config *configuration) (bool, error) {
if !parentExists(config.Parent) {

This comment has been minimized.

Copy link
@chiragtayal

chiragtayal Jul 25, 2019

We are checking if parent link does not exists and then only we try to create dummy link or vlan link.
I don't think we need to check dummyLinkExists or vlanLinkExists.

Code looks good as is

// if the --internal flag is set, create a dummy link
if config.Internal {
if !dummyLinkExists(getDummyName(stringid.TruncateID(config.ID))) {
err := createDummyLink(config.Parent, getDummyName(stringid.TruncateID(config.ID)))
if err != nil {
return false, err
}
config.CreatedSlaveLink = true

} else {
logrus.Debugf("Dummy Link %s for ipvlan already exists", getDummyName(stringid.TruncateID(config.ID)))
err := createDummyLink(config.Parent, getDummyName(stringid.TruncateID(config.ID)))
if err != nil {
return false, err
}
config.CreatedSlaveLink = true

// notify the user in logs they have limited communications
if config.Parent == getDummyName(stringid.TruncateID(config.ID)) {
Expand All @@ -116,17 +111,12 @@ func (d *driver) createNetwork(config *configuration) (bool, error) {
} else {
// if the subinterface parent_iface.vlan_id checks do not pass, return err.
// a valid example is 'eth0.10' for a parent iface 'eth0' with a vlan id '10'
if !vlanLinkExists(config.Parent) {
err := createVlanLink(config.Parent)
if err != nil {
return false, err
}
// if driver created the networks slave link, record it for future deletion
config.CreatedSlaveLink = true
} else {
logrus.Debugf("Parent Sub Interface %s already Exists NetID %s", config.Parent, config.ID)
err := createVlanLink(config.Parent)
if err != nil {
return false, err
}

// if driver created the networks slave link, record it for future deletion
config.CreatedSlaveLink = true
}
}
if !foundExisting {
Expand Down
10 changes: 10 additions & 0 deletions drivers/ipvlan/ipvlan_setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ func vlanLinkExists(linkStr string) bool {

// createVlanLink parses sub-interfaces and vlan id for creation
func createVlanLink(parentName string) error {
if vlanLinkExists(parentName) {
logrus.Debugf("Parent Sub Interface %s already exists", parentName)
return nil
}

if strings.Contains(parentName, ".") {
parent, vidInt, err := parseVlan(parentName)
if err != nil {
Expand Down Expand Up @@ -176,6 +181,11 @@ func dummyLinkExists(dummyName string) bool {

// createDummyLink creates a dummy0 parent link
func createDummyLink(dummyName, truncNetID string) error {
// check if dummyLinkExists and return if it does
if dummyLinkExists(truncNetID) {
logrus.Debugf("Dummy Link %s for ipvlan already exists", truncNetID)
return nil
}
// create a parent interface since one was not specified
parent := &netlink.Dummy{
LinkAttrs: netlink.LinkAttrs{
Expand Down
29 changes: 9 additions & 20 deletions drivers/macvlan/macvlan_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,11 @@ func (d *driver) createNetwork(config *configuration) (bool, error) {
if !parentExists(config.Parent) {
// if the --internal flag is set, create a dummy link
if config.Internal {
if !dummyLinkExists(getDummyName(stringid.TruncateID(config.ID))) {
err := createDummyLink(config.Parent, getDummyName(stringid.TruncateID(config.ID)))
if err != nil {
return false, err
}
config.CreatedSlaveLink = true
} else {
logrus.Debugf("Dummy Link %s for Mac Vlan already exists", getDummyName(stringid.TruncateID(config.ID)))
err := createDummyLink(config.Parent, getDummyName(stringid.TruncateID(config.ID)))
if err != nil {
return false, err
}
config.CreatedSlaveLink = true
// notify the user in logs they have limited communications
if config.Parent == getDummyName(stringid.TruncateID(config.ID)) {
logrus.Debugf("Empty -o parent= and --internal flags limit communications to other containers inside of network: %s",
Expand All @@ -119,19 +115,12 @@ func (d *driver) createNetwork(config *configuration) (bool, error) {
} else {
// if the subinterface parent_iface.vlan_id checks do not pass, return err.
// a valid example is 'eth0.10' for a parent iface 'eth0' with a vlan id '10'

if !vlanLinkExists(config.Parent) {
// if the subinterface parent_iface.vlan_id checks do not pass, return err.
// a valid example is 'eth0.10' for a parent iface 'eth0' with a vlan id '10'
err := createVlanLink(config.Parent)
if err != nil {
return false, err
}
// if driver created the networks slave link, record it for future deletion
config.CreatedSlaveLink = true
} else {
logrus.Debugf("Parent Sub Interface %s already Exists NetID %s", config.Parent, config.ID)
err := createVlanLink(config.Parent)
if err != nil {
return false, err
}
// if driver created the networks slave link, record it for future deletion
config.CreatedSlaveLink = true
}
}
if !foundExisting {
Expand Down
8 changes: 8 additions & 0 deletions drivers/macvlan/macvlan_setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ func vlanLinkExists(linkStr string) bool {

// createVlanLink parses sub-interfaces and vlan id for creation
func createVlanLink(parentName string) error {
if vlanLinkExists(parentName) {
logrus.Debugf("Parent Sub Interface %s already exists", parentName)
return nil
}
if strings.Contains(parentName, ".") {
parent, vidInt, err := parseVlan(parentName)
if err != nil {
Expand Down Expand Up @@ -180,6 +184,10 @@ func dummyLinkExists(dummyName string) bool {

// createDummyLink creates a dummy0 parent link
func createDummyLink(dummyName, truncNetID string) error {
if dummyLinkExists(truncNetID) {
logrus.Debugf("Dummy Link %s for Mac Vlan already exists", truncNetID)
return nil
}
// create a parent interface since one was not specified
parent := &netlink.Dummy{
LinkAttrs: netlink.LinkAttrs{
Expand Down

0 comments on commit ea744fb

Please sign in to comment.