Skip to content

Commit 437e1ae

Browse files
committed
runconfig/opts: deprecate ConvertKVStringsToMap and move internal
This utility is only used in two places, and simple enough to duplicate. There's no external consumers, and a copy of this utility exists in docker/cli for use on the client side, so we could consider skipping deprecation, but just to be on the safe side ':) Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent eb360ef commit 437e1ae

7 files changed

Lines changed: 33 additions & 13 deletions

File tree

builder/dockerfile/buildargs.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ import (
44
"fmt"
55
"io"
66
"sort"
7-
8-
"github.com/docker/docker/runconfig/opts"
97
)
108

119
// builtinAllowedBuildArgs is list of built-in allowed build args
@@ -138,7 +136,7 @@ func (b *BuildArgs) getAllFromMapping(source map[string]*string) map[string]stri
138136
// FilterAllowed returns all allowed args without the filtered args
139137
func (b *BuildArgs) FilterAllowed(filter []string) []string {
140138
envs := []string{}
141-
configEnv := opts.ConvertKVStringsToMap(filter)
139+
configEnv := convertKVStringsToMap(filter)
142140

143141
for key, val := range b.GetAllAllowed() {
144142
if _, ok := configEnv[key]; !ok {

builder/dockerfile/builder.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,3 +381,14 @@ func convertMapToEnvList(m map[string]string) []string {
381381
}
382382
return result
383383
}
384+
385+
// convertKVStringsToMap converts ["key=value"] to {"key":"value"}
386+
func convertKVStringsToMap(values []string) map[string]string {
387+
result := make(map[string]string, len(values))
388+
for _, value := range values {
389+
k, v, _ := strings.Cut(value, "=")
390+
result[k] = v
391+
}
392+
393+
return result
394+
}

builder/dockerfile/evaluator.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ import (
3030
"github.com/docker/docker/errdefs"
3131
"github.com/docker/docker/image"
3232
"github.com/docker/docker/oci"
33-
"github.com/docker/docker/runconfig/opts"
3433
"github.com/moby/buildkit/frontend/dockerfile/instructions"
3534
"github.com/moby/buildkit/frontend/dockerfile/shell"
3635
"github.com/pkg/errors"
@@ -243,7 +242,7 @@ func (s *dispatchState) setDefaultPath() {
243242
if defaultPath == "" {
244243
return
245244
}
246-
envMap := opts.ConvertKVStringsToMap(s.runConfig.Env)
245+
envMap := convertKVStringsToMap(s.runConfig.Env)
247246
if _, ok := envMap["PATH"]; !ok {
248247
s.runConfig.Env = append(s.runConfig.Env, "PATH="+defaultPath)
249248
}

daemon/cluster/filters.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"strings"
66

77
"github.com/docker/docker/api/types/filters"
8-
runconfigopts "github.com/docker/docker/runconfig/opts"
98
swarmapi "github.com/moby/swarmkit/v2/api"
109
)
1110

@@ -24,8 +23,8 @@ func newListNodesFilters(filter filters.Args) (*swarmapi.ListNodesRequest_Filter
2423
f := &swarmapi.ListNodesRequest_Filters{
2524
NamePrefixes: filter.Get("name"),
2625
IDPrefixes: filter.Get("id"),
27-
Labels: runconfigopts.ConvertKVStringsToMap(filter.Get("label")),
28-
NodeLabels: runconfigopts.ConvertKVStringsToMap(filter.Get("node.label")),
26+
Labels: convertKVStringsToMap(filter.Get("label")),
27+
NodeLabels: convertKVStringsToMap(filter.Get("node.label")),
2928
}
3029

3130
for _, r := range filter.Get("role") {
@@ -72,7 +71,7 @@ func newListTasksFilters(filter filters.Args, transformFunc func(filters.Args) e
7271
f := &swarmapi.ListTasksRequest_Filters{
7372
NamePrefixes: filter.Get("name"),
7473
IDPrefixes: filter.Get("id"),
75-
Labels: runconfigopts.ConvertKVStringsToMap(filter.Get("label")),
74+
Labels: convertKVStringsToMap(filter.Get("label")),
7675
ServiceIDs: filter.Get("service"),
7776
NodeIDs: filter.Get("node"),
7877
UpToDate: len(filter.Get("_up-to-date")) != 0,
@@ -104,7 +103,7 @@ func newListSecretsFilters(filter filters.Args) (*swarmapi.ListSecretsRequest_Fi
104103
Names: filter.Get("names"),
105104
NamePrefixes: filter.Get("name"),
106105
IDPrefixes: filter.Get("id"),
107-
Labels: runconfigopts.ConvertKVStringsToMap(filter.Get("label")),
106+
Labels: convertKVStringsToMap(filter.Get("label")),
108107
}, nil
109108
}
110109

@@ -120,6 +119,6 @@ func newListConfigsFilters(filter filters.Args) (*swarmapi.ListConfigsRequest_Fi
120119
return &swarmapi.ListConfigsRequest_Filters{
121120
NamePrefixes: filter.Get("name"),
122121
IDPrefixes: filter.Get("id"),
123-
Labels: runconfigopts.ConvertKVStringsToMap(filter.Get("label")),
122+
Labels: convertKVStringsToMap(filter.Get("label")),
124123
}, nil
125124
}

daemon/cluster/services.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
timetypes "github.com/docker/docker/api/types/time"
2222
"github.com/docker/docker/daemon/cluster/convert"
2323
"github.com/docker/docker/errdefs"
24-
runconfigopts "github.com/docker/docker/runconfig/opts"
2524
gogotypes "github.com/gogo/protobuf/types"
2625
swarmapi "github.com/moby/swarmkit/v2/api"
2726
"github.com/opencontainers/go-digest"
@@ -62,7 +61,7 @@ func (c *Cluster) GetServices(options types.ServiceListOptions) ([]swarm.Service
6261
filters := &swarmapi.ListServicesRequest_Filters{
6362
NamePrefixes: options.Filters.Get("name"),
6463
IDPrefixes: options.Filters.Get("id"),
65-
Labels: runconfigopts.ConvertKVStringsToMap(options.Filters.Get("label")),
64+
Labels: convertKVStringsToMap(options.Filters.Get("label")),
6665
Runtimes: options.Filters.Get("runtime"),
6766
}
6867

daemon/cluster/utils.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,22 @@ import (
44
"encoding/json"
55
"os"
66
"path/filepath"
7+
"strings"
78

89
"github.com/docker/docker/pkg/ioutils"
910
)
1011

12+
// convertKVStringsToMap converts ["key=value"] to {"key":"value"}
13+
func convertKVStringsToMap(values []string) map[string]string {
14+
result := make(map[string]string, len(values))
15+
for _, value := range values {
16+
k, v, _ := strings.Cut(value, "=")
17+
result[k] = v
18+
}
19+
20+
return result
21+
}
22+
1123
func loadPersistentState(root string) (*nodeStartConfig, error) {
1224
dt, err := os.ReadFile(filepath.Join(root, stateFile))
1325
if err != nil {

runconfig/opts/parse.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import (
55
)
66

77
// ConvertKVStringsToMap converts ["key=value"] to {"key":"value"}
8+
//
9+
// Deprecated: this function is no longer used, and will be removed in the next release.
810
func ConvertKVStringsToMap(values []string) map[string]string {
911
result := make(map[string]string, len(values))
1012
for _, value := range values {

0 commit comments

Comments
 (0)