modernize: Use maps.Copy instead of for loops

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
This commit is contained in:
Paweł Gronowski
2025-12-15 18:18:12 +01:00
parent ff33808a79
commit cdce8f4f92
28 changed files with 66 additions and 123 deletions

View File

@@ -3,6 +3,7 @@ package dockerfile
import ( import (
"fmt" "fmt"
"io" "io"
"maps"
"sort" "sort"
) )
@@ -47,12 +48,8 @@ func NewBuildArgs(argsFromOptions map[string]*string) *BuildArgs {
// Clone returns a copy of the BuildArgs type // Clone returns a copy of the BuildArgs type
func (b *BuildArgs) Clone() *BuildArgs { func (b *BuildArgs) Clone() *BuildArgs {
result := NewBuildArgs(b.argsFromOptions) result := NewBuildArgs(b.argsFromOptions)
for k, v := range b.allowedBuildArgs { maps.Copy(result.allowedBuildArgs, b.allowedBuildArgs)
result.allowedBuildArgs[k] = v maps.Copy(result.allowedMetaArgs, b.allowedMetaArgs)
}
for k, v := range b.allowedMetaArgs {
result.allowedMetaArgs[k] = v
}
for k := range b.referencedArgs { for k := range b.referencedArgs {
result.referencedArgs[k] = struct{}{} result.referencedArgs[k] = struct{}{}
} }

View File

@@ -4,6 +4,7 @@ import (
"context" "context"
"encoding/json" "encoding/json"
"fmt" "fmt"
"maps"
"math" "math"
"net" "net"
"net/netip" "net/netip"
@@ -261,15 +262,11 @@ func (c *containerConfig) labels() map[string]string {
) )
// base labels are those defined in the spec. // base labels are those defined in the spec.
for k, v := range c.spec().Labels { maps.Copy(labels, c.spec().Labels)
labels[k] = v
}
// we then apply the overrides from the task, which may be set via the // we then apply the overrides from the task, which may be set via the
// orchestrator. // orchestrator.
for k, v := range c.task.Annotations.Labels { maps.Copy(labels, c.task.Annotations.Labels)
labels[k] = v
}
// finally, we apply the system labels, which override all labels. // finally, we apply the system labels, which override all labels.
for k, v := range system { for k, v := range system {
@@ -367,9 +364,7 @@ func convertMount(m api.Mount) enginemount.Mount {
} }
if m.VolumeOptions.Labels != nil { if m.VolumeOptions.Labels != nil {
mount.VolumeOptions.Labels = make(map[string]string, len(m.VolumeOptions.Labels)) mount.VolumeOptions.Labels = make(map[string]string, len(m.VolumeOptions.Labels))
for k, v := range m.VolumeOptions.Labels { maps.Copy(mount.VolumeOptions.Labels, m.VolumeOptions.Labels)
mount.VolumeOptions.Labels[k] = v
}
} }
if m.VolumeOptions.DriverConfig != nil { if m.VolumeOptions.DriverConfig != nil {
mount.VolumeOptions.DriverConfig = &enginemount.Driver{ mount.VolumeOptions.DriverConfig = &enginemount.Driver{
@@ -377,9 +372,7 @@ func convertMount(m api.Mount) enginemount.Mount {
} }
if m.VolumeOptions.DriverConfig.Options != nil { if m.VolumeOptions.DriverConfig.Options != nil {
mount.VolumeOptions.DriverConfig.Options = make(map[string]string, len(m.VolumeOptions.DriverConfig.Options)) mount.VolumeOptions.DriverConfig.Options = make(map[string]string, len(m.VolumeOptions.DriverConfig.Options))
for k, v := range m.VolumeOptions.DriverConfig.Options { maps.Copy(mount.VolumeOptions.DriverConfig.Options, m.VolumeOptions.DriverConfig.Options)
mount.VolumeOptions.DriverConfig.Options[k] = v
}
} }
} }
} }

View File

@@ -3,6 +3,7 @@ package daemon
import ( import (
"context" "context"
"fmt" "fmt"
"maps"
"runtime" "runtime"
"strings" "strings"
"time" "time"
@@ -109,9 +110,7 @@ func merge(userConf, imageConf *containertypes.Config) error {
if len(userConf.Volumes) == 0 { if len(userConf.Volumes) == 0 {
userConf.Volumes = imageConf.Volumes userConf.Volumes = imageConf.Volumes
} else { } else {
for k, v := range imageConf.Volumes { maps.Copy(userConf.Volumes, imageConf.Volumes)
userConf.Volumes[k] = v
}
} }
if userConf.StopSignal == "" { if userConf.StopSignal == "" {

View File

@@ -5,6 +5,7 @@ import (
"encoding/json" "encoding/json"
stderrors "errors" stderrors "errors"
"fmt" "fmt"
"maps"
"net" "net"
"net/netip" "net/netip"
"net/url" "net/url"
@@ -587,9 +588,7 @@ func configValuesSet(config map[string]any) map[string]any {
flatten := make(map[string]any) flatten := make(map[string]any)
for k, v := range config { for k, v := range config {
if m, isMap := v.(map[string]any); isMap && !flatOptions[k] { if m, isMap := v.(map[string]any); isMap && !flatOptions[k] {
for km, vm := range m { maps.Copy(flatten, m)
flatten[km] = vm
}
continue continue
} }

View File

@@ -2,6 +2,7 @@ package container
import ( import (
"context" "context"
"maps"
"runtime" "runtime"
"sync" "sync"
@@ -91,9 +92,7 @@ func NewExecStore() *ExecStore {
func (e *ExecStore) Commands() map[string]*ExecConfig { func (e *ExecStore) Commands() map[string]*ExecConfig {
e.mu.RLock() e.mu.RLock()
byID := make(map[string]*ExecConfig, len(e.byID)) byID := make(map[string]*ExecConfig, len(e.byID))
for id, config := range e.byID { maps.Copy(byID, e.byID)
byID[id] = config
}
e.mu.RUnlock() e.mu.RUnlock()
return byID return byID
} }

View File

@@ -4,6 +4,7 @@ import (
"context" "context"
"errors" "errors"
"fmt" "fmt"
"maps"
"net/netip" "net/netip"
"os" "os"
"runtime" "runtime"
@@ -413,9 +414,7 @@ func (daemon *Daemon) allocateNetwork(ctx context.Context, cfg *config.Config, c
// An intermediate map is necessary because "connectToNetwork" modifies "container.NetworkSettings.Networks" // An intermediate map is necessary because "connectToNetwork" modifies "container.NetworkSettings.Networks"
networks := make(map[string]*network.EndpointSettings) networks := make(map[string]*network.EndpointSettings)
for n, epConf := range ctr.NetworkSettings.Networks { maps.Copy(networks, ctr.NetworkSettings.Networks)
networks[n] = epConf
}
for netName, epConf := range networks { for netName, epConf := range networks {
cleanOperationalData(epConf) cleanOperationalData(epConf)
if err := daemon.connectToNetwork(ctx, cfg, ctr, netName, epConf); err != nil { if err := daemon.connectToNetwork(ctx, cfg, ctr, netName, epConf); err != nil {

View File

@@ -2,6 +2,7 @@ package containerd
import ( import (
"context" "context"
"maps"
c8dimages "github.com/containerd/containerd/v2/core/images" c8dimages "github.com/containerd/containerd/v2/core/images"
"github.com/moby/moby/api/types/events" "github.com/moby/moby/api/types/events"
@@ -45,7 +46,5 @@ func copyAttributes(attributes, labels map[string]string) {
if labels == nil { if labels == nil {
return return
} }
for k, v := range labels { maps.Copy(attributes, labels)
attributes[k] = v
}
} }

View File

@@ -2,6 +2,7 @@ package daemon
import ( import (
"context" "context"
"maps"
"strconv" "strconv"
"strings" "strings"
"time" "time"
@@ -94,9 +95,7 @@ func copyAttributes(attributes, labels map[string]string) {
if labels == nil { if labels == nil {
return return
} }
for k, v := range labels { maps.Copy(attributes, labels)
attributes[k] = v
}
} }
// ProcessClusterNotifications gets changes from store and add them to event list // ProcessClusterNotifications gets changes from store and add them to event list

View File

@@ -2,6 +2,7 @@ package images
import ( import (
"context" "context"
"maps"
"github.com/moby/moby/api/types/events" "github.com/moby/moby/api/types/events"
"github.com/moby/moby/v2/daemon/server/imagebackend" "github.com/moby/moby/v2/daemon/server/imagebackend"
@@ -32,7 +33,5 @@ func copyAttributes(attributes, labels map[string]string) {
if labels == nil { if labels == nil {
return return
} }
for k, v := range labels { maps.Copy(attributes, labels)
attributes[k] = v
}
} }

View File

@@ -4,6 +4,7 @@ import (
"context" "context"
"errors" "errors"
"fmt" "fmt"
"maps"
"runtime" "runtime"
"time" "time"
@@ -35,9 +36,7 @@ func (daemon *Daemon) ContainerInspect(ctx context.Context, name string, options
// TODO(thaJeztah): do we need a deep copy here? Otherwise we could use maps.Clone (see https://github.com/moby/moby/commit/7917a36cc787ada58987320e67cc6d96858f3b55) // TODO(thaJeztah): do we need a deep copy here? Otherwise we could use maps.Clone (see https://github.com/moby/moby/commit/7917a36cc787ada58987320e67cc6d96858f3b55)
ports := make(networktypes.PortMap, len(ctr.NetworkSettings.Ports)) ports := make(networktypes.PortMap, len(ctr.NetworkSettings.Ports))
for k, pm := range ctr.NetworkSettings.Ports { maps.Copy(ports, ctr.NetworkSettings.Ports)
ports[k] = pm
}
apiNetworks := make(map[string]*networktypes.EndpointSettings) apiNetworks := make(map[string]*networktypes.EndpointSettings)
for nwName, epConf := range ctr.NetworkSettings.Networks { for nwName, epConf := range ctr.NetworkSettings.Networks {

View File

@@ -4,6 +4,7 @@ import (
"context" "context"
"fmt" "fmt"
"io" "io"
"maps"
"net/netip" "net/netip"
"strconv" "strconv"
"strings" "strings"
@@ -213,9 +214,7 @@ func (b *Builder) Prune(ctx context.Context, opts buildbackend.CachePruneOptions
validFilters["until"] = true validFilters["until"] = true
validFilters["label"] = true // TODO(tiborvass): handle label validFilters["label"] = true // TODO(tiborvass): handle label
validFilters["label!"] = true // TODO(tiborvass): handle label! validFilters["label!"] = true // TODO(tiborvass): handle label!
for k, v := range cacheFields { maps.Copy(validFilters, cacheFields)
validFilters[k] = v
}
if err := opts.Filters.Validate(validFilters); err != nil { if err := opts.Filters.Validate(validFilters); err != nil {
return 0, nil, err return 0, nil, err
} }

View File

@@ -6,6 +6,7 @@ package filters
import ( import (
"encoding/json" "encoding/json"
"maps"
"regexp" "regexp"
"strings" "strings"
) )
@@ -280,9 +281,7 @@ func (args Args) Clone() (newArgs Args) {
var mm map[string]bool var mm map[string]bool
if m != nil { if m != nil {
mm = make(map[string]bool, len(m)) mm = make(map[string]bool, len(m))
for kk, v := range m { maps.Copy(mm, m)
mm[kk] = v
}
} }
newArgs.fields[k] = mm newArgs.fields[k] = mm
} }

View File

@@ -3,6 +3,7 @@ package cnmallocator
import ( import (
"context" "context"
"fmt" "fmt"
"maps"
"net" "net"
"net/netip" "net/netip"
"slices" "slices"
@@ -725,14 +726,10 @@ func (na *cnmNetworkAllocator) allocateDriverState(d *networkDriver, n *api.Netw
// reconcile the driver specific options from the network spec // reconcile the driver specific options from the network spec
// and from the operational state retrieved from the store // and from the operational state retrieved from the store
if n.Spec.DriverConfig != nil { if n.Spec.DriverConfig != nil {
for k, v := range n.Spec.DriverConfig.Options { maps.Copy(options, n.Spec.DriverConfig.Options)
options[k] = v
}
} }
if n.DriverState != nil { if n.DriverState != nil {
for k, v := range n.DriverState.Options { maps.Copy(options, n.DriverState.Options)
options[k] = v
}
} }
// Construct IPAM data for driver consumption. // Construct IPAM data for driver consumption.

View File

@@ -1036,9 +1036,7 @@ func (ep *Endpoint) getEtcHostsAddrs() []netip.Addr {
// in a Dictionary of Key-Value pair // in a Dictionary of Key-Value pair
func EndpointOptionGeneric(generic map[string]any) EndpointOption { func EndpointOptionGeneric(generic map[string]any) EndpointOption {
return func(ep *Endpoint) { return func(ep *Endpoint) {
for k, v := range generic { maps.Copy(ep.generic, generic)
ep.generic[k] = v
}
} }
} }

View File

@@ -476,9 +476,7 @@ func (n *Network) applyConfigurationTo(to *Network) error {
} }
if len(n.generic) > 0 { if len(n.generic) > 0 {
to.generic = options.Generic{} to.generic = options.Generic{}
for k, v := range n.generic { maps.Copy(to.generic, n.generic)
to.generic[k] = v
}
} }
// Network drivers only see generic flags. So, make sure they match. // Network drivers only see generic flags. So, make sure they match.
@@ -525,15 +523,11 @@ func (n *Network) CopyTo(o datastore.KVObject) error {
if dstN.labels == nil { if dstN.labels == nil {
dstN.labels = make(map[string]string, len(n.labels)) dstN.labels = make(map[string]string, len(n.labels))
} }
for k, v := range n.labels { maps.Copy(dstN.labels, n.labels)
dstN.labels[k] = v
}
if n.ipamOptions != nil { if n.ipamOptions != nil {
dstN.ipamOptions = make(map[string]string, len(n.ipamOptions)) dstN.ipamOptions = make(map[string]string, len(n.ipamOptions))
for k, v := range n.ipamOptions { maps.Copy(dstN.ipamOptions, n.ipamOptions)
dstN.ipamOptions[k] = v
}
} }
for _, c := range n.ipamV4Config { for _, c := range n.ipamV4Config {
@@ -553,9 +547,7 @@ func (n *Network) CopyTo(o datastore.KVObject) error {
} }
dstN.generic = options.Generic{} dstN.generic = options.Generic{}
for k, v := range n.generic { maps.Copy(dstN.generic, n.generic)
dstN.generic[k] = v
}
return nil return nil
} }
@@ -793,9 +785,7 @@ func NetworkOptionGeneric(generic map[string]any) NetworkOption {
if val, ok := generic[netlabel.Internal]; ok { if val, ok := generic[netlabel.Internal]; ok {
n.internal = val.(bool) n.internal = val.(bool)
} }
for k, v := range generic { maps.Copy(n.generic, generic)
n.generic[k] = v
}
} }
} }
@@ -1875,9 +1865,7 @@ func (n *Network) Labels() map[string]string {
defer n.mu.Unlock() defer n.mu.Unlock()
lbls := make(map[string]string, len(n.labels)) lbls := make(map[string]string, len(n.labels))
for k, v := range n.labels { maps.Copy(lbls, n.labels)
lbls[k] = v
}
return lbls return lbls
} }

View File

@@ -4,6 +4,7 @@ import (
"context" "context"
"encoding/json" "encoding/json"
"fmt" "fmt"
"maps"
"net" "net"
"net/netip" "net/netip"
"slices" "slices"
@@ -126,9 +127,7 @@ func (sb *Sandbox) Labels() map[string]any {
sb.mu.Lock() sb.mu.Lock()
defer sb.mu.Unlock() defer sb.mu.Unlock()
opts := make(map[string]any, len(sb.config.generic)) opts := make(map[string]any, len(sb.config.generic))
for k, v := range sb.config.generic { maps.Copy(opts, sb.config.generic)
opts[k] = v
}
return opts return opts
} }
@@ -280,9 +279,7 @@ func (sb *Sandbox) UpdateLabels(labels map[string]any) {
if sb.config.generic == nil { if sb.config.generic == nil {
sb.config.generic = make(map[string]any, len(labels)) sb.config.generic = make(map[string]any, len(labels))
} }
for k, v := range labels { maps.Copy(sb.config.generic, labels)
sb.config.generic[k] = v
}
} }
func (sb *Sandbox) MarshalJSON() ([]byte, error) { func (sb *Sandbox) MarshalJSON() ([]byte, error) {

View File

@@ -4,6 +4,7 @@ package fluentd
import ( import (
"context" "context"
"maps"
"math" "math"
"net/url" "net/url"
"strconv" "strconv"
@@ -120,9 +121,7 @@ func (f *fluentd) Log(msg *logger.Message) error {
"source": msg.Source, "source": msg.Source,
"log": string(msg.Line), "log": string(msg.Line),
} }
for k, v := range f.extra { maps.Copy(data, f.extra)
data[k] = v
}
if msg.PLogMetaData != nil { if msg.PLogMetaData != nil {
data["partial_message"] = "true" data["partial_message"] = "true"
data["partial_id"] = msg.PLogMetaData.ID data["partial_id"] = msg.PLogMetaData.ID

View File

@@ -3,6 +3,7 @@ package fluentd
import ( import (
"bufio" "bufio"
"context" "context"
"maps"
"net" "net"
"path/filepath" "path/filepath"
"runtime" "runtime"
@@ -350,9 +351,7 @@ func TestReadWriteTimeoutsAreEffective(t *testing.T) {
"fluentd-buffer-limit": "1", "fluentd-buffer-limit": "1",
} }
// Update the config with test specific configs. // Update the config with test specific configs.
for k, v := range tc.cfg { maps.Copy(cfg, tc.cfg)
cfg[k] = v
}
f, err := New(logger.Info{ f, err := New(logger.Info{
ContainerName: "/test-container", ContainerName: "/test-container",

View File

@@ -5,6 +5,7 @@ package journald
import ( import (
"errors" "errors"
"fmt" "fmt"
"maps"
"strconv" "strconv"
"sync/atomic" "sync/atomic"
"time" "time"
@@ -129,9 +130,7 @@ func newJournald(info logger.Info) (*journald, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
for k, v := range extraAttrs { maps.Copy(vars, extraAttrs)
vars[k] = v
}
return &journald{ return &journald{
epoch: epoch, epoch: epoch,
vars: vars, vars: vars,
@@ -159,9 +158,7 @@ func validateLogOpt(cfg map[string]string) error {
func (s *journald) Log(msg *logger.Message) error { func (s *journald) Log(msg *logger.Message) error {
vars := map[string]string{} vars := map[string]string{}
for k, v := range s.vars { maps.Copy(vars, s.vars)
vars[k] = v
}
if !msg.Timestamp.IsZero() { if !msg.Timestamp.IsZero() {
vars[fieldSyslogTimestamp] = msg.Timestamp.Format(time.RFC3339Nano) vars[fieldSyslogTimestamp] = msg.Timestamp.Format(time.RFC3339Nano)
} }

View File

@@ -1,5 +1,7 @@
package logger package logger
import "maps"
var externalValidators []LogOptValidator var externalValidators []LogOptValidator
// RegisterExternalValidator adds the validator to the list of external validators. // RegisterExternalValidator adds the validator to the list of external validators.
@@ -14,9 +16,7 @@ func RegisterExternalValidator(v LogOptValidator) {
// not be exposed as a usable log driver to the API. // not be exposed as a usable log driver to the API.
// This should only be called on package initialization. // This should only be called on package initialization.
func AddBuiltinLogOpts(opts map[string]bool) { func AddBuiltinLogOpts(opts map[string]bool) {
for k, v := range opts { maps.Copy(builtInLogOpts, opts)
builtInLogOpts[k] = v
}
} }
func validateExternal(cfg map[string]string) error { func validateExternal(cfg map[string]string) error {

View File

@@ -304,9 +304,7 @@ func (daemon *Daemon) createNetwork(ctx context.Context, cfg *config.Config, cre
} }
networkOptions := make(map[string]string) networkOptions := make(map[string]string)
for k, v := range create.Options { maps.Copy(networkOptions, create.Options)
networkOptions[k] = v
}
if defaultOpts, ok := cfg.DefaultNetworkOpts[driver]; create.ConfigFrom == nil && ok { if defaultOpts, ok := cfg.DefaultNetworkOpts[driver]; create.ConfigFrom == nil && ok {
for k, v := range defaultOpts { for k, v := range defaultOpts {
if _, ok := networkOptions[k]; !ok { if _, ok := networkOptions[k]; !ok {

View File

@@ -3,6 +3,7 @@ package daemon
import ( import (
"context" "context"
"fmt" "fmt"
"maps"
"os" "os"
"path/filepath" "path/filepath"
"strconv" "strconv"
@@ -985,9 +986,7 @@ func WithSysctls(c *container.Container) coci.SpecOpts {
} }
// We merge the sysctls injected above with the HostConfig (latter takes // We merge the sysctls injected above with the HostConfig (latter takes
// precedence for backwards-compatibility reasons). // precedence for backwards-compatibility reasons).
for k, v := range c.HostConfig.Sysctls { maps.Copy(s.Linux.Sysctl, c.HostConfig.Sysctls)
s.Linux.Sysctl[k] = v
}
return nil return nil
} }
} }

View File

@@ -102,9 +102,7 @@ func newServiceConfig(options ServiceOptions) (*serviceConfig, error) {
// copy constructs a new ServiceConfig with a copy of the configuration in config. // copy constructs a new ServiceConfig with a copy of the configuration in config.
func (config *serviceConfig) copy() *registry.ServiceConfig { func (config *serviceConfig) copy() *registry.ServiceConfig {
ic := make(map[string]*registry.IndexInfo) ic := make(map[string]*registry.IndexInfo)
for key, value := range config.IndexConfigs { maps.Copy(ic, config.IndexConfigs)
ic[key] = value
}
return &registry.ServiceConfig{ return &registry.ServiceConfig{
InsecureRegistryCIDRs: slices.Clone(config.InsecureRegistryCIDRs), InsecureRegistryCIDRs: slices.Clone(config.InsecureRegistryCIDRs),
IndexConfigs: ic, IndexConfigs: ic,

View File

@@ -1,6 +1,7 @@
package container package container
import ( import (
"maps"
"strings" "strings"
"testing" "testing"
@@ -315,9 +316,7 @@ func TestHandleSysctlBC(t *testing.T) {
NetworkMode: container.NetworkMode(tc.networkMode), NetworkMode: container.NetworkMode(tc.networkMode),
Sysctls: map[string]string{}, Sysctls: map[string]string{},
} }
for k, v := range tc.sysctls { maps.Copy(hostCfg.Sysctls, tc.sysctls)
hostCfg.Sysctls[k] = v
}
netCfg := &network.NetworkingConfig{ netCfg := &network.NetworkingConfig{
EndpointsConfig: tc.epConfig, EndpointsConfig: tc.epConfig,
} }

View File

@@ -3,6 +3,7 @@ package drivers
import ( import (
"context" "context"
"errors" "errors"
"maps"
"strings" "strings"
"time" "time"
@@ -169,8 +170,6 @@ func (a *volumeAdapter) CreatedAt() (time.Time, error) {
func (a *volumeAdapter) Status() map[string]any { func (a *volumeAdapter) Status() map[string]any {
out := make(map[string]any, len(a.status)) out := make(map[string]any, len(a.status))
for k, v := range a.status { maps.Copy(out, a.status)
out[k] = v
}
return out return out
} }

View File

@@ -3,6 +3,7 @@ package service
import ( import (
"context" "context"
"fmt" "fmt"
"maps"
"net" "net"
"os" "os"
"path/filepath" "path/filepath"
@@ -39,9 +40,7 @@ func (v volumeWrapper) Options() map[string]string {
return nil return nil
} }
options := make(map[string]string, len(v.options)) options := make(map[string]string, len(v.options))
for key, value := range v.options { maps.Copy(options, v.options)
options[key] = value
}
return options return options
} }
@@ -51,9 +50,7 @@ func (v volumeWrapper) Labels() map[string]string {
} }
labels := make(map[string]string, len(v.labels)) labels := make(map[string]string, len(v.labels))
for key, value := range v.labels { maps.Copy(labels, v.labels)
labels[key] = value
}
return labels return labels
} }

View File

@@ -3,6 +3,7 @@ package daemon
import ( import (
"context" "context"
"encoding/hex" "encoding/hex"
"maps"
"os" "os"
"path/filepath" "path/filepath"
"sort" "sort"
@@ -97,9 +98,7 @@ func (daemon *Daemon) registerMountPoints(ctr *container.Container, defaultReadO
} }
// 1. Read already configured mount points. // 1. Read already configured mount points.
for destination, point := range ctr.MountPoints { maps.Copy(mountPoints, ctr.MountPoints)
mountPoints[destination] = point
}
// 2. Read volumes from other containers. // 2. Read volumes from other containers.
for _, v := range ctr.HostConfig.VolumesFrom { for _, v := range ctr.HostConfig.VolumesFrom {

View File

@@ -1,6 +1,7 @@
package labelstore package labelstore
import ( import (
"maps"
"sync" "sync"
"github.com/opencontainers/go-digest" "github.com/opencontainers/go-digest"
@@ -40,9 +41,7 @@ func (s *InMemory) Update(dgst digest.Digest, update map[string]string) (map[str
if !ok { if !ok {
labels = map[string]string{} labels = map[string]string{}
} }
for k, v := range update { maps.Copy(labels, update)
labels[k] = v
}
if s.labels == nil { if s.labels == nil {
s.labels = map[digest.Digest]map[string]string{} s.labels = map[digest.Digest]map[string]string{}
} }