Prechádzať zdrojové kódy

libnetwork: ipvlan: reduce use of const for driver name

Inlining the string makes the code more grep'able; renaming the
const to "driverName" to reflect the remaining uses of it.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Sebastiaan van Stijn 3 rokov pred
rodič
commit
aca80d1cda

+ 3 - 3
libnetwork/drivers/ipvlan/ipvlan.go

@@ -18,7 +18,7 @@ const (
 	containerVethPrefix = "eth"
 	vethPrefix          = "veth"
 
-	ipvlanType    = "ipvlan"      // driver type name
+	driverName    = "ipvlan"      // driver type name
 	parentOpt     = "parent"      // parent interface -o parent
 	driverModeOpt = "ipvlan_mode" // mode -o ipvlan_mode
 	driverFlagOpt = "ipvlan_flag" // flag -o ipvlan_flag
@@ -75,7 +75,7 @@ func Init(dc driverapi.DriverCallback, config map[string]interface{}) error {
 		return err
 	}
 
-	return dc.RegisterDriver(ipvlanType, d, c)
+	return dc.RegisterDriver(driverName, d, c)
 }
 
 func (d *driver) NetworkAllocate(id string, option map[string]string, ipV4Data, ipV6Data []driverapi.IPAMData) (map[string]string, error) {
@@ -91,7 +91,7 @@ func (d *driver) EndpointOperInfo(nid, eid string) (map[string]interface{}, erro
 }
 
 func (d *driver) Type() string {
-	return ipvlanType
+	return driverName
 }
 
 func (d *driver) IsBuiltIn() bool {

+ 3 - 3
libnetwork/drivers/ipvlan/ipvlan_endpoint.go

@@ -27,7 +27,7 @@ func (d *driver) CreateEndpoint(nid, eid string, ifInfo driverapi.InterfaceInfo,
 		return fmt.Errorf("network id %q not found", nid)
 	}
 	if ifInfo.MacAddress() != nil {
-		return fmt.Errorf("%s interfaces do not support custom mac address assignment", ipvlanType)
+		return fmt.Errorf("ipvlan interfaces do not support custom mac address assignment")
 	}
 	ep := &endpoint{
 		id:     eid,
@@ -42,7 +42,7 @@ func (d *driver) CreateEndpoint(nid, eid string, ifInfo driverapi.InterfaceInfo,
 	if opt, ok := epOptions[netlabel.PortMap]; ok {
 		if _, ok := opt.([]types.PortBinding); ok {
 			if len(opt.([]types.PortBinding)) > 0 {
-				logrus.Warnf("%s driver does not support port mappings", ipvlanType)
+				logrus.Warnf("ipvlan driver does not support port mappings")
 			}
 		}
 	}
@@ -50,7 +50,7 @@ func (d *driver) CreateEndpoint(nid, eid string, ifInfo driverapi.InterfaceInfo,
 	if opt, ok := epOptions[netlabel.ExposedPorts]; ok {
 		if _, ok := opt.([]types.TransportPort); ok {
 			if len(opt.([]types.TransportPort)) > 0 {
-				logrus.Warnf("%s driver does not support port exposures", ipvlanType)
+				logrus.Warnf("ipvlan driver does not support port exposures")
 			}
 		}
 	}

+ 5 - 4
libnetwork/drivers/ipvlan/ipvlan_network.go

@@ -22,7 +22,7 @@ func (d *driver) CreateNetwork(nid string, option map[string]interface{}, nInfo
 	defer osl.InitOSContext()()
 	kv, err := kernel.GetKernelVersion()
 	if err != nil {
-		return fmt.Errorf("Failed to check kernel version for %s driver support: %v", ipvlanType, err)
+		return fmt.Errorf("failed to check kernel version for ipvlan driver support: %v", err)
 	}
 	// ensure Kernel version is >= v4.2 for ipvlan support
 	if kv.Kernel < ipvlanKernelVer || (kv.Kernel == ipvlanKernelVer && kv.Major < ipvlanMajorVer) {
@@ -52,6 +52,7 @@ func (d *driver) CreateNetwork(nid string, option map[string]interface{}, nInfo
 	if foundExisting {
 		return types.InternalMaskableErrorf("restoring existing network %s", config.ID)
 	}
+
 	// update persistent db, rollback on fail
 	err = d.storeUpdate(config)
 	if err != nil {
@@ -87,7 +88,7 @@ func (d *driver) createNetwork(config *configuration) (bool, error) {
 			}
 			config.CreatedSlaveLink = true
 
-			// notify the user in logs they have limited communications
+			// notify the user in logs that they have limited communications
 			logrus.Debugf("Empty -o parent= flags limit communications to other containers inside of network: %s",
 				config.Parent)
 		} else {
@@ -115,7 +116,7 @@ func (d *driver) createNetwork(config *configuration) (bool, error) {
 	return foundExisting, nil
 }
 
-// DeleteNetwork the network for the specified driver type
+// DeleteNetwork deletes the network for the specified driver type
 func (d *driver) DeleteNetwork(nid string) error {
 	defer osl.InitOSContext()()
 	n := d.network(nid)
@@ -164,7 +165,7 @@ func (d *driver) DeleteNetwork(nid string) error {
 	return nil
 }
 
-// parseNetworkOptions parse docker network options
+// parseNetworkOptions parses docker network options
 func parseNetworkOptions(id string, option options.Generic) (*configuration, error) {
 	var (
 		err    error

+ 3 - 3
libnetwork/drivers/ipvlan/ipvlan_setup.go

@@ -38,7 +38,7 @@ func createIPVlan(containerIfName, parent, ipvlanMode, ipvlanFlag string) (strin
 	// Get the link for the master index (Example: the docker host eth iface)
 	parentLink, err := ns.NlHandle().LinkByName(parent)
 	if err != nil {
-		return "", fmt.Errorf("error occurred looking up the %s parent iface %s error: %s", ipvlanType, parent, err)
+		return "", fmt.Errorf("error occurred looking up the ipvlan parent iface %s error: %s", parent, err)
 	}
 	// Create an ipvlan link
 	ipvlan := &netlink.IPVlan{
@@ -51,7 +51,7 @@ func createIPVlan(containerIfName, parent, ipvlanMode, ipvlanFlag string) (strin
 	}
 	if err := ns.NlHandle().LinkAdd(ipvlan); err != nil {
 		// If a user creates a macvlan and ipvlan on same parent, only one slave iface can be active at a time.
-		return "", fmt.Errorf("failed to create the %s port: %v", ipvlanType, err)
+		return "", fmt.Errorf("failed to create the ipvlan port: %v", err)
 	}
 
 	return ipvlan.Attrs().Name, nil
@@ -190,7 +190,7 @@ func createDummyLink(dummyName, truncNetID string) error {
 	}
 	parentDummyLink, err := ns.NlHandle().LinkByName(dummyName)
 	if err != nil {
-		return fmt.Errorf("error occurred looking up the %s parent iface %s error: %s", ipvlanType, dummyName, err)
+		return fmt.Errorf("error occurred looking up the ipvlan parent iface %s error: %s", dummyName, err)
 	}
 	// bring the new netlink iface up
 	if err := ns.NlHandle().LinkSetUp(parentDummyLink); err != nil {