Browse code

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 authored on 2022/07/01 18:30:46
Showing 4 changed files
... ...
@@ -18,7 +18,7 @@ const (
18 18
 	containerVethPrefix = "eth"
19 19
 	vethPrefix          = "veth"
20 20
 
21
-	ipvlanType    = "ipvlan"      // driver type name
21
+	driverName    = "ipvlan"      // driver type name
22 22
 	parentOpt     = "parent"      // parent interface -o parent
23 23
 	driverModeOpt = "ipvlan_mode" // mode -o ipvlan_mode
24 24
 	driverFlagOpt = "ipvlan_flag" // flag -o ipvlan_flag
... ...
@@ -75,7 +75,7 @@ func Init(dc driverapi.DriverCallback, config map[string]interface{}) error {
75 75
 		return err
76 76
 	}
77 77
 
78
-	return dc.RegisterDriver(ipvlanType, d, c)
78
+	return dc.RegisterDriver(driverName, d, c)
79 79
 }
80 80
 
81 81
 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
91 91
 }
92 92
 
93 93
 func (d *driver) Type() string {
94
-	return ipvlanType
94
+	return driverName
95 95
 }
96 96
 
97 97
 func (d *driver) IsBuiltIn() bool {
... ...
@@ -27,7 +27,7 @@ func (d *driver) CreateEndpoint(nid, eid string, ifInfo driverapi.InterfaceInfo,
27 27
 		return fmt.Errorf("network id %q not found", nid)
28 28
 	}
29 29
 	if ifInfo.MacAddress() != nil {
30
-		return fmt.Errorf("%s interfaces do not support custom mac address assignment", ipvlanType)
30
+		return fmt.Errorf("ipvlan interfaces do not support custom mac address assignment")
31 31
 	}
32 32
 	ep := &endpoint{
33 33
 		id:     eid,
... ...
@@ -42,7 +42,7 @@ func (d *driver) CreateEndpoint(nid, eid string, ifInfo driverapi.InterfaceInfo,
42 42
 	if opt, ok := epOptions[netlabel.PortMap]; ok {
43 43
 		if _, ok := opt.([]types.PortBinding); ok {
44 44
 			if len(opt.([]types.PortBinding)) > 0 {
45
-				logrus.Warnf("%s driver does not support port mappings", ipvlanType)
45
+				logrus.Warnf("ipvlan driver does not support port mappings")
46 46
 			}
47 47
 		}
48 48
 	}
... ...
@@ -50,7 +50,7 @@ func (d *driver) CreateEndpoint(nid, eid string, ifInfo driverapi.InterfaceInfo,
50 50
 	if opt, ok := epOptions[netlabel.ExposedPorts]; ok {
51 51
 		if _, ok := opt.([]types.TransportPort); ok {
52 52
 			if len(opt.([]types.TransportPort)) > 0 {
53
-				logrus.Warnf("%s driver does not support port exposures", ipvlanType)
53
+				logrus.Warnf("ipvlan driver does not support port exposures")
54 54
 			}
55 55
 		}
56 56
 	}
... ...
@@ -22,7 +22,7 @@ func (d *driver) CreateNetwork(nid string, option map[string]interface{}, nInfo
22 22
 	defer osl.InitOSContext()()
23 23
 	kv, err := kernel.GetKernelVersion()
24 24
 	if err != nil {
25
-		return fmt.Errorf("Failed to check kernel version for %s driver support: %v", ipvlanType, err)
25
+		return fmt.Errorf("failed to check kernel version for ipvlan driver support: %v", err)
26 26
 	}
27 27
 	// ensure Kernel version is >= v4.2 for ipvlan support
28 28
 	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
52 52
 	if foundExisting {
53 53
 		return types.InternalMaskableErrorf("restoring existing network %s", config.ID)
54 54
 	}
55
+
55 56
 	// update persistent db, rollback on fail
56 57
 	err = d.storeUpdate(config)
57 58
 	if err != nil {
... ...
@@ -87,7 +88,7 @@ func (d *driver) createNetwork(config *configuration) (bool, error) {
87 87
 			}
88 88
 			config.CreatedSlaveLink = true
89 89
 
90
-			// notify the user in logs they have limited communications
90
+			// notify the user in logs that they have limited communications
91 91
 			logrus.Debugf("Empty -o parent= flags limit communications to other containers inside of network: %s",
92 92
 				config.Parent)
93 93
 		} else {
... ...
@@ -115,7 +116,7 @@ func (d *driver) createNetwork(config *configuration) (bool, error) {
115 115
 	return foundExisting, nil
116 116
 }
117 117
 
118
-// DeleteNetwork the network for the specified driver type
118
+// DeleteNetwork deletes the network for the specified driver type
119 119
 func (d *driver) DeleteNetwork(nid string) error {
120 120
 	defer osl.InitOSContext()()
121 121
 	n := d.network(nid)
... ...
@@ -164,7 +165,7 @@ func (d *driver) DeleteNetwork(nid string) error {
164 164
 	return nil
165 165
 }
166 166
 
167
-// parseNetworkOptions parse docker network options
167
+// parseNetworkOptions parses docker network options
168 168
 func parseNetworkOptions(id string, option options.Generic) (*configuration, error) {
169 169
 	var (
170 170
 		err    error
... ...
@@ -38,7 +38,7 @@ func createIPVlan(containerIfName, parent, ipvlanMode, ipvlanFlag string) (strin
38 38
 	// Get the link for the master index (Example: the docker host eth iface)
39 39
 	parentLink, err := ns.NlHandle().LinkByName(parent)
40 40
 	if err != nil {
41
-		return "", fmt.Errorf("error occurred looking up the %s parent iface %s error: %s", ipvlanType, parent, err)
41
+		return "", fmt.Errorf("error occurred looking up the ipvlan parent iface %s error: %s", parent, err)
42 42
 	}
43 43
 	// Create an ipvlan link
44 44
 	ipvlan := &netlink.IPVlan{
... ...
@@ -51,7 +51,7 @@ func createIPVlan(containerIfName, parent, ipvlanMode, ipvlanFlag string) (strin
51 51
 	}
52 52
 	if err := ns.NlHandle().LinkAdd(ipvlan); err != nil {
53 53
 		// If a user creates a macvlan and ipvlan on same parent, only one slave iface can be active at a time.
54
-		return "", fmt.Errorf("failed to create the %s port: %v", ipvlanType, err)
54
+		return "", fmt.Errorf("failed to create the ipvlan port: %v", err)
55 55
 	}
56 56
 
57 57
 	return ipvlan.Attrs().Name, nil
... ...
@@ -190,7 +190,7 @@ func createDummyLink(dummyName, truncNetID string) error {
190 190
 	}
191 191
 	parentDummyLink, err := ns.NlHandle().LinkByName(dummyName)
192 192
 	if err != nil {
193
-		return fmt.Errorf("error occurred looking up the %s parent iface %s error: %s", ipvlanType, dummyName, err)
193
+		return fmt.Errorf("error occurred looking up the ipvlan parent iface %s error: %s", dummyName, err)
194 194
 	}
195 195
 	// bring the new netlink iface up
196 196
 	if err := ns.NlHandle().LinkSetUp(parentDummyLink); err != nil {