Browse Source

daemon: format code with gofumpt

Formatting the code with https://github.com/mvdan/gofumpt

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Sebastiaan van Stijn 3 years ago
parent
commit
210932b3bf

+ 2 - 2
daemon/checkpoint.go

@@ -31,7 +31,7 @@ func getCheckpointDir(checkDir, checkpointID, ctrName, ctrID, ctrCheckpointDir s
 		case err == nil && stat.IsDir():
 			err2 = fmt.Errorf("checkpoint with name %s already exists for container %s", checkpointID, ctrName)
 		case err != nil && os.IsNotExist(err):
-			err2 = os.MkdirAll(checkpointAbsDir, 0700)
+			err2 = os.MkdirAll(checkpointAbsDir, 0o700)
 		case err != nil:
 			err2 = err
 		default:
@@ -111,7 +111,7 @@ func (daemon *Daemon) CheckpointList(name string, config types.CheckpointListOpt
 		return nil, err
 	}
 
-	if err := os.MkdirAll(checkpointDir, 0755); err != nil {
+	if err := os.MkdirAll(checkpointDir, 0o755); err != nil {
 		return nil, err
 	}
 

+ 0 - 1
daemon/container_operations.go

@@ -685,7 +685,6 @@ func cleanOperationalData(es *network.EndpointSettings) {
 }
 
 func (daemon *Daemon) updateNetworkConfig(container *container.Container, n libnetwork.Network, endpointConfig *networktypes.EndpointSettings, updateSettings bool) error {
-
 	if containertypes.NetworkMode(n.Name()).IsUserDefined() {
 		addShortID := true
 		shortID := stringid.TruncateID(container.ID)

+ 5 - 5
daemon/container_operations_unix.go

@@ -141,7 +141,7 @@ func (daemon *Daemon) setupIpcDirs(c *container.Container) error {
 				return err
 			}
 
-			if err := idtools.MkdirAllAndChown(shmPath, 0700, rootIDs); err != nil {
+			if err := idtools.MkdirAllAndChown(shmPath, 0o700, rootIDs); err != nil {
 				return err
 			}
 
@@ -196,7 +196,7 @@ func (daemon *Daemon) setupSecretDir(c *container.Container) (setupErr error) {
 		if err != nil {
 			return errors.Wrap(err, "error getting secret file path")
 		}
-		if err := idtools.MkdirAllAndChown(filepath.Dir(fPath), 0700, rootIDs); err != nil {
+		if err := idtools.MkdirAllAndChown(filepath.Dir(fPath), 0o700, rootIDs); err != nil {
 			return errors.Wrap(err, "error creating secret mount path")
 		}
 
@@ -247,7 +247,7 @@ func (daemon *Daemon) setupSecretDir(c *container.Container) (setupErr error) {
 		if err != nil {
 			return errors.Wrap(err, "error getting config file path for container")
 		}
-		if err := idtools.MkdirAllAndChown(filepath.Dir(fPath), 0700, rootIDs); err != nil {
+		if err := idtools.MkdirAllAndChown(filepath.Dir(fPath), 0o700, rootIDs); err != nil {
 			return errors.Wrap(err, "error creating config mount path")
 		}
 
@@ -294,7 +294,7 @@ func (daemon *Daemon) createSecretsDir(c *container.Container) error {
 	}
 
 	// create tmpfs
-	if err := idtools.MkdirAllAndChown(dir, 0700, rootIDs); err != nil {
+	if err := idtools.MkdirAllAndChown(dir, 0o700, rootIDs); err != nil {
 		return errors.Wrap(err, "error creating secret local mount path")
 	}
 
@@ -461,5 +461,5 @@ func (daemon *Daemon) setupContainerMountsRoot(c *container.Container) error {
 	if err != nil {
 		return err
 	}
-	return idtools.MkdirAllAndChown(p, 0710, idtools.Identity{UID: idtools.CurrentIdentity().UID, GID: daemon.IdentityMapping().RootPair().GID})
+	return idtools.MkdirAllAndChown(p, 0o710, idtools.Identity{UID: idtools.CurrentIdentity().UID, GID: daemon.IdentityMapping().RootPair().GID})
 }

+ 0 - 1
daemon/container_operations_windows.go

@@ -169,7 +169,6 @@ func (daemon *Daemon) setupPathsAndSandboxOptions(container *container.Container
 }
 
 func (daemon *Daemon) initializeNetworkingPaths(container *container.Container, nc *container.Container) error {
-
 	if nc.HostConfig.Isolation.IsHyperV() {
 		return fmt.Errorf("sharing of hyperv containers network is not supported")
 	}

+ 2 - 2
daemon/content.go

@@ -17,10 +17,10 @@ import (
 )
 
 func (daemon *Daemon) configureLocalContentStore(ns string) (content.Store, leases.Manager, error) {
-	if err := os.MkdirAll(filepath.Join(daemon.root, "content"), 0700); err != nil {
+	if err := os.MkdirAll(filepath.Join(daemon.root, "content"), 0o700); err != nil {
 		return nil, nil, errors.Wrap(err, "error creating dir for content store")
 	}
-	db, err := bbolt.Open(filepath.Join(daemon.root, "content", "metadata.db"), 0600, nil)
+	db, err := bbolt.Open(filepath.Join(daemon.root, "content", "metadata.db"), 0o600, nil)
 	if err != nil {
 		return nil, nil, errors.Wrap(err, "error opening bolt db for content metadata store")
 	}

+ 2 - 2
daemon/create.go

@@ -197,10 +197,10 @@ func (daemon *Daemon) create(ctx context.Context, daemonCfg *config.Config, opts
 	}
 
 	current := idtools.CurrentIdentity()
-	if err := idtools.MkdirAndChown(ctr.Root, 0710, idtools.Identity{UID: current.UID, GID: daemon.IdentityMapping().RootPair().GID}); err != nil {
+	if err := idtools.MkdirAndChown(ctr.Root, 0o710, idtools.Identity{UID: current.UID, GID: daemon.IdentityMapping().RootPair().GID}); err != nil {
 		return nil, err
 	}
-	if err := idtools.MkdirAndChown(ctr.CheckpointDir(), 0700, current); err != nil {
+	if err := idtools.MkdirAndChown(ctr.CheckpointDir(), 0o700, current); err != nil {
 		return nil, err
 	}
 

+ 3 - 3
daemon/daemon_linux_test.go

@@ -258,9 +258,9 @@ func TestRootMountCleanup(t *testing.T) {
 	cfg.ExecRoot = filepath.Join(testRoot, "exec")
 	cfg.Root = filepath.Join(testRoot, "daemon")
 
-	err = os.Mkdir(cfg.ExecRoot, 0755)
+	err = os.Mkdir(cfg.ExecRoot, 0o755)
 	assert.NilError(t, err)
-	err = os.Mkdir(cfg.Root, 0755)
+	err = os.Mkdir(cfg.Root, 0o755)
 	assert.NilError(t, err)
 
 	d := &Daemon{root: cfg.Root}
@@ -319,7 +319,7 @@ func TestRootMountCleanup(t *testing.T) {
 		err = mount.MakeShared(testRoot)
 		assert.NilError(t, err)
 		defer mount.MakePrivate(testRoot)
-		err = os.WriteFile(unmountFile, nil, 0644)
+		err = os.WriteFile(unmountFile, nil, 0o644)
 		assert.NilError(t, err)
 
 		err = setupDaemonRootPropagation(&cfg.Config)

+ 3 - 3
daemon/daemon_test.go

@@ -150,7 +150,7 @@ func TestContainerInitDNS(t *testing.T) {
 
 	containerID := "d59df5276e7b219d510fe70565e0404bc06350e0d4b43fe961f22f339980170e"
 	containerPath := filepath.Join(tmp, containerID)
-	if err := os.MkdirAll(containerPath, 0755); err != nil {
+	if err := os.MkdirAll(containerPath, 0o755); err != nil {
 		t.Fatal(err)
 	}
 
@@ -176,7 +176,7 @@ func TestContainerInitDNS(t *testing.T) {
 	if err != nil {
 		t.Fatal(err)
 	}
-	if err = os.WriteFile(configPath, []byte(config), 0644); err != nil {
+	if err = os.WriteFile(configPath, []byte(config), 0o644); err != nil {
 		t.Fatal(err)
 	}
 
@@ -189,7 +189,7 @@ func TestContainerInitDNS(t *testing.T) {
 	if err != nil {
 		t.Fatal(err)
 	}
-	if err = os.WriteFile(hostConfigPath, []byte(hostConfig), 0644); err != nil {
+	if err = os.WriteFile(hostConfigPath, []byte(hostConfig), 0o644); err != nil {
 		t.Fatal(err)
 	}
 

+ 8 - 8
daemon/daemon_unix.go

@@ -1213,19 +1213,19 @@ func setupDaemonRoot(config *config.Config, rootDir string, remappedRoot idtools
 	// layer content subtrees.
 	if _, err := os.Stat(rootDir); err == nil {
 		// root current exists; verify the access bits are correct by setting them
-		if err = os.Chmod(rootDir, 0711); err != nil {
+		if err = os.Chmod(rootDir, 0o711); err != nil {
 			return err
 		}
 	} else if os.IsNotExist(err) {
 		// no root exists yet, create it 0711 with root:root ownership
-		if err := os.MkdirAll(rootDir, 0711); err != nil {
+		if err := os.MkdirAll(rootDir, 0o711); err != nil {
 			return err
 		}
 	}
 
 	id := idtools.Identity{UID: idtools.CurrentIdentity().UID, GID: remappedRoot.GID}
 	// First make sure the current root dir has the correct perms.
-	if err := idtools.MkdirAllAndChown(config.Root, 0710, id); err != nil {
+	if err := idtools.MkdirAllAndChown(config.Root, 0o710, id); err != nil {
 		return errors.Wrapf(err, "could not create or set daemon root permissions: %s", config.Root)
 	}
 
@@ -1237,7 +1237,7 @@ func setupDaemonRoot(config *config.Config, rootDir string, remappedRoot idtools
 		config.Root = filepath.Join(rootDir, fmt.Sprintf("%d.%d", remappedRoot.UID, remappedRoot.GID))
 		log.G(context.TODO()).Debugf("Creating user namespaced daemon root: %s", config.Root)
 		// Create the root directory if it doesn't exist
-		if err := idtools.MkdirAllAndChown(config.Root, 0710, id); err != nil {
+		if err := idtools.MkdirAllAndChown(config.Root, 0o710, id); err != nil {
 			return fmt.Errorf("Cannot create daemon root: %s: %v", config.Root, err)
 		}
 		// we also need to verify that any pre-existing directories in the path to
@@ -1323,11 +1323,11 @@ func setupDaemonRootPropagation(cfg *config.Config) error {
 		return nil
 	}
 
-	if err := os.MkdirAll(filepath.Dir(cleanupFile), 0700); err != nil {
+	if err := os.MkdirAll(filepath.Dir(cleanupFile), 0o700); err != nil {
 		return errors.Wrap(err, "error creating dir to store mount cleanup file")
 	}
 
-	if err := os.WriteFile(cleanupFile, nil, 0600); err != nil {
+	if err := os.WriteFile(cleanupFile, nil, 0o600); err != nil {
 		return errors.Wrap(err, "error writing file to signal mount cleanup on shutdown")
 	}
 	return nil
@@ -1446,7 +1446,7 @@ func (daemon *Daemon) initCPURtController(cfg *config.Config, mnt, path string)
 	}
 
 	path = filepath.Join(mnt, path)
-	if err := os.MkdirAll(path, 0755); err != nil {
+	if err := os.MkdirAll(path, 0o755); err != nil {
 		return err
 	}
 	if err := maybeCreateCPURealTimeFile(cfg.CPURealtimePeriod, "cpu.rt_period_us", path); err != nil {
@@ -1459,7 +1459,7 @@ func maybeCreateCPURealTimeFile(configValue int64, file string, path string) err
 	if configValue == 0 {
 		return nil
 	}
-	return os.WriteFile(filepath.Join(path, file), []byte(strconv.FormatInt(configValue, 10)), 0700)
+	return os.WriteFile(filepath.Join(path, file), []byte(strconv.FormatInt(configValue, 10)), 0o700)
 }
 
 func (daemon *Daemon) setupSeccompProfile(cfg *config.Config) error {

+ 2 - 4
daemon/daemon_windows.go

@@ -10,6 +10,7 @@ import (
 
 	"github.com/Microsoft/hcsshim"
 	"github.com/Microsoft/hcsshim/osversion"
+	"github.com/containerd/containerd/log"
 	containertypes "github.com/docker/docker/api/types/container"
 	"github.com/docker/docker/container"
 	"github.com/docker/docker/daemon/config"
@@ -28,7 +29,6 @@ import (
 	"github.com/docker/docker/pkg/system"
 	"github.com/docker/docker/runconfig"
 	"github.com/pkg/errors"
-	"github.com/containerd/containerd/log"
 	"golang.org/x/sys/windows"
 	"golang.org/x/sys/windows/svc/mgr"
 )
@@ -198,7 +198,7 @@ func checkSystem() error {
 
 	// Ensure that the required Host Network Service and vmcompute services
 	// are running. Docker will fail in unexpected ways if this is not present.
-	var requiredServices = []string{"hns", "vmcompute"}
+	requiredServices := []string{"hns", "vmcompute"}
 	if err := ensureServicesInstalled(requiredServices); err != nil {
 		return errors.Wrap(err, "a required service is not installed, ensure the Containers feature is installed")
 	}
@@ -390,7 +390,6 @@ func (daemon *Daemon) initNetworkController(daemonCfg *config.Config, activeSand
 			}),
 			libnetwork.NetworkOptionIpam("default", "", v4Conf, v6Conf, nil),
 		)
-
 		if err != nil {
 			log.G(context.TODO()).Errorf("Error occurred when creating network %v", err)
 		}
@@ -482,7 +481,6 @@ func (daemon *Daemon) runAsHyperVContainer(hostConfig *containertypes.HostConfig
 
 	// Container is requesting an isolation mode. Honour it.
 	return hostConfig.Isolation.IsHyperV()
-
 }
 
 // conditionalMountOnStart is a platform specific helper function during the

+ 1 - 1
daemon/delete.go

@@ -116,7 +116,7 @@ func (daemon *Daemon) cleanupContainer(container *container.Container, config ty
 	//
 	// If you arrived here and know the answer, you earned yourself a picture
 	// of a cute animal of your own choosing.
-	var stopTimeout = 3
+	stopTimeout := 3
 	if err := daemon.containerStop(context.TODO(), container, containertypes.StopOptions{Timeout: &stopTimeout}); err != nil {
 		return err
 	}

+ 6 - 3
daemon/delete_test.go

@@ -45,7 +45,8 @@ func TestContainerDelete(t *testing.T) {
 			fixMsg: "Unpause and then stop the container before attempting removal or force remove",
 			initContainer: func() *container.Container {
 				return newContainerWithState(&container.State{Paused: true, Running: true})
-			}},
+			},
+		},
 		// a restarting container
 		{
 			errMsg: "cannot remove a restarting container",
@@ -55,14 +56,16 @@ func TestContainerDelete(t *testing.T) {
 				c.SetRunning(nil, nil, true)
 				c.SetRestarting(&container.ExitStatus{})
 				return c
-			}},
+			},
+		},
 		// a running container
 		{
 			errMsg: "cannot remove a running container",
 			fixMsg: "Stop the container before attempting removal or force remove",
 			initContainer: func() *container.Container {
 				return newContainerWithState(&container.State{Running: true})
-			}},
+			},
+		},
 	}
 
 	for _, te := range tt {

+ 5 - 7
daemon/events.go

@@ -16,13 +16,11 @@ import (
 	swarmapi "github.com/moby/swarmkit/v2/api"
 )
 
-var (
-	clusterEventAction = map[swarmapi.WatchActionKind]string{
-		swarmapi.WatchActionKindCreate: "create",
-		swarmapi.WatchActionKindUpdate: "update",
-		swarmapi.WatchActionKindRemove: "remove",
-	}
-)
+var clusterEventAction = map[swarmapi.WatchActionKind]string{
+	swarmapi.WatchActionKindCreate: "create",
+	swarmapi.WatchActionKindUpdate: "update",
+	swarmapi.WatchActionKindRemove: "remove",
+}
 
 // LogContainerEvent generates an event related to a container with only the default attributes.
 func (daemon *Daemon) LogContainerEvent(container *container.Container, action string) {

+ 1 - 1
daemon/id.go

@@ -20,7 +20,7 @@ func loadOrCreateID(idPath string) (string, error) {
 	idb, err := os.ReadFile(idPath)
 	if os.IsNotExist(err) {
 		id = uuid.New().String()
-		if err := ioutils.AtomicWriteFile(idPath, []byte(id), os.FileMode(0600)); err != nil {
+		if err := ioutils.AtomicWriteFile(idPath, []byte(id), os.FileMode(0o600)); err != nil {
 			return "", errors.Wrap(err, "error saving ID file")
 		}
 	} else if err != nil {

+ 3 - 3
daemon/initlayer/setup_unix.go

@@ -42,16 +42,16 @@ func Setup(initLayerFs string, rootIdentity idtools.Identity) error {
 
 		if _, err := os.Stat(filepath.Join(initLayer, pth)); err != nil {
 			if os.IsNotExist(err) {
-				if err := idtools.MkdirAllAndChownNew(filepath.Join(initLayer, filepath.Dir(pth)), 0755, rootIdentity); err != nil {
+				if err := idtools.MkdirAllAndChownNew(filepath.Join(initLayer, filepath.Dir(pth)), 0o755, rootIdentity); err != nil {
 					return err
 				}
 				switch typ {
 				case "dir":
-					if err := idtools.MkdirAllAndChownNew(filepath.Join(initLayer, pth), 0755, rootIdentity); err != nil {
+					if err := idtools.MkdirAllAndChownNew(filepath.Join(initLayer, pth), 0o755, rootIdentity); err != nil {
 						return err
 					}
 				case "file":
-					f, err := os.OpenFile(filepath.Join(initLayer, pth), os.O_CREATE, 0755)
+					f, err := os.OpenFile(filepath.Join(initLayer, pth), os.O_CREATE, 0o755)
 					if err != nil {
 						return err
 					}

+ 0 - 1
daemon/list.go

@@ -330,7 +330,6 @@ func (daemon *Daemon) foldFilter(ctx context.Context, view *container.View, conf
 			// Then walk down the graph and put the imageIds in imagesFilter
 			return populateImageFilterByParents(ctx, imagesFilter, img.ID(), daemon.imageService.Children)
 		})
-
 		if err != nil {
 			return nil, err
 		}

+ 1 - 1
daemon/list_test.go

@@ -40,7 +40,7 @@ func setupContainerWithName(t *testing.T, name string, daemon *Daemon) *containe
 		computedImageID = image.ID(digest.FromString(id))
 		cRoot           = filepath.Join(root, id)
 	)
-	if err := os.MkdirAll(cRoot, 0755); err != nil {
+	if err := os.MkdirAll(cRoot, 0o755); err != nil {
 		t.Fatal(err)
 	}
 

+ 1 - 3
daemon/network.go

@@ -1076,9 +1076,7 @@ func buildEndpointInfo(networkSettings *internalnetwork.Settings, n libnetwork.N
 }
 
 // buildJoinOptions builds endpoint Join options from a given network.
-func buildJoinOptions(networkSettings *internalnetwork.Settings, n interface {
-	Name() string
-}) ([]libnetwork.EndpointOption, error) {
+func buildJoinOptions(networkSettings *internalnetwork.Settings, n interface{ Name() string }) ([]libnetwork.EndpointOption, error) {
 	var joinOptions []libnetwork.EndpointOption
 	if epConfig, ok := networkSettings.Networks[n.Name()]; ok {
 		for _, str := range epConfig.Links {

+ 1 - 1
daemon/oci_linux_test.go

@@ -24,7 +24,7 @@ func setupFakeDaemon(t *testing.T, c *container.Container) *Daemon {
 	root := t.TempDir()
 
 	rootfs := filepath.Join(root, "rootfs")
-	err := os.MkdirAll(rootfs, 0755)
+	err := os.MkdirAll(rootfs, 0o755)
 	assert.NilError(t, err)
 
 	netController, err := libnetwork.New()

+ 0 - 1
daemon/oci_windows.go

@@ -219,7 +219,6 @@ func (daemon *Daemon) createSpec(ctx context.Context, daemonCfg *configStore, c
 
 // Sets the Windows-specific fields of the OCI spec
 func (daemon *Daemon) createSpecWindowsFields(c *container.Container, s *specs.Spec, isHyperV bool) error {
-
 	s.Hostname = c.FullHostname()
 
 	if len(s.Process.Cwd) == 0 {

+ 1 - 1
daemon/oci_windows_test.go

@@ -70,7 +70,7 @@ func TestSetWindowsCredentialSpecInSpec(t *testing.T) {
 		assert.NilError(t, err)
 		dummyCredFileName := "dummy-cred-spec.json"
 		dummyCredFilePath := filepath.Join(credSpecsDir, dummyCredFileName)
-		err = os.WriteFile(dummyCredFilePath, []byte(dummyCredFileContents), 0644)
+		err = os.WriteFile(dummyCredFilePath, []byte(dummyCredFileContents), 0o644)
 		defer func() {
 			assert.NilError(t, os.Remove(dummyCredFilePath))
 		}()

+ 0 - 1
daemon/restart.go

@@ -55,7 +55,6 @@ func (daemon *Daemon) containerRestart(ctx context.Context, daemonCfg *configSto
 		container.Unlock()
 
 		err := daemon.containerStop(ctx, container, options)
-
 		if err != nil {
 			return err
 		}

+ 2 - 1
daemon/top_windows.go

@@ -64,7 +64,8 @@ func (daemon *Daemon) ContainerTop(name string, psArgs string) (*containertypes.
 			j.ImageName,
 			fmt.Sprint(j.ProcessID),
 			fmt.Sprintf("%02d:%02d:%02d.%03d", int(d.Hours()), int(d.Minutes())%60, int(d.Seconds())%60, int(d.Nanoseconds()/1000000)%1000),
-			units.HumanSize(float64(j.MemoryWorkingSetPrivateBytes))})
+			units.HumanSize(float64(j.MemoryWorkingSetPrivateBytes)),
+		})
 	}
 
 	return procList, nil