plugin: format code with gofumpt

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

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2022-01-20 14:12:23 +01:00
parent 169fab5146
commit 83b2daca6a
No known key found for this signature in database
GPG key ID: 76698F39D527CE8C
5 changed files with 17 additions and 14 deletions

View file

@ -32,7 +32,7 @@ func TestAtomicRemoveAllAlreadyExists(t *testing.T) {
} }
defer os.RemoveAll(dir) // just try to make sure this gets cleaned up defer os.RemoveAll(dir) // just try to make sure this gets cleaned up
if err := os.MkdirAll(dir+"-removing", 0755); err != nil { if err := os.MkdirAll(dir+"-removing", 0o755); err != nil {
t.Fatal(err) t.Fatal(err)
} }
defer os.RemoveAll(dir + "-removing") defer os.RemoveAll(dir + "-removing")
@ -63,7 +63,7 @@ func TestAtomicRemoveAllNotExist(t *testing.T) {
// create the removing dir, but not the "real" one // create the removing dir, but not the "real" one
foo := filepath.Join(dir, "foo") foo := filepath.Join(dir, "foo")
removing := dir + "-removing" removing := dir + "-removing"
if err := os.MkdirAll(removing, 0755); err != nil { if err := os.MkdirAll(removing, 0o755); err != nil {
t.Fatal(err) t.Fatal(err)
} }

View file

@ -29,8 +29,10 @@ import (
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
) )
const configFileName = "config.json" const (
const rootFSFileName = "rootfs" configFileName = "config.json"
rootFSFileName = "rootfs"
)
var validFullID = regexp.MustCompile(`^([a-f0-9]{64})$`) var validFullID = regexp.MustCompile(`^([a-f0-9]{64})$`)
@ -95,7 +97,7 @@ func NewManager(config ManagerConfig) (*Manager, error) {
config: config, config: config,
} }
for _, dirName := range []string{manager.config.Root, manager.config.ExecRoot, manager.tmpDir()} { for _, dirName := range []string{manager.config.Root, manager.config.ExecRoot, manager.tmpDir()} {
if err := os.MkdirAll(dirName, 0700); err != nil { if err := os.MkdirAll(dirName, 0o700); err != nil {
return nil, errors.Wrapf(err, "failed to mkdir %v", dirName) return nil, errors.Wrapf(err, "failed to mkdir %v", dirName)
} }
} }
@ -227,7 +229,7 @@ func (pm *Manager) reload() error { // todo: restore
} }
} }
if err := os.MkdirAll(propRoot, 0755); err != nil { if err := os.MkdirAll(propRoot, 0o755); err != nil {
log.G(context.TODO()).Errorf("failed to create PropagatedMount directory at %s: %v", propRoot, err) log.G(context.TODO()).Errorf("failed to create PropagatedMount directory at %s: %v", propRoot, err)
} }
} }
@ -272,7 +274,7 @@ func (pm *Manager) save(p *v2.Plugin) error {
if err != nil { if err != nil {
return errors.Wrap(err, "failed to marshal plugin json") return errors.Wrap(err, "failed to marshal plugin json")
} }
if err := ioutils.AtomicWriteFile(filepath.Join(pm.config.Root, p.GetID(), configFileName), pluginJSON, 0600); err != nil { if err := ioutils.AtomicWriteFile(filepath.Join(pm.config.Root, p.GetID(), configFileName), pluginJSON, 0o600); err != nil {
return errors.Wrap(err, "failed to write atomically plugin json") return errors.Wrap(err, "failed to write atomically plugin json")
} }
return nil return nil

View file

@ -45,7 +45,7 @@ func (pm *Manager) enable(p *v2.Plugin, c *controller, force bool) error {
if p.PluginObj.Config.PropagatedMount != "" { if p.PluginObj.Config.PropagatedMount != "" {
propRoot = filepath.Join(filepath.Dir(p.Rootfs), "propagated-mount") propRoot = filepath.Join(filepath.Dir(p.Rootfs), "propagated-mount")
if err := os.MkdirAll(propRoot, 0755); err != nil { if err := os.MkdirAll(propRoot, 0o755); err != nil {
log.G(context.TODO()).Errorf("failed to create PropagatedMount directory at %s: %v", propRoot, err) log.G(context.TODO()).Errorf("failed to create PropagatedMount directory at %s: %v", propRoot, err)
} }
@ -321,7 +321,7 @@ func (pm *Manager) createPlugin(name string, configDigest, manifestDigest digest
} }
pdir := filepath.Join(pm.config.Root, p.PluginObj.ID) pdir := filepath.Join(pm.config.Root, p.PluginObj.ID)
if err := os.MkdirAll(pdir, 0700); err != nil { if err := os.MkdirAll(pdir, 0o700); err != nil {
return nil, errors.Wrapf(err, "failed to mkdir %v", pdir) return nil, errors.Wrapf(err, "failed to mkdir %v", pdir)
} }

View file

@ -55,7 +55,7 @@ func TestManagerWithPluginMounts(t *testing.T) {
// Create a mount to simulate a plugin that has created it's own mounts // Create a mount to simulate a plugin that has created it's own mounts
p2Mount := filepath.Join(p2.Rootfs, "testmount") p2Mount := filepath.Join(p2.Rootfs, "testmount")
if err := os.MkdirAll(p2Mount, 0755); err != nil { if err := os.MkdirAll(p2Mount, 0o755); err != nil {
t.Fatal(err) t.Fatal(err)
} }
if err := mount.Mount("tmpfs", p2Mount, "tmpfs", ""); err != nil { if err := mount.Mount("tmpfs", p2Mount, "tmpfs", ""); err != nil {
@ -73,7 +73,7 @@ func TestManagerWithPluginMounts(t *testing.T) {
func newTestPlugin(t *testing.T, name, cap, root string) *v2.Plugin { func newTestPlugin(t *testing.T, name, cap, root string) *v2.Plugin {
id := stringid.GenerateRandomID() id := stringid.GenerateRandomID()
rootfs := filepath.Join(root, id) rootfs := filepath.Join(root, id)
if err := os.MkdirAll(rootfs, 0755); err != nil { if err := os.MkdirAll(rootfs, 0o755); err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -151,6 +151,7 @@ func (e *executorWithRunning) Create(id string, spec specs.Spec, stdout, stderr
func (e *executorWithRunning) IsRunning(id string) (bool, error) { func (e *executorWithRunning) IsRunning(id string) (bool, error) {
return true, nil return true, nil
} }
func (e *executorWithRunning) Restore(id string, stdout, stderr io.WriteCloser) (bool, error) { func (e *executorWithRunning) Restore(id string, stdout, stderr io.WriteCloser) (bool, error) {
return true, nil return true, nil
} }
@ -211,7 +212,7 @@ func TestPluginAlreadyRunningOnStartup(t *testing.T) {
root := filepath.Join(root, desc) root := filepath.Join(root, desc)
config.Root = filepath.Join(root, "manager") config.Root = filepath.Join(root, "manager")
if err := os.MkdirAll(filepath.Join(config.Root, p.GetID()), 0755); err != nil { if err := os.MkdirAll(filepath.Join(config.Root, p.GetID()), 0o755); err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -244,7 +245,7 @@ func TestPluginAlreadyRunningOnStartup(t *testing.T) {
} }
func listenTestPlugin(sockAddr string, exit chan struct{}) (net.Listener, error) { func listenTestPlugin(sockAddr string, exit chan struct{}) (net.Listener, error) {
if err := os.MkdirAll(filepath.Dir(sockAddr), 0755); err != nil { if err := os.MkdirAll(filepath.Dir(sockAddr), 0o755); err != nil {
return nil, err return nil, err
} }
l, err := net.Listen("unix", sockAddr) l, err := net.Listen("unix", sockAddr)

View file

@ -27,7 +27,7 @@ func (p *Plugin) InitSpec(execRoot string) (*specs.Spec, error) {
} }
execRoot = filepath.Join(execRoot, p.PluginObj.ID) execRoot = filepath.Join(execRoot, p.PluginObj.ID)
if err := os.MkdirAll(execRoot, 0700); err != nil { if err := os.MkdirAll(execRoot, 0o700); err != nil {
return nil, errors.WithStack(err) return nil, errors.WithStack(err)
} }