Move dummyLinkExists into createDummyLink

Signed-off-by: Arko Dasgupta <arko.dasgupta@docker.com>
This commit is contained in:
Arko Dasgupta 2019-07-24 17:06:04 -07:00
parent ddd22a8198
commit d22824dc11
4 changed files with 36 additions and 39 deletions

View File

@ -97,16 +97,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 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)) {
@ -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 {

View File

@ -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 {
@ -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{

View File

@ -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",
@ -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 {

View File

@ -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 {
@ -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{