diff --git a/libnetwork/controller.go b/libnetwork/controller.go index 8c66cd27cd..ead654ceac 100644 --- a/libnetwork/controller.go +++ b/libnetwork/controller.go @@ -406,11 +406,12 @@ func (c *controller) makeDriverConfig(ntype string) map[string]interface{} { cfg := map[string]interface{}{} for _, label := range c.cfg.Labels { - if !strings.HasPrefix(netlabel.Key(label), netlabel.DriverPrefix+"."+ntype) { + key, val, _ := strings.Cut(label, "=") + if !strings.HasPrefix(key, netlabel.DriverPrefix+"."+ntype) { continue } - cfg[netlabel.Key(label)] = netlabel.Value(label) + cfg[key] = val } drvCfg, ok := c.cfg.DriverCfg[ntype] diff --git a/libnetwork/netlabel/labels.go b/libnetwork/netlabel/labels.go index 3d472a3a7c..c002a4ef22 100644 --- a/libnetwork/netlabel/labels.go +++ b/libnetwork/netlabel/labels.go @@ -1,9 +1,5 @@ package netlabel -import ( - "strings" -) - const ( // Prefix constant marks the reserved label space for libnetwork Prefix = "com.docker.network" @@ -101,21 +97,3 @@ func MakeKVProviderConfig(scope string) string { func MakeKVClient(scope string) string { return DriverPrivatePrefix + scope + "kv_client" } - -// Key extracts the key portion of the label -func Key(label string) (key string) { - key, _, _ = strings.Cut(label, "=") - return key -} - -// Value extracts the value portion of the label -func Value(label string) (value string) { - _, value, _ = strings.Cut(label, "=") - return value -} - -// KeyValue decomposes the label in the (key,value) pair -func KeyValue(label string) (key string, value string) { - key, value, _ = strings.Cut(label, "=") - return key, value -} diff --git a/libnetwork/netlabel/labels_test.go b/libnetwork/netlabel/labels_test.go deleted file mode 100644 index 01a660bc73..0000000000 --- a/libnetwork/netlabel/labels_test.go +++ /dev/null @@ -1,28 +0,0 @@ -package netlabel - -import ( - "testing" -) - -var input = []struct { - label string - key string - value string -}{ - {"com.directory.person.name=joe", "com.directory.person.name", "joe"}, - {"com.directory.person.age=24", "com.directory.person.age", "24"}, - {"com.directory.person.address=1234 First st.", "com.directory.person.address", "1234 First st."}, - {"com.directory.person.friends=", "com.directory.person.friends", ""}, - {"com.directory.person.nickname=o=u=8", "com.directory.person.nickname", "o=u=8"}, - {"", "", ""}, - {"com.directory.person.student", "com.directory.person.student", ""}, -} - -func TestKeyValue(t *testing.T) { - for _, i := range input { - k, v := KeyValue(i.label) - if k != i.key || v != i.value { - t.Fatalf("unexpected: %s, %s", k, v) - } - } -}