makeDriverConfig is written in such a way that it seems to support
label-based driver configuration. That is, you could hypothetically use
labels starting with `com.docker.network.driver.<driver-name>.` to
define the configuration of a driver.
These labels come from the Controller's `cfg.Labels` which are set by
the daemon through libnet's OptionLabels which takes the list of labels
set on the daemon through dockerd's --label flag, or the equivalent
daemon.json field.
However, the daemon forbids setting labels that start with
`com.docker.*`. For instance:
label com.docker.network.driver.bridge.EnableProxy=false is not allowed: the namespaces com.docker.*, io.docker.*, and org.dockerproject.* are reserved for internal use
Hence, this is dead code — remove it.
Also, makeDriverConfig is checking if the Controller's cfg field is
nil... But the Controller struct is instantiated in a single place (i.e.
NewController) and it always set that field. Drop that nil check too.
Signed-off-by: Albin Kerouanton <albinker@gmail.com>
| ... | ... |
@@ -1649,7 +1649,6 @@ func (daemon *Daemon) networkOptions(conf *config.Config, pg plugingetter.Plugin |
| 1649 | 1649 |
nwconfig.OptionExecRoot(conf.GetExecRoot()), |
| 1650 | 1650 |
nwconfig.OptionDefaultDriver(network.DefaultNetwork), |
| 1651 | 1651 |
nwconfig.OptionDefaultNetwork(network.DefaultNetwork), |
| 1652 |
- nwconfig.OptionLabels(conf.Labels), |
|
| 1653 | 1652 |
nwconfig.OptionNetworkControlPlaneMTU(conf.NetworkControlPlaneMTU), |
| 1654 | 1653 |
nwconfig.OptionFirewallBackend(conf.FirewallBackend), |
| 1655 | 1654 |
} |
| ... | ... |
@@ -8,7 +8,6 @@ import ( |
| 8 | 8 |
"github.com/moby/moby/v2/daemon/libnetwork/cluster" |
| 9 | 9 |
"github.com/moby/moby/v2/daemon/libnetwork/datastore" |
| 10 | 10 |
"github.com/moby/moby/v2/daemon/libnetwork/ipamutils" |
| 11 |
- "github.com/moby/moby/v2/daemon/libnetwork/netlabel" |
|
| 12 | 11 |
"github.com/moby/moby/v2/pkg/plugingetter" |
| 13 | 12 |
) |
| 14 | 13 |
|
| ... | ... |
@@ -99,17 +98,6 @@ func OptionDriverConfig(networkType string, config map[string]any) Option {
|
| 99 | 99 |
} |
| 100 | 100 |
} |
| 101 | 101 |
|
| 102 |
-// OptionLabels function returns an option setter for labels |
|
| 103 |
-func OptionLabels(labels []string) Option {
|
|
| 104 |
- return func(c *Config) {
|
|
| 105 |
- for _, label := range labels {
|
|
| 106 |
- if strings.HasPrefix(label, netlabel.Prefix) {
|
|
| 107 |
- c.Labels = append(c.Labels, label) |
|
| 108 |
- } |
|
| 109 |
- } |
|
| 110 |
- } |
|
| 111 |
-} |
|
| 112 |
- |
|
| 113 | 102 |
// OptionDataDir function returns an option setter for data folder |
| 114 | 103 |
func OptionDataDir(dataDir string) Option {
|
| 115 | 104 |
return func(c *Config) {
|
| 116 | 105 |
deleted file mode 100644 |
| ... | ... |
@@ -1,28 +0,0 @@ |
| 1 |
-package config |
|
| 2 |
- |
|
| 3 |
-import ( |
|
| 4 |
- "strings" |
|
| 5 |
- "testing" |
|
| 6 |
- |
|
| 7 |
- "github.com/moby/moby/v2/daemon/libnetwork/netlabel" |
|
| 8 |
-) |
|
| 9 |
- |
|
| 10 |
-func TestOptionsLabels(t *testing.T) {
|
|
| 11 |
- c := &Config{}
|
|
| 12 |
- l := []string{
|
|
| 13 |
- "com.docker.network.key1=value1", |
|
| 14 |
- "com.docker.storage.key1=value1", |
|
| 15 |
- "com.docker.network.driver.key1=value1", |
|
| 16 |
- "com.docker.network.driver.key2=value2", |
|
| 17 |
- } |
|
| 18 |
- f := OptionLabels(l) |
|
| 19 |
- f(c) |
|
| 20 |
- if len(c.Labels) != 3 {
|
|
| 21 |
- t.Fatalf("Expecting 3 labels, seen %d", len(c.Labels))
|
|
| 22 |
- } |
|
| 23 |
- for _, l := range c.Labels {
|
|
| 24 |
- if !strings.HasPrefix(l, netlabel.Prefix) {
|
|
| 25 |
- t.Fatalf("config must accept only libnetwork labels. Not : %s", l)
|
|
| 26 |
- } |
|
| 27 |
- } |
|
| 28 |
-} |
| ... | ... |
@@ -46,6 +46,7 @@ package libnetwork |
| 46 | 46 |
import ( |
| 47 | 47 |
"context" |
| 48 | 48 |
"fmt" |
| 49 |
+ "maps" |
|
| 49 | 50 |
"net" |
| 50 | 51 |
"path/filepath" |
| 51 | 52 |
"runtime" |
| ... | ... |
@@ -384,26 +385,7 @@ func (c *Controller) agentStopComplete() {
|
| 384 | 384 |
} |
| 385 | 385 |
|
| 386 | 386 |
func (c *Controller) makeDriverConfig(ntype string) map[string]any {
|
| 387 |
- if c.cfg == nil {
|
|
| 388 |
- return nil |
|
| 389 |
- } |
|
| 390 |
- |
|
| 391 |
- cfg := map[string]any{}
|
|
| 392 |
- for _, label := range c.cfg.Labels {
|
|
| 393 |
- key, val, _ := strings.Cut(label, "=") |
|
| 394 |
- if !strings.HasPrefix(key, netlabel.DriverPrefix+"."+ntype) {
|
|
| 395 |
- continue |
|
| 396 |
- } |
|
| 397 |
- |
|
| 398 |
- cfg[key] = val |
|
| 399 |
- } |
|
| 400 |
- |
|
| 401 |
- // Merge in the existing config for this driver. |
|
| 402 |
- for k, v := range c.cfg.DriverConfig(ntype) {
|
|
| 403 |
- cfg[k] = v |
|
| 404 |
- } |
|
| 405 |
- |
|
| 406 |
- return cfg |
|
| 387 |
+ return maps.Clone(c.cfg.DriverConfig(ntype)) |
|
| 407 | 388 |
} |
| 408 | 389 |
|
| 409 | 390 |
// ID returns the controller's unique identity. |