diff --git a/.golangci.yml b/.golangci.yml index aa201a7f67..66fdab6c8f 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -215,6 +215,7 @@ linters: - name: superfluous-else arguments: - preserve-scope + - name: use-any - name: use-errors-new - name: var-declaration diff --git a/client/container_start_test.go b/client/container_start_test.go index 99979660cd..fd3f6478af 100644 --- a/client/container_start_test.go +++ b/client/container_start_test.go @@ -41,7 +41,7 @@ func TestContainerStart(t *testing.T) { } // we're not expecting any payload, but if one is supplied, check it is valid. if req.Header.Get("Content-Type") == "application/json" { - var startConfig interface{} + var startConfig any if err := json.NewDecoder(req.Body).Decode(&startConfig); err != nil { return nil, fmt.Errorf("Unable to parse json: %s", err) } diff --git a/client/hijack.go b/client/hijack.go index 46608d93cb..f06f53a323 100644 --- a/client/hijack.go +++ b/client/hijack.go @@ -14,7 +14,7 @@ import ( ) // postHijacked sends a POST request and hijacks the connection. -func (cli *Client) postHijacked(ctx context.Context, path string, query url.Values, body interface{}, headers map[string][]string) (HijackedResponse, error) { +func (cli *Client) postHijacked(ctx context.Context, path string, query url.Values, body any, headers map[string][]string) (HijackedResponse, error) { jsonBody, err := jsonEncode(body) if err != nil { return HijackedResponse{}, err diff --git a/client/request.go b/client/request.go index 803ff6d2a6..45be416a29 100644 --- a/client/request.go +++ b/client/request.go @@ -28,7 +28,7 @@ func (cli *Client) get(ctx context.Context, path string, query url.Values, heade } // post sends an http POST request to the API. -func (cli *Client) post(ctx context.Context, path string, query url.Values, body interface{}, headers http.Header) (*http.Response, error) { +func (cli *Client) post(ctx context.Context, path string, query url.Values, body any, headers http.Header) (*http.Response, error) { jsonBody, headers, err := prepareJSONRequest(body, headers) if err != nil { return nil, err @@ -40,7 +40,7 @@ func (cli *Client) postRaw(ctx context.Context, path string, query url.Values, b return cli.sendRequest(ctx, http.MethodPost, path, query, body, headers) } -func (cli *Client) put(ctx context.Context, path string, query url.Values, body interface{}, headers http.Header) (*http.Response, error) { +func (cli *Client) put(ctx context.Context, path string, query url.Values, body any, headers http.Header) (*http.Response, error) { jsonBody, headers, err := prepareJSONRequest(body, headers) if err != nil { return nil, err @@ -70,7 +70,7 @@ func (cli *Client) delete(ctx context.Context, path string, query url.Values, he // // TODO(thaJeztah): should this return an error if a different Content-Type is already set? // TODO(thaJeztah): is "nil" the appropriate approach for an empty body, or should we use [http.NoBody] (or similar)? -func prepareJSONRequest(body interface{}, headers http.Header) (io.Reader, http.Header, error) { +func prepareJSONRequest(body any, headers http.Header) (io.Reader, http.Header, error) { if body == nil { return nil, headers, nil } @@ -309,7 +309,7 @@ func (cli *Client) addHeaders(req *http.Request, headers http.Header) *http.Requ return req } -func jsonEncode(data interface{}) (io.Reader, error) { +func jsonEncode(data any) (io.Reader, error) { var params bytes.Buffer if data != nil { if err := json.NewEncoder(¶ms).Encode(data); err != nil { diff --git a/daemon/builder/dockerfile/builder.go b/daemon/builder/dockerfile/builder.go index 096c53565b..3cc4a8c486 100644 --- a/daemon/builder/dockerfile/builder.go +++ b/daemon/builder/dockerfile/builder.go @@ -240,7 +240,7 @@ func processMetaArg(meta instructions.ArgCommand, shlex *shell.Lex, args *BuildA return nil } -func printCommand(out io.Writer, currentCommandIndex int, totalCommands int, cmd interface{}) int { +func printCommand(out io.Writer, currentCommandIndex int, totalCommands int, cmd any) int { _, _ = fmt.Fprintf(out, stepFormat, currentCommandIndex, totalCommands, cmd) _, _ = fmt.Fprintln(out) return currentCommandIndex + 1 diff --git a/daemon/builder/dockerfile/copy.go b/daemon/builder/dockerfile/copy.go index 51505f0080..f46f27df41 100644 --- a/daemon/builder/dockerfile/copy.go +++ b/daemon/builder/dockerfile/copy.go @@ -32,8 +32,8 @@ import ( const unnamedFilename = "__unnamed__" type pathCache interface { - Load(key interface{}) (value interface{}, ok bool) - Store(key, value interface{}) + Load(key any) (value any, ok bool) + Store(key, value any) } // copyInfo is a data object which stores the metadata about each source file in diff --git a/daemon/cluster/controllers/plugin/controller.go b/daemon/cluster/controllers/plugin/controller.go index 9fe18fa6e1..9abdd86392 100644 --- a/daemon/cluster/controllers/plugin/controller.go +++ b/daemon/cluster/controllers/plugin/controller.go @@ -50,7 +50,7 @@ type Backend interface { Pull(ctx context.Context, ref reference.Named, name string, metaHeaders http.Header, authConfig *registry.AuthConfig, privileges plugintypes.Privileges, outStream io.Writer, opts ...plugin.CreateOpt) error Upgrade(ctx context.Context, ref reference.Named, name string, metaHeaders http.Header, authConfig *registry.AuthConfig, privileges plugintypes.Privileges, outStream io.Writer) error Get(name string) (*v2.Plugin, error) - SubscribeEvents(buffer int, events ...plugin.Event) (eventCh <-chan interface{}, cancel func()) + SubscribeEvents(buffer int, events ...plugin.Event) (eventCh <-chan any, cancel func()) } // NewController returns a new cluster plugin controller diff --git a/daemon/cluster/controllers/plugin/controller_test.go b/daemon/cluster/controllers/plugin/controller_test.go index eb32015270..a2500a9c27 100644 --- a/daemon/cluster/controllers/plugin/controller_test.go +++ b/daemon/cluster/controllers/plugin/controller_test.go @@ -385,7 +385,7 @@ func (m *mockBackend) Get(name string) (*v2.Plugin, error) { return m.p, nil } -func (m *mockBackend) SubscribeEvents(buffer int, events ...plugin.Event) (eventCh <-chan interface{}, cancel func()) { +func (m *mockBackend) SubscribeEvents(buffer int, events ...plugin.Event) (eventCh <-chan any, cancel func()) { ch := m.pub.SubscribeTopicWithBuffer(nil, buffer) cancel = func() { m.pub.Evict(ch) } return ch, cancel diff --git a/daemon/cluster/executor/backend.go b/daemon/cluster/executor/backend.go index 0536a5774b..d3e2fe000c 100644 --- a/daemon/cluster/executor/backend.go +++ b/daemon/cluster/executor/backend.go @@ -57,8 +57,8 @@ type Backend interface { DaemonJoinsCluster(provider cluster.Provider) DaemonLeavesCluster() IsSwarmCompatible() error - SubscribeToEvents(since, until time.Time, filter filters.Args) ([]events.Message, chan interface{}) - UnsubscribeFromEvents(listener chan interface{}) + SubscribeToEvents(since, until time.Time, filter filters.Args) ([]events.Message, chan any) + UnsubscribeFromEvents(listener chan any) UpdateAttachment(string, string, string, *network.NetworkingConfig) error WaitForDetachment(context.Context, string, string, string, string) error PluginManager() *plugin.Manager diff --git a/daemon/cluster/executor/container/adapter.go b/daemon/cluster/executor/container/adapter.go index a6eba1cda4..f2ab628c8a 100644 --- a/daemon/cluster/executor/container/adapter.go +++ b/daemon/cluster/executor/container/adapter.go @@ -113,7 +113,7 @@ func (c *containerAdapter) pullImage(ctx context.Context) error { dec := json.NewDecoder(pr) dec.UseNumber() - m := map[string]interface{}{} + m := map[string]any{} spamLimiter := rate.NewLimiter(rate.Every(time.Second), 1) lastStatus := "" @@ -128,7 +128,7 @@ func (c *containerAdapter) pullImage(ctx context.Context) error { // limit pull progress logs unless the status changes if spamLimiter.Allow() || lastStatus != m["status"] { // if we have progress details, we have everything we need - if progress, ok := m["progressDetail"].(map[string]interface{}); ok { + if progress, ok := m["progressDetail"].(map[string]any); ok { // first, log the image and status l = l.WithFields(log.Fields{ "image": c.container.image(), diff --git a/daemon/config/config.go b/daemon/config/config.go index fd0d376b02..67646903d3 100644 --- a/daemon/config/config.go +++ b/daemon/config/config.go @@ -257,7 +257,7 @@ type CommonConfig struct { // FIXME(vdemeester) This part is not that clear and is mainly dependent on cli flags // It should probably be handled outside this package. - ValuesSet map[string]interface{} `json:"-"` + ValuesSet map[string]any `json:"-"` Experimental bool `json:"experimental"` // Experimental indicates whether experimental features should be exposed or not @@ -512,7 +512,7 @@ func getConflictFreeConfiguration(configFile string, flags *pflag.FlagSet) (*Con } if flags != nil { - var jsonConfig map[string]interface{} + var jsonConfig map[string]any if err := json.Unmarshal(b, &jsonConfig); err != nil { return nil, err } @@ -528,7 +528,7 @@ func getConflictFreeConfiguration(configFile string, flags *pflag.FlagSet) (*Con // See https://github.com/moby/moby/issues/20289 for an example. // // TODO: Rewrite configuration logic to avoid same issue with other nullable values, like numbers. - namedOptions := make(map[string]interface{}) + namedOptions := make(map[string]any) for key, value := range configSet { f := flags.Lookup(key) if f == nil { // ignore named flags that don't match @@ -568,10 +568,10 @@ func getConflictFreeConfiguration(configFile string, flags *pflag.FlagSet) (*Con } // configValuesSet returns the configuration values explicitly set in the file. -func configValuesSet(config map[string]interface{}) map[string]interface{} { - flatten := make(map[string]interface{}) +func configValuesSet(config map[string]any) map[string]any { + flatten := make(map[string]any) for k, v := range config { - if m, isMap := v.(map[string]interface{}); isMap && !flatOptions[k] { + if m, isMap := v.(map[string]any); isMap && !flatOptions[k] { for km, vm := range m { flatten[km] = vm } @@ -586,9 +586,9 @@ func configValuesSet(config map[string]interface{}) map[string]interface{} { // findConfigurationConflicts iterates over the provided flags searching for // duplicated configurations and unknown keys. It returns an error with all the conflicts if // it finds any. -func findConfigurationConflicts(config map[string]interface{}, flags *pflag.FlagSet) error { +func findConfigurationConflicts(config map[string]any, flags *pflag.FlagSet) error { // 1. Search keys from the file that we don't recognize as flags. - unknownKeys := make(map[string]interface{}) + unknownKeys := make(map[string]any) for key, value := range config { if flag := flags.Lookup(key); flag == nil && !skipValidateOptions[key] { unknownKeys[key] = value @@ -615,7 +615,7 @@ func findConfigurationConflicts(config map[string]interface{}, flags *pflag.Flag } // 3. Search keys that are present as a flag and as a file option. - printConflict := func(name string, flagValue, fileValue interface{}) string { + printConflict := func(name string, flagValue, fileValue any) string { switch name { case "http-proxy", "https-proxy": flagValue = MaskCredentials(flagValue.(string)) diff --git a/daemon/config/config_test.go b/daemon/config/config_test.go index bed80d803f..418de6f6c0 100644 --- a/daemon/config/config_test.go +++ b/daemon/config/config_test.go @@ -94,7 +94,7 @@ func TestDaemonConfigurationInvalidUnicode(t *testing.T) { } func TestFindConfigurationConflicts(t *testing.T) { - config := map[string]interface{}{"authorization-plugins": "foobar"} + config := map[string]any{"authorization-plugins": "foobar"} flags := pflag.NewFlagSet("test", pflag.ContinueOnError) flags.String("authorization-plugins", "", "") @@ -103,7 +103,7 @@ func TestFindConfigurationConflicts(t *testing.T) { } func TestFindConfigurationConflictsWithNamedOptions(t *testing.T) { - config := map[string]interface{}{"hosts": []string{"qwer"}} + config := map[string]any{"hosts": []string{"qwer"}} flags := pflag.NewFlagSet("test", pflag.ContinueOnError) var hosts []string @@ -195,7 +195,7 @@ func TestDaemonConfigurationMergeDefaultAddressPools(t *testing.T) { } func TestFindConfigurationConflictsWithUnknownKeys(t *testing.T) { - config := map[string]interface{}{"tls-verify": "true"} + config := map[string]any{"tls-verify": "true"} flags := pflag.NewFlagSet("test", pflag.ContinueOnError) flags.Bool("tlsverify", false, "") @@ -205,7 +205,7 @@ func TestFindConfigurationConflictsWithUnknownKeys(t *testing.T) { func TestFindConfigurationConflictsWithMergedValues(t *testing.T) { var hosts []string - config := map[string]interface{}{"hosts": "tcp://127.0.0.1:2345"} + config := map[string]any{"hosts": "tcp://127.0.0.1:2345"} flags := pflag.NewFlagSet("base", pflag.ContinueOnError) flags.VarP(opts.NewNamedListOptsRef("hosts", &hosts, nil), "host", "H", "") diff --git a/daemon/container_operations_windows.go b/daemon/container_operations_windows.go index ddd79352cb..475a7296f0 100644 --- a/daemon/container_operations_windows.go +++ b/daemon/container_operations_windows.go @@ -199,7 +199,7 @@ func (daemon *Daemon) initializeNetworkingPaths(ctr *container.Container, nc *co } if data["GW_INFO"] != nil { - gwInfo := data["GW_INFO"].(map[string]interface{}) + gwInfo := data["GW_INFO"].(map[string]any) if gwInfo["hnsid"] != nil { ctr.SharedEndpointList = append(ctr.SharedEndpointList, gwInfo["hnsid"].(string)) } diff --git a/daemon/containerd/image_import.go b/daemon/containerd/image_import.go index 0bf7b480c0..f1f63280a7 100644 --- a/daemon/containerd/image_import.go +++ b/daemon/containerd/image_import.go @@ -343,7 +343,7 @@ func fillUncompressedLabel(ctx context.Context, cs content.Store, compressedDige } // storeJson marshals the provided object as json and stores it. -func storeJson(ctx context.Context, cs content.Ingester, mt string, obj interface{}, labels map[string]string) (ocispec.Descriptor, error) { +func storeJson(ctx context.Context, cs content.Ingester, mt string, obj any, labels map[string]string) (ocispec.Descriptor, error) { configData, err := json.Marshal(obj) if err != nil { return ocispec.Descriptor{}, errdefs.InvalidParameter(err) diff --git a/daemon/containerd/image_list.go b/daemon/containerd/image_list.go index 7e7811b0b0..9fcb6032fe 100644 --- a/daemon/containerd/image_list.go +++ b/daemon/containerd/image_list.go @@ -732,7 +732,7 @@ func computeSharedSize(chainIDs []digest.Digest, layers map[digest.Digest]int, s } // readJSON reads content pointed by the descriptor and unmarshals it into a specified output. -func readJSON(ctx context.Context, store content.Provider, desc ocispec.Descriptor, out interface{}) error { +func readJSON(ctx context.Context, store content.Provider, desc ocispec.Descriptor, out any) error { data, err := content.ReadBlob(ctx, store, desc) if err != nil { err = errors.Wrapf(err, "failed to read config content") diff --git a/daemon/containerd/image_manifest.go b/daemon/containerd/image_manifest.go index f2343b96eb..5093578e94 100644 --- a/daemon/containerd/image_manifest.go +++ b/daemon/containerd/image_manifest.go @@ -232,7 +232,7 @@ func (im *ImageManifest) ImagePlatform(ctx context.Context) (ocispec.Platform, e // ReadConfig gets the image config and unmarshals it into the provided struct. // The provided struct should be a pointer to the config struct or its subset. -func (im *ImageManifest) ReadConfig(ctx context.Context, outConfig interface{}) error { +func (im *ImageManifest) ReadConfig(ctx context.Context, outConfig any) error { configDesc, err := im.Config(ctx) if err != nil { return err diff --git a/daemon/daemon_unsupported.go b/daemon/daemon_unsupported.go index 855e753580..06d28a54b0 100644 --- a/daemon/daemon_unsupported.go +++ b/daemon/daemon_unsupported.go @@ -12,7 +12,7 @@ func checkSystem() error { return errors.New("the Docker daemon is not supported on this platform") } -func setupResolvConf(_ *interface{}) {} +func setupResolvConf(_ *any) {} func getSysInfo(_ *Daemon) *sysinfo.SysInfo { return sysinfo.New() diff --git a/daemon/daemon_windows.go b/daemon/daemon_windows.go index db3ee73534..42310b1414 100644 --- a/daemon/daemon_windows.go +++ b/daemon/daemon_windows.go @@ -233,7 +233,7 @@ func configureMaxThreads(_ context.Context) error { return nil } -func (daemon *Daemon) initNetworkController(daemonCfg *config.Config, activeSandboxes map[string]interface{}) error { +func (daemon *Daemon) initNetworkController(daemonCfg *config.Config, activeSandboxes map[string]any) error { netOptions, err := daemon.networkOptions(daemonCfg, nil, daemon.id, nil) if err != nil { return err diff --git a/daemon/events.go b/daemon/events.go index 2d161a2af6..597969b821 100644 --- a/daemon/events.go +++ b/daemon/events.go @@ -79,13 +79,13 @@ func (daemon *Daemon) LogDaemonEventWithAttributes(action events.Action, attribu } // SubscribeToEvents returns the currently record of events, a channel to stream new events from, and a function to cancel the stream of events. -func (daemon *Daemon) SubscribeToEvents(since, until time.Time, filter filters.Args) ([]events.Message, chan interface{}) { +func (daemon *Daemon) SubscribeToEvents(since, until time.Time, filter filters.Args) ([]events.Message, chan any) { return daemon.EventsService.SubscribeTopic(since, until, daemonevents.NewFilter(filter)) } // UnsubscribeFromEvents stops the event subscription for a client by closing the // channel where the daemon sends events to. -func (daemon *Daemon) UnsubscribeFromEvents(listener chan interface{}) { +func (daemon *Daemon) UnsubscribeFromEvents(listener chan any) { daemon.EventsService.Evict(listener) } diff --git a/daemon/events/events.go b/daemon/events/events.go index aae91d40df..28eef7980f 100644 --- a/daemon/events/events.go +++ b/daemon/events/events.go @@ -33,7 +33,7 @@ func New() *Events { // last events, a channel in which you can expect new events (in form // of interface{}, so you need type assertion), and a function to call // to stop the stream of events. -func (e *Events) Subscribe() ([]eventtypes.Message, chan interface{}, func()) { +func (e *Events) Subscribe() ([]eventtypes.Message, chan any, func()) { metrics.EventSubscribers.Inc() e.mu.Lock() current := make([]eventtypes.Message, len(e.events)) @@ -50,18 +50,18 @@ func (e *Events) Subscribe() ([]eventtypes.Message, chan interface{}, func()) { // SubscribeTopic adds new listener to events, returns slice of 256 stored // last events, a channel in which you can expect new events (in form // of interface{}, so you need type assertion). -func (e *Events) SubscribeTopic(since, until time.Time, ef *Filter) ([]eventtypes.Message, chan interface{}) { +func (e *Events) SubscribeTopic(since, until time.Time, ef *Filter) ([]eventtypes.Message, chan any) { metrics.EventSubscribers.Inc() e.mu.Lock() - var topic func(m interface{}) bool + var topic func(m any) bool if ef != nil && ef.filter.Len() > 0 { - topic = func(m interface{}) bool { return ef.Include(m.(eventtypes.Message)) } + topic = func(m any) bool { return ef.Include(m.(eventtypes.Message)) } } buffered := e.loadBufferedEvents(since, until, topic) - var ch chan interface{} + var ch chan any if topic != nil { ch = e.pub.SubscribeTopic(topic) } else { @@ -74,7 +74,7 @@ func (e *Events) SubscribeTopic(since, until time.Time, ef *Filter) ([]eventtype } // Evict evicts listener from pubsub -func (e *Events) Evict(l chan interface{}) { +func (e *Events) Evict(l chan any) { metrics.EventSubscribers.Dec() e.pub.Evict(l) } @@ -133,7 +133,7 @@ func (e *Events) SubscribersCount() int { // and returns those that were emitted between two specific dates. // It uses `time.Unix(seconds, nanoseconds)` to generate valid dates with those arguments. // It filters those buffered messages with a topic function if it's not nil, otherwise it adds all messages. -func (e *Events) loadBufferedEvents(since, until time.Time, topic func(interface{}) bool) []eventtypes.Message { +func (e *Events) loadBufferedEvents(since, until time.Time, topic func(any) bool) []eventtypes.Message { var buffered []eventtypes.Message if since.IsZero() && until.IsZero() { return buffered diff --git a/daemon/events_test.go b/daemon/events_test.go index d9fe1b283d..07d497346d 100644 --- a/daemon/events_test.go +++ b/daemon/events_test.go @@ -70,7 +70,7 @@ func TestLogContainerEventWithAttributes(t *testing.T) { }) } -func validateTestAttributes(t *testing.T, l chan interface{}, expectedAttributesToTest map[string]string) { +func validateTestAttributes(t *testing.T, l chan any, expectedAttributesToTest map[string]string) { select { case ev := <-l: event, ok := ev.(eventtypes.Message) diff --git a/daemon/internal/builder-next/builder.go b/daemon/internal/builder-next/builder.go index a3c1029e90..b6ac12ba39 100644 --- a/daemon/internal/builder-next/builder.go +++ b/daemon/internal/builder-next/builder.go @@ -490,7 +490,7 @@ func (sp *streamProxy) Context() context.Context { return sp.ctx } -func (sp *streamProxy) RecvMsg(m interface{}) error { +func (sp *streamProxy) RecvMsg(m any) error { return io.EOF } @@ -503,7 +503,7 @@ func (sp *statusProxy) Send(resp *controlapi.StatusResponse) error { return sp.SendMsg(resp) } -func (sp *statusProxy) SendMsg(m interface{}) error { +func (sp *statusProxy) SendMsg(m any) error { if sr, ok := m.(*controlapi.StatusResponse); ok { sp.ch <- sr } @@ -519,7 +519,7 @@ func (sp *pruneProxy) Send(resp *controlapi.UsageRecord) error { return sp.SendMsg(resp) } -func (sp *pruneProxy) SendMsg(m interface{}) error { +func (sp *pruneProxy) SendMsg(m any) error { if sr, ok := m.(*controlapi.UsageRecord); ok { sp.ch <- sr } diff --git a/daemon/internal/builder-next/executor_others.go b/daemon/internal/builder-next/executor_others.go index 5e4f2a921a..30ed22208b 100644 --- a/daemon/internal/builder-next/executor_others.go +++ b/daemon/internal/builder-next/executor_others.go @@ -2,6 +2,14 @@ package buildkit +import ( + "github.com/moby/buildkit/executor" + "github.com/moby/buildkit/executor/oci" + "github.com/moby/buildkit/solver/llbsolver/cdidevices" + "github.com/moby/moby/v2/daemon/libnetwork" + "github.com/moby/sys/user" +) + func newExecutor(_, _ string, _ *libnetwork.Controller, _ *oci.DNSConfig, _ bool, _ user.IdentityMapping, _ string, _ *cdidevices.Manager, _, _ string) (executor.Executor, error) { return &stubExecutor{}, nil } diff --git a/daemon/internal/image/v1/imagev1.go b/daemon/internal/image/v1/imagev1.go index f5362fdf11..b4779f71ac 100644 --- a/daemon/internal/image/v1/imagev1.go +++ b/daemon/internal/image/v1/imagev1.go @@ -39,7 +39,7 @@ func CreateID(v1Image image.V1Image, layerID layer.ChainID, parent digest.Digest return digest.FromBytes(configJSON), nil } -func rawJSON(value interface{}) *json.RawMessage { +func rawJSON(value any) *json.RawMessage { jsonval, err := json.Marshal(value) if err != nil { return nil diff --git a/daemon/internal/libcontainerd/local/local_windows.go b/daemon/internal/libcontainerd/local/local_windows.go index ee84136341..d7f027ee78 100644 --- a/daemon/internal/libcontainerd/local/local_windows.go +++ b/daemon/internal/libcontainerd/local/local_windows.go @@ -145,7 +145,7 @@ func (c *client) Version(ctx context.Context) (containerd.Version, error) { // "ImagePath": "C:\\\\control\\\\windowsfilter\\\\65bf96e5760a09edf1790cb229e2dfb2dbd0fcdc0bf7451bae099106bfbfea0c\\\\UtilityVM" // }, // } -func (c *client) NewContainer(_ context.Context, id string, spec *specs.Spec, _ string, _ interface{}, _ ...containerd.NewContainerOpts) (libcontainerdtypes.Container, error) { +func (c *client) NewContainer(_ context.Context, id string, spec *specs.Spec, _ string, _ any, _ ...containerd.NewContainerOpts) (libcontainerdtypes.Container, error) { if spec.Linux != nil { return nil, errors.New("linux containers are not supported on this platform") } diff --git a/daemon/internal/libcontainerd/remote/client.go b/daemon/internal/libcontainerd/remote/client.go index 7085c225af..350e136516 100644 --- a/daemon/internal/libcontainerd/remote/client.go +++ b/daemon/internal/libcontainerd/remote/client.go @@ -118,7 +118,7 @@ func (c *container) AttachTask(ctx context.Context, attachStdio libcontainerdtyp return c.newTask(t), nil } -func (c *client) NewContainer(ctx context.Context, id string, ociSpec *specs.Spec, shim string, runtimeOptions interface{}, opts ...containerd.NewContainerOpts) (libcontainerdtypes.Container, error) { +func (c *client) NewContainer(ctx context.Context, id string, ociSpec *specs.Spec, shim string, runtimeOptions any, opts ...containerd.NewContainerOpts) (libcontainerdtypes.Container, error) { bdir := c.bundleDir(id) c.logger.WithField("bundle", bdir).WithField("root", ociSpec.Root.Path).Debug("bundle dir created") diff --git a/daemon/internal/libcontainerd/remote/client_linux.go b/daemon/internal/libcontainerd/remote/client_linux.go index ced05836a2..e7e2c35eff 100644 --- a/daemon/internal/libcontainerd/remote/client_linux.go +++ b/daemon/internal/libcontainerd/remote/client_linux.go @@ -16,7 +16,7 @@ import ( "github.com/opencontainers/runtime-spec/specs-go" ) -func summaryFromInterface(i interface{}) (*libcontainerdtypes.Summary, error) { +func summaryFromInterface(i any) (*libcontainerdtypes.Summary, error) { return &libcontainerdtypes.Summary{}, nil } diff --git a/daemon/internal/libcontainerd/remote/client_windows.go b/daemon/internal/libcontainerd/remote/client_windows.go index 1ae2154e1f..815f2557dd 100644 --- a/daemon/internal/libcontainerd/remote/client_windows.go +++ b/daemon/internal/libcontainerd/remote/client_windows.go @@ -16,7 +16,7 @@ import ( "github.com/pkg/errors" ) -func summaryFromInterface(i interface{}) (*libcontainerdtypes.Summary, error) { +func summaryFromInterface(i any) (*libcontainerdtypes.Summary, error) { switch pd := i.(type) { case *options.ProcessDetails: return &libcontainerdtypes.Summary{ diff --git a/daemon/internal/libcontainerd/replace.go b/daemon/internal/libcontainerd/replace.go index d6b7a468a4..fd2a31d47e 100644 --- a/daemon/internal/libcontainerd/replace.go +++ b/daemon/internal/libcontainerd/replace.go @@ -14,7 +14,7 @@ import ( // ReplaceContainer creates a new container, replacing any existing container // with the same id if necessary. -func ReplaceContainer(ctx context.Context, client types.Client, id string, spec *specs.Spec, shim string, runtimeOptions interface{}, opts ...containerd.NewContainerOpts) (types.Container, error) { +func ReplaceContainer(ctx context.Context, client types.Client, id string, spec *specs.Spec, shim string, runtimeOptions any, opts ...containerd.NewContainerOpts) (types.Container, error) { newContainer := func() (types.Container, error) { return client.NewContainer(ctx, id, spec, shim, runtimeOptions, opts...) } diff --git a/daemon/internal/libcontainerd/shimopts/convert.go b/daemon/internal/libcontainerd/shimopts/convert.go index 71a40ce54d..2a19ec00a6 100644 --- a/daemon/internal/libcontainerd/shimopts/convert.go +++ b/daemon/internal/libcontainerd/shimopts/convert.go @@ -10,12 +10,12 @@ import ( // Generate converts opts into a runtime options value for the runtimeType which // can be passed into containerd. -func Generate(runtimeType string, opts map[string]interface{}) (interface{}, error) { +func Generate(runtimeType string, opts map[string]any) (any, error) { // This is horrible, but we have no other choice. The containerd client // can only handle options values which can be marshaled into a // typeurl.Any. And we're in good company: cri-containerd handles shim // options in the same way. - var out interface{} + var out any switch runtimeType { case plugins.RuntimeRuncV2: out = &runcoptions.Options{} diff --git a/daemon/internal/libcontainerd/types/types.go b/daemon/internal/libcontainerd/types/types.go index 1c90239c1e..cc64dc141c 100644 --- a/daemon/internal/libcontainerd/types/types.go +++ b/daemon/internal/libcontainerd/types/types.go @@ -59,7 +59,7 @@ type Client interface { // LoadContainer loads the metadata for a container from containerd. LoadContainer(ctx context.Context, containerID string) (Container, error) // NewContainer creates a new containerd container. - NewContainer(ctx context.Context, containerID string, spec *specs.Spec, shim string, runtimeOptions interface{}, opts ...containerd.NewContainerOpts) (Container, error) + NewContainer(ctx context.Context, containerID string, spec *specs.Spec, shim string, runtimeOptions any, opts ...containerd.NewContainerOpts) (Container, error) } // Container provides access to a containerd container. diff --git a/daemon/internal/libcontainerd/types/types_linux.go b/daemon/internal/libcontainerd/types/types_linux.go index d702d8f6fd..90352a6f9d 100644 --- a/daemon/internal/libcontainerd/types/types_linux.go +++ b/daemon/internal/libcontainerd/types/types_linux.go @@ -15,11 +15,11 @@ type Stats struct { // Metrics is expected to be either one of: // * github.com/containerd/cgroups/v3/cgroup1/stats.Metrics // * github.com/containerd/cgroups/v3/cgroup2/stats.Metrics - Metrics interface{} + Metrics any } // InterfaceToStats returns a stats object from the platform-specific interface. -func InterfaceToStats(read time.Time, v interface{}) *Stats { +func InterfaceToStats(read time.Time, v any) *Stats { return &Stats{ Metrics: v, Read: read, diff --git a/daemon/internal/libcontainerd/types/types_windows.go b/daemon/internal/libcontainerd/types/types_windows.go index d43dda62a7..f63f569990 100644 --- a/daemon/internal/libcontainerd/types/types_windows.go +++ b/daemon/internal/libcontainerd/types/types_windows.go @@ -16,7 +16,7 @@ type Stats struct { } // InterfaceToStats returns a stats object from the platform-specific interface. -func InterfaceToStats(read time.Time, v interface{}) *Stats { +func InterfaceToStats(read time.Time, v any) *Stats { return &Stats{ HCSStats: v.(*hcsshim.Statistics), Read: read, diff --git a/daemon/internal/plugin/executor/containerd/containerd.go b/daemon/internal/plugin/executor/containerd/containerd.go index 7fa1da8bfa..8cc9f74fcc 100644 --- a/daemon/internal/plugin/executor/containerd/containerd.go +++ b/daemon/internal/plugin/executor/containerd/containerd.go @@ -24,7 +24,7 @@ type ExitHandler interface { } // New creates a new containerd plugin executor -func New(ctx context.Context, rootDir string, cli *containerd.Client, ns string, exitHandler ExitHandler, shim string, shimOpts interface{}) (*Executor, error) { +func New(ctx context.Context, rootDir string, cli *containerd.Client, ns string, exitHandler ExitHandler, shim string, shimOpts any) (*Executor, error) { e := &Executor{ rootDir: rootDir, exitHandler: exitHandler, @@ -47,7 +47,7 @@ type Executor struct { client libcontainerdtypes.Client exitHandler ExitHandler shim string - shimOpts interface{} + shimOpts any mu sync.Mutex // Guards plugins map plugins map[string]*c8dPlugin diff --git a/daemon/internal/runconfig/config.go b/daemon/internal/runconfig/config.go index 708eae398e..4eaab3430d 100644 --- a/daemon/internal/runconfig/config.go +++ b/daemon/internal/runconfig/config.go @@ -81,7 +81,7 @@ func validateCreateRequest(w container.CreateRequest, si *sysinfo.SysInfo) error } // loadJSON is similar to api/server/httputils.ReadJSON() -func loadJSON(src io.Reader, out interface{}) error { +func loadJSON(src io.Reader, out any) error { dec := json.NewDecoder(src) if err := dec.Decode(&out); err != nil { // invalidJSONError allows unwrapping the error to detect io.EOF etc. diff --git a/daemon/internal/stream/bytespipe/bytespipe.go b/daemon/internal/stream/bytespipe/bytespipe.go index b0956b581c..499cbfecc9 100644 --- a/daemon/internal/stream/bytespipe/bytespipe.go +++ b/daemon/internal/stream/bytespipe/bytespipe.go @@ -180,7 +180,7 @@ func getBuffer(size int) *fixedBuffer { bufPoolsLock.Lock() pool, ok := bufPools[size] if !ok { - pool = &sync.Pool{New: func() interface{} { return &fixedBuffer{buf: make([]byte, 0, size)} }} + pool = &sync.Pool{New: func() any { return &fixedBuffer{buf: make([]byte, 0, size)} }} bufPools[size] = pool } bufPoolsLock.Unlock() diff --git a/daemon/libnetwork/cnmallocator/manager.go b/daemon/libnetwork/cnmallocator/manager.go index 3f0656c0f5..0a6df14dbd 100644 --- a/daemon/libnetwork/cnmallocator/manager.go +++ b/daemon/libnetwork/cnmallocator/manager.go @@ -28,7 +28,7 @@ func (d *manager) NetworkFree(id string) error { return types.NotImplementedErrorf("not implemented") } -func (d *manager) CreateNetwork(ctx context.Context, id string, option map[string]interface{}, nInfo driverapi.NetworkInfo, ipV4Data, ipV6Data []driverapi.IPAMData) error { +func (d *manager) CreateNetwork(ctx context.Context, id string, option map[string]any, nInfo driverapi.NetworkInfo, ipV4Data, ipV6Data []driverapi.IPAMData) error { return types.NotImplementedErrorf("not implemented") } @@ -36,7 +36,7 @@ func (d *manager) DeleteNetwork(nid string) error { return types.NotImplementedErrorf("not implemented") } -func (d *manager) CreateEndpoint(_ context.Context, nid, eid string, ifInfo driverapi.InterfaceInfo, epOptions map[string]interface{}) error { +func (d *manager) CreateEndpoint(_ context.Context, nid, eid string, ifInfo driverapi.InterfaceInfo, epOptions map[string]any) error { return types.NotImplementedErrorf("not implemented") } @@ -44,11 +44,11 @@ func (d *manager) DeleteEndpoint(nid, eid string) error { return types.NotImplementedErrorf("not implemented") } -func (d *manager) EndpointOperInfo(nid, eid string) (map[string]interface{}, error) { +func (d *manager) EndpointOperInfo(nid, eid string) (map[string]any, error) { return nil, types.NotImplementedErrorf("not implemented") } -func (d *manager) Join(_ context.Context, nid, eid string, sboxKey string, jinfo driverapi.JoinInfo, _, _ map[string]interface{}) error { +func (d *manager) Join(_ context.Context, nid, eid string, sboxKey string, jinfo driverapi.JoinInfo, _, _ map[string]any) error { return types.NotImplementedErrorf("not implemented") } diff --git a/daemon/libnetwork/controller.go b/daemon/libnetwork/controller.go index 363886d148..3672375cbf 100644 --- a/daemon/libnetwork/controller.go +++ b/daemon/libnetwork/controller.go @@ -383,12 +383,12 @@ func (c *Controller) agentStopComplete() { c.mu.Unlock() } -func (c *Controller) makeDriverConfig(ntype string) map[string]interface{} { +func (c *Controller) makeDriverConfig(ntype string) map[string]any { if c.cfg == nil { return nil } - cfg := map[string]interface{}{} + cfg := map[string]any{} for _, label := range c.cfg.Labels { key, val, _ := strings.Cut(label, "=") if !strings.HasPrefix(key, netlabel.DriverPrefix+"."+ntype) { @@ -551,7 +551,7 @@ func (c *Controller) NewNetwork(ctx context.Context, networkType, name string, i nw := &Network{ name: name, networkType: networkType, - generic: map[string]interface{}{netlabel.GenericData: make(map[string]string)}, + generic: map[string]any{netlabel.GenericData: make(map[string]string)}, ipamType: defaultIpam, enableIPv4: true, id: id, diff --git a/daemon/libnetwork/datastore/datastore_test.go b/daemon/libnetwork/datastore/datastore_test.go index 904384c239..21e5e7da7e 100644 --- a/daemon/libnetwork/datastore/datastore_test.go +++ b/daemon/libnetwork/datastore/datastore_test.go @@ -123,7 +123,7 @@ func (n *dummyObject) Skip() bool { } func (n *dummyObject) MarshalJSON() ([]byte, error) { - return json.Marshal(map[string]interface{}{ + return json.Marshal(map[string]any{ "name": n.Name, "networkType": n.NetworkType, "enableIPv6": n.EnableIPv6, @@ -132,14 +132,14 @@ func (n *dummyObject) MarshalJSON() ([]byte, error) { } func (n *dummyObject) UnmarshalJSON(b []byte) error { - var netMap map[string]interface{} + var netMap map[string]any if err := json.Unmarshal(b, &netMap); err != nil { return err } n.Name = netMap["name"].(string) n.NetworkType = netMap["networkType"].(string) n.EnableIPv6 = netMap["enableIPv6"].(bool) - n.Generic = netMap["generic"].(map[string]interface{}) + n.Generic = netMap["generic"].(map[string]any) return nil } @@ -213,7 +213,7 @@ func dummyKVObject(id string, retValue bool) *dummyObject { ReturnValue: retValue, DBExists: false, SkipSave: false, - Generic: map[string]interface{}{ + Generic: map[string]any{ "label1": &recStruct{Name: "value1", Field1: 1, Dict: cDict}, "label2": "subnet=10.1.1.0/16", }, diff --git a/daemon/libnetwork/discoverapi/discoverapi.go b/daemon/libnetwork/discoverapi/discoverapi.go index f71013544e..565a5c35af 100644 --- a/daemon/libnetwork/discoverapi/discoverapi.go +++ b/daemon/libnetwork/discoverapi/discoverapi.go @@ -4,10 +4,10 @@ package discoverapi // like new node joining the cluster or datastore updates type Discover interface { // DiscoverNew is a notification for a new discovery event, Example:a new node joining a cluster - DiscoverNew(dType DiscoveryType, data interface{}) error + DiscoverNew(dType DiscoveryType, data any) error // DiscoverDelete is a notification for a discovery delete event, Example:a node leaving a cluster - DiscoverDelete(dType DiscoveryType, data interface{}) error + DiscoverDelete(dType DiscoveryType, data any) error } // DiscoveryType represents the type of discovery element the DiscoverNew function is invoked on @@ -36,7 +36,7 @@ type DatastoreConfigData struct { Scope string Provider string Address string - Config interface{} + Config any } // DriverEncryptionConfig contains the initial datapath encryption key(s) diff --git a/daemon/libnetwork/driverapi/driverapi.go b/daemon/libnetwork/driverapi/driverapi.go index f9c221347d..35db522425 100644 --- a/daemon/libnetwork/driverapi/driverapi.go +++ b/daemon/libnetwork/driverapi/driverapi.go @@ -31,7 +31,7 @@ type Driver interface { // notification when a CRUD operation is performed on any // entry in that table. This will be ignored for local scope // drivers. - CreateNetwork(ctx context.Context, nid string, options map[string]interface{}, nInfo NetworkInfo, ipV4Data, ipV6Data []IPAMData) error + CreateNetwork(ctx context.Context, nid string, options map[string]any, nInfo NetworkInfo, ipV4Data, ipV6Data []IPAMData) error // DeleteNetwork invokes the driver method to delete network passing // the network id. @@ -42,17 +42,17 @@ type Driver interface { // specific config. The endpoint information can be either consumed by // the driver or populated by the driver. The config mechanism will // eventually be replaced with labels which are yet to be introduced. - CreateEndpoint(ctx context.Context, nid, eid string, ifInfo InterfaceInfo, options map[string]interface{}) error + CreateEndpoint(ctx context.Context, nid, eid string, ifInfo InterfaceInfo, options map[string]any) error // DeleteEndpoint invokes the driver method to delete an endpoint // passing the network id and endpoint id. DeleteEndpoint(nid, eid string) error // EndpointOperInfo retrieves from the driver the operational data related to the specified endpoint - EndpointOperInfo(nid, eid string) (map[string]interface{}, error) + EndpointOperInfo(nid, eid string) (map[string]any, error) // Join method is invoked when a Sandbox is attached to an endpoint. - Join(ctx context.Context, nid, eid string, sboxKey string, jinfo JoinInfo, epOpts, sbOpts map[string]interface{}) error + Join(ctx context.Context, nid, eid string, sboxKey string, jinfo JoinInfo, epOpts, sbOpts map[string]any) error // Leave method is invoked when a Sandbox detaches from an endpoint. Leave(nid, eid string) error diff --git a/daemon/libnetwork/driverapi/ipamdata.go b/daemon/libnetwork/driverapi/ipamdata.go index 0ecdf12bb8..ecf0d7f161 100644 --- a/daemon/libnetwork/driverapi/ipamdata.go +++ b/daemon/libnetwork/driverapi/ipamdata.go @@ -10,7 +10,7 @@ import ( // MarshalJSON encodes IPAMData into json message func (i *IPAMData) MarshalJSON() ([]byte, error) { - m := map[string]interface{}{} + m := map[string]any{} m["AddressSpace"] = i.AddressSpace if i.Pool != nil { m["Pool"] = i.Pool.String() @@ -31,7 +31,7 @@ func (i *IPAMData) MarshalJSON() ([]byte, error) { // UnmarshalJSON decodes a json message into IPAMData func (i *IPAMData) UnmarshalJSON(data []byte) error { var ( - m map[string]interface{} + m map[string]any err error ) if err := json.Unmarshal(data, &m); err != nil { diff --git a/daemon/libnetwork/drivers/bridge/bridge_linux.go b/daemon/libnetwork/drivers/bridge/bridge_linux.go index fcac619b50..84e66a7715 100644 --- a/daemon/libnetwork/drivers/bridge/bridge_linux.go +++ b/daemon/libnetwork/drivers/bridge/bridge_linux.go @@ -187,7 +187,7 @@ func newDriver(store *datastore.Store, pms *drvregistry.PortMappers) *driver { } // Register registers a new instance of bridge driver. -func Register(r driverapi.Registerer, store *datastore.Store, pms *drvregistry.PortMappers, config map[string]interface{}) error { +func Register(r driverapi.Registerer, store *datastore.Store, pms *drvregistry.PortMappers, config map[string]any) error { d := newDriver(store, pms) if err := d.configure(config); err != nil { return err @@ -504,7 +504,7 @@ func (n *bridgeNetwork) getEndpoint(eid string) (*bridgeEndpoint, error) { return nil, nil } -func (d *driver) configure(option map[string]interface{}) error { +func (d *driver) configure(option map[string]any) error { var config configuration switch opt := option[netlabel.GenericData].(type) { case options.Generic: @@ -581,7 +581,7 @@ func (d *driver) getNetwork(id string) (*bridgeNetwork, error) { return nil, types.NotFoundErrorf("network not found: %s", id) } -func parseNetworkGenericOptions(data interface{}) (*networkConfiguration, error) { +func parseNetworkGenericOptions(data any) (*networkConfiguration, error) { var ( err error config *networkConfiguration @@ -721,7 +721,7 @@ func (d *driver) GetSkipGwAlloc(opts options.Generic) (ipv4, ipv6 bool, _ error) } // CreateNetwork creates a new network using the bridge driver. -func (d *driver) CreateNetwork(ctx context.Context, id string, option map[string]interface{}, nInfo driverapi.NetworkInfo, ipV4Data, ipV6Data []driverapi.IPAMData) error { +func (d *driver) CreateNetwork(ctx context.Context, id string, option map[string]any, nInfo driverapi.NetworkInfo, ipV4Data, ipV6Data []driverapi.IPAMData) error { // Sanity checks d.mu.Lock() if _, ok := d.networks[id]; ok { @@ -1046,7 +1046,7 @@ func setHairpinMode(nlh nlwrap.Handle, link netlink.Link, enable bool) error { return nil } -func (d *driver) CreateEndpoint(ctx context.Context, nid, eid string, ifInfo driverapi.InterfaceInfo, _ map[string]interface{}) error { +func (d *driver) CreateEndpoint(ctx context.Context, nid, eid string, ifInfo driverapi.InterfaceInfo, _ map[string]any) error { if ifInfo == nil { return errors.New("invalid interface info passed") } @@ -1353,7 +1353,7 @@ func (d *driver) DeleteEndpoint(nid, eid string) error { return nil } -func (d *driver) EndpointOperInfo(nid, eid string) (map[string]interface{}, error) { +func (d *driver) EndpointOperInfo(nid, eid string) (map[string]any, error) { // Get the network handler and make sure it exists d.mu.Lock() n, ok := d.networks[nid] @@ -1382,7 +1382,7 @@ func (d *driver) EndpointOperInfo(nid, eid string) (map[string]interface{}, erro return nil, driverapi.ErrNoEndpoint(eid) } - m := make(map[string]interface{}) + m := make(map[string]any) if ep.extConnConfig != nil && ep.extConnConfig.ExposedPorts != nil { // Return a copy of the config data @@ -1410,7 +1410,7 @@ func (d *driver) EndpointOperInfo(nid, eid string) (map[string]interface{}, erro } // Join method is invoked when a Sandbox is attached to an endpoint. -func (d *driver) Join(ctx context.Context, nid, eid string, sboxKey string, jinfo driverapi.JoinInfo, epOpts, sbOpts map[string]interface{}) error { +func (d *driver) Join(ctx context.Context, nid, eid string, sboxKey string, jinfo driverapi.JoinInfo, epOpts, sbOpts map[string]any) error { ctx, span := otel.Tracer("").Start(ctx, spanPrefix+".Join", trace.WithAttributes( attribute.String("nid", nid), attribute.String("eid", eid), @@ -1753,7 +1753,7 @@ func (d *driver) handleFirewalldReloadNw(nid string) { } } -func LegacyContainerLinkOptions(parentEndpoints, childEndpoints []string) map[string]interface{} { +func LegacyContainerLinkOptions(parentEndpoints, childEndpoints []string) map[string]any { return options.Generic{ netlabel.GenericData: options.Generic{ "ParentEndpoints": parentEndpoints, @@ -1848,7 +1848,7 @@ func (d *driver) IsBuiltIn() bool { return true } -func parseContainerOptions(cOptions map[string]interface{}) (*containerConfiguration, error) { +func parseContainerOptions(cOptions map[string]any) (*containerConfiguration, error) { if cOptions == nil { return nil, nil } @@ -1870,7 +1870,7 @@ func parseContainerOptions(cOptions map[string]interface{}) (*containerConfigura } } -func parseConnectivityOptions(cOptions map[string]interface{}) (*connectivityConfiguration, error) { +func parseConnectivityOptions(cOptions map[string]any) (*connectivityConfiguration, error) { if cOptions == nil { return nil, nil } diff --git a/daemon/libnetwork/drivers/bridge/bridge_linux_test.go b/daemon/libnetwork/drivers/bridge/bridge_linux_test.go index 6c9fccfddd..90bf4df4cf 100644 --- a/daemon/libnetwork/drivers/bridge/bridge_linux_test.go +++ b/daemon/libnetwork/drivers/bridge/bridge_linux_test.go @@ -294,14 +294,14 @@ func TestCreateFullOptions(t *testing.T) { br, _ := types.ParseCIDR("172.16.0.1/16") defgw, _ := types.ParseCIDR("172.16.0.100/16") - genericOption := make(map[string]interface{}) + genericOption := make(map[string]any) genericOption[netlabel.GenericData] = config if err := d.configure(genericOption); err != nil { t.Fatalf("Failed to setup driver config: %v", err) } - netOption := make(map[string]interface{}) + netOption := make(map[string]any) netOption[netlabel.EnableIPv4] = true netOption[netlabel.EnableIPv6] = true netOption[netlabel.GenericData] = &networkConfiguration{ @@ -321,7 +321,7 @@ func TestCreateFullOptions(t *testing.T) { } // Verify the IP address allocated for the endpoint belongs to the container network - epOptions := make(map[string]interface{}) + epOptions := make(map[string]any) te := newTestEndpoint(cnw, 10) err = d.CreateEndpoint(context.Background(), "dummy", "ep1", te.Interface(), epOptions) if err != nil { @@ -340,7 +340,7 @@ func TestCreateNoConfig(t *testing.T) { assert.NilError(t, err) netconfig := &networkConfiguration{BridgeName: DefaultBridgeName, EnableIPv4: true} - genericOption := make(map[string]interface{}) + genericOption := make(map[string]any) genericOption[netlabel.GenericData] = netconfig if err := d.CreateNetwork(context.Background(), "dummy", genericOption, nil, getIPv4Data(t), nil); err != nil { @@ -355,7 +355,7 @@ func TestCreateFullOptionsLabels(t *testing.T) { config := &configuration{ EnableIPForwarding: true, } - genericOption := make(map[string]interface{}) + genericOption := make(map[string]any) genericOption[netlabel.GenericData] = config if err := d.configure(genericOption); err != nil { @@ -378,7 +378,7 @@ func TestCreateFullOptionsLabels(t *testing.T) { netlabel.HostIPv4: testHostIPv4, } - netOption := make(map[string]interface{}) + netOption := make(map[string]any) netOption[netlabel.EnableIPv4] = true netOption[netlabel.EnableIPv6] = true netOption[netlabel.GenericData] = labels @@ -443,7 +443,7 @@ func TestCreateFullOptionsLabels(t *testing.T) { // Check that a MAC address is generated if not already configured. te1 := newTestEndpoint(ipdList[0].Pool, 20) - err = d.CreateEndpoint(context.Background(), "dummy", "ep1", te1.Interface(), map[string]interface{}{}) + err = d.CreateEndpoint(context.Background(), "dummy", "ep1", te1.Interface(), map[string]any{}) assert.NilError(t, err) assert.Check(t, is.Len(te1.iface.mac, 6)) @@ -451,7 +451,7 @@ func TestCreateFullOptionsLabels(t *testing.T) { te2 := newTestEndpoint(ipdList[0].Pool, 20) const macAddr = "aa:bb:cc:dd:ee:ff" te2.iface.mac = netutils.MustParseMAC(macAddr) - err = d.CreateEndpoint(context.Background(), "dummy", "ep2", te2.Interface(), map[string]interface{}{}) + err = d.CreateEndpoint(context.Background(), "dummy", "ep2", te2.Interface(), map[string]any{}) assert.NilError(t, err) assert.Check(t, is.Equal(te2.iface.mac.String(), macAddr)) } @@ -544,7 +544,7 @@ func TestCreate(t *testing.T) { } netconfig := &networkConfiguration{BridgeName: DefaultBridgeName, EnableIPv4: true} - genericOption := make(map[string]interface{}) + genericOption := make(map[string]any) genericOption[netlabel.GenericData] = netconfig if err := d.CreateNetwork(context.Background(), "dummy", genericOption, nil, getIPv4Data(t), nil); err != nil { @@ -570,7 +570,7 @@ func TestCreateFail(t *testing.T) { } netconfig := &networkConfiguration{BridgeName: "dummy0", DefaultBridge: true} - genericOption := make(map[string]interface{}) + genericOption := make(map[string]any) genericOption[netlabel.GenericData] = netconfig if err := d.CreateNetwork(context.Background(), "dummy", genericOption, nil, getIPv4Data(t), nil); err == nil { @@ -599,7 +599,7 @@ func TestCreateMultipleNetworks(t *testing.T) { config := &configuration{ EnableIPTables: true, } - genericOption := make(map[string]interface{}) + genericOption := make(map[string]any) genericOption[netlabel.GenericData] = config if err := d.configure(genericOption); err != nil { @@ -607,7 +607,7 @@ func TestCreateMultipleNetworks(t *testing.T) { } config1 := &networkConfiguration{BridgeName: "net_test_1", EnableIPv4: true} - genericOption = make(map[string]interface{}) + genericOption = make(map[string]any) genericOption[netlabel.GenericData] = config1 if err := d.CreateNetwork(context.Background(), "1", genericOption, nil, getIPv4Data(t), nil); err != nil { t.Fatalf("Failed to create bridge: %v", err) @@ -806,7 +806,7 @@ func testQueryEndpointInfo(t *testing.T, ulPxyEnabled bool) { config := &configuration{ EnableIPTables: true, } - genericOption := make(map[string]interface{}) + genericOption := make(map[string]any) genericOption[netlabel.GenericData] = config if err := d.configure(genericOption); err != nil { @@ -818,7 +818,7 @@ func testQueryEndpointInfo(t *testing.T, ulPxyEnabled bool) { EnableIPv4: true, EnableICC: false, } - genericOption = make(map[string]interface{}) + genericOption = make(map[string]any) genericOption[netlabel.GenericData] = netconfig ipdList := getIPv4Data(t) @@ -827,7 +827,7 @@ func testQueryEndpointInfo(t *testing.T, ulPxyEnabled bool) { t.Fatalf("Failed to create bridge: %v", err) } - sbOptions := make(map[string]interface{}) + sbOptions := make(map[string]any) sbOptions[netlabel.PortMap] = getPortMapping() te := newTestEndpoint(ipdList[0].Pool, 11) @@ -909,7 +909,7 @@ func TestLinkContainers(t *testing.T) { config := &configuration{ EnableIPTables: true, } - genericOption := make(map[string]interface{}) + genericOption := make(map[string]any) genericOption[netlabel.GenericData] = config if err := d.configure(genericOption); err != nil { @@ -921,7 +921,7 @@ func TestLinkContainers(t *testing.T) { EnableIPv4: true, EnableICC: false, } - genericOption = make(map[string]interface{}) + genericOption = make(map[string]any) genericOption[netlabel.GenericData] = netconfig ipdList := getIPv4Data(t) @@ -937,7 +937,7 @@ func TestLinkContainers(t *testing.T) { } exposedPorts := getExposedPorts() - sbOptions := make(map[string]interface{}) + sbOptions := make(map[string]any) sbOptions[netlabel.ExposedPorts] = exposedPorts err = d.Join(context.Background(), "net1", "ep1", "sbox", te1, nil, sbOptions) @@ -966,7 +966,7 @@ func TestLinkContainers(t *testing.T) { t.Fatal("No Ipv4 address assigned to the endpoint: ep2") } - sbOptions = make(map[string]interface{}) + sbOptions = make(map[string]any) sbOptions[netlabel.GenericData] = options.Generic{ "ChildEndpoints": []string{"ep1"}, } @@ -1006,7 +1006,7 @@ func TestLinkContainers(t *testing.T) { checkLink(false) // Error condition test with an invalid endpoint-id "ep4" - sbOptions = make(map[string]interface{}) + sbOptions = make(map[string]any) sbOptions[netlabel.GenericData] = options.Generic{ "ChildEndpoints": []string{"ep1", "ep4"}, } @@ -1186,7 +1186,7 @@ func TestSetDefaultGw(t *testing.T) { gw6 := types.GetIPCopy(ipam6[0].Pool.IP) gw6[15] = 0x42 - option := map[string]interface{}{ + option := map[string]any{ netlabel.EnableIPv4: true, netlabel.EnableIPv6: true, netlabel.GenericData: &networkConfiguration{ @@ -1253,7 +1253,7 @@ func TestCreateWithExistingBridge(t *testing.T) { } netconfig := &networkConfiguration{BridgeName: brName, EnableIPv4: true} - genericOption := make(map[string]interface{}) + genericOption := make(map[string]any) genericOption[netlabel.GenericData] = netconfig ipv4Data := []driverapi.IPAMData{{ @@ -1309,7 +1309,7 @@ func TestCreateParallel(t *testing.T) { name := "net" + strconv.Itoa(i) c.Go(t, func() { config := &networkConfiguration{BridgeName: name, EnableIPv4: true} - genericOption := make(map[string]interface{}) + genericOption := make(map[string]any) genericOption[netlabel.GenericData] = config if err := d.CreateNetwork(context.Background(), name, genericOption, nil, ipV4Data, nil); err != nil { ch <- fmt.Errorf("failed to create %s", name) @@ -1351,7 +1351,7 @@ func TestSetupIP6TablesWithHostIPv4(t *testing.T) { EnableIPTables: true, EnableIP6Tables: true, } - if err := d.configure(map[string]interface{}{netlabel.GenericData: dc}); err != nil { + if err := d.configure(map[string]any{netlabel.GenericData: dc}); err != nil { t.Fatal(err) } nc := &networkConfiguration{ diff --git a/daemon/libnetwork/drivers/bridge/bridge_store.go b/daemon/libnetwork/drivers/bridge/bridge_store.go index d7ce18f20e..92a7dc20d1 100644 --- a/daemon/libnetwork/drivers/bridge/bridge_store.go +++ b/daemon/libnetwork/drivers/bridge/bridge_store.go @@ -138,7 +138,7 @@ func (d *driver) storeDelete(kvObject datastore.KVObject) error { } func (ncfg *networkConfiguration) MarshalJSON() ([]byte, error) { - nMap := make(map[string]interface{}) + nMap := make(map[string]any) nMap["ID"] = ncfg.ID nMap["BridgeName"] = ncfg.BridgeName nMap["EnableIPv4"] = ncfg.EnableIPv4 @@ -175,7 +175,7 @@ func (ncfg *networkConfiguration) MarshalJSON() ([]byte, error) { func (ncfg *networkConfiguration) UnmarshalJSON(b []byte) error { var ( err error - nMap map[string]interface{} + nMap map[string]any ) if err = json.Unmarshal(b, &nMap); err != nil { @@ -294,7 +294,7 @@ func (ncfg *networkConfiguration) CopyTo(o datastore.KVObject) error { } func (ep *bridgeEndpoint) MarshalJSON() ([]byte, error) { - epMap := make(map[string]interface{}) + epMap := make(map[string]any) epMap["id"] = ep.id epMap["nid"] = ep.nid epMap["SrcName"] = ep.srcName @@ -315,7 +315,7 @@ func (ep *bridgeEndpoint) MarshalJSON() ([]byte, error) { func (ep *bridgeEndpoint) UnmarshalJSON(b []byte) error { var ( err error - epMap map[string]interface{} + epMap map[string]any ) if err = json.Unmarshal(b, &epMap); err != nil { diff --git a/daemon/libnetwork/drivers/bridge/brmanager/brmanager.go b/daemon/libnetwork/drivers/bridge/brmanager/brmanager.go index 5819072dc7..415269d5a4 100644 --- a/daemon/libnetwork/drivers/bridge/brmanager/brmanager.go +++ b/daemon/libnetwork/drivers/bridge/brmanager/brmanager.go @@ -28,7 +28,7 @@ func (d *driver) NetworkFree(id string) error { return types.NotImplementedErrorf("not implemented") } -func (d *driver) CreateNetwork(ctx context.Context, id string, option map[string]interface{}, nInfo driverapi.NetworkInfo, ipV4Data, ipV6Data []driverapi.IPAMData) error { +func (d *driver) CreateNetwork(ctx context.Context, id string, option map[string]any, nInfo driverapi.NetworkInfo, ipV4Data, ipV6Data []driverapi.IPAMData) error { return types.NotImplementedErrorf("not implemented") } @@ -36,7 +36,7 @@ func (d *driver) DeleteNetwork(nid string) error { return types.NotImplementedErrorf("not implemented") } -func (d *driver) CreateEndpoint(_ context.Context, nid, eid string, ifInfo driverapi.InterfaceInfo, epOptions map[string]interface{}) error { +func (d *driver) CreateEndpoint(_ context.Context, nid, eid string, ifInfo driverapi.InterfaceInfo, epOptions map[string]any) error { return types.NotImplementedErrorf("not implemented") } @@ -44,11 +44,11 @@ func (d *driver) DeleteEndpoint(nid, eid string) error { return types.NotImplementedErrorf("not implemented") } -func (d *driver) EndpointOperInfo(nid, eid string) (map[string]interface{}, error) { +func (d *driver) EndpointOperInfo(nid, eid string) (map[string]any, error) { return nil, types.NotImplementedErrorf("not implemented") } -func (d *driver) Join(_ context.Context, nid, eid string, sboxKey string, jinfo driverapi.JoinInfo, _, _ map[string]interface{}) error { +func (d *driver) Join(_ context.Context, nid, eid string, sboxKey string, jinfo driverapi.JoinInfo, _, _ map[string]any) error { return types.NotImplementedErrorf("not implemented") } diff --git a/daemon/libnetwork/drivers/bridge/network_linux_test.go b/daemon/libnetwork/drivers/bridge/network_linux_test.go index 8638e239b9..20eb3422ec 100644 --- a/daemon/libnetwork/drivers/bridge/network_linux_test.go +++ b/daemon/libnetwork/drivers/bridge/network_linux_test.go @@ -21,7 +21,7 @@ func TestLinkCreate(t *testing.T) { assert.NilError(t, err) mtu := 1490 - option := map[string]interface{}{ + option := map[string]any{ netlabel.GenericData: &networkConfiguration{ BridgeName: DefaultBridgeName, EnableIPv4: true, @@ -83,7 +83,7 @@ func TestLinkCreateTwo(t *testing.T) { err := d.configure(nil) assert.NilError(t, err) - option := map[string]interface{}{ + option := map[string]any{ netlabel.GenericData: &networkConfiguration{ BridgeName: DefaultBridgeName, EnableIPv4: true, @@ -111,7 +111,7 @@ func TestLinkCreateNoEnableIPv6(t *testing.T) { err := d.configure(nil) assert.NilError(t, err) - option := map[string]interface{}{ + option := map[string]any{ netlabel.GenericData: &networkConfiguration{ BridgeName: DefaultBridgeName, EnableIPv4: true, @@ -136,7 +136,7 @@ func TestLinkDelete(t *testing.T) { err := d.configure(nil) assert.NilError(t, err) - option := map[string]interface{}{ + option := map[string]any{ netlabel.GenericData: &networkConfiguration{ BridgeName: DefaultBridgeName, EnableIPv4: true, diff --git a/daemon/libnetwork/drivers/bridge/port_mapping_linux_test.go b/daemon/libnetwork/drivers/bridge/port_mapping_linux_test.go index 4d1ef78691..7bf61a3113 100644 --- a/daemon/libnetwork/drivers/bridge/port_mapping_linux_test.go +++ b/daemon/libnetwork/drivers/bridge/port_mapping_linux_test.go @@ -47,7 +47,7 @@ func TestPortMappingConfig(t *testing.T) { EnableIPTables: true, Hairpin: true, } - genericOption := make(map[string]interface{}) + genericOption := make(map[string]any) genericOption[netlabel.GenericData] = config if err := d.configure(genericOption); err != nil { @@ -59,10 +59,10 @@ func TestPortMappingConfig(t *testing.T) { binding3 := types.PortBinding{Proto: types.TCP, Port: 500, HostPort: 65000} portBindings := []types.PortBinding{binding1, binding2, binding3} - sbOptions := make(map[string]interface{}) + sbOptions := make(map[string]any) sbOptions[netlabel.PortMap] = portBindings - netOptions := map[string]interface{}{ + netOptions := map[string]any{ netlabel.GenericData: &networkConfiguration{ BridgeName: DefaultBridgeName, EnableIPv4: true, @@ -137,7 +137,7 @@ func TestPortMappingV6Config(t *testing.T) { EnableIPTables: true, EnableIP6Tables: true, } - genericOption := make(map[string]interface{}) + genericOption := make(map[string]any) genericOption[netlabel.GenericData] = config if err := d.configure(genericOption); err != nil { @@ -150,13 +150,13 @@ func TestPortMappingV6Config(t *testing.T) { {Proto: types.SCTP, Port: 500, HostPort: 65000}, } - sbOptions := make(map[string]interface{}) + sbOptions := make(map[string]any) sbOptions[netlabel.PortMap] = portBindings netConfig := &networkConfiguration{ BridgeName: DefaultBridgeName, EnableIPv6: true, } - netOptions := make(map[string]interface{}) + netOptions := make(map[string]any) netOptions[netlabel.GenericData] = netConfig ipdList4 := getIPv4Data(t) @@ -787,7 +787,7 @@ func TestAddPortMappings(t *testing.T) { bridge: &bridgeInterface{}, driver: newDriver(storeutils.NewTempStore(t), pms), } - genericOption := map[string]interface{}{ + genericOption := map[string]any{ netlabel.GenericData: &configuration{ EnableIPTables: true, EnableIP6Tables: true, diff --git a/daemon/libnetwork/drivers/host/host.go b/daemon/libnetwork/drivers/host/host.go index 31cda2023f..4c81e2ac44 100644 --- a/daemon/libnetwork/drivers/host/host.go +++ b/daemon/libnetwork/drivers/host/host.go @@ -31,7 +31,7 @@ func (d *driver) NetworkFree(id string) error { return types.NotImplementedErrorf("not implemented") } -func (d *driver) CreateNetwork(ctx context.Context, id string, option map[string]interface{}, nInfo driverapi.NetworkInfo, ipV4Data, ipV6Data []driverapi.IPAMData) error { +func (d *driver) CreateNetwork(ctx context.Context, id string, option map[string]any, nInfo driverapi.NetworkInfo, ipV4Data, ipV6Data []driverapi.IPAMData) error { d.Lock() defer d.Unlock() @@ -48,7 +48,7 @@ func (d *driver) DeleteNetwork(nid string) error { return types.ForbiddenErrorf("network of type %q cannot be deleted", NetworkType) } -func (d *driver) CreateEndpoint(_ context.Context, nid, eid string, ifInfo driverapi.InterfaceInfo, epOptions map[string]interface{}) error { +func (d *driver) CreateEndpoint(_ context.Context, nid, eid string, ifInfo driverapi.InterfaceInfo, epOptions map[string]any) error { return nil } @@ -56,12 +56,12 @@ func (d *driver) DeleteEndpoint(nid, eid string) error { return nil } -func (d *driver) EndpointOperInfo(nid, eid string) (map[string]interface{}, error) { - return make(map[string]interface{}), nil +func (d *driver) EndpointOperInfo(nid, eid string) (map[string]any, error) { + return make(map[string]any), nil } // Join method is invoked when a Sandbox is attached to an endpoint. -func (d *driver) Join(_ context.Context, nid, eid string, sboxKey string, jinfo driverapi.JoinInfo, _, _ map[string]interface{}) error { +func (d *driver) Join(_ context.Context, nid, eid string, sboxKey string, jinfo driverapi.JoinInfo, _, _ map[string]any) error { return nil } diff --git a/daemon/libnetwork/drivers/ipvlan/ipvlan.go b/daemon/libnetwork/drivers/ipvlan/ipvlan.go index b30f1b31e2..38f8ef7894 100644 --- a/daemon/libnetwork/drivers/ipvlan/ipvlan.go +++ b/daemon/libnetwork/drivers/ipvlan/ipvlan.go @@ -62,7 +62,7 @@ type network struct { } // Register initializes and registers the libnetwork ipvlan driver. -func Register(r driverapi.Registerer, store *datastore.Store, config map[string]interface{}) error { +func Register(r driverapi.Registerer, store *datastore.Store, config map[string]any) error { d := &driver{ store: store, networks: networkTable{}, @@ -84,8 +84,8 @@ func (d *driver) NetworkFree(id string) error { return types.NotImplementedErrorf("not implemented") } -func (d *driver) EndpointOperInfo(nid, eid string) (map[string]interface{}, error) { - return make(map[string]interface{}), nil +func (d *driver) EndpointOperInfo(nid, eid string) (map[string]any, error) { + return make(map[string]any), nil } func (d *driver) Type() string { diff --git a/daemon/libnetwork/drivers/ipvlan/ipvlan_endpoint.go b/daemon/libnetwork/drivers/ipvlan/ipvlan_endpoint.go index 9f764b3db7..728ebb3b0e 100644 --- a/daemon/libnetwork/drivers/ipvlan/ipvlan_endpoint.go +++ b/daemon/libnetwork/drivers/ipvlan/ipvlan_endpoint.go @@ -16,7 +16,7 @@ import ( ) // CreateEndpoint assigns the mac, ip and endpoint id for the new container -func (d *driver) CreateEndpoint(ctx context.Context, nid, eid string, ifInfo driverapi.InterfaceInfo, epOptions map[string]interface{}) error { +func (d *driver) CreateEndpoint(ctx context.Context, nid, eid string, ifInfo driverapi.InterfaceInfo, epOptions map[string]any) error { if err := validateID(nid, eid); err != nil { return err } diff --git a/daemon/libnetwork/drivers/ipvlan/ipvlan_joinleave.go b/daemon/libnetwork/drivers/ipvlan/ipvlan_joinleave.go index 466c6e6e3d..baa2bda8cf 100644 --- a/daemon/libnetwork/drivers/ipvlan/ipvlan_joinleave.go +++ b/daemon/libnetwork/drivers/ipvlan/ipvlan_joinleave.go @@ -30,7 +30,7 @@ const ( ) // Join method is invoked when a Sandbox is attached to an endpoint. -func (d *driver) Join(ctx context.Context, nid, eid string, sboxKey string, jinfo driverapi.JoinInfo, epOpts, _ map[string]interface{}) error { +func (d *driver) Join(ctx context.Context, nid, eid string, sboxKey string, jinfo driverapi.JoinInfo, epOpts, _ map[string]any) error { ctx, span := otel.Tracer("").Start(ctx, "libnetwork.drivers.ipvlan.Join", trace.WithAttributes( attribute.String("nid", nid), attribute.String("eid", eid), diff --git a/daemon/libnetwork/drivers/ipvlan/ipvlan_network.go b/daemon/libnetwork/drivers/ipvlan/ipvlan_network.go index f1351a21e5..b75e9e3b97 100644 --- a/daemon/libnetwork/drivers/ipvlan/ipvlan_network.go +++ b/daemon/libnetwork/drivers/ipvlan/ipvlan_network.go @@ -18,7 +18,7 @@ import ( ) // CreateNetwork the network for the specified driver type -func (d *driver) CreateNetwork(ctx context.Context, nid string, option map[string]interface{}, nInfo driverapi.NetworkInfo, ipV4Data, ipV6Data []driverapi.IPAMData) error { +func (d *driver) CreateNetwork(ctx context.Context, nid string, option map[string]any, nInfo driverapi.NetworkInfo, ipV4Data, ipV6Data []driverapi.IPAMData) error { kv, err := kernel.GetKernelVersion() if err != nil { return fmt.Errorf("failed to check kernel version for ipvlan driver support: %v", err) @@ -240,7 +240,7 @@ func parseNetworkOptions(id string, option options.Generic) (*configuration, err } // parseNetworkGenericOptions parse generic driver docker network options -func parseNetworkGenericOptions(data interface{}) (*configuration, error) { +func parseNetworkGenericOptions(data any) (*configuration, error) { switch opt := data.(type) { case *configuration: return opt, nil diff --git a/daemon/libnetwork/drivers/ipvlan/ipvlan_store.go b/daemon/libnetwork/drivers/ipvlan/ipvlan_store.go index 602c1e4bfe..f107dfe8f9 100644 --- a/daemon/libnetwork/drivers/ipvlan/ipvlan_store.go +++ b/daemon/libnetwork/drivers/ipvlan/ipvlan_store.go @@ -126,7 +126,7 @@ func (d *driver) storeDelete(kvObject datastore.KVObject) error { } func (config *configuration) MarshalJSON() ([]byte, error) { - nMap := make(map[string]interface{}) + nMap := make(map[string]any) nMap["ID"] = config.ID nMap["Mtu"] = config.Mtu nMap["Parent"] = config.Parent @@ -155,7 +155,7 @@ func (config *configuration) MarshalJSON() ([]byte, error) { func (config *configuration) UnmarshalJSON(b []byte) error { var ( err error - nMap map[string]interface{} + nMap map[string]any ) if err = json.Unmarshal(b, &nMap); err != nil { @@ -235,7 +235,7 @@ func (config *configuration) CopyTo(o datastore.KVObject) error { } func (ep *endpoint) MarshalJSON() ([]byte, error) { - epMap := make(map[string]interface{}) + epMap := make(map[string]any) epMap["id"] = ep.id epMap["nid"] = ep.nid epMap["SrcName"] = ep.srcName @@ -254,7 +254,7 @@ func (ep *endpoint) MarshalJSON() ([]byte, error) { func (ep *endpoint) UnmarshalJSON(b []byte) error { var ( err error - epMap map[string]interface{} + epMap map[string]any ) if err = json.Unmarshal(b, &epMap); err != nil { diff --git a/daemon/libnetwork/drivers/ipvlan/ivmanager/ivmanager.go b/daemon/libnetwork/drivers/ipvlan/ivmanager/ivmanager.go index 2d484f9a81..2e5f293967 100644 --- a/daemon/libnetwork/drivers/ipvlan/ivmanager/ivmanager.go +++ b/daemon/libnetwork/drivers/ipvlan/ivmanager/ivmanager.go @@ -28,7 +28,7 @@ func (d *driver) NetworkFree(id string) error { return types.NotImplementedErrorf("not implemented") } -func (d *driver) CreateNetwork(ctx context.Context, id string, option map[string]interface{}, nInfo driverapi.NetworkInfo, ipV4Data, ipV6Data []driverapi.IPAMData) error { +func (d *driver) CreateNetwork(ctx context.Context, id string, option map[string]any, nInfo driverapi.NetworkInfo, ipV4Data, ipV6Data []driverapi.IPAMData) error { return types.NotImplementedErrorf("not implemented") } @@ -36,7 +36,7 @@ func (d *driver) DeleteNetwork(nid string) error { return types.NotImplementedErrorf("not implemented") } -func (d *driver) CreateEndpoint(_ context.Context, nid, eid string, ifInfo driverapi.InterfaceInfo, epOptions map[string]interface{}) error { +func (d *driver) CreateEndpoint(_ context.Context, nid, eid string, ifInfo driverapi.InterfaceInfo, epOptions map[string]any) error { return types.NotImplementedErrorf("not implemented") } @@ -44,11 +44,11 @@ func (d *driver) DeleteEndpoint(nid, eid string) error { return types.NotImplementedErrorf("not implemented") } -func (d *driver) EndpointOperInfo(nid, eid string) (map[string]interface{}, error) { +func (d *driver) EndpointOperInfo(nid, eid string) (map[string]any, error) { return nil, types.NotImplementedErrorf("not implemented") } -func (d *driver) Join(_ context.Context, nid, eid string, sboxKey string, jinfo driverapi.JoinInfo, _, _ map[string]interface{}) error { +func (d *driver) Join(_ context.Context, nid, eid string, sboxKey string, jinfo driverapi.JoinInfo, _, _ map[string]any) error { return types.NotImplementedErrorf("not implemented") } diff --git a/daemon/libnetwork/drivers/macvlan/macvlan.go b/daemon/libnetwork/drivers/macvlan/macvlan.go index 7500d8e539..907df4b08e 100644 --- a/daemon/libnetwork/drivers/macvlan/macvlan.go +++ b/daemon/libnetwork/drivers/macvlan/macvlan.go @@ -56,7 +56,7 @@ type network struct { } // Register initializes and registers the libnetwork macvlan driver -func Register(r driverapi.Registerer, store *datastore.Store, _ map[string]interface{}) error { +func Register(r driverapi.Registerer, store *datastore.Store, _ map[string]any) error { d := &driver{ store: store, networks: networkTable{}, @@ -78,8 +78,8 @@ func (d *driver) NetworkFree(id string) error { return types.NotImplementedErrorf("not implemented") } -func (d *driver) EndpointOperInfo(nid, eid string) (map[string]interface{}, error) { - return make(map[string]interface{}), nil +func (d *driver) EndpointOperInfo(nid, eid string) (map[string]any, error) { + return make(map[string]any), nil } func (d *driver) Type() string { diff --git a/daemon/libnetwork/drivers/macvlan/macvlan_endpoint.go b/daemon/libnetwork/drivers/macvlan/macvlan_endpoint.go index 1362c778b2..5cfab2e165 100644 --- a/daemon/libnetwork/drivers/macvlan/macvlan_endpoint.go +++ b/daemon/libnetwork/drivers/macvlan/macvlan_endpoint.go @@ -16,7 +16,7 @@ import ( ) // CreateEndpoint assigns the mac, ip and endpoint id for the new container -func (d *driver) CreateEndpoint(ctx context.Context, nid, eid string, ifInfo driverapi.InterfaceInfo, epOptions map[string]interface{}) error { +func (d *driver) CreateEndpoint(ctx context.Context, nid, eid string, ifInfo driverapi.InterfaceInfo, epOptions map[string]any) error { if err := validateID(nid, eid); err != nil { return err } diff --git a/daemon/libnetwork/drivers/macvlan/macvlan_joinleave.go b/daemon/libnetwork/drivers/macvlan/macvlan_joinleave.go index bdb827a625..504d4f3ebf 100644 --- a/daemon/libnetwork/drivers/macvlan/macvlan_joinleave.go +++ b/daemon/libnetwork/drivers/macvlan/macvlan_joinleave.go @@ -18,7 +18,7 @@ import ( ) // Join method is invoked when a Sandbox is attached to an endpoint. -func (d *driver) Join(ctx context.Context, nid, eid string, sboxKey string, jinfo driverapi.JoinInfo, epOpts, _ map[string]interface{}) error { +func (d *driver) Join(ctx context.Context, nid, eid string, sboxKey string, jinfo driverapi.JoinInfo, epOpts, _ map[string]any) error { ctx, span := otel.Tracer("").Start(ctx, "libnetwork.drivers.macvlan.Join", trace.WithAttributes( attribute.String("nid", nid), attribute.String("eid", eid), diff --git a/daemon/libnetwork/drivers/macvlan/macvlan_network.go b/daemon/libnetwork/drivers/macvlan/macvlan_network.go index 12bfc739e7..01cd12e882 100644 --- a/daemon/libnetwork/drivers/macvlan/macvlan_network.go +++ b/daemon/libnetwork/drivers/macvlan/macvlan_network.go @@ -17,7 +17,7 @@ import ( ) // CreateNetwork the network for the specified driver type -func (d *driver) CreateNetwork(ctx context.Context, nid string, option map[string]interface{}, nInfo driverapi.NetworkInfo, ipV4Data, ipV6Data []driverapi.IPAMData) error { +func (d *driver) CreateNetwork(ctx context.Context, nid string, option map[string]any, nInfo driverapi.NetworkInfo, ipV4Data, ipV6Data []driverapi.IPAMData) error { // reject a null v4 network if ipv4 is required if v, ok := option[netlabel.EnableIPv4]; ok && v.(bool) { if len(ipV4Data) == 0 || ipV4Data[0].Pool.String() == "0.0.0.0/0" { @@ -241,7 +241,7 @@ func parseNetworkOptions(id string, option options.Generic) (*configuration, err } // parseNetworkGenericOptions parses generic driver docker network options -func parseNetworkGenericOptions(data interface{}) (*configuration, error) { +func parseNetworkGenericOptions(data any) (*configuration, error) { switch opt := data.(type) { case *configuration: return opt, nil diff --git a/daemon/libnetwork/drivers/macvlan/macvlan_store.go b/daemon/libnetwork/drivers/macvlan/macvlan_store.go index 672ce5c520..b701810c08 100644 --- a/daemon/libnetwork/drivers/macvlan/macvlan_store.go +++ b/daemon/libnetwork/drivers/macvlan/macvlan_store.go @@ -125,7 +125,7 @@ func (d *driver) storeDelete(kvObject datastore.KVObject) error { } func (config *configuration) MarshalJSON() ([]byte, error) { - nMap := make(map[string]interface{}) + nMap := make(map[string]any) nMap["ID"] = config.ID nMap["Mtu"] = config.Mtu nMap["Parent"] = config.Parent @@ -153,7 +153,7 @@ func (config *configuration) MarshalJSON() ([]byte, error) { func (config *configuration) UnmarshalJSON(b []byte) error { var ( err error - nMap map[string]interface{} + nMap map[string]any ) if err = json.Unmarshal(b, &nMap); err != nil { @@ -229,7 +229,7 @@ func (config *configuration) CopyTo(o datastore.KVObject) error { } func (ep *endpoint) MarshalJSON() ([]byte, error) { - epMap := make(map[string]interface{}) + epMap := make(map[string]any) epMap["id"] = ep.id epMap["nid"] = ep.nid epMap["SrcName"] = ep.srcName @@ -248,7 +248,7 @@ func (ep *endpoint) MarshalJSON() ([]byte, error) { func (ep *endpoint) UnmarshalJSON(b []byte) error { var ( err error - epMap map[string]interface{} + epMap map[string]any ) if err = json.Unmarshal(b, &epMap); err != nil { diff --git a/daemon/libnetwork/drivers/macvlan/mvmanager/mvmanager.go b/daemon/libnetwork/drivers/macvlan/mvmanager/mvmanager.go index 5c9c408bcb..72fbdb4ab3 100644 --- a/daemon/libnetwork/drivers/macvlan/mvmanager/mvmanager.go +++ b/daemon/libnetwork/drivers/macvlan/mvmanager/mvmanager.go @@ -28,7 +28,7 @@ func (d *driver) NetworkFree(id string) error { return types.NotImplementedErrorf("not implemented") } -func (d *driver) CreateNetwork(ctx context.Context, id string, option map[string]interface{}, nInfo driverapi.NetworkInfo, ipV4Data, ipV6Data []driverapi.IPAMData) error { +func (d *driver) CreateNetwork(ctx context.Context, id string, option map[string]any, nInfo driverapi.NetworkInfo, ipV4Data, ipV6Data []driverapi.IPAMData) error { return types.NotImplementedErrorf("not implemented") } @@ -36,7 +36,7 @@ func (d *driver) DeleteNetwork(nid string) error { return types.NotImplementedErrorf("not implemented") } -func (d *driver) CreateEndpoint(_ context.Context, nid, eid string, ifInfo driverapi.InterfaceInfo, epOptions map[string]interface{}) error { +func (d *driver) CreateEndpoint(_ context.Context, nid, eid string, ifInfo driverapi.InterfaceInfo, epOptions map[string]any) error { return types.NotImplementedErrorf("not implemented") } @@ -44,11 +44,11 @@ func (d *driver) DeleteEndpoint(nid, eid string) error { return types.NotImplementedErrorf("not implemented") } -func (d *driver) EndpointOperInfo(nid, eid string) (map[string]interface{}, error) { +func (d *driver) EndpointOperInfo(nid, eid string) (map[string]any, error) { return nil, types.NotImplementedErrorf("not implemented") } -func (d *driver) Join(_ context.Context, nid, eid string, sboxKey string, jinfo driverapi.JoinInfo, _, _ map[string]interface{}) error { +func (d *driver) Join(_ context.Context, nid, eid string, sboxKey string, jinfo driverapi.JoinInfo, _, _ map[string]any) error { return types.NotImplementedErrorf("not implemented") } diff --git a/daemon/libnetwork/drivers/null/null.go b/daemon/libnetwork/drivers/null/null.go index f32923da15..948dcfeaae 100644 --- a/daemon/libnetwork/drivers/null/null.go +++ b/daemon/libnetwork/drivers/null/null.go @@ -31,7 +31,7 @@ func (d *driver) NetworkFree(id string) error { return types.NotImplementedErrorf("not implemented") } -func (d *driver) CreateNetwork(ctx context.Context, id string, option map[string]interface{}, nInfo driverapi.NetworkInfo, ipV4Data, ipV6Data []driverapi.IPAMData) error { +func (d *driver) CreateNetwork(ctx context.Context, id string, option map[string]any, nInfo driverapi.NetworkInfo, ipV4Data, ipV6Data []driverapi.IPAMData) error { d.Lock() defer d.Unlock() @@ -48,7 +48,7 @@ func (d *driver) DeleteNetwork(nid string) error { return types.ForbiddenErrorf("network of type %q cannot be deleted", NetworkType) } -func (d *driver) CreateEndpoint(_ context.Context, nid, eid string, ifInfo driverapi.InterfaceInfo, epOptions map[string]interface{}) error { +func (d *driver) CreateEndpoint(_ context.Context, nid, eid string, ifInfo driverapi.InterfaceInfo, epOptions map[string]any) error { return nil } @@ -56,12 +56,12 @@ func (d *driver) DeleteEndpoint(nid, eid string) error { return nil } -func (d *driver) EndpointOperInfo(nid, eid string) (map[string]interface{}, error) { - return make(map[string]interface{}), nil +func (d *driver) EndpointOperInfo(nid, eid string) (map[string]any, error) { + return make(map[string]any), nil } // Join method is invoked when a Sandbox is attached to an endpoint. -func (d *driver) Join(_ context.Context, nid, eid string, sboxKey string, jinfo driverapi.JoinInfo, _, _ map[string]interface{}) error { +func (d *driver) Join(_ context.Context, nid, eid string, sboxKey string, jinfo driverapi.JoinInfo, _, _ map[string]any) error { return nil } diff --git a/daemon/libnetwork/drivers/overlay/joinleave.go b/daemon/libnetwork/drivers/overlay/joinleave.go index fd8b6b9f43..dcbe99e706 100644 --- a/daemon/libnetwork/drivers/overlay/joinleave.go +++ b/daemon/libnetwork/drivers/overlay/joinleave.go @@ -23,7 +23,7 @@ import ( ) // Join method is invoked when a Sandbox is attached to an endpoint. -func (d *driver) Join(ctx context.Context, nid, eid string, sboxKey string, jinfo driverapi.JoinInfo, epOpts, _ map[string]interface{}) error { +func (d *driver) Join(ctx context.Context, nid, eid string, sboxKey string, jinfo driverapi.JoinInfo, epOpts, _ map[string]any) error { ctx, span := otel.Tracer("").Start(ctx, "libnetwork.drivers.overlay.Join", trace.WithAttributes( attribute.String("nid", nid), attribute.String("eid", eid), diff --git a/daemon/libnetwork/drivers/overlay/ov_endpoint.go b/daemon/libnetwork/drivers/overlay/ov_endpoint.go index 690f2ae86f..031846a4d7 100644 --- a/daemon/libnetwork/drivers/overlay/ov_endpoint.go +++ b/daemon/libnetwork/drivers/overlay/ov_endpoint.go @@ -26,7 +26,7 @@ type endpoint struct { addr netip.Prefix } -func (d *driver) CreateEndpoint(_ context.Context, nid, eid string, ifInfo driverapi.InterfaceInfo, epOptions map[string]interface{}) error { +func (d *driver) CreateEndpoint(_ context.Context, nid, eid string, ifInfo driverapi.InterfaceInfo, epOptions map[string]any) error { var err error if err = validateID(nid, eid); err != nil { return err @@ -117,6 +117,6 @@ func (d *driver) DeleteEndpoint(nid, eid string) error { return nil } -func (d *driver) EndpointOperInfo(nid, eid string) (map[string]interface{}, error) { - return make(map[string]interface{}), nil +func (d *driver) EndpointOperInfo(nid, eid string) (map[string]any, error) { + return make(map[string]any), nil } diff --git a/daemon/libnetwork/drivers/overlay/ov_network.go b/daemon/libnetwork/drivers/overlay/ov_network.go index 0a63b2ca02..73f53a6b6f 100644 --- a/daemon/libnetwork/drivers/overlay/ov_network.go +++ b/daemon/libnetwork/drivers/overlay/ov_network.go @@ -91,7 +91,7 @@ func (d *driver) NetworkFree(id string) error { return types.NotImplementedErrorf("not implemented") } -func (d *driver) CreateNetwork(ctx context.Context, id string, option map[string]interface{}, nInfo driverapi.NetworkInfo, ipV4Data, ipV6Data []driverapi.IPAMData) error { +func (d *driver) CreateNetwork(ctx context.Context, id string, option map[string]any, nInfo driverapi.NetworkInfo, ipV4Data, ipV6Data []driverapi.IPAMData) error { if id == "" { return errors.New("invalid network id") } diff --git a/daemon/libnetwork/drivers/overlay/overlay.go b/daemon/libnetwork/drivers/overlay/overlay.go index 2780500bac..bbb3be9b46 100644 --- a/daemon/libnetwork/drivers/overlay/overlay.go +++ b/daemon/libnetwork/drivers/overlay/overlay.go @@ -33,7 +33,7 @@ var ( type driver struct { // Immutable; mu does not need to be held when accessing these fields. - config map[string]interface{} + config map[string]any initOS sync.Once // encrMu guards secMap and keys, @@ -58,7 +58,7 @@ type driver struct { } // Register registers a new instance of the overlay driver. -func Register(r driverapi.Registerer, config map[string]interface{}) error { +func Register(r driverapi.Registerer, config map[string]any) error { d := &driver{ networks: networkTable{}, secMap: encrMap{}, @@ -113,7 +113,7 @@ func (d *driver) nodeJoin(data discoverapi.NodeDiscoveryData) error { } // DiscoverNew is a notification for a new discovery event, such as a new node joining a cluster -func (d *driver) DiscoverNew(dType discoverapi.DiscoveryType, data interface{}) error { +func (d *driver) DiscoverNew(dType discoverapi.DiscoveryType, data any) error { switch dType { case discoverapi.NodeDiscovery: nodeData, ok := data.(discoverapi.NodeDiscoveryData) @@ -170,6 +170,6 @@ func (d *driver) DiscoverNew(dType discoverapi.DiscoveryType, data interface{}) } // DiscoverDelete is a notification for a discovery delete event, such as a node leaving a cluster -func (d *driver) DiscoverDelete(dType discoverapi.DiscoveryType, data interface{}) error { +func (d *driver) DiscoverDelete(dType discoverapi.DiscoveryType, data any) error { return nil } diff --git a/daemon/libnetwork/drivers/overlay/ovmanager/ovmanager.go b/daemon/libnetwork/drivers/overlay/ovmanager/ovmanager.go index e705735c64..62abcd7e56 100644 --- a/daemon/libnetwork/drivers/overlay/ovmanager/ovmanager.go +++ b/daemon/libnetwork/drivers/overlay/ovmanager/ovmanager.go @@ -163,7 +163,7 @@ func (n *network) releaseVxlanID() { } } -func (d *driver) CreateNetwork(ctx context.Context, id string, option map[string]interface{}, nInfo driverapi.NetworkInfo, ipV4Data, ipV6Data []driverapi.IPAMData) error { +func (d *driver) CreateNetwork(ctx context.Context, id string, option map[string]any, nInfo driverapi.NetworkInfo, ipV4Data, ipV6Data []driverapi.IPAMData) error { return types.NotImplementedErrorf("not implemented") } @@ -171,7 +171,7 @@ func (d *driver) DeleteNetwork(nid string) error { return types.NotImplementedErrorf("not implemented") } -func (d *driver) CreateEndpoint(_ context.Context, nid, eid string, ifInfo driverapi.InterfaceInfo, epOptions map[string]interface{}) error { +func (d *driver) CreateEndpoint(_ context.Context, nid, eid string, ifInfo driverapi.InterfaceInfo, epOptions map[string]any) error { return types.NotImplementedErrorf("not implemented") } @@ -179,12 +179,12 @@ func (d *driver) DeleteEndpoint(nid, eid string) error { return types.NotImplementedErrorf("not implemented") } -func (d *driver) EndpointOperInfo(nid, eid string) (map[string]interface{}, error) { +func (d *driver) EndpointOperInfo(nid, eid string) (map[string]any, error) { return nil, types.NotImplementedErrorf("not implemented") } // Join method is invoked when a Sandbox is attached to an endpoint. -func (d *driver) Join(_ context.Context, nid, eid string, sboxKey string, jinfo driverapi.JoinInfo, _, _ map[string]interface{}) error { +func (d *driver) Join(_ context.Context, nid, eid string, sboxKey string, jinfo driverapi.JoinInfo, _, _ map[string]any) error { return types.NotImplementedErrorf("not implemented") } diff --git a/daemon/libnetwork/drivers/remote/api/api.go b/daemon/libnetwork/drivers/remote/api/api.go index f3422f4edc..8e4d1af1c1 100644 --- a/daemon/libnetwork/drivers/remote/api/api.go +++ b/daemon/libnetwork/drivers/remote/api/api.go @@ -70,7 +70,7 @@ type FreeNetworkResponse struct { // [CreateNetworkRequest]. type GwAllocCheckerRequest struct { // Options has the same form as Options in [CreateNetworkRequest]. - Options map[string]interface{} + Options map[string]any } // GwAllocCheckerResponse is the response to a [GwAllocCheckerRequest]. @@ -93,7 +93,7 @@ type CreateNetworkRequest struct { NetworkID string // A free form map->object interface for communication of options. - Options map[string]interface{} + Options map[string]any // IPAMData contains the address pool information for this network IPv4Data, IPv6Data []driverapi.IPAMData @@ -122,7 +122,7 @@ type CreateEndpointRequest struct { // The ID of the endpoint for later reference. EndpointID string Interface *EndpointInterface - Options map[string]interface{} + Options map[string]any } // EndpointInterface represents an interface endpoint. @@ -165,7 +165,7 @@ type EndpointInfoRequest struct { // EndpointInfoResponse is the response to an EndpointInfoRequest. type EndpointInfoResponse struct { Response - Value map[string]interface{} + Value map[string]any } // JoinRequest describes the API for joining an endpoint to a sandbox. @@ -173,7 +173,7 @@ type JoinRequest struct { NetworkID string EndpointID string SandboxKey string - Options map[string]interface{} + Options map[string]any } // InterfaceName is the struct representation of a pair of devices with source @@ -216,7 +216,7 @@ type LeaveResponse struct { type ProgramExternalConnectivityRequest struct { NetworkID string EndpointID string - Options map[string]interface{} + Options map[string]any } // ProgramExternalConnectivityResponse is the answer to ProgramExternalConnectivityRequest. @@ -238,7 +238,7 @@ type RevokeExternalConnectivityResponse struct { // DiscoveryNotification represents a discovery notification type DiscoveryNotification struct { DiscoveryType discoverapi.DiscoveryType - DiscoveryData interface{} + DiscoveryData any } // DiscoveryResponse is used by libnetwork to log any plugin error processing the discovery notifications diff --git a/daemon/libnetwork/drivers/remote/driver.go b/daemon/libnetwork/drivers/remote/driver.go index e2543732a7..ea358cdeff 100644 --- a/daemon/libnetwork/drivers/remote/driver.go +++ b/daemon/libnetwork/drivers/remote/driver.go @@ -138,11 +138,11 @@ func (d *driver) getCapabilities() (*driverapi.Capability, error) { // Config is not implemented for remote drivers, since it is assumed // to be supplied to the remote process out-of-band (e.g., as command // line arguments). -func (d *driver) Config(option map[string]interface{}) error { +func (d *driver) Config(option map[string]any) error { return &driverapi.ErrNotImplemented{} } -func (d *driver) call(methodName string, arg interface{}, retVal maybeError) error { +func (d *driver) call(methodName string, arg any, retVal maybeError) error { method := driverapi.NetworkPluginEndpointType + "." + methodName err := d.endpoint.Call(method, arg, retVal) if err != nil { @@ -171,7 +171,7 @@ func (d *driver) NetworkFree(id string) error { return d.call("FreeNetwork", fr, &api.FreeNetworkResponse{}) } -func (d *driver) CreateNetwork(ctx context.Context, id string, options map[string]interface{}, nInfo driverapi.NetworkInfo, ipV4Data, ipV6Data []driverapi.IPAMData) error { +func (d *driver) CreateNetwork(ctx context.Context, id string, options map[string]any, nInfo driverapi.NetworkInfo, ipV4Data, ipV6Data []driverapi.IPAMData) error { create := &api.CreateNetworkRequest{ NetworkID: id, Options: options, @@ -196,7 +196,7 @@ func (d *driver) DeleteNetwork(nid string) error { return d.call("DeleteNetwork", &api.DeleteNetworkRequest{NetworkID: nid}, &api.DeleteNetworkResponse{}) } -func (d *driver) CreateEndpoint(_ context.Context, nid, eid string, ifInfo driverapi.InterfaceInfo, epOptions map[string]interface{}) (retErr error) { +func (d *driver) CreateEndpoint(_ context.Context, nid, eid string, ifInfo driverapi.InterfaceInfo, epOptions map[string]any) (retErr error) { if ifInfo == nil { return errors.New("must not be called with nil InterfaceInfo") } @@ -269,7 +269,7 @@ func (d *driver) DeleteEndpoint(nid, eid string) error { return d.call("DeleteEndpoint", deleteRequest, &api.DeleteEndpointResponse{}) } -func (d *driver) EndpointOperInfo(nid, eid string) (map[string]interface{}, error) { +func (d *driver) EndpointOperInfo(nid, eid string) (map[string]any, error) { info := &api.EndpointInfoRequest{ NetworkID: nid, EndpointID: eid, @@ -282,7 +282,7 @@ func (d *driver) EndpointOperInfo(nid, eid string) (map[string]interface{}, erro } // Join method is invoked when a Sandbox is attached to an endpoint. -func (d *driver) Join(_ context.Context, nid, eid string, sboxKey string, jinfo driverapi.JoinInfo, _, options map[string]interface{}) (retErr error) { +func (d *driver) Join(_ context.Context, nid, eid string, sboxKey string, jinfo driverapi.JoinInfo, _, options map[string]any) (retErr error) { join := &api.JoinRequest{ NetworkID: nid, EndpointID: eid, @@ -437,7 +437,7 @@ func (d *driver) IsBuiltIn() bool { } // DiscoverNew is a notification for a new discovery event, such as a new node joining a cluster -func (d *driver) DiscoverNew(dType discoverapi.DiscoveryType, data interface{}) error { +func (d *driver) DiscoverNew(dType discoverapi.DiscoveryType, data any) error { if dType != discoverapi.NodeDiscovery { return nil } @@ -449,7 +449,7 @@ func (d *driver) DiscoverNew(dType discoverapi.DiscoveryType, data interface{}) } // DiscoverDelete is a notification for a discovery delete event, such as a node leaving a cluster -func (d *driver) DiscoverDelete(dType discoverapi.DiscoveryType, data interface{}) error { +func (d *driver) DiscoverDelete(dType discoverapi.DiscoveryType, data any) error { if dType != discoverapi.NodeDiscovery { return nil } diff --git a/daemon/libnetwork/drivers/remote/driver_test.go b/daemon/libnetwork/drivers/remote/driver_test.go index c7e4abe5c9..f04970bc85 100644 --- a/daemon/libnetwork/drivers/remote/driver_test.go +++ b/daemon/libnetwork/drivers/remote/driver_test.go @@ -24,9 +24,9 @@ import ( "gotest.tools/v3/assert" ) -func handle(t *testing.T, mux *http.ServeMux, method string, h func(map[string]interface{}) interface{}) { +func handle(t *testing.T, mux *http.ServeMux, method string, h func(map[string]any) any) { mux.HandleFunc(fmt.Sprintf("/%s.%s", driverapi.NetworkPluginEndpointType, method), func(w http.ResponseWriter, r *http.Request) { - var ask map[string]interface{} + var ask map[string]any err := json.NewDecoder(r.Body).Decode(&ask) if err != nil && !errors.Is(err, io.EOF) { t.Fatal(err) @@ -218,8 +218,8 @@ func TestGetEmptyCapabilities(t *testing.T) { mux := http.NewServeMux() defer setupPlugin(t, plugin, mux)() - handle(t, mux, "GetCapabilities", func(msg map[string]interface{}) interface{} { - return map[string]interface{}{} + handle(t, mux, "GetCapabilities", func(msg map[string]any) any { + return map[string]any{} }) p, err := plugins.Get(plugin, driverapi.NetworkPluginEndpointType) @@ -248,8 +248,8 @@ func TestGetExtraCapabilities(t *testing.T) { mux := http.NewServeMux() defer setupPlugin(t, plugin, mux)() - handle(t, mux, "GetCapabilities", func(msg map[string]interface{}) interface{} { - return map[string]interface{}{ + handle(t, mux, "GetCapabilities", func(msg map[string]any) any { + return map[string]any{ "Scope": "local", "foo": "bar", "ConnectivityScope": "global", @@ -286,8 +286,8 @@ func TestGetInvalidCapabilities(t *testing.T) { mux := http.NewServeMux() defer setupPlugin(t, plugin, mux)() - handle(t, mux, "GetCapabilities", func(msg map[string]interface{}) interface{} { - return map[string]interface{}{ + handle(t, mux, "GetCapabilities", func(msg map[string]any) any { + return map[string]any{ "Scope": "fake", } }) @@ -336,60 +336,60 @@ func TestRemoteDriver(t *testing.T) { var networkID string - handle(t, mux, "GetCapabilities", func(msg map[string]interface{}) interface{} { - return map[string]interface{}{ + handle(t, mux, "GetCapabilities", func(msg map[string]any) any { + return map[string]any{ "Scope": "global", "GwAllocChecker": true, } }) - handle(t, mux, "GwAllocCheck", func(msg map[string]interface{}) interface{} { - options := msg["Options"].(map[string]interface{}) - return map[string]interface{}{ + handle(t, mux, "GwAllocCheck", func(msg map[string]any) any { + options := msg["Options"].(map[string]any) + return map[string]any{ "SkipIPv4": options["skip4"].(bool), "SkipIPv6": options["skip6"].(bool), } }) - handle(t, mux, "CreateNetwork", func(msg map[string]interface{}) interface{} { + handle(t, mux, "CreateNetwork", func(msg map[string]any) any { nid := msg["NetworkID"] var ok bool if networkID, ok = nid.(string); !ok { t.Fatal("RPC did not include network ID string") } - return map[string]interface{}{} + return map[string]any{} }) - handle(t, mux, "DeleteNetwork", func(msg map[string]interface{}) interface{} { + handle(t, mux, "DeleteNetwork", func(msg map[string]any) any { if nid, ok := msg["NetworkID"]; !ok || nid != networkID { t.Fatal("Network ID missing or does not match that created") } - return map[string]interface{}{} + return map[string]any{} }) - handle(t, mux, "CreateEndpoint", func(msg map[string]interface{}) interface{} { - iface := map[string]interface{}{ + handle(t, mux, "CreateEndpoint", func(msg map[string]any) any { + iface := map[string]any{ "MacAddress": ep.macAddress, "Address": ep.address, "AddressIPv6": ep.addressIPv6, } - return map[string]interface{}{ + return map[string]any{ "Interface": iface, } }) - handle(t, mux, "Join", func(msg map[string]interface{}) interface{} { - opts := msg["Options"].(map[string]interface{}) + handle(t, mux, "Join", func(msg map[string]any) any { + opts := msg["Options"].(map[string]any) foo, ok := opts["foo"].(string) if !ok || foo != "fooValue" { t.Fatalf("Did not receive expected foo string in request options: %+v", msg) } - return map[string]interface{}{ + return map[string]any{ "Gateway": ep.gateway, "GatewayIPv6": ep.gatewayIPv6, "HostsPath": ep.hostsPath, "ResolvConfPath": ep.resolvConfPath, - "InterfaceName": map[string]interface{}{ + "InterfaceName": map[string]any{ "SrcName": ep.srcName, "DstPrefix": ep.dstPrefix, "DstName": ep.dstName, }, - "StaticRoutes": []map[string]interface{}{ + "StaticRoutes": []map[string]any{ { "Destination": ep.destination, "RouteType": ep.routeType, @@ -398,25 +398,25 @@ func TestRemoteDriver(t *testing.T) { }, } }) - handle(t, mux, "Leave", func(msg map[string]interface{}) interface{} { + handle(t, mux, "Leave", func(msg map[string]any) any { return map[string]string{} }) - handle(t, mux, "DeleteEndpoint", func(msg map[string]interface{}) interface{} { - return map[string]interface{}{} + handle(t, mux, "DeleteEndpoint", func(msg map[string]any) any { + return map[string]any{} }) - handle(t, mux, "EndpointOperInfo", func(msg map[string]interface{}) interface{} { - return map[string]interface{}{ + handle(t, mux, "EndpointOperInfo", func(msg map[string]any) any { + return map[string]any{ "Value": map[string]string{ "Arbitrary": "key", "Value": "pairs?", }, } }) - handle(t, mux, "DiscoverNew", func(msg map[string]interface{}) interface{} { + handle(t, mux, "DiscoverNew", func(msg map[string]any) any { return map[string]string{} }) - handle(t, mux, "DiscoverDelete", func(msg map[string]interface{}) interface{} { - return map[string]interface{}{} + handle(t, mux, "DiscoverDelete", func(msg map[string]any) any { + return map[string]any{} }) p, err := plugins.Get(plugin, driverapi.NetworkPluginEndpointType) @@ -454,14 +454,14 @@ func TestRemoteDriver(t *testing.T) { } netID := "dummy-network" - err = d.CreateNetwork(context.Background(), netID, map[string]interface{}{}, nil, nil, nil) + err = d.CreateNetwork(context.Background(), netID, map[string]any{}, nil, nil, nil) if err != nil { t.Fatal(err) } endID := "dummy-endpoint" ifInfo := &testEndpoint{} - err = d.CreateEndpoint(context.Background(), netID, endID, ifInfo, map[string]interface{}{}) + err = d.CreateEndpoint(context.Background(), netID, endID, ifInfo, map[string]any{}) if err != nil { t.Fatal(err) } @@ -473,7 +473,7 @@ func TestRemoteDriver(t *testing.T) { ifInfo.MacAddress(), ifInfo.Address(), ifInfo.AddressIPv6()) } - joinOpts := map[string]interface{}{"foo": "fooValue"} + joinOpts := map[string]any{"foo": "fooValue"} err = d.Join(context.Background(), netID, endID, "sandbox-key", ep, nil, joinOpts) if err != nil { t.Fatal(err) @@ -508,8 +508,8 @@ func TestDriverError(t *testing.T) { mux := http.NewServeMux() defer setupPlugin(t, plugin, mux)() - handle(t, mux, "CreateEndpoint", func(msg map[string]interface{}) interface{} { - return map[string]interface{}{ + handle(t, mux, "CreateEndpoint", func(msg map[string]any) any { + return map[string]any{ "Err": "this should get raised as an error", } }) @@ -525,7 +525,7 @@ func TestDriverError(t *testing.T) { } d := newDriver(plugin, client) - if err := d.CreateEndpoint(context.Background(), "dummy", "dummy", &testEndpoint{t: t}, map[string]interface{}{}); err == nil { + if err := d.CreateEndpoint(context.Background(), "dummy", "dummy", &testEndpoint{t: t}, map[string]any{}); err == nil { t.Fatal("Expected error from driver") } } @@ -540,13 +540,13 @@ func TestMissingValues(t *testing.T) { t: t, } - handle(t, mux, "CreateEndpoint", func(msg map[string]interface{}) interface{} { - iface := map[string]interface{}{ + handle(t, mux, "CreateEndpoint", func(msg map[string]any) any { + iface := map[string]any{ "Address": ep.address, "AddressIPv6": ep.addressIPv6, "MacAddress": ep.macAddress, } - return map[string]interface{}{ + return map[string]any{ "Interface": iface, } }) @@ -562,7 +562,7 @@ func TestMissingValues(t *testing.T) { } d := newDriver(plugin, client) - if err := d.CreateEndpoint(context.Background(), "dummy", "dummy", ep, map[string]interface{}{}); err != nil { + if err := d.CreateEndpoint(context.Background(), "dummy", "dummy", ep, map[string]any{}); err != nil { t.Fatal(err) } } @@ -605,19 +605,19 @@ func TestRollback(t *testing.T) { rolledback := false - handle(t, mux, "CreateEndpoint", func(msg map[string]interface{}) interface{} { - iface := map[string]interface{}{ + handle(t, mux, "CreateEndpoint", func(msg map[string]any) any { + iface := map[string]any{ "Address": "192.168.4.5/16", "AddressIPv6": "", "MacAddress": "7a:12:34:56:78:90", } - return map[string]interface{}{ - "Interface": interface{}(iface), + return map[string]any{ + "Interface": any(iface), } }) - handle(t, mux, "DeleteEndpoint", func(msg map[string]interface{}) interface{} { + handle(t, mux, "DeleteEndpoint", func(msg map[string]any) any { rolledback = true - return map[string]interface{}{} + return map[string]any{} }) p, err := plugins.Get(plugin, driverapi.NetworkPluginEndpointType) @@ -632,7 +632,7 @@ func TestRollback(t *testing.T) { d := newDriver(plugin, client) ep := &rollbackEndpoint{} - if err := d.CreateEndpoint(context.Background(), "dummy", "dummy", ep.Interface(), map[string]interface{}{}); err == nil { + if err := d.CreateEndpoint(context.Background(), "dummy", "dummy", ep.Interface(), map[string]any{}); err == nil { t.Fatal("Expected error from driver") } if !rolledback { diff --git a/daemon/libnetwork/drivers/windows/overlay/joinleave_windows.go b/daemon/libnetwork/drivers/windows/overlay/joinleave_windows.go index 84fa39df01..358f4a72c1 100644 --- a/daemon/libnetwork/drivers/windows/overlay/joinleave_windows.go +++ b/daemon/libnetwork/drivers/windows/overlay/joinleave_windows.go @@ -14,7 +14,7 @@ import ( ) // Join method is invoked when a Sandbox is attached to an endpoint. -func (d *driver) Join(ctx context.Context, nid, eid string, sboxKey string, jinfo driverapi.JoinInfo, _, options map[string]interface{}) error { +func (d *driver) Join(ctx context.Context, nid, eid string, sboxKey string, jinfo driverapi.JoinInfo, _, options map[string]any) error { ctx, span := otel.Tracer("").Start(ctx, "libnetwork.drivers.windows_overlay.Join", trace.WithAttributes( attribute.String("nid", nid), attribute.String("eid", eid), diff --git a/daemon/libnetwork/drivers/windows/overlay/ov_endpoint_windows.go b/daemon/libnetwork/drivers/windows/overlay/ov_endpoint_windows.go index fdb39f0bee..089e0dca11 100644 --- a/daemon/libnetwork/drivers/windows/overlay/ov_endpoint_windows.go +++ b/daemon/libnetwork/drivers/windows/overlay/ov_endpoint_windows.go @@ -85,7 +85,7 @@ func (n *network) removeEndpointWithAddress(addr *net.IPNet) { } } -func (d *driver) CreateEndpoint(ctx context.Context, nid, eid string, ifInfo driverapi.InterfaceInfo, epOptions map[string]interface{}) error { +func (d *driver) CreateEndpoint(ctx context.Context, nid, eid string, ifInfo driverapi.InterfaceInfo, epOptions map[string]any) error { var err error if err = validateID(nid, eid); err != nil { return err @@ -239,7 +239,7 @@ func (d *driver) DeleteEndpoint(nid, eid string) error { return nil } -func (d *driver) EndpointOperInfo(nid, eid string) (map[string]interface{}, error) { +func (d *driver) EndpointOperInfo(nid, eid string) (map[string]any, error) { if err := validateID(nid, eid); err != nil { return nil, err } @@ -254,7 +254,7 @@ func (d *driver) EndpointOperInfo(nid, eid string) (map[string]interface{}, erro return nil, fmt.Errorf("endpoint id %q not found", eid) } - data := make(map[string]interface{}, 1) + data := make(map[string]any, 1) data["hnsid"] = ep.profileID data["AllowUnqualifiedDNSQuery"] = true diff --git a/daemon/libnetwork/drivers/windows/overlay/ov_network_windows.go b/daemon/libnetwork/drivers/windows/overlay/ov_network_windows.go index 4f15ed8981..8474db7130 100644 --- a/daemon/libnetwork/drivers/windows/overlay/ov_network_windows.go +++ b/daemon/libnetwork/drivers/windows/overlay/ov_network_windows.go @@ -62,7 +62,7 @@ func (d *driver) NetworkFree(id string) error { return types.NotImplementedErrorf("not implemented") } -func (d *driver) CreateNetwork(ctx context.Context, id string, option map[string]interface{}, nInfo driverapi.NetworkInfo, ipV4Data, ipV6Data []driverapi.IPAMData) error { +func (d *driver) CreateNetwork(ctx context.Context, id string, option map[string]any, nInfo driverapi.NetworkInfo, ipV4Data, ipV6Data []driverapi.IPAMData) error { var ( networkName string interfaceName string diff --git a/daemon/libnetwork/drivers/windows/windows.go b/daemon/libnetwork/drivers/windows/windows.go index 06ac17ff0b..0b42117f74 100644 --- a/daemon/libnetwork/drivers/windows/windows.go +++ b/daemon/libnetwork/drivers/windows/windows.go @@ -322,7 +322,7 @@ func (d *driver) createNetwork(config *networkConfiguration) *hnsNetwork { } // Create a new network -func (d *driver) CreateNetwork(ctx context.Context, id string, option map[string]interface{}, nInfo driverapi.NetworkInfo, ipV4Data, ipV6Data []driverapi.IPAMData) error { +func (d *driver) CreateNetwork(ctx context.Context, id string, option map[string]any, nInfo driverapi.NetworkInfo, ipV4Data, ipV6Data []driverapi.IPAMData) error { if _, err := d.getNetwork(id); err == nil { return types.ForbiddenErrorf("network %s exists", id) } @@ -585,7 +585,7 @@ func ParsePortBindingPolicies(policies []json.RawMessage) ([]types.PortBinding, return bindings, nil } -func parseEndpointOptions(epOptions map[string]interface{}) (*endpointOption, error) { +func parseEndpointOptions(epOptions map[string]any) (*endpointOption, error) { if epOptions == nil { return nil, nil } @@ -636,7 +636,7 @@ func parseEndpointOptions(epOptions map[string]interface{}) (*endpointOption, er } // ParseEndpointConnectivity parses options passed to CreateEndpoint, specifically port bindings, and store in a endpointConnectivity object. -func ParseEndpointConnectivity(epOptions map[string]interface{}) (*EndpointConnectivity, error) { +func ParseEndpointConnectivity(epOptions map[string]any) (*EndpointConnectivity, error) { if epOptions == nil { return nil, nil } @@ -661,7 +661,7 @@ func ParseEndpointConnectivity(epOptions map[string]interface{}) (*EndpointConne return ec, nil } -func (d *driver) CreateEndpoint(ctx context.Context, nid, eid string, ifInfo driverapi.InterfaceInfo, epOptions map[string]interface{}) error { +func (d *driver) CreateEndpoint(ctx context.Context, nid, eid string, ifInfo driverapi.InterfaceInfo, epOptions map[string]any) error { ctx, span := otel.Tracer("").Start(ctx, fmt.Sprintf("libnetwork.drivers.windows_%s.CreateEndpoint", d.name), trace.WithAttributes( attribute.String("nid", nid), attribute.String("eid", eid))) @@ -845,7 +845,7 @@ func (d *driver) DeleteEndpoint(nid, eid string) error { return nil } -func (d *driver) EndpointOperInfo(nid, eid string) (map[string]interface{}, error) { +func (d *driver) EndpointOperInfo(nid, eid string) (map[string]any, error) { network, err := d.getNetwork(nid) if err != nil { return nil, err @@ -856,7 +856,7 @@ func (d *driver) EndpointOperInfo(nid, eid string) (map[string]interface{}, erro return nil, err } - data := make(map[string]interface{}, 1) + data := make(map[string]any, 1) if network.driver.name == "nat" { data["AllowUnqualifiedDNSQuery"] = true } @@ -887,7 +887,7 @@ func (d *driver) EndpointOperInfo(nid, eid string) (map[string]interface{}, erro } // Join method is invoked when a Sandbox is attached to an endpoint. -func (d *driver) Join(ctx context.Context, nid, eid string, sboxKey string, jinfo driverapi.JoinInfo, _, options map[string]interface{}) error { +func (d *driver) Join(ctx context.Context, nid, eid string, sboxKey string, jinfo driverapi.JoinInfo, _, options map[string]any) error { ctx, span := otel.Tracer("").Start(ctx, fmt.Sprintf("libnetwork.drivers.windows_%s.Join", d.name), trace.WithAttributes( attribute.String("nid", nid), attribute.String("eid", eid), diff --git a/daemon/libnetwork/drivers/windows/windows_store.go b/daemon/libnetwork/drivers/windows/windows_store.go index 6b8cce97c4..fb5286b78f 100644 --- a/daemon/libnetwork/drivers/windows/windows_store.go +++ b/daemon/libnetwork/drivers/windows/windows_store.go @@ -109,7 +109,7 @@ func (d *driver) storeDelete(kvObject datastore.KVObject) error { } func (ncfg *networkConfiguration) MarshalJSON() ([]byte, error) { - nMap := make(map[string]interface{}) + nMap := make(map[string]any) nMap["ID"] = ncfg.ID nMap["Type"] = ncfg.Type @@ -128,7 +128,7 @@ func (ncfg *networkConfiguration) MarshalJSON() ([]byte, error) { func (ncfg *networkConfiguration) UnmarshalJSON(b []byte) error { var ( err error - nMap map[string]interface{} + nMap map[string]any ) if err = json.Unmarshal(b, &nMap); err != nil { @@ -196,7 +196,7 @@ func (ncfg *networkConfiguration) CopyTo(o datastore.KVObject) error { } func (ep *hnsEndpoint) MarshalJSON() ([]byte, error) { - epMap := make(map[string]interface{}) + epMap := make(map[string]any) epMap["id"] = ep.id epMap["nid"] = ep.nid epMap["Type"] = ep.Type @@ -218,7 +218,7 @@ func (ep *hnsEndpoint) MarshalJSON() ([]byte, error) { func (ep *hnsEndpoint) UnmarshalJSON(b []byte) error { var ( err error - epMap map[string]interface{} + epMap map[string]any ) if err = json.Unmarshal(b, &epMap); err != nil { diff --git a/daemon/libnetwork/drivers/windows/windows_test.go b/daemon/libnetwork/drivers/windows/windows_test.go index 08f2dc7704..b4816971a8 100644 --- a/daemon/libnetwork/drivers/windows/windows_test.go +++ b/daemon/libnetwork/drivers/windows/windows_test.go @@ -20,7 +20,7 @@ func testNetwork(networkType string, t *testing.T) { bnw, _ := types.ParseCIDR("172.16.0.0/24") br, _ := types.ParseCIDR("172.16.0.1/16") - netOption := make(map[string]interface{}) + netOption := make(map[string]any) networkOptions := map[string]string{ NetworkName: "TestNetwork", } @@ -44,7 +44,7 @@ func testNetwork(networkType string, t *testing.T) { } }() - epOptions := make(map[string]interface{}) + epOptions := make(map[string]any) te := &testEndpoint{} err = d.CreateEndpoint(context.TODO(), "dummy", "ep1", te.Interface(), epOptions) if err != nil { diff --git a/daemon/libnetwork/drivers_freebsd.go b/daemon/libnetwork/drivers_freebsd.go index 115ad8e777..1f81207f1a 100644 --- a/daemon/libnetwork/drivers_freebsd.go +++ b/daemon/libnetwork/drivers_freebsd.go @@ -5,6 +5,6 @@ import ( "github.com/moby/moby/v2/daemon/libnetwork/drivers/null" ) -func registerNetworkDrivers(r driverapi.Registerer, driverConfig func(string) map[string]interface{}) error { +func registerNetworkDrivers(r driverapi.Registerer, driverConfig func(string) map[string]any) error { return null.Register(r) } diff --git a/daemon/libnetwork/drivers_linux.go b/daemon/libnetwork/drivers_linux.go index 862813bd35..d5037b86a0 100644 --- a/daemon/libnetwork/drivers_linux.go +++ b/daemon/libnetwork/drivers_linux.go @@ -22,23 +22,23 @@ import ( "github.com/moby/moby/v2/daemon/libnetwork/types" ) -func registerNetworkDrivers(r driverapi.Registerer, store *datastore.Store, pms *drvregistry.PortMappers, driverConfig func(string) map[string]interface{}) error { +func registerNetworkDrivers(r driverapi.Registerer, store *datastore.Store, pms *drvregistry.PortMappers, driverConfig func(string) map[string]any) error { for _, nr := range []struct { ntype string - register func(driverapi.Registerer, *datastore.Store, map[string]interface{}) error + register func(driverapi.Registerer, *datastore.Store, map[string]any) error }{ - {ntype: bridge.NetworkType, register: func(r driverapi.Registerer, store *datastore.Store, cfg map[string]interface{}) error { + {ntype: bridge.NetworkType, register: func(r driverapi.Registerer, store *datastore.Store, cfg map[string]any) error { return bridge.Register(r, store, pms, cfg) }}, - {ntype: host.NetworkType, register: func(r driverapi.Registerer, _ *datastore.Store, _ map[string]interface{}) error { + {ntype: host.NetworkType, register: func(r driverapi.Registerer, _ *datastore.Store, _ map[string]any) error { return host.Register(r) }}, {ntype: ipvlan.NetworkType, register: ipvlan.Register}, {ntype: macvlan.NetworkType, register: macvlan.Register}, - {ntype: null.NetworkType, register: func(r driverapi.Registerer, _ *datastore.Store, _ map[string]interface{}) error { + {ntype: null.NetworkType, register: func(r driverapi.Registerer, _ *datastore.Store, _ map[string]any) error { return null.Register(r) }}, - {ntype: overlay.NetworkType, register: func(r driverapi.Registerer, _ *datastore.Store, config map[string]interface{}) error { + {ntype: overlay.NetworkType, register: func(r driverapi.Registerer, _ *datastore.Store, config map[string]any) error { return overlay.Register(r, config) }}, } { diff --git a/daemon/libnetwork/drivers_unsupported.go b/daemon/libnetwork/drivers_unsupported.go index c916bcbc1f..f50b5219fe 100644 --- a/daemon/libnetwork/drivers_unsupported.go +++ b/daemon/libnetwork/drivers_unsupported.go @@ -4,6 +4,6 @@ package libnetwork import "github.com/moby/moby/v2/daemon/libnetwork/driverapi" -func registerNetworkDrivers(r driverapi.Registerer, driverConfig func(string) map[string]interface{}) error { +func registerNetworkDrivers(r driverapi.Registerer, driverConfig func(string) map[string]any) error { return nil } diff --git a/daemon/libnetwork/drivers_windows.go b/daemon/libnetwork/drivers_windows.go index 3c8175e2b7..1f28f42c6e 100644 --- a/daemon/libnetwork/drivers_windows.go +++ b/daemon/libnetwork/drivers_windows.go @@ -13,7 +13,7 @@ import ( "github.com/moby/moby/v2/daemon/libnetwork/drvregistry" ) -func registerNetworkDrivers(r driverapi.Registerer, store *datastore.Store, _ *drvregistry.PortMappers, _ func(string) map[string]interface{}) error { +func registerNetworkDrivers(r driverapi.Registerer, store *datastore.Store, _ *drvregistry.PortMappers, _ func(string) map[string]any) error { for _, nr := range []struct { ntype string register func(driverapi.Registerer) error diff --git a/daemon/libnetwork/endpoint_info.go b/daemon/libnetwork/endpoint_info.go index 8897b19708..730b47e030 100644 --- a/daemon/libnetwork/endpoint_info.go +++ b/daemon/libnetwork/endpoint_info.go @@ -52,7 +52,7 @@ type EndpointInterface struct { } func (epi *EndpointInterface) MarshalJSON() ([]byte, error) { - epMap := make(map[string]interface{}) + epMap := make(map[string]any) if epi.mac != nil { epMap["mac"] = epi.mac.String() } @@ -86,7 +86,7 @@ func (epi *EndpointInterface) MarshalJSON() ([]byte, error) { func (epi *EndpointInterface) UnmarshalJSON(b []byte) error { var ( err error - epMap map[string]interface{} + epMap map[string]any ) if err = json.Unmarshal(b, &epMap); err != nil { return err @@ -107,7 +107,7 @@ func (epi *EndpointInterface) UnmarshalJSON(b []byte) error { } } if v, ok := epMap["llAddrs"]; ok { - list := v.([]interface{}) + list := v.([]any) epi.llAddrs = make([]*net.IPNet, 0, len(list)) for _, llS := range list { ll, err := types.ParseCIDR(llS.(string)) @@ -456,7 +456,7 @@ func (ep *Endpoint) DisableGatewayService() { } func (epj *endpointJoinInfo) MarshalJSON() ([]byte, error) { - epMap := make(map[string]interface{}) + epMap := make(map[string]any) if epj.gw != nil { epMap["gw"] = epj.gw.String() } @@ -471,7 +471,7 @@ func (epj *endpointJoinInfo) MarshalJSON() ([]byte, error) { func (epj *endpointJoinInfo) UnmarshalJSON(b []byte) error { var ( err error - epMap map[string]interface{} + epMap map[string]any ) if err = json.Unmarshal(b, &epMap); err != nil { return err diff --git a/daemon/libnetwork/endpoint_info_unix.go b/daemon/libnetwork/endpoint_info_unix.go index bcf485c0f5..20e6ff54e4 100644 --- a/daemon/libnetwork/endpoint_info_unix.go +++ b/daemon/libnetwork/endpoint_info_unix.go @@ -5,7 +5,7 @@ package libnetwork import "fmt" // DriverInfo returns a collection of driver operational data related to this endpoint retrieved from the driver. -func (ep *Endpoint) DriverInfo() (map[string]interface{}, error) { +func (ep *Endpoint) DriverInfo() (map[string]any, error) { ep, err := ep.retrieveFromStore() if err != nil { return nil, err diff --git a/daemon/libnetwork/endpoint_info_windows.go b/daemon/libnetwork/endpoint_info_windows.go index 595d2ca54f..777c02ca38 100644 --- a/daemon/libnetwork/endpoint_info_windows.go +++ b/daemon/libnetwork/endpoint_info_windows.go @@ -5,13 +5,13 @@ package libnetwork import "fmt" // DriverInfo returns a collection of driver operational data related to this endpoint retrieved from the driver. -func (ep *Endpoint) DriverInfo() (map[string]interface{}, error) { +func (ep *Endpoint) DriverInfo() (map[string]any, error) { ep, err := ep.retrieveFromStore() if err != nil { return nil, err } - var gwDriverInfo map[string]interface{} + var gwDriverInfo map[string]any if sb, ok := ep.getSandbox(); ok { if gwep := sb.getEndpointInGWNetwork(); gwep != nil && gwep.ID() != ep.ID() { diff --git a/daemon/libnetwork/internal/nftables/nftables_linux.go b/daemon/libnetwork/internal/nftables/nftables_linux.go index da6fc51559..a871e6c52a 100644 --- a/daemon/libnetwork/internal/nftables/nftables_linux.go +++ b/daemon/libnetwork/internal/nftables/nftables_linux.go @@ -472,7 +472,7 @@ func (t TableRef) Chain(ctx context.Context, name string) ChainRef { } // ChainUpdateFunc is a function that can add rules to a chain, or remove rules from it. -type ChainUpdateFunc func(context.Context, RuleGroup, string, ...interface{}) error +type ChainUpdateFunc func(context.Context, RuleGroup, string, ...any) error // ChainUpdateFunc returns a [ChainUpdateFunc] to add rules to the named chain if // enable is true, or to remove rules from the chain if enable is false. @@ -514,7 +514,7 @@ func (c ChainRef) SetPolicy(policy string) error { } // AppendRule appends a rule to a [RuleGroup] in a [ChainRef]. -func (c ChainRef) AppendRule(ctx context.Context, group RuleGroup, rule string, args ...interface{}) error { +func (c ChainRef) AppendRule(ctx context.Context, group RuleGroup, rule string, args ...any) error { if len(args) > 0 { rule = fmt.Sprintf(rule, args...) } @@ -534,7 +534,7 @@ func (c ChainRef) AppendRule(ctx context.Context, group RuleGroup, rule string, } // AppendRuleCf calls AppendRule and returns a cleanup function or an error. -func (c ChainRef) AppendRuleCf(ctx context.Context, group RuleGroup, rule string, args ...interface{}) (func(context.Context) error, error) { +func (c ChainRef) AppendRuleCf(ctx context.Context, group RuleGroup, rule string, args ...any) (func(context.Context) error, error) { if err := c.AppendRule(ctx, group, rule, args...); err != nil { return nil, err } @@ -544,7 +544,7 @@ func (c ChainRef) AppendRuleCf(ctx context.Context, group RuleGroup, rule string // DeleteRule deletes a rule from a [RuleGroup] in a [ChainRef]. It is an error // to delete from a group that does not exist, or to delete a rule that does not // exist. -func (c ChainRef) DeleteRule(ctx context.Context, group RuleGroup, rule string, args ...interface{}) error { +func (c ChainRef) DeleteRule(ctx context.Context, group RuleGroup, rule string, args ...any) error { if len(args) > 0 { rule = fmt.Sprintf(rule, args...) } diff --git a/daemon/libnetwork/ipams/remote/remote.go b/daemon/libnetwork/ipams/remote/remote.go index e75210e96b..6adad909f2 100644 --- a/daemon/libnetwork/ipams/remote/remote.go +++ b/daemon/libnetwork/ipams/remote/remote.go @@ -87,7 +87,7 @@ func getPluginClient(p plugingetter.CompatPlugin) (*plugins.Client, error) { return client, nil } -func (a *allocator) call(methodName string, arg interface{}, retVal PluginResponse) error { +func (a *allocator) call(methodName string, arg any, retVal PluginResponse) error { method := ipamapi.PluginEndpointType + "." + methodName err := a.endpoint.Call(method, arg, retVal) if err != nil { diff --git a/daemon/libnetwork/ipams/remote/remote_test.go b/daemon/libnetwork/ipams/remote/remote_test.go index 18fc720098..27825ac407 100644 --- a/daemon/libnetwork/ipams/remote/remote_test.go +++ b/daemon/libnetwork/ipams/remote/remote_test.go @@ -19,9 +19,9 @@ import ( is "gotest.tools/v3/assert/cmp" ) -func handle(t *testing.T, mux *http.ServeMux, method string, h func(map[string]interface{}) interface{}) { +func handle(t *testing.T, mux *http.ServeMux, method string, h func(map[string]any) any) { mux.HandleFunc(fmt.Sprintf("/%s.%s", ipamapi.PluginEndpointType, method), func(w http.ResponseWriter, r *http.Request) { - var ask map[string]interface{} + var ask map[string]any err := json.NewDecoder(r.Body).Decode(&ask) if err != nil && !errors.Is(err, io.EOF) { t.Fatal(err) @@ -78,8 +78,8 @@ func TestGetCapabilities(t *testing.T) { mux := http.NewServeMux() defer setupPlugin(t, plugin, mux)() - handle(t, mux, "GetCapabilities", func(msg map[string]interface{}) interface{} { - return map[string]interface{}{ + handle(t, mux, "GetCapabilities", func(msg map[string]any) any { + return map[string]any{ "RequiresMACAddress": true, } }) @@ -134,8 +134,8 @@ func TestGetDefaultAddressSpaces(t *testing.T) { mux := http.NewServeMux() defer setupPlugin(t, plugin, mux)() - handle(t, mux, "GetDefaultAddressSpaces", func(msg map[string]interface{}) interface{} { - return map[string]interface{}{ + handle(t, mux, "GetDefaultAddressSpaces", func(msg map[string]any) any { + return map[string]any{ "LocalDefaultAddressSpace": "white", "GlobalDefaultAddressSpace": "blue", } @@ -168,14 +168,14 @@ func TestRemoteDriver(t *testing.T) { mux := http.NewServeMux() defer setupPlugin(t, plugin, mux)() - handle(t, mux, "GetDefaultAddressSpaces", func(msg map[string]interface{}) interface{} { - return map[string]interface{}{ + handle(t, mux, "GetDefaultAddressSpaces", func(msg map[string]any) any { + return map[string]any{ "LocalDefaultAddressSpace": "white", "GlobalDefaultAddressSpace": "blue", } }) - handle(t, mux, "RequestPool", func(msg map[string]interface{}) interface{} { + handle(t, mux, "RequestPool", func(msg map[string]any) any { as := "white" if v, ok := msg["AddressSpace"]; ok && v.(string) != "" { as = v.(string) @@ -193,21 +193,21 @@ func TestRemoteDriver(t *testing.T) { if sp != "" { pid = fmt.Sprintf("%s/%s", pid, sp) } - return map[string]interface{}{ + return map[string]any{ "PoolID": pid, "Pool": pl, "Data": map[string]string{"DNS": "8.8.8.8"}, } }) - handle(t, mux, "ReleasePool", func(msg map[string]interface{}) interface{} { + handle(t, mux, "ReleasePool", func(msg map[string]any) any { if _, ok := msg["PoolID"]; !ok { t.Fatal("Missing PoolID in Release request") } - return map[string]interface{}{} + return map[string]any{} }) - handle(t, mux, "RequestAddress", func(msg map[string]interface{}) interface{} { + handle(t, mux, "RequestAddress", func(msg map[string]any) any { if _, ok := msg["PoolID"]; !ok { t.Fatal("Missing PoolID in address request") } @@ -220,19 +220,19 @@ func TestRemoteDriver(t *testing.T) { ip = "172.20.0.34" } ip = fmt.Sprintf("%s/16", ip) - return map[string]interface{}{ + return map[string]any{ "Address": ip, } }) - handle(t, mux, "ReleaseAddress", func(msg map[string]interface{}) interface{} { + handle(t, mux, "ReleaseAddress", func(msg map[string]any) any { if _, ok := msg["PoolID"]; !ok { t.Fatal("Missing PoolID in address request") } if _, ok := msg["Address"]; !ok { t.Fatal("Missing Address in release address request") } - return map[string]interface{}{} + return map[string]any{} }) p, err := plugins.Get(plugin, ipamapi.PluginEndpointType) diff --git a/daemon/libnetwork/iptables/firewalld.go b/daemon/libnetwork/iptables/firewalld.go index abf8e59024..8dee26acd8 100644 --- a/daemon/libnetwork/iptables/firewalld.go +++ b/daemon/libnetwork/iptables/firewalld.go @@ -132,7 +132,7 @@ func signalHandler() { } } -func dbusConnectionChanged(args []interface{}) { +func dbusConnectionChanged(args []any) { name := args[0].(string) oldOwner := args[1].(string) newOwner := args[2].(string) @@ -206,15 +206,15 @@ type firewalldZone struct { unused bool target string services []string - ports [][]interface{} + ports [][]any icmpBlocks []string masquerade bool - forwardPorts [][]interface{} + forwardPorts [][]any interfaces []string sourceAddresses []string richRules []string protocols []string - sourcePorts [][]interface{} + sourcePorts [][]any icmpBlockInversion bool } @@ -223,8 +223,8 @@ type firewalldZone struct { // which is deprecated, requires this whole struct. Its replacement, 'addZone2' // (introduced in firewalld 0.9.0) accepts a dictionary where only non-default // values need to be specified. -func (z firewalldZone) settings() []interface{} { - return []interface{}{ +func (z firewalldZone) settings() []any { + return []any{ z.version, z.name, z.description, @@ -276,7 +276,7 @@ func setupDockerZone() (bool, error) { // The bool return value is true if a firewalld reload is required. func setupDockerForwardingPolicy() (bool, error) { // https://firewalld.org/documentation/man-pages/firewalld.dbus.html#FirewallD1.config - policy := map[string]interface{}{ + policy := map[string]any{ "version": "1.0", "description": "allow forwarding to the docker zone", "ingress_zones": []string{"ANY"}, diff --git a/daemon/libnetwork/libnetwork_internal_test.go b/daemon/libnetwork/libnetwork_internal_test.go index 1f1a50812f..02451f23fa 100644 --- a/daemon/libnetwork/libnetwork_internal_test.go +++ b/daemon/libnetwork/libnetwork_internal_test.go @@ -785,7 +785,7 @@ func badDriverRegister(reg driverapi.Registerer) error { return reg.RegisterDriver(badDriverName, &bd, driverapi.Capability{DataScope: scope.Local}) } -func (b *badDriver) CreateNetwork(ctx context.Context, nid string, options map[string]interface{}, nInfo driverapi.NetworkInfo, ipV4Data, ipV6Data []driverapi.IPAMData) error { +func (b *badDriver) CreateNetwork(ctx context.Context, nid string, options map[string]any, nInfo driverapi.NetworkInfo, ipV4Data, ipV6Data []driverapi.IPAMData) error { if b.failNetworkCreation { return errors.New("I will not create any network") } @@ -796,7 +796,7 @@ func (b *badDriver) DeleteNetwork(nid string) error { return nil } -func (b *badDriver) CreateEndpoint(_ context.Context, nid, eid string, ifInfo driverapi.InterfaceInfo, options map[string]interface{}) error { +func (b *badDriver) CreateEndpoint(_ context.Context, nid, eid string, ifInfo driverapi.InterfaceInfo, options map[string]any) error { return errors.New("I will not create any endpoint") } @@ -804,11 +804,11 @@ func (b *badDriver) DeleteEndpoint(nid, eid string) error { return nil } -func (b *badDriver) EndpointOperInfo(nid, eid string) (map[string]interface{}, error) { +func (b *badDriver) EndpointOperInfo(nid, eid string) (map[string]any, error) { return nil, nil } -func (b *badDriver) Join(_ context.Context, nid, eid string, sboxKey string, jinfo driverapi.JoinInfo, _, _ map[string]interface{}) error { +func (b *badDriver) Join(_ context.Context, nid, eid string, sboxKey string, jinfo driverapi.JoinInfo, _, _ map[string]any) error { return errors.New("I will not allow any join") } diff --git a/daemon/libnetwork/libnetwork_linux_test.go b/daemon/libnetwork/libnetwork_linux_test.go index 95f2f0e460..d09fb5acf6 100644 --- a/daemon/libnetwork/libnetwork_linux_test.go +++ b/daemon/libnetwork/libnetwork_linux_test.go @@ -48,7 +48,7 @@ func newController(t *testing.T) *libnetwork.Controller { c, err := libnetwork.New( context.Background(), config.OptionDataDir(t.TempDir()), - config.OptionDriverConfig(bridgeNetType, map[string]interface{}{ + config.OptionDriverConfig(bridgeNetType, map[string]any{ netlabel.GenericData: options.Generic{ "EnableIPForwarding": true, }, @@ -66,8 +66,8 @@ func createTestNetwork(c *libnetwork.Controller, networkType, networkName string libnetwork.NetworkOptionIpam(defaultipam.DriverName, "", ipamV4Configs, ipamV6Configs, nil)) } -func getEmptyGenericOption() map[string]interface{} { - return map[string]interface{}{netlabel.GenericData: map[string]string{}} +func getEmptyGenericOption() map[string]any { + return map[string]any{netlabel.GenericData: map[string]string{}} } func getPortMapping() []types.PortBinding { diff --git a/daemon/libnetwork/netlabel/labels.go b/daemon/libnetwork/netlabel/labels.go index d8ce1e4038..49806281f6 100644 --- a/daemon/libnetwork/netlabel/labels.go +++ b/daemon/libnetwork/netlabel/labels.go @@ -77,7 +77,7 @@ const ( // GetIfname returns the value associated to the Ifname netlabel from the // provided options. If there's no Ifname netlabel, or if the value isn't a // string, it returns an empty string. -func GetIfname(opts map[string]interface{}) string { +func GetIfname(opts map[string]any) string { ifname, _ := opts[Ifname].(string) return ifname } diff --git a/daemon/libnetwork/netlabel/labels_test.go b/daemon/libnetwork/netlabel/labels_test.go index 8dd1464088..d527ae0e32 100644 --- a/daemon/libnetwork/netlabel/labels_test.go +++ b/daemon/libnetwork/netlabel/labels_test.go @@ -9,7 +9,7 @@ import ( func TestGetIfname(t *testing.T) { testcases := []struct { name string - opts map[string]interface{} + opts map[string]any expIfname string }{ { @@ -19,33 +19,33 @@ func TestGetIfname(t *testing.T) { }, { name: "no ifname", - opts: map[string]interface{}{}, + opts: map[string]any{}, expIfname: "", }, { name: "ifname set", - opts: map[string]interface{}{ + opts: map[string]any{ Ifname: "foobar", }, expIfname: "foobar", }, { name: "ifname set to empty string", - opts: map[string]interface{}{ + opts: map[string]any{ Ifname: "", }, expIfname: "", }, { name: "ifname set to nil", - opts: map[string]interface{}{ + opts: map[string]any{ Ifname: nil, }, expIfname: "", }, { name: "ifname set to int", - opts: map[string]interface{}{ + opts: map[string]any{ Ifname: 42, }, expIfname: "", diff --git a/daemon/libnetwork/networkdb/message.go b/daemon/libnetwork/networkdb/message.go index 81a6d832a6..2efee651b0 100644 --- a/daemon/libnetwork/networkdb/message.go +++ b/daemon/libnetwork/networkdb/message.go @@ -26,7 +26,7 @@ func encodeRawMessage(t MessageType, raw []byte) ([]byte, error) { return buf, nil } -func encodeMessage(t MessageType, msg interface{}) ([]byte, error) { +func encodeMessage(t MessageType, msg any) ([]byte, error) { buf, err := proto.Marshal(msg.(proto.Message)) if err != nil { return nil, err diff --git a/daemon/libnetwork/sandbox_options.go b/daemon/libnetwork/sandbox_options.go index ea6e972872..cf25b38347 100644 --- a/daemon/libnetwork/sandbox_options.go +++ b/daemon/libnetwork/sandbox_options.go @@ -109,7 +109,7 @@ func OptionUseExternalKey() SandboxOption { func OptionExposedPorts(exposedPorts []types.TransportPort) SandboxOption { return func(sb *Sandbox) { if sb.config.generic == nil { - sb.config.generic = make(map[string]interface{}) + sb.config.generic = make(map[string]any) } // Defensive copy eps := make([]types.TransportPort, len(exposedPorts)) @@ -125,7 +125,7 @@ func OptionExposedPorts(exposedPorts []types.TransportPort) SandboxOption { func OptionPortMapping(portBindings []types.PortBinding) SandboxOption { return func(sb *Sandbox) { if sb.config.generic == nil { - sb.config.generic = make(map[string]interface{}) + sb.config.generic = make(map[string]any) } // Store a copy of the bindings as generic data to pass to the driver pbs := make([]types.PortBinding, len(portBindings)) diff --git a/daemon/libnetwork/sandbox_store.go b/daemon/libnetwork/sandbox_store.go index ba7facf2b3..95f9581368 100644 --- a/daemon/libnetwork/sandbox_store.go +++ b/daemon/libnetwork/sandbox_store.go @@ -169,7 +169,7 @@ func (sb *Sandbox) storeDelete() error { } // sandboxRestore restores Sandbox objects from the store, deleting them if they're not active. -func (c *Controller) sandboxRestore(activeSandboxes map[string]interface{}) error { +func (c *Controller) sandboxRestore(activeSandboxes map[string]any) error { sandboxStates, err := c.store.List(&sbState{c: c}) if err != nil { if errors.Is(err, datastore.ErrKeyNotFound) { diff --git a/daemon/libnetwork/store_test.go b/daemon/libnetwork/store_test.go index 1a84e04fce..75bce4b682 100644 --- a/daemon/libnetwork/store_test.go +++ b/daemon/libnetwork/store_test.go @@ -13,7 +13,7 @@ func testLocalBackend(t *testing.T, path, bucket string) { cfgOptions := []config.Option{ config.OptionDataDir(path), func(c *config.Config) { c.DatastoreBucket = bucket }, - config.OptionDriverConfig("host", map[string]interface{}{ + config.OptionDriverConfig("host", map[string]any{ netlabel.GenericData: options.Generic{}, }), } diff --git a/daemon/libnetwork/types/types.go b/daemon/libnetwork/types/types.go index 1dec068d4c..4e52fc5e45 100644 --- a/daemon/libnetwork/types/types.go +++ b/daemon/libnetwork/types/types.go @@ -415,37 +415,37 @@ type InternalError interface { ******************************/ // InvalidParameterErrorf creates an instance of InvalidParameterError -func InvalidParameterErrorf(format string, params ...interface{}) error { +func InvalidParameterErrorf(format string, params ...any) error { return errdefs.InvalidParameter(fmt.Errorf(format, params...)) } // NotFoundErrorf creates an instance of NotFoundError -func NotFoundErrorf(format string, params ...interface{}) error { +func NotFoundErrorf(format string, params ...any) error { return errdefs.NotFound(fmt.Errorf(format, params...)) } // ForbiddenErrorf creates an instance of ForbiddenError -func ForbiddenErrorf(format string, params ...interface{}) error { +func ForbiddenErrorf(format string, params ...any) error { return errdefs.Forbidden(fmt.Errorf(format, params...)) } // UnavailableErrorf creates an instance of UnavailableError -func UnavailableErrorf(format string, params ...interface{}) error { +func UnavailableErrorf(format string, params ...any) error { return errdefs.Unavailable(fmt.Errorf(format, params...)) } // NotImplementedErrorf creates an instance of NotImplementedError -func NotImplementedErrorf(format string, params ...interface{}) error { +func NotImplementedErrorf(format string, params ...any) error { return errdefs.NotImplemented(fmt.Errorf(format, params...)) } // InternalErrorf creates an instance of InternalError -func InternalErrorf(format string, params ...interface{}) error { +func InternalErrorf(format string, params ...any) error { return internal(fmt.Sprintf(format, params...)) } // InternalMaskableErrorf creates an instance of InternalError and MaskableError -func InternalMaskableErrorf(format string, params ...interface{}) error { +func InternalMaskableErrorf(format string, params ...any) error { return maskInternal(fmt.Sprintf(format, params...)) } diff --git a/daemon/logger/gelf/gelf.go b/daemon/logger/gelf/gelf.go index b02523bfff..64e907804d 100644 --- a/daemon/logger/gelf/gelf.go +++ b/daemon/logger/gelf/gelf.go @@ -56,7 +56,7 @@ func New(info logger.Info) (logger.Logger, error) { return nil, err } - extra := map[string]interface{}{ + extra := map[string]any{ "_container_id": info.ContainerID, "_container_name": info.Name(), "_image_id": info.ContainerImageID, diff --git a/daemon/logger/jsonfilelog/jsonfilelog.go b/daemon/logger/jsonfilelog/jsonfilelog.go index e3119eb44f..572cd2f7bc 100644 --- a/daemon/logger/jsonfilelog/jsonfilelog.go +++ b/daemon/logger/jsonfilelog/jsonfilelog.go @@ -25,7 +25,7 @@ const Name = "json-file" // So let's start with a buffer bigger than this. const initialBufSize = 256 -var buffersPool = sync.Pool{New: func() interface{} { return bytes.NewBuffer(make([]byte, 0, initialBufSize)) }} +var buffersPool = sync.Pool{New: func() any { return bytes.NewBuffer(make([]byte, 0, initialBufSize)) }} // JSONFileLogger is Logger implementation for default Docker logging. type JSONFileLogger struct { diff --git a/daemon/logger/jsonfilelog/jsonlog/jsonlogbytes_test.go b/daemon/logger/jsonfilelog/jsonlog/jsonlogbytes_test.go index 6db2409d7a..90663b944e 100644 --- a/daemon/logger/jsonfilelog/jsonlog/jsonlogbytes_test.go +++ b/daemon/logger/jsonfilelog/jsonlog/jsonlogbytes_test.go @@ -38,7 +38,7 @@ func TestJSONLogsMarshalJSONBuf(t *testing.T) { assert.NilError(t, err) assert.Assert(t, regexP(buf.String(), expression)) - assert.NilError(t, json.Unmarshal(buf.Bytes(), &map[string]interface{}{})) + assert.NilError(t, json.Unmarshal(buf.Bytes(), &map[string]any{})) } } diff --git a/daemon/logger/local/local.go b/daemon/logger/local/local.go index 5f32f3d147..b2a8ce8717 100644 --- a/daemon/logger/local/local.go +++ b/daemon/logger/local/local.go @@ -30,7 +30,7 @@ const ( defaultCompressLogs = true ) -var buffersPool = sync.Pool{New: func() interface{} { +var buffersPool = sync.Pool{New: func() any { b := make([]byte, initialBufSize) return &b }} diff --git a/daemon/logger/logger.go b/daemon/logger/logger.go index 417f70691b..efa9ee00ba 100644 --- a/daemon/logger/logger.go +++ b/daemon/logger/logger.go @@ -29,7 +29,7 @@ const ( logWatcherBufferSize = 4096 ) -var messagePool = &sync.Pool{New: func() interface{} { return &Message{Line: make([]byte, 0, 256)} }} +var messagePool = &sync.Pool{New: func() any { return &Message{Line: make([]byte, 0, 256)} }} // NewMessage returns a new message from the message sync.Pool func NewMessage() *Message { diff --git a/daemon/logger/proxy.go b/daemon/logger/proxy.go index 215c4e5107..0fad882621 100644 --- a/daemon/logger/proxy.go +++ b/daemon/logger/proxy.go @@ -6,8 +6,8 @@ import ( ) type client interface { - Call(string, interface{}, interface{}) error - Stream(string, interface{}) (io.ReadCloser, error) + Call(string, any, any) error + Stream(string, any) (io.ReadCloser, error) } type logPluginProxy struct { diff --git a/daemon/logger/splunk/splunk.go b/daemon/logger/splunk/splunk.go index e95a44f2fc..44d438703c 100644 --- a/daemon/logger/splunk/splunk.go +++ b/daemon/logger/splunk/splunk.go @@ -119,16 +119,16 @@ type splunkLoggerRaw struct { } type splunkMessage struct { - Event interface{} `json:"event"` - Time string `json:"time"` - Host string `json:"host"` - Source string `json:"source,omitempty"` - SourceType string `json:"sourcetype,omitempty"` - Index string `json:"index,omitempty"` + Event any `json:"event"` + Time string `json:"time"` + Host string `json:"host"` + Source string `json:"source,omitempty"` + SourceType string `json:"sourcetype,omitempty"` + Index string `json:"index,omitempty"` } type splunkMessageEvent struct { - Line interface{} `json:"line"` + Line any `json:"line"` Source string `json:"source"` Tag string `json:"tag,omitempty"` Attrs map[string]string `json:"attrs,omitempty"` diff --git a/daemon/logger/splunk/splunk_test.go b/daemon/logger/splunk/splunk_test.go index 17b0182de4..7d1eb710a3 100644 --- a/daemon/logger/splunk/splunk_test.go +++ b/daemon/logger/splunk/splunk_test.go @@ -330,8 +330,8 @@ func TestInlineFormatWithNonDefaultOptions(t *testing.T) { if event["line"] != "1" || event["source"] != "stdout" || event["tag"] != "container_image_name/container_name" || - event["attrs"].(map[string]interface{})["a"] != "b" || - event["attrs"].(map[string]interface{})["foo_finder"] != "bar" || + event["attrs"].(map[string]any)["a"] != "b" || + event["attrs"].(map[string]any)["foo_finder"] != "bar" || len(event) != 4 { t.Fatalf("Unexpected event in message %v", event) } @@ -427,7 +427,7 @@ func TestJsonFormat(t *testing.T) { if event, err := message1.EventAsMap(); err != nil { t.Fatal(err) } else { - if event["line"].(map[string]interface{})["a"] != "b" || + if event["line"].(map[string]any)["a"] != "b" || event["source"] != "stdout" || event["tag"] != "containeriid" || len(event) != 3 { diff --git a/daemon/logger/splunk/splunkhecmock_test.go b/daemon/logger/splunk/splunkhecmock_test.go index a2a09f9ffa..bc9a0766ad 100644 --- a/daemon/logger/splunk/splunkhecmock_test.go +++ b/daemon/logger/splunk/splunkhecmock_test.go @@ -20,8 +20,8 @@ func (message *splunkMessage) EventAsString() (string, error) { return "", fmt.Errorf("Cannot cast Event %v to string", message.Event) } -func (message *splunkMessage) EventAsMap() (map[string]interface{}, error) { - if val, ok := message.Event.(map[string]interface{}); ok { +func (message *splunkMessage) EventAsMap() (map[string]any, error) { + if val, ok := message.Event.(map[string]any); ok { return val, nil } return nil, fmt.Errorf("Cannot cast Event %v to map", message.Event) diff --git a/daemon/logger/syslog/syslog_test.go b/daemon/logger/syslog/syslog_test.go index 7fe8e87450..4b35df87c8 100644 --- a/daemon/logger/syslog/syslog_test.go +++ b/daemon/logger/syslog/syslog_test.go @@ -13,7 +13,7 @@ import ( syslog "github.com/RackSec/srslog" ) -func functionMatches(expectedFun interface{}, actualFun interface{}) bool { +func functionMatches(expectedFun any, actualFun any) bool { return reflect.ValueOf(expectedFun).Pointer() == reflect.ValueOf(actualFun).Pointer() } diff --git a/daemon/logger/templates/templates.go b/daemon/logger/templates/templates.go index 9ca2066329..a7c4533e87 100644 --- a/daemon/logger/templates/templates.go +++ b/daemon/logger/templates/templates.go @@ -10,7 +10,7 @@ import ( // basicFunctions are the set of initial // functions provided to every template. var basicFunctions = template.FuncMap{ - "json": func(v interface{}) string { + "json": func(v any) string { buf := &bytes.Buffer{} enc := json.NewEncoder(buf) enc.SetEscapeHTML(false) diff --git a/daemon/oci_windows.go b/daemon/oci_windows.go index a7b36b867c..46d074f6c4 100644 --- a/daemon/oci_windows.go +++ b/daemon/oci_windows.go @@ -167,7 +167,7 @@ func (daemon *Daemon) createSpec(ctx context.Context, daemonCfg *configStore, c } if data["GW_INFO"] != nil { - gwInfo := data["GW_INFO"].(map[string]interface{}) + gwInfo := data["GW_INFO"].(map[string]any) if gwInfo["hnsid"] != nil { gwHNSID = gwInfo["hnsid"].(string) } diff --git a/daemon/pkg/plugin/events.go b/daemon/pkg/plugin/events.go index f7e0482eb5..85ab3ed3d2 100644 --- a/daemon/pkg/plugin/events.go +++ b/daemon/pkg/plugin/events.go @@ -89,8 +89,8 @@ func (e EventEnable) matches(observed Event) bool { // the plugin manager actions, CRUD operations. // The caller must call the returned `cancel()` function once done with the channel // or this will leak resources. -func (pm *Manager) SubscribeEvents(buffer int, watchEvents ...Event) (eventCh <-chan interface{}, cancel func()) { - topic := func(i interface{}) bool { +func (pm *Manager) SubscribeEvents(buffer int, watchEvents ...Event) (eventCh <-chan any, cancel func()) { + topic := func(i any) bool { observed, ok := i.(Event) if !ok { panic(fmt.Sprintf("unexpected type passed to event channel: %v", reflect.TypeOf(i))) diff --git a/daemon/pkg/registry/errors.go b/daemon/pkg/registry/errors.go index d37155a789..c693076713 100644 --- a/daemon/pkg/registry/errors.go +++ b/daemon/pkg/registry/errors.go @@ -22,11 +22,11 @@ func invalidParam(err error) error { return invalidParameterErr{err} } -func invalidParamf(format string, args ...interface{}) error { +func invalidParamf(format string, args ...any) error { return invalidParameterErr{errors.Errorf(format, args...)} } -func invalidParamWrapf(err error, format string, args ...interface{}) error { +func invalidParamWrapf(err error, format string, args ...any) error { return invalidParameterErr{errors.Wrapf(err, format, args...)} } diff --git a/daemon/pkg/registry/registry_mock_test.go b/daemon/pkg/registry/registry_mock_test.go index 986e7ee649..6c20daaeae 100644 --- a/daemon/pkg/registry/registry_mock_test.go +++ b/daemon/pkg/registry/registry_mock_test.go @@ -77,7 +77,7 @@ func writeHeaders(w http.ResponseWriter) { h.Add("Cache-Control", "no-cache") } -func writeResponse(w http.ResponseWriter, message interface{}, code int) { +func writeResponse(w http.ResponseWriter, message any, code int) { writeHeaders(w) w.WriteHeader(code) body, err := json.Marshal(message) diff --git a/daemon/pkg/registry/search_test.go b/daemon/pkg/registry/search_test.go index bbd8da6f0d..df48e99aa8 100644 --- a/daemon/pkg/registry/search_test.go +++ b/daemon/pkg/registry/search_test.go @@ -48,7 +48,7 @@ func spawnTestRegistrySession(t *testing.T) (*http.Client, *v1Endpoint) { type debugTransport struct { http.RoundTripper - log func(...interface{}) + log func(...any) } func (tr debugTransport) RoundTrip(req *http.Request) (*http.Response, error) { diff --git a/daemon/reload_test.go b/daemon/reload_test.go index f2a88c2d44..9d970cd593 100644 --- a/daemon/reload_test.go +++ b/daemon/reload_test.go @@ -42,7 +42,7 @@ func TestDaemonReloadLabels(t *testing.T) { }) muteLogs(t) - valuesSets := make(map[string]interface{}) + valuesSets := make(map[string]any) valuesSets["labels"] = "foo:baz" newConfig := &config.Config{ CommonConfig: config.CommonConfig{ @@ -110,7 +110,7 @@ func TestDaemonReloadMirrors(t *testing.T) { } for _, value := range loadMirrors { - valuesSets := make(map[string]interface{}) + valuesSets := make(map[string]any) valuesSets["registry-mirrors"] = value.mirrors newConfig := &config.Config{ @@ -195,7 +195,7 @@ func TestDaemonReloadInsecureRegistries(t *testing.T) { "https://mirror.test.example.com", } - valuesSets := make(map[string]interface{}) + valuesSets := make(map[string]any) valuesSets["insecure-registries"] = insecureRegistries valuesSets["registry-mirrors"] = mirrors @@ -269,7 +269,7 @@ func TestDaemonReloadNotAffectOthers(t *testing.T) { }) muteLogs(t) - valuesSets := make(map[string]interface{}) + valuesSets := make(map[string]any) valuesSets["labels"] = "foo:baz" newConfig := &config.Config{ CommonConfig: config.CommonConfig{ @@ -301,7 +301,7 @@ func TestDaemonReloadNetworkDiagnosticPort(t *testing.T) { enableConfig := &config.Config{ CommonConfig: config.CommonConfig{ NetworkDiagnosticPort: 2000, - ValuesSet: map[string]interface{}{ + ValuesSet: map[string]any{ "network-diagnostic-port": 2000, }, }, diff --git a/daemon/runtime_unix.go b/daemon/runtime_unix.go index 87e82fc6aa..3965afd0e7 100644 --- a/daemon/runtime_unix.go +++ b/daemon/runtime_unix.go @@ -35,7 +35,7 @@ const ( type shimConfig struct { Shim string - Opts interface{} + Opts any Features *features.Features // Check if the ShimConfig is valid given the current state of the system. @@ -200,7 +200,7 @@ func wrapRuntime(dir, name, binary string, args []string) (string, error) { // Get returns the containerd runtime and options for name, suitable to pass // into containerd.WithRuntime(). The runtime and options for the default // runtime are returned when name is the empty string. -func (r *runtimes) Get(name string) (string, interface{}, error) { +func (r *runtimes) Get(name string) (string, any, error) { if name == "" { name = r.Default } diff --git a/daemon/runtime_unix_test.go b/daemon/runtime_unix_test.go index 4072a85172..a5d62eabc3 100644 --- a/daemon/runtime_unix_test.go +++ b/daemon/runtime_unix_test.go @@ -49,7 +49,7 @@ func TestSetupRuntimes(t *testing.T) { name: "OptionsOnly", config: &config.Config{ Runtimes: map[string]system.Runtime{ - "myruntime": {Options: map[string]interface{}{"hello": "world"}}, + "myruntime": {Options: map[string]any{"hello": "world"}}, }, }, expectErr: "either a runtimeType or a path must be configured", @@ -67,7 +67,7 @@ func TestSetupRuntimes(t *testing.T) { name: "PathAndOptions", config: &config.Config{ Runtimes: map[string]system.Runtime{ - "myruntime": {Path: "/bin/true", Options: map[string]interface{}{"a": "b"}}, + "myruntime": {Path: "/bin/true", Options: map[string]any{"a": "b"}}, }, }, expectErr: "options cannot be used with a path runtime", @@ -88,7 +88,7 @@ func TestSetupRuntimes(t *testing.T) { "myruntime": { Path: "/bin/true", Args: []string{"--version"}, - Options: map[string]interface{}{"hmm": 3}, + Options: map[string]any{"hmm": 3}, }, }, }, @@ -100,7 +100,7 @@ func TestSetupRuntimes(t *testing.T) { Runtimes: map[string]system.Runtime{ "myruntime": { Type: "io.containerd.kata.v2", - Options: map[string]interface{}{"a": "b"}, + Options: map[string]any{"a": "b"}, Args: []string{"--help"}, }, }, @@ -115,7 +115,7 @@ func TestSetupRuntimes(t *testing.T) { Path: "/bin/true", Args: []string{"foo"}, Type: "io.containerd.runsc.v1", - Options: map[string]interface{}{"a": "b"}, + Options: map[string]any{"a": "b"}, }, }, }, @@ -203,7 +203,7 @@ func TestGetRuntime(t *testing.T) { const shimWithOptsName = "shimwithopts" shimWithOpts := system.Runtime{ Type: plugins.RuntimeRuncV2, - Options: map[string]interface{}{"IoUid": 42}, + Options: map[string]any{"IoUid": 42}, } const shimAliasName = "wasmedge" @@ -217,7 +217,7 @@ func TestGetRuntime(t *testing.T) { const gvisorName = "gvisor" gvisorRuntime := system.Runtime{ Type: "io.containerd.runsc.v1", - Options: map[string]interface{}{ + Options: map[string]any{ "TypeUrl": "io.containerd.runsc.v1.options", "ConfigPath": "/path/to/runsc.toml", }, diff --git a/daemon/runtime_windows.go b/daemon/runtime_windows.go index e631e63dd8..fed5a38294 100644 --- a/daemon/runtime_windows.go +++ b/daemon/runtime_windows.go @@ -8,7 +8,7 @@ import ( type runtimes struct{} -func (r *runtimes) Get(name string) (string, interface{}, error) { +func (r *runtimes) Get(name string) (string, any, error) { return "", nil, errors.New("not implemented") } diff --git a/daemon/server/backend/build.go b/daemon/server/backend/build.go index 3176b0ec50..ba5f247138 100644 --- a/daemon/server/backend/build.go +++ b/daemon/server/backend/build.go @@ -31,7 +31,7 @@ type ProgressWriter struct { // AuxEmitter is an interface for emitting aux messages during build progress type AuxEmitter interface { - Emit(string, interface{}) error + Emit(string, any) error } // BuildConfig is the configuration used by a BuildManager to start a build diff --git a/daemon/server/httputils/httputils.go b/daemon/server/httputils/httputils.go index de2c7b0a33..53309a90f8 100644 --- a/daemon/server/httputils/httputils.go +++ b/daemon/server/httputils/httputils.go @@ -32,7 +32,7 @@ func HijackConnection(w http.ResponseWriter) (io.ReadCloser, io.Writer, error) { } // CloseStreams ensures that a list for http streams are properly closed. -func CloseStreams(streams ...interface{}) { +func CloseStreams(streams ...any) { for _, stream := range streams { if tcpc, ok := stream.(interface { CloseWrite() error @@ -59,7 +59,7 @@ func CheckForJSON(r *http.Request) error { // ReadJSON validates the request to have the correct content-type, and decodes // the request's Body into out. -func ReadJSON(r *http.Request, out interface{}) error { +func ReadJSON(r *http.Request, out any) error { err := CheckForJSON(r) if err != nil { return err @@ -87,7 +87,7 @@ func ReadJSON(r *http.Request, out interface{}) error { } // WriteJSON writes the value v to the http response stream as json with standard json encoding. -func WriteJSON(w http.ResponseWriter, code int, v interface{}) error { +func WriteJSON(w http.ResponseWriter, code int, v any) error { w.Header().Set("Content-Type", "application/json") w.WriteHeader(code) enc := json.NewEncoder(w) diff --git a/daemon/server/middleware/debug.go b/daemon/server/middleware/debug.go index 42b9a8ef07..e19941b5a2 100644 --- a/daemon/server/middleware/debug.go +++ b/daemon/server/middleware/debug.go @@ -61,7 +61,7 @@ func DebugRequestMiddleware(handler func(ctx context.Context, w http.ResponseWri return handleWithLogs(ctx, w, r, vars) } - var postForm map[string]interface{} + var postForm map[string]any if err := json.Unmarshal(b, &postForm); err == nil { maskSecretKeys(postForm) // TODO(thaJeztah): is there a better way to detect if we're using JSON-formatted logs? @@ -80,15 +80,15 @@ func DebugRequestMiddleware(handler func(ctx context.Context, w http.ResponseWri } } -func maskSecretKeys(inp interface{}) { - if arr, ok := inp.([]interface{}); ok { +func maskSecretKeys(inp any) { + if arr, ok := inp.([]any); ok { for _, f := range arr { maskSecretKeys(f) } return } - if form, ok := inp.(map[string]interface{}); ok { + if form, ok := inp.(map[string]any); ok { scrub := []string{ // Note: The Data field contains the base64-encoded secret in 'secret' // and 'config' create and update requests. Currently, no other POST diff --git a/daemon/server/middleware/debug_test.go b/daemon/server/middleware/debug_test.go index eed22d5243..49c45da3c7 100644 --- a/daemon/server/middleware/debug_test.go +++ b/daemon/server/middleware/debug_test.go @@ -10,23 +10,23 @@ import ( func TestMaskSecretKeys(t *testing.T) { tests := []struct { doc string - input map[string]interface{} - expected map[string]interface{} + input map[string]any + expected map[string]any }{ { doc: "secret/config create and update requests", - input: map[string]interface{}{"Data": "foo", "Name": "name", "Labels": map[string]interface{}{}}, - expected: map[string]interface{}{"Data": "*****", "Name": "name", "Labels": map[string]interface{}{}}, + input: map[string]any{"Data": "foo", "Name": "name", "Labels": map[string]any{}}, + expected: map[string]any{"Data": "*****", "Name": "name", "Labels": map[string]any{}}, }, { doc: "masking other fields (recursively)", - input: map[string]interface{}{ + input: map[string]any{ "password": "pass", "secret": "secret", "jointoken": "jointoken", "unlockkey": "unlockkey", "signingcakey": "signingcakey", - "other": map[string]interface{}{ + "other": map[string]any{ "password": "pass", "secret": "secret", "jointoken": "jointoken", @@ -34,13 +34,13 @@ func TestMaskSecretKeys(t *testing.T) { "signingcakey": "signingcakey", }, }, - expected: map[string]interface{}{ + expected: map[string]any{ "password": "*****", "secret": "*****", "jointoken": "*****", "unlockkey": "*****", "signingcakey": "*****", - "other": map[string]interface{}{ + "other": map[string]any{ "password": "*****", "secret": "*****", "jointoken": "*****", @@ -51,15 +51,15 @@ func TestMaskSecretKeys(t *testing.T) { }, { doc: "case insensitive field matching", - input: map[string]interface{}{ + input: map[string]any{ "PASSWORD": "pass", - "other": map[string]interface{}{ + "other": map[string]any{ "PASSWORD": "pass", }, }, - expected: map[string]interface{}{ + expected: map[string]any{ "PASSWORD": "*****", - "other": map[string]interface{}{ + "other": map[string]any{ "PASSWORD": "*****", }, }, diff --git a/daemon/server/router/system/backend.go b/daemon/server/router/system/backend.go index 6d2b29d162..12525fb007 100644 --- a/daemon/server/router/system/backend.go +++ b/daemon/server/router/system/backend.go @@ -20,8 +20,8 @@ type Backend interface { SystemInfo(context.Context) (*system.Info, error) SystemVersion(context.Context) (types.Version, error) SystemDiskUsage(ctx context.Context, opts backend.DiskUsageOptions) (*backend.DiskUsage, error) - SubscribeToEvents(since, until time.Time, ef filters.Args) ([]events.Message, chan interface{}) - UnsubscribeFromEvents(chan interface{}) + SubscribeToEvents(since, until time.Time, ef filters.Args) ([]events.Message, chan any) + UnsubscribeFromEvents(chan any) AuthenticateToRegistry(ctx context.Context, authConfig *registry.AuthConfig) (string, error) } diff --git a/daemon/start_unix.go b/daemon/start_unix.go index 8e3c4ab07c..ba839094ef 100644 --- a/daemon/start_unix.go +++ b/daemon/start_unix.go @@ -9,7 +9,7 @@ import ( ) // getLibcontainerdCreateOptions callers must hold a lock on the container -func (daemon *Daemon) getLibcontainerdCreateOptions(daemonCfg *configStore, container *container.Container) (string, interface{}, error) { +func (daemon *Daemon) getLibcontainerdCreateOptions(daemonCfg *configStore, container *container.Container) (string, any, error) { // Ensure a runtime has been assigned to this container if container.HostConfig.Runtime == "" { container.HostConfig.Runtime = daemonCfg.Runtimes.Default diff --git a/daemon/start_windows.go b/daemon/start_windows.go index 836b98e426..0e4c398cd3 100644 --- a/daemon/start_windows.go +++ b/daemon/start_windows.go @@ -7,7 +7,7 @@ import ( "github.com/moby/moby/v2/daemon/internal/libcontainerd" ) -func (daemon *Daemon) getLibcontainerdCreateOptions(*configStore, *container.Container) (string, interface{}, error) { +func (daemon *Daemon) getLibcontainerdCreateOptions(*configStore, *container.Container) (string, any, error) { if libcontainerd.ContainerdRuntimeEnabled { opts := &options.Options{} return config.WindowsV2RuntimeName, opts, nil diff --git a/daemon/stats.go b/daemon/stats.go index 0850c03c8a..ee14588bd3 100644 --- a/daemon/stats.go +++ b/daemon/stats.go @@ -47,7 +47,7 @@ func (daemon *Daemon) ContainerStats(ctx context.Context, prefixOrName string, c var preCPUStats containertypes.CPUStats var preRead time.Time - getStatJSON := func(v interface{}) *containertypes.StatsResponse { + getStatJSON := func(v any) *containertypes.StatsResponse { ss := v.(containertypes.StatsResponse) ss.Name = ctr.Name ss.ID = ctr.ID @@ -90,11 +90,11 @@ func (daemon *Daemon) ContainerStats(ctx context.Context, prefixOrName string, c } } -func (daemon *Daemon) subscribeToContainerStats(c *container.Container) chan interface{} { +func (daemon *Daemon) subscribeToContainerStats(c *container.Container) chan any { return daemon.statsCollector.Collect(c) } -func (daemon *Daemon) unsubscribeToContainerStats(c *container.Container, ch chan interface{}) { +func (daemon *Daemon) unsubscribeToContainerStats(c *container.Container, ch chan any) { daemon.statsCollector.Unsubscribe(c, ch) } diff --git a/daemon/stats/collector.go b/daemon/stats/collector.go index 9d6e945ef8..5450f7cecf 100644 --- a/daemon/stats/collector.go +++ b/daemon/stats/collector.go @@ -37,7 +37,7 @@ type supervisor interface { // Collect registers the container with the collector and adds it to // the event loop for collection on the specified interval returning // a channel for the subscriber to receive on. -func (s *Collector) Collect(c *container.Container) chan interface{} { +func (s *Collector) Collect(c *container.Container) chan any { s.cond.L.Lock() defer s.cond.L.Unlock() @@ -63,7 +63,7 @@ func (s *Collector) StopCollection(c *container.Container) { } // Unsubscribe removes a specific subscriber from receiving updates for a container's stats. -func (s *Collector) Unsubscribe(c *container.Container, ch chan interface{}) { +func (s *Collector) Unsubscribe(c *container.Container, ch chan any) { s.m.Lock() publisher := s.publishers[c] if publisher != nil { diff --git a/daemon/volume/drivers/adapter.go b/daemon/volume/drivers/adapter.go index 9199e18e6b..2178a8316e 100644 --- a/daemon/volume/drivers/adapter.go +++ b/daemon/volume/drivers/adapter.go @@ -119,14 +119,14 @@ type volumeAdapter struct { driverName string eMount string // ephemeral host volume path createdAt time.Time // time the directory was created - status map[string]interface{} + status map[string]any } type proxyVolume struct { Name string Mountpoint string CreatedAt time.Time - Status map[string]interface{} + Status map[string]any } func (a *volumeAdapter) Name() string { @@ -167,8 +167,8 @@ func (a *volumeAdapter) CreatedAt() (time.Time, error) { return a.createdAt, nil } -func (a *volumeAdapter) Status() map[string]interface{} { - out := make(map[string]interface{}, len(a.status)) +func (a *volumeAdapter) Status() map[string]any { + out := make(map[string]any, len(a.status)) for k, v := range a.status { out[k] = v } diff --git a/daemon/volume/local/local.go b/daemon/volume/local/local.go index 499ea4226d..c0088afabb 100644 --- a/daemon/volume/local/local.go +++ b/daemon/volume/local/local.go @@ -362,7 +362,7 @@ func (v *localVolume) Unmount(id string) error { return v.unmount() } -func (v *localVolume) Status() map[string]interface{} { +func (v *localVolume) Status() map[string]any { return nil } diff --git a/daemon/volume/testutils/testutils.go b/daemon/volume/testutils/testutils.go index 1512350756..850fec93df 100644 --- a/daemon/volume/testutils/testutils.go +++ b/daemon/volume/testutils/testutils.go @@ -32,7 +32,7 @@ func (NoopVolume) Mount(_ string) (string, error) { return "noop", nil } func (NoopVolume) Unmount(_ string) error { return nil } // Status provides low-level details about the volume -func (NoopVolume) Status() map[string]interface{} { return nil } +func (NoopVolume) Status() map[string]any { return nil } // CreatedAt provides the time the volume (directory) was created at func (NoopVolume) CreatedAt() (time.Time, error) { return time.Now(), nil } @@ -65,8 +65,8 @@ func (FakeVolume) Mount(_ string) (string, error) { return "fake", nil } func (FakeVolume) Unmount(_ string) error { return nil } // Status provides low-level details about the volume -func (FakeVolume) Status() map[string]interface{} { - return map[string]interface{}{"datakey": "datavalue"} +func (FakeVolume) Status() map[string]any { + return map[string]any{"datakey": "datavalue"} } // CreatedAt provides the time the volume (directory) was created at diff --git a/daemon/volume/volume.go b/daemon/volume/volume.go index c808e67466..276ab718e6 100644 --- a/daemon/volume/volume.go +++ b/daemon/volume/volume.go @@ -58,7 +58,7 @@ type Volume interface { // CreatedAt returns Volume Creation time CreatedAt() (time.Time, error) // Status returns low-level status information about a volume - Status() map[string]interface{} + Status() map[string]any } // LiveRestorer is an optional interface that can be implemented by a volume driver diff --git a/daemon/volumes.go b/daemon/volumes.go index e819df1358..f995d6fc2f 100644 --- a/daemon/volumes.go +++ b/daemon/volumes.go @@ -361,7 +361,7 @@ func (v *volumeWrapper) CreatedAt() (time.Time, error) { return time.Time{}, errors.New("not implemented") } -func (v *volumeWrapper) Status() map[string]interface{} { +func (v *volumeWrapper) Status() map[string]any { return v.v.Status } diff --git a/integration-cli/checker/checker.go b/integration-cli/checker/checker.go index 678b1433b2..3598bbef88 100644 --- a/integration-cli/checker/checker.go +++ b/integration-cli/checker/checker.go @@ -10,39 +10,39 @@ import ( ) // Compare defines the interface to compare values -type Compare func(x interface{}) assert.BoolOrComparison +type Compare func(x any) assert.BoolOrComparison // False checks if the value is false func False() Compare { - return func(x interface{}) assert.BoolOrComparison { + return func(x any) assert.BoolOrComparison { return !x.(bool) } } // True checks if the value is true func True() Compare { - return func(x interface{}) assert.BoolOrComparison { + return func(x any) assert.BoolOrComparison { return x } } // Equals checks if the value is equal to the given value -func Equals(y interface{}) Compare { - return func(x interface{}) assert.BoolOrComparison { +func Equals(y any) Compare { + return func(x any) assert.BoolOrComparison { return is.Equal(x, y) } } // Contains checks if the value contains the given value -func Contains(y interface{}) Compare { - return func(x interface{}) assert.BoolOrComparison { +func Contains(y any) Compare { + return func(x any) assert.BoolOrComparison { return is.Contains(x, y) } } // Not checks if two values are not func Not(c Compare) Compare { - return func(x interface{}) assert.BoolOrComparison { + return func(x any) assert.BoolOrComparison { r := c(x) switch r := r.(type) { case bool: @@ -56,29 +56,29 @@ func Not(c Compare) Compare { } // DeepEquals checks if two values are equal -func DeepEquals(y interface{}) Compare { - return func(x interface{}) assert.BoolOrComparison { +func DeepEquals(y any) Compare { + return func(x any) assert.BoolOrComparison { return is.DeepEqual(x, y) } } // HasLen checks if the value has the expected number of elements func HasLen(y int) Compare { - return func(x interface{}) assert.BoolOrComparison { + return func(x any) assert.BoolOrComparison { return is.Len(x, y) } } // IsNil checks if the value is nil func IsNil() Compare { - return func(x interface{}) assert.BoolOrComparison { + return func(x any) assert.BoolOrComparison { return is.Nil(x) } } // GreaterThan checks if the value is greater than the given value func GreaterThan(y int) Compare { - return func(x interface{}) assert.BoolOrComparison { + return func(x any) assert.BoolOrComparison { return x.(int) > y } } diff --git a/integration-cli/daemon/daemon.go b/integration-cli/daemon/daemon.go index a3d32a5c31..e94c0ce935 100644 --- a/integration-cli/daemon/daemon.go +++ b/integration-cli/daemon/daemon.go @@ -83,8 +83,8 @@ func (d *Daemon) inspectFieldWithError(name, field string) (string, error) { // CheckActiveContainerCount returns the number of active containers // FIXME(vdemeester) should re-use ActivateContainers in some way -func (d *Daemon) CheckActiveContainerCount(ctx context.Context) func(t *testing.T) (interface{}, string) { - return func(t *testing.T) (interface{}, string) { +func (d *Daemon) CheckActiveContainerCount(ctx context.Context) func(t *testing.T) (any, string) { + return func(t *testing.T) (any, string) { t.Helper() apiClient, err := client.NewClientWithOpts(client.FromEnv, client.WithHost(d.Sock())) assert.NilError(t, err) diff --git a/integration-cli/daemon/daemon_swarm.go b/integration-cli/daemon/daemon_swarm.go index 5547ac0212..0842d0406a 100644 --- a/integration-cli/daemon/daemon_swarm.go +++ b/integration-cli/daemon/daemon_swarm.go @@ -15,8 +15,8 @@ import ( // CheckServiceTasksInState returns the number of tasks with a matching state, // and optional message substring. -func (d *Daemon) CheckServiceTasksInState(ctx context.Context, service string, state swarm.TaskState, message string) func(*testing.T) (interface{}, string) { - return func(t *testing.T) (interface{}, string) { +func (d *Daemon) CheckServiceTasksInState(ctx context.Context, service string, state swarm.TaskState, message string) func(*testing.T) (any, string) { + return func(t *testing.T) (any, string) { tasks := d.GetServiceTasks(ctx, t, service) var count int for _, task := range tasks { @@ -32,8 +32,8 @@ func (d *Daemon) CheckServiceTasksInState(ctx context.Context, service string, s // CheckServiceTasksInStateWithError returns the number of tasks with a matching state, // and optional message substring. -func (d *Daemon) CheckServiceTasksInStateWithError(ctx context.Context, service string, state swarm.TaskState, errorMessage string) func(*testing.T) (interface{}, string) { - return func(t *testing.T) (interface{}, string) { +func (d *Daemon) CheckServiceTasksInStateWithError(ctx context.Context, service string, state swarm.TaskState, errorMessage string) func(*testing.T) (any, string) { + return func(t *testing.T) (any, string) { tasks := d.GetServiceTasks(ctx, t, service) var count int for _, task := range tasks { @@ -48,13 +48,13 @@ func (d *Daemon) CheckServiceTasksInStateWithError(ctx context.Context, service } // CheckServiceRunningTasks returns the number of running tasks for the specified service -func (d *Daemon) CheckServiceRunningTasks(ctx context.Context, service string) func(*testing.T) (interface{}, string) { +func (d *Daemon) CheckServiceRunningTasks(ctx context.Context, service string) func(*testing.T) (any, string) { return d.CheckServiceTasksInState(ctx, service, swarm.TaskStateRunning, "") } // CheckServiceUpdateState returns the current update state for the specified service -func (d *Daemon) CheckServiceUpdateState(ctx context.Context, service string) func(*testing.T) (interface{}, string) { - return func(t *testing.T) (interface{}, string) { +func (d *Daemon) CheckServiceUpdateState(ctx context.Context, service string) func(*testing.T) (any, string) { + return func(t *testing.T) (any, string) { service := d.GetService(ctx, t, service) if service.UpdateStatus == nil { return "", "" @@ -64,8 +64,8 @@ func (d *Daemon) CheckServiceUpdateState(ctx context.Context, service string) fu } // CheckPluginRunning returns the runtime state of the plugin -func (d *Daemon) CheckPluginRunning(ctx context.Context, plugin string) func(c *testing.T) (interface{}, string) { - return func(t *testing.T) (interface{}, string) { +func (d *Daemon) CheckPluginRunning(ctx context.Context, plugin string) func(c *testing.T) (any, string) { + return func(t *testing.T) (any, string) { apiclient := d.NewClientT(t) resp, _, err := apiclient.PluginInspectWithRaw(ctx, plugin) if cerrdefs.IsNotFound(err) { @@ -77,8 +77,8 @@ func (d *Daemon) CheckPluginRunning(ctx context.Context, plugin string) func(c * } // CheckPluginImage returns the runtime state of the plugin -func (d *Daemon) CheckPluginImage(ctx context.Context, plugin string) func(c *testing.T) (interface{}, string) { - return func(t *testing.T) (interface{}, string) { +func (d *Daemon) CheckPluginImage(ctx context.Context, plugin string) func(c *testing.T) (any, string) { + return func(t *testing.T) (any, string) { apiclient := d.NewClientT(t) resp, _, err := apiclient.PluginInspectWithRaw(ctx, plugin) if cerrdefs.IsNotFound(err) { @@ -90,16 +90,16 @@ func (d *Daemon) CheckPluginImage(ctx context.Context, plugin string) func(c *te } // CheckServiceTasks returns the number of tasks for the specified service -func (d *Daemon) CheckServiceTasks(ctx context.Context, service string) func(*testing.T) (interface{}, string) { - return func(t *testing.T) (interface{}, string) { +func (d *Daemon) CheckServiceTasks(ctx context.Context, service string) func(*testing.T) (any, string) { + return func(t *testing.T) (any, string) { tasks := d.GetServiceTasks(ctx, t, service) return len(tasks), "" } } // CheckRunningTaskNetworks returns the number of times each network is referenced from a task. -func (d *Daemon) CheckRunningTaskNetworks(ctx context.Context) func(t *testing.T) (interface{}, string) { - return func(t *testing.T) (interface{}, string) { +func (d *Daemon) CheckRunningTaskNetworks(ctx context.Context) func(t *testing.T) (any, string) { + return func(t *testing.T) (any, string) { cli := d.NewClientT(t) defer cli.Close() @@ -119,8 +119,8 @@ func (d *Daemon) CheckRunningTaskNetworks(ctx context.Context) func(t *testing.T } // CheckRunningTaskImages returns the times each image is running as a task. -func (d *Daemon) CheckRunningTaskImages(ctx context.Context) func(t *testing.T) (interface{}, string) { - return func(t *testing.T) (interface{}, string) { +func (d *Daemon) CheckRunningTaskImages(ctx context.Context) func(t *testing.T) (any, string) { + return func(t *testing.T) (any, string) { cli := d.NewClientT(t) defer cli.Close() @@ -140,8 +140,8 @@ func (d *Daemon) CheckRunningTaskImages(ctx context.Context) func(t *testing.T) } // CheckNodeReadyCount returns the number of ready node on the swarm -func (d *Daemon) CheckNodeReadyCount(ctx context.Context) func(t *testing.T) (interface{}, string) { - return func(t *testing.T) (interface{}, string) { +func (d *Daemon) CheckNodeReadyCount(ctx context.Context) func(t *testing.T) (any, string) { + return func(t *testing.T) (any, string) { nodes := d.ListNodes(ctx, t) var readyCount int for _, node := range nodes { @@ -154,16 +154,16 @@ func (d *Daemon) CheckNodeReadyCount(ctx context.Context) func(t *testing.T) (in } // CheckLocalNodeState returns the current swarm node state -func (d *Daemon) CheckLocalNodeState(ctx context.Context) func(t *testing.T) (interface{}, string) { - return func(t *testing.T) (interface{}, string) { +func (d *Daemon) CheckLocalNodeState(ctx context.Context) func(t *testing.T) (any, string) { + return func(t *testing.T) (any, string) { info := d.SwarmInfo(ctx, t) return info.LocalNodeState, "" } } // CheckControlAvailable returns the current swarm control available -func (d *Daemon) CheckControlAvailable(ctx context.Context) func(t *testing.T) (interface{}, string) { - return func(t *testing.T) (interface{}, string) { +func (d *Daemon) CheckControlAvailable(ctx context.Context) func(t *testing.T) (any, string) { + return func(t *testing.T) (any, string) { info := d.SwarmInfo(ctx, t) assert.Equal(t, info.LocalNodeState, swarm.LocalNodeStateActive) return info.ControlAvailable, "" @@ -171,8 +171,8 @@ func (d *Daemon) CheckControlAvailable(ctx context.Context) func(t *testing.T) ( } // CheckLeader returns whether there is a leader on the swarm or not -func (d *Daemon) CheckLeader(ctx context.Context) func(t *testing.T) (interface{}, string) { - return func(t *testing.T) (interface{}, string) { +func (d *Daemon) CheckLeader(ctx context.Context) func(t *testing.T) (any, string) { + return func(t *testing.T) (any, string) { cli := d.NewClientT(t) defer cli.Close() diff --git a/integration-cli/docker_api_containers_test.go b/integration-cli/docker_api_containers_test.go index 20248ed355..12d08e555b 100644 --- a/integration-cli/docker_api_containers_test.go +++ b/integration-cli/docker_api_containers_test.go @@ -616,7 +616,7 @@ func (s *DockerAPISuite) TestContainerAPICreateWithCpuSharesCpuset(c *testing.T) } func (s *DockerAPISuite) TestContainerAPIVerifyHeader(c *testing.T) { - config := map[string]interface{}{ + config := map[string]any{ "Image": "busybox", } @@ -1031,7 +1031,7 @@ func (s *DockerAPISuite) TestContainerAPIDeleteRemoveVolume(c *testing.T) { // Regression test for https://github.com/moby/moby/issues/6231 func (s *DockerAPISuite) TestContainerAPIChunkedEncoding(c *testing.T) { - config := map[string]interface{}{ + config := map[string]any{ "Image": "busybox", "Cmd": append([]string{"/bin/sh", "-c"}, sleepCommandForDaemonPlatform()...), "OpenStdin": true, diff --git a/integration-cli/docker_api_exec_resize_test.go b/integration-cli/docker_api_exec_resize_test.go index bdd7643769..51bd96bec3 100644 --- a/integration-cli/docker_api_exec_resize_test.go +++ b/integration-cli/docker_api_exec_resize_test.go @@ -34,7 +34,7 @@ func (s *DockerAPISuite) TestExecResizeImmediatelyAfterExecStart(c *testing.T) { cli.DockerCmd(c, "run", "-d", "-i", "-t", "--name", name, "--restart", "always", "busybox", "/bin/sh") testExecResize := func() error { - data := map[string]interface{}{ + data := map[string]any{ "AttachStdin": true, "Cmd": []string{"/bin/sh"}, } diff --git a/integration-cli/docker_api_exec_test.go b/integration-cli/docker_api_exec_test.go index 781c6c07d9..09bfc0db24 100644 --- a/integration-cli/docker_api_exec_test.go +++ b/integration-cli/docker_api_exec_test.go @@ -28,7 +28,7 @@ func (s *DockerAPISuite) TestExecAPICreateNoCmd(c *testing.T) { name := "exec_test" cli.DockerCmd(c, "run", "-d", "-t", "--name", name, "busybox", "/bin/sh") - res, body, err := request.Post(testutil.GetContext(c), fmt.Sprintf("/containers/%s/exec", name), request.JSONBody(map[string]interface{}{"Cmd": nil})) + res, body, err := request.Post(testutil.GetContext(c), fmt.Sprintf("/containers/%s/exec", name), request.JSONBody(map[string]any{"Cmd": nil})) assert.NilError(c, err) assert.Equal(c, res.StatusCode, http.StatusBadRequest) b, err := request.ReadBody(body) @@ -41,7 +41,7 @@ func (s *DockerAPISuite) TestExecAPICreateNoValidContentType(c *testing.T) { cli.DockerCmd(c, "run", "-d", "-t", "--name", name, "busybox", "/bin/sh") jsonData := bytes.NewBuffer(nil) - if err := json.NewEncoder(jsonData).Encode(map[string]interface{}{"Cmd": nil}); err != nil { + if err := json.NewEncoder(jsonData).Encode(map[string]any{"Cmd": nil}); err != nil { c.Fatalf("Can not encode data to json %s", err) } @@ -193,7 +193,7 @@ func (s *DockerAPISuite) TestExecStateCleanup(c *testing.T) { stateDir := "/var/run/docker/containerd/" + cid - checkReadDir := func(t *testing.T) (interface{}, string) { + checkReadDir := func(t *testing.T) (any, string) { fi, err := os.ReadDir(stateDir) assert.NilError(t, err) return len(fi), "" @@ -228,7 +228,7 @@ func createExec(t *testing.T, name string) string { } func createExecCmd(t *testing.T, name string, cmd string) string { - _, reader, err := request.Post(testutil.GetContext(t), fmt.Sprintf("/containers/%s/exec", name), request.JSONBody(map[string]interface{}{"Cmd": []string{cmd}})) + _, reader, err := request.Post(testutil.GetContext(t), fmt.Sprintf("/containers/%s/exec", name), request.JSONBody(map[string]any{"Cmd": []string{cmd}})) assert.NilError(t, err) b, err := io.ReadAll(reader) assert.NilError(t, err) @@ -249,7 +249,7 @@ func startExec(t *testing.T, id string, code int) { assert.Equal(t, resp.StatusCode, code, "response body: %s", b) } -func inspectExec(ctx context.Context, t *testing.T, id string, out interface{}) { +func inspectExec(ctx context.Context, t *testing.T, id string, out any) { resp, body, err := request.Get(ctx, fmt.Sprintf("/exec/%s/json", id)) assert.NilError(t, err) defer body.Close() @@ -275,7 +275,7 @@ func waitForExec(ctx context.Context, t *testing.T, id string) { } } -func inspectContainer(ctx context.Context, t *testing.T, id string, out interface{}) { +func inspectContainer(ctx context.Context, t *testing.T, id string, out any) { resp, body, err := request.Get(ctx, "/containers/"+id+"/json") assert.NilError(t, err) defer body.Close() diff --git a/integration-cli/docker_api_inspect_test.go b/integration-cli/docker_api_inspect_test.go index ee21d0aa75..ae47d43d94 100644 --- a/integration-cli/docker_api_inspect_test.go +++ b/integration-cli/docker_api_inspect_test.go @@ -32,7 +32,7 @@ func (s *DockerAPISuite) TestInspectAPIContainerResponse(c *testing.T) { for _, cs := range cases { body := getInspectBody(c, cs.version, cleanedContainerID) - var inspectJSON map[string]interface{} + var inspectJSON map[string]any err := json.Unmarshal(body, &inspectJSON) assert.NilError(c, err, "Unable to unmarshal body for version %s", cs.version) @@ -53,19 +53,19 @@ func (s *DockerAPISuite) TestInspectAPIContainerVolumeDriver(c *testing.T) { body := getInspectBody(c, "v1.25", cleanedContainerID) - var inspectJSON map[string]interface{} + var inspectJSON map[string]any err := json.Unmarshal(body, &inspectJSON) assert.NilError(c, err, "Unable to unmarshal body for version 1.25") config, ok := inspectJSON["Config"] assert.Assert(c, ok, "Unable to find 'Config'") - cfg := config.(map[string]interface{}) + cfg := config.(map[string]any) _, ok = cfg["VolumeDriver"] assert.Assert(c, !ok, "API version 1.25 expected to not include VolumeDriver in 'Config'") config, ok = inspectJSON["HostConfig"] assert.Assert(c, ok, "Unable to find 'HostConfig'") - cfg = config.(map[string]interface{}) + cfg = config.(map[string]any) _, ok = cfg["VolumeDriver"] assert.Assert(c, ok, "API version 1.25 expected to include VolumeDriver in 'HostConfig'") } diff --git a/integration-cli/docker_api_stats_test.go b/integration-cli/docker_api_stats_test.go index 25ef6cb109..fce3b53639 100644 --- a/integration-cli/docker_api_stats_test.go +++ b/integration-cli/docker_api_stats_test.go @@ -191,9 +191,9 @@ func getNetworkStats(t *testing.T, id string) map[string]container.NetworkStats // container with id using an API call with version apiVersion. Since the // stats result type differs between API versions, we simply return // map[string]interface{}. -func getStats(t *testing.T, id string) map[string]interface{} { +func getStats(t *testing.T, id string) map[string]any { t.Helper() - stats := make(map[string]interface{}) + stats := make(map[string]any) _, body, err := request.Get(testutil.GetContext(t), "/containers/"+id+"/stats?stream=false") assert.NilError(t, err) @@ -205,17 +205,17 @@ func getStats(t *testing.T, id string) map[string]interface{} { return stats } -func jsonBlobHasGTE121NetworkStats(blob map[string]interface{}) bool { +func jsonBlobHasGTE121NetworkStats(blob map[string]any) bool { networksStatsIntfc, ok := blob["networks"] if !ok { return false } - networksStats, ok := networksStatsIntfc.(map[string]interface{}) + networksStats, ok := networksStatsIntfc.(map[string]any) if !ok { return false } for _, networkInterfaceStatsIntfc := range networksStats { - networkInterfaceStats, ok := networkInterfaceStatsIntfc.(map[string]interface{}) + networkInterfaceStats, ok := networkInterfaceStatsIntfc.(map[string]any) if !ok { return false } diff --git a/integration-cli/docker_api_swarm_service_test.go b/integration-cli/docker_api_swarm_service_test.go index d4ade179b2..77b8cb2f9a 100644 --- a/integration-cli/docker_api_swarm_service_test.go +++ b/integration-cli/docker_api_swarm_service_test.go @@ -224,7 +224,7 @@ func (s *DockerSwarmSuite) TestAPISwarmServicesUpdateStartFirst(c *testing.T) { checkStartingTasks := func(expected int) []swarm.Task { var startingTasks []swarm.Task - poll.WaitOn(c, pollCheck(c, func(t *testing.T) (interface{}, string) { + poll.WaitOn(c, pollCheck(c, func(t *testing.T) (any, string) { tasks := d.GetServiceTasks(ctx, t, id) startingTasks = nil for _, t := range tasks { diff --git a/integration-cli/docker_api_swarm_test.go b/integration-cli/docker_api_swarm_test.go index cbbd31dea9..d95ec867f6 100644 --- a/integration-cli/docker_api_swarm_test.go +++ b/integration-cli/docker_api_swarm_test.go @@ -228,7 +228,7 @@ func (s *DockerSwarmSuite) TestAPISwarmPromoteDemote(c *testing.T) { // back to manager quickly might cause the node to pause for awhile // while waiting for the role to change to worker, and the test can // time out during this interval. - poll.WaitOn(c, pollCheck(c, func(t *testing.T) (interface{}, string) { + poll.WaitOn(c, pollCheck(c, func(t *testing.T) (any, string) { certBytes, err := os.ReadFile(filepath.Join(d2.Folder, "root", "swarm", "certificates", "swarm-node.crt")) if err != nil { return "", fmt.Sprintf("error: %v", err) @@ -324,7 +324,7 @@ func (s *DockerSwarmSuite) TestAPISwarmLeaderElection(c *testing.T) { ) var lastErr error checkLeader := func(nodes ...*daemon.Daemon) checkF { - return func(t *testing.T) (interface{}, string) { + return func(t *testing.T) (any, string) { // clear these out before each run leader = nil followers = nil @@ -412,7 +412,7 @@ func (s *DockerSwarmSuite) TestAPISwarmRaftQuorum(c *testing.T) { defer cli.Close() // d1 will eventually step down from leader because there is no longer an active quorum, wait for that to happen - poll.WaitOn(c, pollCheck(c, func(t *testing.T) (interface{}, string) { + poll.WaitOn(c, pollCheck(c, func(t *testing.T) (any, string) { _, err := cli.ServiceCreate(testutil.GetContext(t), service.Spec, swarm.ServiceCreateOptions{}) return err.Error(), "" }, checker.Contains("Make sure more than half of the managers are online.")), poll.WithTimeout(defaultReconciliationTimeout*2)) @@ -753,7 +753,7 @@ func checkClusterHealth(t *testing.T, cl []*daemon.Daemon, managerCount, workerC var info swarm.Info // check info in a poll.WaitOn(), because if the cluster doesn't have a leader, `info` will return an error - checkInfo := func(t *testing.T) (interface{}, string) { + checkInfo := func(t *testing.T) (any, string) { client := d.NewClientT(t) daemonInfo, err := client.Info(ctx) info = daemonInfo.Swarm @@ -770,7 +770,7 @@ func checkClusterHealth(t *testing.T, cl []*daemon.Daemon, managerCount, workerC var mCount, wCount int for _, n := range d.ListNodes(ctx, t) { - waitReady := func(t *testing.T) (interface{}, string) { + waitReady := func(t *testing.T) (any, string) { if n.Status.State == swarm.NodeStateReady { return true, "" } @@ -780,7 +780,7 @@ func checkClusterHealth(t *testing.T, cl []*daemon.Daemon, managerCount, workerC } poll.WaitOn(t, pollCheck(t, waitReady, checker.True()), poll.WithTimeout(defaultReconciliationTimeout)) - waitActive := func(t *testing.T) (interface{}, string) { + waitActive := func(t *testing.T) (any, string) { if n.Spec.Availability == swarm.NodeAvailabilityActive { return true, "" } diff --git a/integration-cli/docker_cli_build_test.go b/integration-cli/docker_cli_build_test.go index 4e89e3e25e..4a4fb4815a 100644 --- a/integration-cli/docker_cli_build_test.go +++ b/integration-cli/docker_cli_build_test.go @@ -107,7 +107,7 @@ func (s *DockerCLIBuildSuite) TestBuildEnvironmentReplacementVolume(c *testing.T VOLUME ${volume} `)) - var volumes map[string]interface{} + var volumes map[string]any inspectFieldAndUnmarshall(c, name, "Config.Volumes", &volumes) if _, ok := volumes[volumePath]; !ok { c.Fatal("Volume " + volumePath + " from environment not in Config.Volumes on image") @@ -127,7 +127,7 @@ func (s *DockerCLIBuildSuite) TestBuildEnvironmentReplacementExpose(c *testing.T EXPOSE ${ports} `)) - var exposedPorts map[string]interface{} + var exposedPorts map[string]any inspectFieldAndUnmarshall(c, name, "Config.ExposedPorts", &exposedPorts) exp := []int{80, 99, 100} for _, p := range exp { @@ -1621,7 +1621,7 @@ func (s *DockerCLIBuildSuite) TestBuildExposeMorePorts(c *testing.T) { // check if all the ports are saved inside Config.ExposedPorts res := inspectFieldJSON(c, name, "Config.ExposedPorts") - var exposedPorts map[string]interface{} + var exposedPorts map[string]any if err := json.Unmarshal([]byte(res), &exposedPorts); err != nil { c.Fatal(err) } @@ -4362,7 +4362,7 @@ func (s *DockerCLIBuildSuite) TestBuildBuildTimeArgExpansion(c *testing.T) { envVar, envVal, resArr) } - var resMap map[string]interface{} + var resMap map[string]any inspectFieldAndUnmarshall(c, imgName, "Config.ExposedPorts", &resMap) if _, ok := resMap[fmt.Sprintf("%s/tcp", exposeVal)]; !ok { c.Fatalf("Config.ExposedPorts value mismatch. Expected exposed port: %s/tcp, got: %v", exposeVal, resMap) diff --git a/integration-cli/docker_cli_daemon_test.go b/integration-cli/docker_cli_daemon_test.go index f787a72d75..c92b25697a 100644 --- a/integration-cli/docker_cli_daemon_test.go +++ b/integration-cli/docker_cli_daemon_test.go @@ -1379,7 +1379,7 @@ func (s *DockerDaemonSuite) TestDaemonRestartWithUnpausedRunningContainer(t *tes // Give time to containerd to process the command if we don't // the resume event might be received after we do the inspect - poll.WaitOn(t, pollCheck(t, func(*testing.T) (interface{}, string) { + poll.WaitOn(t, pollCheck(t, func(*testing.T) (any, string) { result := icmd.RunCommand("kill", "-0", strings.TrimSpace(pid)) return result.ExitCode, "" }, checker.Equals(0)), poll.WithTimeout(defaultReconciliationTimeout)) diff --git a/integration-cli/docker_cli_external_volume_driver_test.go b/integration-cli/docker_cli_external_volume_driver_test.go index 6c851f7ce1..1a38cf1932 100644 --- a/integration-cli/docker_cli_external_volume_driver_test.go +++ b/integration-cli/docker_cli_external_volume_driver_test.go @@ -74,7 +74,7 @@ type vol struct { Name string Mountpoint string Ninja bool // hack used to trigger a null volume return on `Get` - Status map[string]interface{} + Status map[string]any Options map[string]string } @@ -104,7 +104,7 @@ func newVolumePlugin(t *testing.T, name string) *volumePlugin { return pr, err } - send := func(w http.ResponseWriter, data interface{}) { + send := func(w http.ResponseWriter, data any) { switch d := data.(type) { case error: http.Error(w, d.Error(), http.StatusInternalServerError) @@ -133,7 +133,7 @@ func newVolumePlugin(t *testing.T, name string) *volumePlugin { return } _, isNinja := pr.Opts["ninja"] - status := map[string]interface{}{"Hello": "world"} + status := map[string]any{"Hello": "world"} s.vols[pr.Name] = vol{Name: pr.Name, Ninja: isNinja, Status: status, Options: pr.Opts} send(w, nil) }) diff --git a/integration-cli/docker_cli_info_test.go b/integration-cli/docker_cli_info_test.go index 4bf4c19129..762b075274 100644 --- a/integration-cli/docker_cli_info_test.go +++ b/integration-cli/docker_cli_info_test.go @@ -116,7 +116,7 @@ func (s *DockerCLIInfoSuite) TestInfoDisplaysStoppedContainers(c *testing.T) { func existingContainerStates(t *testing.T) map[string]int { out := cli.DockerCmd(t, "info", "--format", "{{json .}}").Stdout() - var m map[string]interface{} + var m map[string]any err := json.Unmarshal([]byte(out), &m) assert.NilError(t, err) res := map[string]int{} diff --git a/integration-cli/docker_cli_network_unix_test.go b/integration-cli/docker_cli_network_unix_test.go index 7b0c505bbc..d0b25b05b7 100644 --- a/integration-cli/docker_cli_network_unix_test.go +++ b/integration-cli/docker_cli_network_unix_test.go @@ -782,7 +782,7 @@ func (s *DockerNetworkSuite) TestDockerNetworkDriverOptions(c *testing.T) { assertNwIsAvailable(c, "testopt") gopts := remoteDriverNetworkRequest.Options[netlabel.GenericData] assert.Assert(c, gopts != nil) - opts, ok := gopts.(map[string]interface{}) + opts, ok := gopts.(map[string]any) assert.Equal(c, ok, true) assert.Equal(c, opts["opt1"], "drv1") assert.Equal(c, opts["opt2"], "drv2") diff --git a/integration-cli/docker_cli_prune_unix_test.go b/integration-cli/docker_cli_prune_unix_test.go index 33a8967454..8b4ef1dca4 100644 --- a/integration-cli/docker_cli_prune_unix_test.go +++ b/integration-cli/docker_cli_prune_unix_test.go @@ -35,7 +35,7 @@ func pruneNetworkAndVerify(t *testing.T, d *daemon.Daemon, kept, pruned []string assert.NilError(t, err) for _, s := range kept { - poll.WaitOn(t, pollCheck(t, func(*testing.T) (interface{}, string) { + poll.WaitOn(t, pollCheck(t, func(*testing.T) (any, string) { out, err := d.Cmd("network", "ls", "--format", "{{.Name}}") assert.NilError(t, err) return out, "" @@ -43,7 +43,7 @@ func pruneNetworkAndVerify(t *testing.T, d *daemon.Daemon, kept, pruned []string } for _, s := range pruned { - poll.WaitOn(t, pollCheck(t, func(*testing.T) (interface{}, string) { + poll.WaitOn(t, pollCheck(t, func(*testing.T) (any, string) { out, err := d.Cmd("network", "ls", "--format", "{{.Name}}") assert.NilError(t, err) return out, "" diff --git a/integration-cli/docker_cli_restart_test.go b/integration-cli/docker_cli_restart_test.go index c868fcf3e7..243c9fa9d0 100644 --- a/integration-cli/docker_cli_restart_test.go +++ b/integration-cli/docker_cli_restart_test.go @@ -32,7 +32,7 @@ func (s *DockerCLIRestartSuite) TestRestartStoppedContainer(c *testing.T) { cID := cli.DockerCmd(c, "run", "-d", "busybox", "sh", "-c", "echo foobar && exit 0").Stdout() cID = strings.TrimSpace(cID) - getLogs := func(t *testing.T) (interface{}, string) { + getLogs := func(t *testing.T) (any, string) { out := cli.DockerCmd(t, "logs", cID).Combined() return out, "" } @@ -52,7 +52,7 @@ func (s *DockerCLIRestartSuite) TestRestartRunningContainer(c *testing.T) { cID = strings.TrimSpace(cID) cli.WaitRun(c, cID) - getLogs := func(t *testing.T) (interface{}, string) { + getLogs := func(t *testing.T) (any, string) { out := cli.DockerCmd(t, "logs", cID).Combined() return out, "" } diff --git a/integration-cli/docker_cli_service_create_test.go b/integration-cli/docker_cli_service_create_test.go index cf799c6bfc..a5888c901c 100644 --- a/integration-cli/docker_cli_service_create_test.go +++ b/integration-cli/docker_cli_service_create_test.go @@ -27,13 +27,13 @@ func (s *DockerSwarmSuite) TestServiceCreateMountVolume(c *testing.T) { id := strings.TrimSpace(out) var tasks []swarm.Task - poll.WaitOn(c, pollCheck(c, func(t *testing.T) (interface{}, string) { + poll.WaitOn(c, pollCheck(c, func(t *testing.T) (any, string) { tasks = d.GetServiceTasks(ctx, t, id) return len(tasks) > 0, "" }, checker.Equals(true)), poll.WithTimeout(defaultReconciliationTimeout)) task := tasks[0] - poll.WaitOn(c, pollCheck(c, func(t *testing.T) (interface{}, string) { + poll.WaitOn(c, pollCheck(c, func(t *testing.T) (any, string) { if task.NodeID == "" || task.Status.ContainerStatus == nil { task = d.GetTask(ctx, t, task.ID) } @@ -143,13 +143,13 @@ func (s *DockerSwarmSuite) TestServiceCreateWithSecretSourceTargetPaths(c *testi assert.Equal(c, len(refs), len(testPaths)) var tasks []swarm.Task - poll.WaitOn(c, pollCheck(c, func(t *testing.T) (interface{}, string) { + poll.WaitOn(c, pollCheck(c, func(t *testing.T) (any, string) { tasks = d.GetServiceTasks(ctx, t, serviceName) return len(tasks) > 0, "" }, checker.Equals(true)), poll.WithTimeout(defaultReconciliationTimeout)) task := tasks[0] - poll.WaitOn(c, pollCheck(c, func(t *testing.T) (interface{}, string) { + poll.WaitOn(c, pollCheck(c, func(t *testing.T) (any, string) { if task.NodeID == "" || task.Status.ContainerStatus == nil { task = d.GetTask(ctx, t, task.ID) } @@ -194,13 +194,13 @@ func (s *DockerSwarmSuite) TestServiceCreateWithSecretReferencedTwice(c *testing assert.Equal(c, len(refs), 2) var tasks []swarm.Task - poll.WaitOn(c, pollCheck(c, func(t *testing.T) (interface{}, string) { + poll.WaitOn(c, pollCheck(c, func(t *testing.T) (any, string) { tasks = d.GetServiceTasks(ctx, t, serviceName) return len(tasks) > 0, "" }, checker.Equals(true)), poll.WithTimeout(defaultReconciliationTimeout)) task := tasks[0] - poll.WaitOn(c, pollCheck(c, func(t *testing.T) (interface{}, string) { + poll.WaitOn(c, pollCheck(c, func(t *testing.T) (any, string) { if task.NodeID == "" || task.Status.ContainerStatus == nil { task = d.GetTask(ctx, t, task.ID) } @@ -293,13 +293,13 @@ func (s *DockerSwarmSuite) TestServiceCreateWithConfigSourceTargetPaths(c *testi assert.Equal(c, len(refs), len(testPaths)) var tasks []swarm.Task - poll.WaitOn(c, pollCheck(c, func(t *testing.T) (interface{}, string) { + poll.WaitOn(c, pollCheck(c, func(t *testing.T) (any, string) { tasks = d.GetServiceTasks(ctx, t, serviceName) return len(tasks) > 0, "" }, checker.Equals(true)), poll.WithTimeout(defaultReconciliationTimeout)) task := tasks[0] - poll.WaitOn(c, pollCheck(c, func(t *testing.T) (interface{}, string) { + poll.WaitOn(c, pollCheck(c, func(t *testing.T) (any, string) { if task.NodeID == "" || task.Status.ContainerStatus == nil { task = d.GetTask(ctx, t, task.ID) } @@ -344,13 +344,13 @@ func (s *DockerSwarmSuite) TestServiceCreateWithConfigReferencedTwice(c *testing assert.Equal(c, len(refs), 2) var tasks []swarm.Task - poll.WaitOn(c, pollCheck(c, func(t *testing.T) (interface{}, string) { + poll.WaitOn(c, pollCheck(c, func(t *testing.T) (any, string) { tasks = d.GetServiceTasks(ctx, t, serviceName) return len(tasks) > 0, "" }, checker.Equals(true)), poll.WithTimeout(defaultReconciliationTimeout)) task := tasks[0] - poll.WaitOn(c, pollCheck(c, func(t *testing.T) (interface{}, string) { + poll.WaitOn(c, pollCheck(c, func(t *testing.T) (any, string) { if task.NodeID == "" || task.Status.ContainerStatus == nil { task = d.GetTask(ctx, t, task.ID) } @@ -377,13 +377,13 @@ func (s *DockerSwarmSuite) TestServiceCreateMountTmpfs(c *testing.T) { id := strings.TrimSpace(out) var tasks []swarm.Task - poll.WaitOn(c, pollCheck(c, func(t *testing.T) (interface{}, string) { + poll.WaitOn(c, pollCheck(c, func(t *testing.T) (any, string) { tasks = d.GetServiceTasks(ctx, t, id) return len(tasks) > 0, "" }, checker.Equals(true)), poll.WithTimeout(defaultReconciliationTimeout)) task := tasks[0] - poll.WaitOn(c, pollCheck(c, func(t *testing.T) (interface{}, string) { + poll.WaitOn(c, pollCheck(c, func(t *testing.T) (any, string) { if task.NodeID == "" || task.Status.ContainerStatus == nil { task = d.GetTask(ctx, t, task.ID) } @@ -434,13 +434,13 @@ func (s *DockerSwarmSuite) TestServiceCreateWithNetworkAlias(c *testing.T) { id := strings.TrimSpace(out) var tasks []swarm.Task - poll.WaitOn(c, pollCheck(c, func(t *testing.T) (interface{}, string) { + poll.WaitOn(c, pollCheck(c, func(t *testing.T) (any, string) { tasks = d.GetServiceTasks(ctx, t, id) return len(tasks) > 0, "" }, checker.Equals(true)), poll.WithTimeout(defaultReconciliationTimeout)) task := tasks[0] - poll.WaitOn(c, pollCheck(c, func(t *testing.T) (interface{}, string) { + poll.WaitOn(c, pollCheck(c, func(t *testing.T) (any, string) { if task.NodeID == "" || task.Status.ContainerStatus == nil { task = d.GetTask(ctx, t, task.ID) } diff --git a/integration-cli/docker_cli_service_health_test.go b/integration-cli/docker_cli_service_health_test.go index 00ca846a4e..50adc1c5ab 100644 --- a/integration-cli/docker_cli_service_health_test.go +++ b/integration-cli/docker_cli_service_health_test.go @@ -42,7 +42,7 @@ func (s *DockerSwarmSuite) TestServiceHealthRun(c *testing.T) { id := strings.TrimSpace(out) var tasks []swarm.Task - poll.WaitOn(c, pollCheck(c, func(t *testing.T) (interface{}, string) { + poll.WaitOn(c, pollCheck(c, func(t *testing.T) (any, string) { tasks = d.GetServiceTasks(ctx, t, id) return tasks, "" }, checker.HasLen(1)), poll.WithTimeout(defaultReconciliationTimeout)) @@ -50,7 +50,7 @@ func (s *DockerSwarmSuite) TestServiceHealthRun(c *testing.T) { task := tasks[0] // wait for task to start - poll.WaitOn(c, pollCheck(c, func(t *testing.T) (interface{}, string) { + poll.WaitOn(c, pollCheck(c, func(t *testing.T) (any, string) { task = d.GetTask(ctx, t, task.ID) return task.Status.State, "" }, checker.Equals(swarm.TaskStateRunning)), poll.WithTimeout(defaultReconciliationTimeout)) @@ -58,7 +58,7 @@ func (s *DockerSwarmSuite) TestServiceHealthRun(c *testing.T) { containerID := task.Status.ContainerStatus.ContainerID // wait for container to be healthy - poll.WaitOn(c, pollCheck(c, func(t *testing.T) (interface{}, string) { + poll.WaitOn(c, pollCheck(c, func(t *testing.T) (any, string) { out, _ := d.Cmd("inspect", "--format={{.State.Health.Status}}", containerID) return strings.TrimSpace(out), "" }, checker.Equals("healthy")), poll.WithTimeout(defaultReconciliationTimeout)) @@ -66,13 +66,13 @@ func (s *DockerSwarmSuite) TestServiceHealthRun(c *testing.T) { // make it fail d.Cmd("exec", containerID, "rm", "/status") // wait for container to be unhealthy - poll.WaitOn(c, pollCheck(c, func(t *testing.T) (interface{}, string) { + poll.WaitOn(c, pollCheck(c, func(t *testing.T) (any, string) { out, _ := d.Cmd("inspect", "--format={{.State.Health.Status}}", containerID) return strings.TrimSpace(out), "" }, checker.Equals("unhealthy")), poll.WithTimeout(defaultReconciliationTimeout)) // Task should be terminated - poll.WaitOn(c, pollCheck(c, func(t *testing.T) (interface{}, string) { + poll.WaitOn(c, pollCheck(c, func(t *testing.T) (any, string) { task = d.GetTask(ctx, t, task.ID) return task.Status.State, "" }, checker.Equals(swarm.TaskStateFailed)), poll.WithTimeout(defaultReconciliationTimeout)) @@ -105,7 +105,7 @@ func (s *DockerSwarmSuite) TestServiceHealthStart(c *testing.T) { id := strings.TrimSpace(out) var tasks []swarm.Task - poll.WaitOn(c, pollCheck(c, func(t *testing.T) (interface{}, string) { + poll.WaitOn(c, pollCheck(c, func(t *testing.T) (any, string) { tasks = d.GetServiceTasks(ctx, t, id) return tasks, "" }, checker.HasLen(1)), poll.WithTimeout(defaultReconciliationTimeout)) @@ -113,7 +113,7 @@ func (s *DockerSwarmSuite) TestServiceHealthStart(c *testing.T) { task := tasks[0] // wait for task to start - poll.WaitOn(c, pollCheck(c, func(t *testing.T) (interface{}, string) { + poll.WaitOn(c, pollCheck(c, func(t *testing.T) (any, string) { task = d.GetTask(ctx, t, task.ID) return task.Status.State, "" }, checker.Equals(swarm.TaskStateStarting)), poll.WithTimeout(defaultReconciliationTimeout)) @@ -121,7 +121,7 @@ func (s *DockerSwarmSuite) TestServiceHealthStart(c *testing.T) { containerID := task.Status.ContainerStatus.ContainerID // wait for health check to work - poll.WaitOn(c, pollCheck(c, func(t *testing.T) (interface{}, string) { + poll.WaitOn(c, pollCheck(c, func(t *testing.T) (any, string) { out, _ := d.Cmd("inspect", "--format={{.State.Health.FailingStreak}}", containerID) failingStreak, _ := strconv.Atoi(strings.TrimSpace(out)) return failingStreak, "" @@ -135,7 +135,7 @@ func (s *DockerSwarmSuite) TestServiceHealthStart(c *testing.T) { d.Cmd("exec", containerID, "touch", "/status") // Task should be at running status - poll.WaitOn(c, pollCheck(c, func(t *testing.T) (interface{}, string) { + poll.WaitOn(c, pollCheck(c, func(t *testing.T) (any, string) { task = d.GetTask(ctx, t, task.ID) return task.Status.State, "" }, checker.Equals(swarm.TaskStateRunning)), poll.WithTimeout(defaultReconciliationTimeout)) diff --git a/integration-cli/docker_cli_service_logs_test.go b/integration-cli/docker_cli_service_logs_test.go index dddabff88b..8893f391c9 100644 --- a/integration-cli/docker_cli_service_logs_test.go +++ b/integration-cli/docker_cli_service_logs_test.go @@ -56,8 +56,8 @@ func (s *DockerSwarmSuite) TestServiceLogs(c *testing.T) { // countLogLines returns a closure that can be used with poll.WaitOn() to // verify that a minimum number of expected container log messages have been // output. -func countLogLines(d *daemon.Daemon, name string) func(*testing.T) (interface{}, string) { - return func(t *testing.T) (interface{}, string) { +func countLogLines(d *daemon.Daemon, name string) func(*testing.T) (any, string) { + return func(t *testing.T) (any, string) { result := icmd.RunCmd(d.Command("service", "logs", "-t", "--raw", name)) result.Assert(t, icmd.Expected{}) // if this returns an emptystring, trying to split it later will return diff --git a/integration-cli/docker_cli_swarm_test.go b/integration-cli/docker_cli_swarm_test.go index 766c220b07..77210c532b 100644 --- a/integration-cli/docker_cli_swarm_test.go +++ b/integration-cli/docker_cli_swarm_test.go @@ -416,7 +416,7 @@ func (s *DockerSwarmSuite) TestSwarmContainerAttachByNetworkId(c *testing.T) { out, err = d.Cmd("network", "rm", "testnet") assert.NilError(c, err, out) - checkNetwork := func(*testing.T) (interface{}, string) { + checkNetwork := func(*testing.T) (any, string) { out, err := d.Cmd("network", "ls") assert.NilError(c, err) return out, "" @@ -583,7 +583,7 @@ func (s *DockerSwarmSuite) TestSwarmTaskListFilter(c *testing.T) { filter := "name=redis-cluster" - checkNumTasks := func(*testing.T) (interface{}, string) { + checkNumTasks := func(*testing.T) (any, string) { out, err := d.Cmd("service", "ps", "--filter", filter, name) assert.NilError(c, err, out) return len(strings.Split(out, "\n")) - 2, "" // includes header and nl in last line @@ -1058,8 +1058,8 @@ func getNodeStatus(t *testing.T, d *daemon.Daemon) swarm.LocalNodeState { return info.LocalNodeState } -func checkKeyIsEncrypted(d *daemon.Daemon) func(*testing.T) (interface{}, string) { - return func(t *testing.T) (interface{}, string) { +func checkKeyIsEncrypted(d *daemon.Daemon) func(*testing.T) (any, string) { + return func(t *testing.T) (any, string) { keyBytes, err := os.ReadFile(filepath.Join(d.Folder, "root", "swarm", "certificates", "swarm-node.key")) if err != nil { return fmt.Errorf("error reading key: %v", err), "" @@ -1294,7 +1294,7 @@ func (s *DockerSwarmSuite) TestSwarmJoinPromoteLocked(c *testing.T) { // (because we never want a manager TLS key to be on disk unencrypted if the cluster // is set to autolock) poll.WaitOn(c, pollCheck(c, d3.CheckControlAvailable(ctx), checker.False()), poll.WithTimeout(defaultReconciliationTimeout)) - poll.WaitOn(c, pollCheck(c, func(t *testing.T) (interface{}, string) { + poll.WaitOn(c, pollCheck(c, func(t *testing.T) (any, string) { certBytes, err := os.ReadFile(filepath.Join(d3.Folder, "root", "swarm", "certificates", "swarm-node.crt")) if err != nil { return "", fmt.Sprintf("error: %v", err) diff --git a/integration-cli/docker_utils_test.go b/integration-cli/docker_utils_test.go index 7168a8cbd3..79f469ada9 100644 --- a/integration-cli/docker_utils_test.go +++ b/integration-cli/docker_utils_test.go @@ -69,7 +69,7 @@ func getContainerCount(t *testing.T) int { return 0 } -func inspectFieldAndUnmarshall(t *testing.T, name, field string, output interface{}) { +func inspectFieldAndUnmarshall(t *testing.T, name, field string, output any) { t.Helper() str := inspectFieldJSON(t, name, field) err := json.Unmarshal([]byte(str), output) @@ -370,11 +370,11 @@ func getErrorMessage(t *testing.T, body []byte) string { } type ( - checkF func(*testing.T) (interface{}, string) - reducer func(...interface{}) interface{} + checkF func(*testing.T) (any, string) + reducer func(...any) any ) -func pollCheck(t *testing.T, f checkF, compare func(x interface{}) assert.BoolOrComparison) poll.Check { +func pollCheck(t *testing.T, f checkF, compare func(x any) assert.BoolOrComparison) poll.Check { return func(poll.LogT) poll.Result { t.Helper() v, comment := f(t) @@ -396,9 +396,9 @@ func pollCheck(t *testing.T, f checkF, compare func(x interface{}) assert.BoolOr } func reducedCheck(r reducer, funcs ...checkF) checkF { - return func(t *testing.T) (interface{}, string) { + return func(t *testing.T) (any, string) { t.Helper() - var values []interface{} + var values []any var comments []string for _, f := range funcs { v, comment := f(t) @@ -411,7 +411,7 @@ func reducedCheck(r reducer, funcs ...checkF) checkF { } } -func sumAsIntegers(vals ...interface{}) interface{} { +func sumAsIntegers(vals ...any) any { var s int for _, v := range vals { s += v.(int) diff --git a/integration/container/inspect_test.go b/integration/container/inspect_test.go index 65ea7c9d0a..01b0aeaf99 100644 --- a/integration/container/inspect_test.go +++ b/integration/container/inspect_test.go @@ -170,7 +170,7 @@ func TestContainerInspectWithRaw(t *testing.T) { assert.NilError(t, err) assert.Check(t, is.Equal(ctrInspect.ID, ctrID)) - var rawInspect map[string]interface{} + var rawInspect map[string]any err = json.Unmarshal(raw, &rawInspect) assert.NilError(t, err, "Should produce valid JSON") diff --git a/integration/image/inspect_test.go b/integration/image/inspect_test.go index 053459c692..d3d20ffaf4 100644 --- a/integration/image/inspect_test.go +++ b/integration/image/inspect_test.go @@ -32,7 +32,7 @@ func TestImageInspectEmptyTagsAndDigests(t *testing.T) { assert.Check(t, is.Len(inspect.RepoTags, 0)) assert.Check(t, is.Len(inspect.RepoDigests, 0)) - var rawJson map[string]interface{} + var rawJson map[string]any err = json.Unmarshal(raw.Bytes(), &rawJson) assert.NilError(t, err) diff --git a/internal/test/suite/suite.go b/internal/test/suite/suite.go index fbf219fb8a..cc0dab41a4 100644 --- a/internal/test/suite/suite.go +++ b/internal/test/suite/suite.go @@ -19,7 +19,7 @@ var TimeoutFlag = flag.Duration("timeout", 0, "DO NOT USE") var typTestingT = reflect.TypeOf(new(testing.T)) // Run takes a testing suite and runs all of the tests attached to it. -func Run(ctx context.Context, t *testing.T, suite interface{}) { +func Run(ctx context.Context, t *testing.T, suite any) { defer failOnPanic(t) ctx = testutil.StartSpan(ctx, t) @@ -71,7 +71,7 @@ func Run(ctx context.Context, t *testing.T, suite interface{}) { } } -func getSetupAllSuite(suite interface{}) (SetupAllSuite, bool) { +func getSetupAllSuite(suite any) (SetupAllSuite, bool) { setupAllSuite, ok := suite.(SetupAllSuite) if ok { return setupAllSuite, ok @@ -86,7 +86,7 @@ func getSetupAllSuite(suite interface{}) (SetupAllSuite, bool) { return nil, false } -func getSetupTestSuite(suite interface{}) (SetupTestSuite, bool) { +func getSetupTestSuite(suite any) (SetupTestSuite, bool) { setupAllTest, ok := suite.(SetupTestSuite) if ok { return setupAllTest, ok @@ -101,7 +101,7 @@ func getSetupTestSuite(suite interface{}) (SetupTestSuite, bool) { return nil, false } -func getTearDownTestSuite(suite interface{}) (TearDownTestSuite, bool) { +func getTearDownTestSuite(suite any) (TearDownTestSuite, bool) { tearDownTest, ok := suite.(TearDownTestSuite) if ok { return tearDownTest, ok @@ -116,7 +116,7 @@ func getTearDownTestSuite(suite interface{}) (TearDownTestSuite, bool) { return nil, false } -func getTeardownAllSuite(suite interface{}) (TearDownAllSuite, bool) { +func getTeardownAllSuite(suite any) (TearDownAllSuite, bool) { tearDownAll, ok := suite.(TearDownAllSuite) if ok { return tearDownAll, ok diff --git a/pkg/plugins/client.go b/pkg/plugins/client.go index d6cab96c3b..7fffc01430 100644 --- a/pkg/plugins/client.go +++ b/pkg/plugins/client.go @@ -119,12 +119,12 @@ func WithRequestTimeout(t time.Duration) func(*RequestOpts) { // Call calls the specified method with the specified arguments for the plugin. // It will retry for 30 seconds if a failure occurs when calling. -func (c *Client) Call(serviceMethod string, args, ret interface{}) error { +func (c *Client) Call(serviceMethod string, args, ret any) error { return c.CallWithOptions(serviceMethod, args, ret) } // CallWithOptions is just like call except it takes options -func (c *Client) CallWithOptions(serviceMethod string, args interface{}, ret interface{}, opts ...func(*RequestOpts)) error { +func (c *Client) CallWithOptions(serviceMethod string, args any, ret any, opts ...func(*RequestOpts)) error { var buf bytes.Buffer if args != nil { if err := json.NewEncoder(&buf).Encode(args); err != nil { @@ -146,7 +146,7 @@ func (c *Client) CallWithOptions(serviceMethod string, args interface{}, ret int } // Stream calls the specified method with the specified arguments for the plugin and returns the response body -func (c *Client) Stream(serviceMethod string, args interface{}) (io.ReadCloser, error) { +func (c *Client) Stream(serviceMethod string, args any) (io.ReadCloser, error) { var buf bytes.Buffer if err := json.NewEncoder(&buf).Encode(args); err != nil { return nil, err @@ -155,7 +155,7 @@ func (c *Client) Stream(serviceMethod string, args interface{}) (io.ReadCloser, } // SendFile calls the specified method, and passes through the IO stream -func (c *Client) SendFile(serviceMethod string, data io.Reader, ret interface{}) error { +func (c *Client) SendFile(serviceMethod string, data io.Reader, ret any) error { body, err := c.callWithRetry(serviceMethod, data, true) if err != nil { return err diff --git a/pkg/plugins/pluginrpc-gen/fixtures/foo.go b/pkg/plugins/pluginrpc-gen/fixtures/foo.go index cd54d92a4c..1eef2eef42 100644 --- a/pkg/plugins/pluginrpc-gen/fixtures/foo.go +++ b/pkg/plugins/pluginrpc-gen/fixtures/foo.go @@ -13,7 +13,7 @@ type wobble struct { } // Fooer is an empty interface used for tests. -type Fooer interface{} +type Fooer interface{} //nolint:revive // any Alias is not supported yet // Fooer2 is an interface used for tests. type Fooer2 interface { diff --git a/pkg/plugins/pluginrpc-gen/parser.go b/pkg/plugins/pluginrpc-gen/parser.go index 02d71d6eb2..2e7dde3e6c 100644 --- a/pkg/plugins/pluginrpc-gen/parser.go +++ b/pkg/plugins/pluginrpc-gen/parser.go @@ -16,7 +16,7 @@ var errBadReturn = errors.New("found return arg with no name: all args must be n type errUnexpectedType struct { expected string - actual interface{} + actual any } func (e errUnexpectedType) Error() string { diff --git a/pkg/pools/pools.go b/pkg/pools/pools.go index ba8b8614be..a9c10ecf0a 100644 --- a/pkg/pools/pools.go +++ b/pkg/pools/pools.go @@ -37,7 +37,7 @@ type BufioReaderPool struct { func newBufioReaderPoolWithSize(size int) *BufioReaderPool { return &BufioReaderPool{ pool: sync.Pool{ - New: func() interface{} { return bufio.NewReaderSize(nil, size) }, + New: func() any { return bufio.NewReaderSize(nil, size) }, }, } } @@ -62,7 +62,7 @@ type bufferPool struct { func newBufferPoolWithSize(size int) *bufferPool { return &bufferPool{ pool: sync.Pool{ - New: func() interface{} { s := make([]byte, size); return &s }, + New: func() any { s := make([]byte, size); return &s }, }, } } @@ -105,7 +105,7 @@ type BufioWriterPool struct { func newBufioWriterPoolWithSize(size int) *BufioWriterPool { return &BufioWriterPool{ pool: sync.Pool{ - New: func() interface{} { return bufio.NewWriterSize(nil, size) }, + New: func() any { return bufio.NewWriterSize(nil, size) }, }, } } diff --git a/testutil/request/ops.go b/testutil/request/ops.go index be4e502ccb..2f98ae6383 100644 --- a/testutil/request/ops.go +++ b/testutil/request/ops.go @@ -64,7 +64,7 @@ func JSON(o *Options) { // JSONBody creates a modifier that encodes the specified data to a JSON string and set it as request body. It also sets // the Content-Type header of the request. -func JSONBody(data interface{}) func(*Options) { +func JSONBody(data any) func(*Options) { return With(func(req *http.Request) error { jsonData := bytes.NewBuffer(nil) if err := json.NewEncoder(jsonData).Encode(data); err != nil { diff --git a/vendor/github.com/moby/moby/client/hijack.go b/vendor/github.com/moby/moby/client/hijack.go index 46608d93cb..f06f53a323 100644 --- a/vendor/github.com/moby/moby/client/hijack.go +++ b/vendor/github.com/moby/moby/client/hijack.go @@ -14,7 +14,7 @@ import ( ) // postHijacked sends a POST request and hijacks the connection. -func (cli *Client) postHijacked(ctx context.Context, path string, query url.Values, body interface{}, headers map[string][]string) (HijackedResponse, error) { +func (cli *Client) postHijacked(ctx context.Context, path string, query url.Values, body any, headers map[string][]string) (HijackedResponse, error) { jsonBody, err := jsonEncode(body) if err != nil { return HijackedResponse{}, err diff --git a/vendor/github.com/moby/moby/client/request.go b/vendor/github.com/moby/moby/client/request.go index 803ff6d2a6..45be416a29 100644 --- a/vendor/github.com/moby/moby/client/request.go +++ b/vendor/github.com/moby/moby/client/request.go @@ -28,7 +28,7 @@ func (cli *Client) get(ctx context.Context, path string, query url.Values, heade } // post sends an http POST request to the API. -func (cli *Client) post(ctx context.Context, path string, query url.Values, body interface{}, headers http.Header) (*http.Response, error) { +func (cli *Client) post(ctx context.Context, path string, query url.Values, body any, headers http.Header) (*http.Response, error) { jsonBody, headers, err := prepareJSONRequest(body, headers) if err != nil { return nil, err @@ -40,7 +40,7 @@ func (cli *Client) postRaw(ctx context.Context, path string, query url.Values, b return cli.sendRequest(ctx, http.MethodPost, path, query, body, headers) } -func (cli *Client) put(ctx context.Context, path string, query url.Values, body interface{}, headers http.Header) (*http.Response, error) { +func (cli *Client) put(ctx context.Context, path string, query url.Values, body any, headers http.Header) (*http.Response, error) { jsonBody, headers, err := prepareJSONRequest(body, headers) if err != nil { return nil, err @@ -70,7 +70,7 @@ func (cli *Client) delete(ctx context.Context, path string, query url.Values, he // // TODO(thaJeztah): should this return an error if a different Content-Type is already set? // TODO(thaJeztah): is "nil" the appropriate approach for an empty body, or should we use [http.NoBody] (or similar)? -func prepareJSONRequest(body interface{}, headers http.Header) (io.Reader, http.Header, error) { +func prepareJSONRequest(body any, headers http.Header) (io.Reader, http.Header, error) { if body == nil { return nil, headers, nil } @@ -309,7 +309,7 @@ func (cli *Client) addHeaders(req *http.Request, headers http.Header) *http.Requ return req } -func jsonEncode(data interface{}) (io.Reader, error) { +func jsonEncode(data any) (io.Reader, error) { var params bytes.Buffer if data != nil { if err := json.NewEncoder(¶ms).Encode(data); err != nil {