internal: fix perfsprint linting

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn committed 2026-09-17 10:47:55 +02:00
1 parent ebe078365d
commit 4b9700c1cf
29 files changed
+60 -49

No files matched your search

+3 -3
View File
@@ -34,7 +34,7 @@ limitations under the License.
package bandwidth
import (
"fmt"
"errors"
"k8s.io/apimachinery/pkg/api/resource"
)
@@ -44,10 +44,10 @@ var maxRsrc = resource.MustParse("1P")
func validateBandwidthIsReasonable(rsrc *resource.Quantity) error {
if rsrc.Value() < minRsrc.Value() {
return fmt.Errorf("resource is unreasonably small (< 1kbit)")
return errors.New("resource is unreasonably small (< 1kbit)")
}
if rsrc.Value() > maxRsrc.Value() {
return fmt.Errorf("resource is unreasonably large (> 1Pbit)")
return errors.New("resource is unreasonably large (> 1Pbit)")
}
return nil
}
+1 -2
View File
@@ -19,7 +19,6 @@ package io
import (
"context"
"errors"
"fmt"
"io"
"strings"
"sync"
@@ -88,7 +87,7 @@ func WithNewFIFOs(root string, tty, stdin bool) ContainerIOOpts {
func WithStreams(address string, tty, stdin bool) ContainerIOOpts {
return func(c *ContainerIO) error {
if address == "" {
return fmt.Errorf("address can not be empty for io stream")
return errors.New("address can not be empty for io stream")
}
fifos, err := newStreams(address, c.id, tty, stdin)
if err != nil {
+3 -4
View File
@@ -75,13 +75,12 @@ func openStream(ctx context.Context, urlStr string) (streamingapi.Stream, error)
// or grpc+vsock://<cid>:<port>, we should get the protocol from the url first.
protocol, scheme, ok := strings.Cut(u.Scheme, "+")
if !ok {
return nil, fmt.Errorf("the scheme of sandbox address should be in " +
" the form of <protocol>+<unix|vsock|tcp>, i.e. ttrpc+unix or grpc+vsock")
return nil, errors.New("the scheme of sandbox address should be in the form of <protocol>+<unix|vsock|tcp>, i.e. ttrpc+unix or grpc+vsock")
}
id := u.Query().Get("streaming_id")
if id == "" {
return nil, fmt.Errorf("no stream id in url queries")
return nil, errors.New("no stream id in url queries")
}
realAddress := fmt.Sprintf("%s://%s/%s", scheme, u.Host, u.Path)
conn, err := shim.AnonReconnectDialer(realAddress, 100*time.Second)
@@ -113,6 +112,6 @@ func openStream(ctx context.Context, urlStr string) (streamingapi.Stream, error)
}
return &ioStream{Stream: stream, c: conn}, nil
default:
return nil, fmt.Errorf("protocol not supported")
return nil, errors.New("protocol not supported")
}
}
+1 -1
View File
@@ -136,7 +136,7 @@ func WithVolumes(volumeMounts map[string]string, platform imagespec.Platform) co
mounts = mount.RemoveIDMapOption(mounts)
mm := client.MountManager()
activationKey := fmt.Sprintf("cri-volume-%s", c.SnapshotKey)
activationKey := "cri-volume-" + c.SnapshotKey
var needsDeactivation bool
info, err := mm.Activate(ctx, activationKey, mounts)
+1 -1
View File
@@ -331,7 +331,7 @@ func WithoutNamespace(t runtimespec.LinuxNamespaceType) oci.SpecOpts {
func WithNamespacePath(t runtimespec.LinuxNamespaceType, nsPath string) oci.SpecOpts {
return func(ctx context.Context, client oci.Client, c *containers.Container, s *runtimespec.Spec) error {
if s.Linux == nil {
return fmt.Errorf("linux spec is required")
return errors.New("linux spec is required")
}
for i, ns := range s.Linux.Namespaces {
+2 -1
View File
@@ -18,6 +18,7 @@ package opts
import (
"context"
"errors"
"fmt"
"os"
"path/filepath"
@@ -86,7 +87,7 @@ func parseMount(osi osinterface.OS, mount *runtime.Mount) (*runtimespec.Mount, e
dst = "C:" + dst
}
} else if dst[0] == 'c' || dst[0] == 'C' {
return nil, fmt.Errorf("destination path can not be C drive")
return nil, errors.New("destination path can not be C drive")
}
}
+2 -1
View File
@@ -17,6 +17,7 @@
package server
import (
"errors"
"fmt"
"os"
"path/filepath"
@@ -99,7 +100,7 @@ func (syncer *cniNetConfSyncer) syncLoop() error {
// If the confDir is removed, stop watching.
if event.Name == syncer.confDir && (event.Has(fsnotify.Rename) || event.Has(fsnotify.Remove)) {
return fmt.Errorf("cni conf dir is removed, stop watching")
return errors.New("cni conf dir is removed, stop watching")
}
lerr := syncer.netPlugin.Load(syncer.loadOpts...)
@@ -366,7 +366,7 @@ func writeCriuCheckpointData(ctx context.Context, store content.Store, desc v1.D
return err
}
if strings.Contains(header.Name, "..") {
return fmt.Errorf("found illegal string '..' in checkpoint archive")
return errors.New("found illegal string '..' in checkpoint archive")
}
destFile, err := os.Create(filepath.Join(checkpointDirectory, header.Name))
if err != nil {
+1 -1
View File
@@ -153,7 +153,7 @@ func (c *criService) mutateImageMount(
return fmt.Errorf("failed to create directory to image volume target path %q: %w", target, err)
}
id := fmt.Sprintf("cri-image-mount-%s", target)
id := "cri-image-mount-" + target
activateOpts := []mount.ActivateOpt{
mount.WithLabels(map[string]string{
"containerd.io/gc.bref.snapshot." + snapshotter: target,
+2 -1
View File
@@ -18,6 +18,7 @@ package server
import (
"context"
"errors"
"fmt"
containerd "github.com/containerd/containerd/v2/client"
@@ -53,7 +54,7 @@ func updateContainerIOOwner(ctx context.Context, cntr containerd.Container, conf
}
if spec.Linux == nil || spec.Process == nil {
return nil, fmt.Errorf("invalid linux platform oci runtime spec")
return nil, errors.New("invalid linux platform oci runtime spec")
}
idMap := userns.IDMap{
@@ -18,6 +18,7 @@ package server
import (
"context"
"errors"
"fmt"
"os"
"path"
@@ -1006,7 +1007,7 @@ func (c *criService) findContainerTaskRootfs(container containers.Container) (st
return rootfsPath, nil
}
return "", fmt.Errorf("could not determine container root path")
return "", errors.New("could not determine container root path")
}
func (c *criService) extractFilesystemMetrics(ctx context.Context, container containerstore.Container, labels []string, timestamp int64) ([]*runtime.Metric, error) {
+2 -1
View File
@@ -18,6 +18,7 @@ package podsandbox
import (
"context"
"errors"
"fmt"
"path/filepath"
@@ -102,7 +103,7 @@ func getMetadata(ctx context.Context, container containerd.Container) (*sandboxs
}
meta, ok := data.(*sandboxstore.Metadata)
if !ok {
return nil, fmt.Errorf("failed to convert the extension to sandbox metadata")
return nil, errors.New("failed to convert the extension to sandbox metadata")
}
return meta, nil
}
+2 -2
View File
@@ -17,7 +17,7 @@
package podsandbox
import (
"fmt"
"errors"
"sync"
"github.com/containerd/containerd/v2/internal/cri/server/podsandbox/types"
@@ -33,7 +33,7 @@ func NewStore() *Store {
func (s *Store) Save(p *types.PodSandbox) error {
if p == nil {
return fmt.Errorf("pod sandbox should not be nil")
return errors.New("pod sandbox should not be nil")
}
s.m.Store(p.ID, p)
return nil
+1 -1
View File
@@ -477,7 +477,7 @@ func cleanupOrphanedIDDirs(ctx context.Context, cntrs []containerd.Container, ba
func (c *criService) createContainerIO(containerID, sandboxID string, config *runtime.ContainerConfig) (*cio.ContainerIO, error) {
if config == nil {
return nil, fmt.Errorf("ContainerConfig should not be nil when create container io")
return nil, errors.New("ContainerConfig should not be nil when create container io")
}
sb, err := c.sandboxStore.Get(sandboxID)
if err != nil {
@@ -21,6 +21,7 @@ import (
"fmt"
"io"
"net"
"strconv"
"time"
"github.com/containerd/log"
@@ -47,7 +48,7 @@ func (c *criService) portForward(ctx context.Context, id string, port int32, str
err = func() error {
var conn net.Conn
conn, err = net.Dial("tcp", net.JoinHostPort(podIP, fmt.Sprintf("%d", port)))
conn, err = net.Dial("tcp", net.JoinHostPort(podIP, strconv.Itoa(int(port))))
if err != nil {
return fmt.Errorf("failed to connect to %s:%d for pod %q: %v", podIP, port, id, err)
}
+4 -3
View File
@@ -17,6 +17,7 @@
package server
import (
"errors"
"fmt"
"syscall"
@@ -43,7 +44,7 @@ func (c *criService) bringUpLoopback(netns string) error {
func (c *criService) setupNetnsWithinUserns(netnsMountDir string, opt *runtime.UserNamespace) (*netns.NetNS, error) {
if opt.GetMode() != runtime.NamespaceMode_POD {
return nil, fmt.Errorf("required pod-level user namespace setting")
return nil, errors.New("required pod-level user namespace setting")
}
uidMaps := opt.GetUids()
@@ -51,7 +52,7 @@ func (c *criService) setupNetnsWithinUserns(netnsMountDir string, opt *runtime.U
return nil, fmt.Errorf("required only one uid mapping, but got %d uid mapping(s)", len(uidMaps))
}
if uidMaps[0] == nil {
return nil, fmt.Errorf("required only one uid mapping, but got empty uid mapping")
return nil, errors.New("required only one uid mapping, but got empty uid mapping")
}
gidMaps := opt.GetGids()
@@ -59,7 +60,7 @@ func (c *criService) setupNetnsWithinUserns(netnsMountDir string, opt *runtime.U
return nil, fmt.Errorf("required only one gid mapping, but got %d gid mapping(s)", len(gidMaps))
}
if gidMaps[0] == nil {
return nil, fmt.Errorf("required only one gid mapping, but got empty gid mapping")
return nil, errors.New("required only one gid mapping, but got empty gid mapping")
}
var netNs *netns.NetNS
+2 -2
View File
@@ -19,7 +19,7 @@
package server
import (
"fmt"
"errors"
"github.com/containerd/containerd/v2/pkg/netns"
runtime "k8s.io/cri-api/pkg/apis/runtime/v1"
@@ -30,5 +30,5 @@ func (c *criService) bringUpLoopback(string) error {
}
func (c *criService) setupNetnsWithinUserns(basedir string, cfg *runtime.UserNamespace) (*netns.NetNS, error) {
return nil, fmt.Errorf("unsupported to setup netns within userns on unix platform")
return nil, errors.New("unsupported to setup netns within userns on unix platform")
}
+2 -2
View File
@@ -17,7 +17,7 @@
package server
import (
"fmt"
"errors"
"github.com/containerd/containerd/v2/pkg/netns"
runtime "k8s.io/cri-api/pkg/apis/runtime/v1"
@@ -28,5 +28,5 @@ func (c *criService) bringUpLoopback(string) error {
}
func (c *criService) setupNetnsWithinUserns(basedir string, cfg *runtime.UserNamespace) (*netns.NetNS, error) {
return nil, fmt.Errorf("unsupported to setup netns within userns on windows platform")
return nil, errors.New("unsupported to setup netns within userns on windows platform")
}
+2 -1
View File
@@ -18,6 +18,7 @@ package server
import (
"context"
"errors"
"fmt"
"time"
@@ -202,7 +203,7 @@ func getAllContainerNetIO(ctx context.Context, netNsPath string) ([]interfaceSta
func decodeSandboxCgroupMetrics(m *types.Metric) (*cgroupMetrics, error) {
if m == nil || m.Data == nil {
return nil, fmt.Errorf("sandbox metric is empty")
return nil, errors.New("sandbox metric is empty")
}
a, err := typeurl.UnmarshalAny(m.Data)
if err != nil {
+2 -1
View File
@@ -18,6 +18,7 @@ package server
import (
"context"
"errors"
"fmt"
"time"
@@ -275,7 +276,7 @@ func (c *criService) convertToCRIStats(stats *wstats.Statistics) (*runtime.Windo
if stats != nil && stats.Container != nil {
wstats := stats.GetWindows()
if wstats == nil {
return nil, fmt.Errorf("windows stats is empty")
return nil, errors.New("windows stats is empty")
}
if wstats.Processor != nil {
cs.Cpu = &runtime.WindowsCpuUsage{
+3 -2
View File
@@ -18,6 +18,7 @@ package server
import (
"context"
"errors"
"fmt"
"io"
"net/http"
@@ -476,14 +477,14 @@ func introspectRuntimeFeatures(ctx context.Context, intro introspection.Service,
return nil, fmt.Errorf("failed to call PluginInfo: %w", err)
}
if infoResp.Extra == nil {
return nil, fmt.Errorf("runtime plugin info has no extra data")
return nil, errors.New("runtime plugin info has no extra data")
}
var info apitypes.RuntimeInfo
if err := typeurl.UnmarshalTo(infoResp.Extra, &info); err != nil {
return nil, fmt.Errorf("failed to get runtime info from plugin info: %w", err)
}
if info.Features == nil {
return nil, fmt.Errorf("runtime info has no features")
return nil, errors.New("runtime info has no features")
}
featuresX, err := typeurl.UnmarshalAny(info.Features)
if err != nil {
+1 -1
View File
@@ -99,7 +99,7 @@ func (c *criService) Status(ctx context.Context, r *runtime.StatusRequest) (*run
if lerr := h.lastStatus(); lerr != nil {
s = lerr.Error()
}
resp.Info[fmt.Sprintf("lastCNILoadStatus.%s", name)] = s
resp.Info["lastCNILoadStatus."+name] = s
if name == defaultNetworkPlugin {
defaultStatus = s
}
+1 -1
View File
@@ -65,7 +65,7 @@ func MetadataPath(layerBlobPath string) string {
}
func DevicePath(name string) string {
return fmt.Sprintf("/dev/mapper/%s", name)
return "/dev/mapper/" + name
}
type DmverityMetadata struct {
+5 -3
View File
@@ -18,7 +18,9 @@ package dmverity
import (
"context"
"encoding/hex"
"encoding/json"
"errors"
"fmt"
"os"
@@ -34,7 +36,7 @@ import (
func IsSupported() (bool, error) {
if _, err := os.Stat("/sys/module/dm_verity"); err != nil {
if os.IsNotExist(err) {
return false, fmt.Errorf("dm_verity module not loaded or built-in")
return false, errors.New("dm_verity module not loaded or built-in")
}
return false, fmt.Errorf("failed to check /sys/module/dm_verity: %w", err)
}
@@ -114,7 +116,7 @@ func Format(dataDevice, hashDevice string, opts *DmverityOptions) (string, error
return "", fmt.Errorf("failed to format dm-verity device: %w", err)
}
return fmt.Sprintf("%x", rootDigest), nil
return hex.EncodeToString(rootDigest), nil
}
// FormatLayer appends a dm-verity hash tree to the erofs layer blob at
@@ -236,7 +238,7 @@ func FormatLayer(ctx context.Context, layerBlobPath string, opts *DmverityOption
// supplied programmatically since there's no superblock to read from.
func Open(dataDevice string, name string, hashDevice string, rootHash string, hashOffset uint64, opts *DmverityOptions) (string, error) {
if rootHash == "" {
return "", fmt.Errorf("rootHash cannot be empty")
return "", errors.New("rootHash cannot be empty")
}
rootDigest, err := utils.ParseRootHash(rootHash)
+2 -2
View File
@@ -20,10 +20,10 @@ package dmverity
import (
"context"
"fmt"
"errors"
)
var errUnsupported = fmt.Errorf("dmverity is only supported on Linux systems")
var errUnsupported = errors.New("dmverity is only supported on Linux systems")
func IsSupported() (bool, error) {
return false, errUnsupported
+4 -4
View File
@@ -18,16 +18,16 @@
package fsverity
import "fmt"
import "errors"
func IsSupported(rootPath string) (bool, error) {
return false, fmt.Errorf("fsverity is only supported on Linux systems")
return false, errors.New("fsverity is only supported on Linux systems")
}
func IsEnabled(path string) (bool, error) {
return false, fmt.Errorf("fsverity is only supported on Linux systems")
return false, errors.New("fsverity is only supported on Linux systems")
}
func Enable(_ string) error {
return fmt.Errorf("fsverity is only supported on Linux systems")
return errors.New("fsverity is only supported on Linux systems")
}
+3 -3
View File
@@ -18,7 +18,7 @@ package nri
import (
"context"
"fmt"
"errors"
"sync"
"github.com/containerd/containerd/v2/pkg/namespaces"
@@ -143,7 +143,7 @@ func (t *domainTable) updateContainers(ctx context.Context, updates []*nri.Conta
}
if len(failed) != 0 {
return failed, fmt.Errorf("NRI update of some containers failed")
return failed, errors.New("NRI update of some containers failed")
}
return nil, nil
@@ -171,7 +171,7 @@ func (t *domainTable) evictContainers(ctx context.Context, evict []*nri.Containe
}
if len(failed) != 0 {
return failed, fmt.Errorf("NRI eviction of some containers failed")
return failed, errors.New("NRI eviction of some containers failed")
}
return nil, nil
+1 -1
View File
@@ -48,7 +48,7 @@ type ErrAmbiguousPrefix struct {
}
func (e ErrAmbiguousPrefix) Error() string {
return fmt.Sprintf("Multiple IDs found with provided prefix: %s", e.prefix)
return "Multiple IDs found with provided prefix: " + e.prefix
}
// TruncIndex allows the retrieval of string identifiers by any of their unique prefixes.
+2 -1
View File
@@ -23,6 +23,7 @@ import (
"context"
"crypto/tls"
"crypto/x509"
"errors"
"fmt"
"io"
@@ -94,7 +95,7 @@ func SetupTLSFromWindowsCertStore(ctx context.Context, commonName string) (*tls.
if key == nil {
certtostore.FreeCertContext(certContext)
store.Close()
return nil, nil, nil, fmt.Errorf("retrieved private key is nil")
return nil, nil, nil, errors.New("retrieved private key is nil")
}
// Convert the x509 certificate chain to a CertPool and chain bytes