From 4e125be9cab7d4a808dfa766c61ba84655a5f6c6 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Thu, 10 Sep 2026 01:35:28 +0200 Subject: [PATCH] plugins: fix perfsprint linting Signed-off-by: Sebastiaan van Stijn --- plugins/content/local/store.go | 2 +- plugins/diff/erofs/dmverity_other.go | 4 ++-- plugins/gc/scheduler.go | 5 +++-- plugins/mount/erofs/plugin_linux.go | 3 ++- plugins/services/sandbox/controller_service.go | 2 +- plugins/snapshots/devmapper/config.go | 8 ++++---- plugins/snapshots/erofs/erofs.go | 18 +++++++++--------- plugins/snapshots/overlay/overlay.go | 13 +++++++------ .../snapshots/overlay/overlayutils/check.go | 3 ++- plugins/snapshots/windows/block_cimfs.go | 9 +++++---- plugins/snapshots/windows/cimfs.go | 7 ++++--- plugins/snapshots/windows/windows.go | 3 ++- 12 files changed, 42 insertions(+), 35 deletions(-) diff --git a/plugins/content/local/store.go b/plugins/content/local/store.go index 7f276b8c15..14c0632f26 100644 --- a/plugins/content/local/store.go +++ b/plugins/content/local/store.go @@ -709,7 +709,7 @@ func writeTimestampFile(p string, t time.Time) error { } func writeToCompletion(path string, data []byte, mode os.FileMode) error { - tmp := fmt.Sprintf("%s.tmp", path) + tmp := path + ".tmp" f, err := os.OpenFile(tmp, os.O_RDWR|os.O_CREATE|os.O_TRUNC|os.O_SYNC, mode) if err != nil { return fmt.Errorf("create tmp file: %w", err) diff --git a/plugins/diff/erofs/dmverity_other.go b/plugins/diff/erofs/dmverity_other.go index 909e13d2c5..8c2d31af6d 100644 --- a/plugins/diff/erofs/dmverity_other.go +++ b/plugins/diff/erofs/dmverity_other.go @@ -20,9 +20,9 @@ package erofs import ( "context" - "fmt" + "errors" ) func (s *erofsDiff) formatDmverityLayer(_ context.Context, _ string) error { - return fmt.Errorf("dm-verity formatting is only supported on Linux systems") + return errors.New("dm-verity formatting is only supported on Linux systems") } diff --git a/plugins/gc/scheduler.go b/plugins/gc/scheduler.go index 42bf406ffa..a74f664ce1 100644 --- a/plugins/gc/scheduler.go +++ b/plugins/gc/scheduler.go @@ -20,6 +20,7 @@ import ( "context" "errors" "fmt" + "strconv" "sync" "time" @@ -112,8 +113,8 @@ func init() { ic.Meta.Exports = map[string]string{ "PauseThreshold": fmt.Sprint(m.pauseThreshold), - "DeletionThreshold": fmt.Sprint(m.deletionThreshold), - "MutationThreshold": fmt.Sprint(m.mutationThreshold), + "DeletionThreshold": strconv.Itoa(m.deletionThreshold), + "MutationThreshold": strconv.Itoa(m.mutationThreshold), "ScheduleDelay": fmt.Sprint(m.scheduleDelay), } diff --git a/plugins/mount/erofs/plugin_linux.go b/plugins/mount/erofs/plugin_linux.go index d7ccebf482..877a43fca2 100644 --- a/plugins/mount/erofs/plugin_linux.go +++ b/plugins/mount/erofs/plugin_linux.go @@ -19,6 +19,7 @@ package erofs import ( "context" "crypto/sha256" + "encoding/hex" "errors" "fmt" "os" @@ -171,7 +172,7 @@ func (h *erofsMountHandler) Mount(ctx context.Context, m mount.Mount, mp string, // same place, where its root hash still matches. func dmverityDeviceName(source, mountpoint string) string { sum := sha256.Sum256([]byte(source + "\x00" + mountpoint)) - return fmt.Sprintf("containerd-erofs-%x", sum[:16]) + return "containerd-erofs-" + hex.EncodeToString(sum[:16]) } // setupDmVerityDevice creates or reuses a dm-verity device for the given EROFS source. diff --git a/plugins/services/sandbox/controller_service.go b/plugins/services/sandbox/controller_service.go index 5a4f5a2f62..cfb5947e13 100644 --- a/plugins/services/sandbox/controller_service.go +++ b/plugins/services/sandbox/controller_service.go @@ -274,7 +274,7 @@ func (s *controllerService) Update( return nil, errgrpc.ToGRPC(err) } if req.Sandbox == nil { - return nil, fmt.Errorf("sandbox can not be nil") + return nil, errors.New("sandbox must not be nil") } err = ctrl.Update(ctx, req.SandboxID, sandbox.FromProto(req.Sandbox), req.Fields...) if err != nil { diff --git a/plugins/snapshots/devmapper/config.go b/plugins/snapshots/devmapper/config.go index 446dc780fc..5b16d3cc5d 100644 --- a/plugins/snapshots/devmapper/config.go +++ b/plugins/snapshots/devmapper/config.go @@ -101,15 +101,15 @@ func (c *Config) Validate() error { var result []error if c.PoolName == "" { - result = append(result, fmt.Errorf("pool_name is required")) + result = append(result, errors.New("pool_name is required")) } if c.RootPath == "" { - result = append(result, fmt.Errorf("root_path is required")) + result = append(result, errors.New("root_path is required")) } if c.BaseImageSize == "" { - result = append(result, fmt.Errorf("base_image_size is required")) + result = append(result, errors.New("base_image_size is required")) } if c.FileSystemType != "" { @@ -119,7 +119,7 @@ func (c *Config) Validate() error { result = append(result, fmt.Errorf("unsupported Filesystem Type: %q", c.FileSystemType)) } } else { - result = append(result, fmt.Errorf("filesystem type cannot be empty")) + result = append(result, errors.New("filesystem type cannot be empty")) } return errors.Join(result...) diff --git a/plugins/snapshots/erofs/erofs.go b/plugins/snapshots/erofs/erofs.go index c9fcc84ef2..bf9d0a641e 100644 --- a/plugins/snapshots/erofs/erofs.go +++ b/plugins/snapshots/erofs/erofs.go @@ -162,7 +162,7 @@ func NewSnapshotter(root string, opts ...Opt) (snapshots.Snapshotter, error) { return nil, fmt.Errorf("failed to check dm-verity support: %w", err) } if !supported { - return nil, fmt.Errorf("dmverity_mode is 'on' but dm-verity is not supported on this system") + return nil, errors.New("dmverity_mode is 'on' but dm-verity is not supported on this system") } } @@ -183,10 +183,10 @@ func NewSnapshotter(root string, opts ...Opt) (snapshots.Snapshotter, error) { // mechanism. if len(config.layerContentCaches) > 0 { if config.enableFsverity { - return nil, fmt.Errorf("enable_fsverity is incompatible with layer_content_caches; use dm-verity for cache integrity") + return nil, errors.New("enable_fsverity is incompatible with layer_content_caches; use dm-verity for cache integrity") } if config.setImmutable { - return nil, fmt.Errorf("set_immutable is incompatible with layer_content_caches") + return nil, errors.New("set_immutable is incompatible with layer_content_caches") } // A cache dir is recorded in a snapshot and mounted later. A relative @@ -216,7 +216,7 @@ func NewSnapshotter(root string, opts ...Opt) (snapshots.Snapshotter, error) { } if config.setImmutable && runtime.GOOS != "linux" { - return nil, fmt.Errorf("setting IMMUTABLE_FL is only supported on Linux") + return nil, errors.New("setting IMMUTABLE_FL is only supported on Linux") } ms, err := storage.NewMetaStore(filepath.Join(root, "metadata.db")) @@ -391,7 +391,7 @@ func (s *snapshotter) applyDmverityPolicy(layerBlob string) (string, error) { // If metadata exists, return the metadata path to a mount option. // The format is: X-containerd.dmverity= if metadataExists { - return fmt.Sprintf("X-containerd.dmverity=%s", metadataPath), nil + return "X-containerd.dmverity=" + metadataPath, nil } return "", nil @@ -509,8 +509,8 @@ func (s *snapshotter) overlayMounts(snap storage.Snapshot, info snapshots.Info, ) } else { options = append(options, - fmt.Sprintf("workdir=%s", s.workPath(snap.ID)), - fmt.Sprintf("upperdir=%s", s.upperPath(snap.ID)), + "workdir="+s.workPath(snap.ID), + "upperdir="+s.upperPath(snap.ID), ) } } @@ -526,10 +526,10 @@ func (s *snapshotter) overlayMounts(snap storage.Snapshot, info snapshots.Info, if s.remapIDs { if v, ok := info.Labels[snapshots.LabelSnapshotUIDMapping]; ok { - options = append(options, fmt.Sprintf("uidmap=%s", v)) + options = append(options, "uidmap="+v) } if v, ok := info.Labels[snapshots.LabelSnapshotGIDMapping]; ok { - options = append(options, fmt.Sprintf("gidmap=%s", v)) + options = append(options, "gidmap="+v) } } diff --git a/plugins/snapshots/overlay/overlay.go b/plugins/snapshots/overlay/overlay.go index c56ffe5bab..72c174970a 100644 --- a/plugins/snapshots/overlay/overlay.go +++ b/plugins/snapshots/overlay/overlay.go @@ -20,6 +20,7 @@ package overlay import ( "context" + "errors" "fmt" "os" "path/filepath" @@ -507,7 +508,7 @@ func (o *snapshotter) createSnapshot(ctx context.Context, kind snapshots.Kind, k } stat, ok := st.Sys().(*syscall.Stat_t) if !ok { - return fmt.Errorf("incompatible types after stat call: *syscall.Stat_t expected") + return errors.New("incompatible types after stat call: *syscall.Stat_t expected") } mappedUID = int(stat.Uid) mappedGID = int(stat.Gid) @@ -557,10 +558,10 @@ func (o *snapshotter) mounts(s storage.Snapshot, info snapshots.Info) []mount.Mo if o.remapIDs { if v, ok := info.Labels[snapshots.LabelSnapshotUIDMapping]; ok { - options = append(options, fmt.Sprintf("uidmap=%s", v)) + options = append(options, "uidmap="+v) } if v, ok := info.Labels[snapshots.LabelSnapshotGIDMapping]; ok { - options = append(options, fmt.Sprintf("gidmap=%s", v)) + options = append(options, "gidmap="+v) } } @@ -585,8 +586,8 @@ func (o *snapshotter) mounts(s storage.Snapshot, info snapshots.Info) []mount.Mo if s.Kind == snapshots.KindActive { options = append(options, - fmt.Sprintf("workdir=%s", o.workPath(s.ID)), - fmt.Sprintf("upperdir=%s", o.upperPath(s.ID)), + "workdir="+o.workPath(s.ID), + "upperdir="+o.upperPath(s.ID), ) } else if len(s.ParentIDs) == 1 { return []mount.Mount{ @@ -605,7 +606,7 @@ func (o *snapshotter) mounts(s storage.Snapshot, info snapshots.Info) []mount.Mo for i := range s.ParentIDs { parentPaths[i] = o.upperPath(s.ParentIDs[i]) } - options = append(options, fmt.Sprintf("lowerdir=%s", strings.Join(parentPaths, ":"))) + options = append(options, "lowerdir="+strings.Join(parentPaths, ":")) options = append(options, o.options...) return []mount.Mount{ diff --git a/plugins/snapshots/overlay/overlayutils/check.go b/plugins/snapshots/overlay/overlayutils/check.go index 2d9a6b9ea3..6a93019ab6 100644 --- a/plugins/snapshots/overlay/overlayutils/check.go +++ b/plugins/snapshots/overlay/overlayutils/check.go @@ -19,6 +19,7 @@ package overlayutils import ( + "errors" "fmt" "os" "path/filepath" @@ -289,7 +290,7 @@ func SupportsIDMappedMounts() (bool, error) { return false, fmt.Errorf("failed to stat %s: %w", filepath.Join(td, "merged"), err) } if stat, ok := st.Sys().(*syscall.Stat_t); !ok { - return false, fmt.Errorf("incompatible types after stat call: *syscall.Stat_t expected") + return false, errors.New("incompatible types after stat call: *syscall.Stat_t expected") } else if int(stat.Uid) != uidMap.HostID || int(stat.Gid) != gidMap.HostID { return false, fmt.Errorf("bad mapping: expected {uid: %d, gid: %d}; real {uid: %d, gid: %d}", uidMap.HostID, gidMap.HostID, int(stat.Uid), int(stat.Gid)) } diff --git a/plugins/snapshots/windows/block_cimfs.go b/plugins/snapshots/windows/block_cimfs.go index 8831696c19..3616a9db43 100644 --- a/plugins/snapshots/windows/block_cimfs.go +++ b/plugins/snapshots/windows/block_cimfs.go @@ -21,6 +21,7 @@ package windows import ( "context" "encoding/json" + "errors" "fmt" "os" "path/filepath" @@ -84,7 +85,7 @@ func init() { config, ok := ic.Config.(*BlockCIMSnapshotterConfig) if !ok { - return nil, fmt.Errorf("invalid block CIM snapshotter configuration") + return nil, errors.New("invalid block CIM snapshotter configuration") } log.G(ic.Context).WithField("config", config).Trace("initializing blockcim snapshotter") @@ -225,7 +226,7 @@ func (s *blockCIMSnapshotter) Mounts(ctx context.Context, key string) (_ []mount func (s *blockCIMSnapshotter) Commit(ctx context.Context, name, key string, opts ...snapshots.Opt) error { if !strings.Contains(key, snapshots.UnpackKeyPrefix) { - return fmt.Errorf("committing a scratch snapshot to read-only cim layer isn't supported yet") + return errors.New("committing a scratch snapshot to read-only cim layer isn't supported yet") } return s.ms.WithTransaction(ctx, true, func(ctx context.Context) error { @@ -295,7 +296,7 @@ func (s *blockCIMSnapshotter) createSnapshot(ctx context.Context, kind snapshots } if len(newSnapshot.ParentIDs) == 0 { - return fmt.Errorf("scratch snapshot without any parents isn't supported") + return errors.New("scratch snapshot without any parents isn't supported") } parentLayerPaths := s.parentIDsToParentPaths(newSnapshot.ParentIDs) @@ -472,7 +473,7 @@ const ( // index. already exists in the 0th snapshot's directory, nothing is done. func (s *blockCIMSnapshotter) prepareMergedCIM(ctx context.Context, snapshotIDs []string) (rErr error) { if len(snapshotIDs) < 2 { - return fmt.Errorf("merging CIM requires at least 2 snapshots") + return errors.New("merging CIM requires at least 2 snapshots") } log.G(ctx).WithFields(log.Fields{ "source snapshots": snapshotIDs, diff --git a/plugins/snapshots/windows/cimfs.go b/plugins/snapshots/windows/cimfs.go index 222d9d95df..734da74892 100644 --- a/plugins/snapshots/windows/cimfs.go +++ b/plugins/snapshots/windows/cimfs.go @@ -21,6 +21,7 @@ package windows import ( "context" "encoding/json" + "errors" "fmt" "os" "path/filepath" @@ -73,7 +74,7 @@ func WithNTFSFormat() scratchCreationOpt { func WithSize(size uint64) scratchCreationOpt { return func(opts *scratchCreationOptions) error { if size == 0 { - return fmt.Errorf("VHD size cannot be zero") + return errors.New("VHD size cannot be zero") } opts.sizeInBytes = size return nil @@ -209,7 +210,7 @@ func (s *cimFSSnapshotter) Mounts(ctx context.Context, key string) (_ []mount.Mo func (s *cimFSSnapshotter) Commit(ctx context.Context, name, key string, opts ...snapshots.Opt) error { if !strings.Contains(key, snapshots.UnpackKeyPrefix) { - return fmt.Errorf("committing a scratch snapshot to read-only cim layer isn't supported yet") + return errors.New("committing a scratch snapshot to read-only cim layer isn't supported yet") } return s.ms.WithTransaction(ctx, true, func(ctx context.Context) error { @@ -289,7 +290,7 @@ func (s *cimFSSnapshotter) createSnapshot(ctx context.Context, kind snapshots.Ki } if len(newSnapshot.ParentIDs) == 0 { - return fmt.Errorf("scratch snapshot without any parents isn't supported") + return errors.New("scratch snapshot without any parents isn't supported") } parentLayerPaths := s.parentIDsToParentPaths(newSnapshot.ParentIDs) diff --git a/plugins/snapshots/windows/windows.go b/plugins/snapshots/windows/windows.go index 475b710ca1..a903ef9478 100644 --- a/plugins/snapshots/windows/windows.go +++ b/plugins/snapshots/windows/windows.go @@ -21,6 +21,7 @@ package windows import ( "context" "encoding/json" + "errors" "fmt" "io" "os" @@ -258,7 +259,7 @@ func (s *wcowSnapshotter) Mounts(ctx context.Context, key string) (_ []mount.Mou func (s *wcowSnapshotter) createScratchLayer(ctx context.Context, snDir string, parentLayers []string, sizeInBytes uint64) error { parentLen := len(parentLayers) if parentLen == 0 { - return fmt.Errorf("no parent layers present") + return errors.New("no parent layers present") } baseLayer := parentLayers[parentLen-1]