Merge pull request #8730 from thaJeztah/sprint_less
replace some fmt.Sprintfs with strconv
This commit is contained in:
commit
1ffe80c7f6
@ -23,6 +23,7 @@ import (
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
"text/tabwriter"
|
||||
"time"
|
||||
@ -207,7 +208,7 @@ var usageCommand = cli.Command{
|
||||
var displaySize func(int64) string
|
||||
if context.Bool("b") {
|
||||
displaySize = func(s int64) string {
|
||||
return fmt.Sprintf("%d", s)
|
||||
return strconv.FormatInt(s, 10)
|
||||
}
|
||||
} else {
|
||||
displaySize = func(s int64) string {
|
||||
|
@ -18,9 +18,9 @@ package client
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
"syscall"
|
||||
"testing"
|
||||
@ -133,7 +133,7 @@ func TestDaemonCustomCgroup(t *testing.T) {
|
||||
t.Skip("skip TestDaemonCustomCgroup since no cgroup path available")
|
||||
}
|
||||
|
||||
customCgroup := fmt.Sprintf("%d", time.Now().Nanosecond())
|
||||
customCgroup := strconv.Itoa(time.Now().Nanosecond())
|
||||
configTOML := `
|
||||
version = 2
|
||||
[cgroup]
|
||||
|
@ -602,7 +602,7 @@ func (tc *nriTest) setup() {
|
||||
tc.prefix = strings.ToLower(tc.name)
|
||||
}
|
||||
if tc.namespace == "" {
|
||||
tc.namespace = tc.prefix + "-" + fmt.Sprintf("%d", os.Getpid())
|
||||
tc.namespace = tc.prefix + "-" + strconv.Itoa(os.Getpid())
|
||||
}
|
||||
|
||||
tc.sbCfg = make(map[string]*runtime.PodSandboxConfig)
|
||||
|
@ -420,7 +420,7 @@ func WithImageConfigArgs(image Image, args []string) SpecOpts {
|
||||
if err := WithUser(config.User)(ctx, client, c, s); err != nil {
|
||||
return err
|
||||
}
|
||||
return WithAdditionalGIDs(fmt.Sprintf("%d", s.Process.User.UID))(ctx, client, c, s)
|
||||
return WithAdditionalGIDs(strconv.FormatInt(int64(s.Process.User.UID), 10))(ctx, client, c, s)
|
||||
}
|
||||
// we should query the image's /etc/group for additional GIDs
|
||||
// even if there is no specified user in the image config
|
||||
|
@ -17,7 +17,7 @@
|
||||
package sbserver
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
|
||||
imagespec "github.com/opencontainers/image-spec/specs-go/v1"
|
||||
runtime "k8s.io/cri-api/pkg/apis/runtime/v1"
|
||||
@ -39,9 +39,8 @@ func snapshotterOpts(snapshotterName string, config *runtime.ContainerConfig) ([
|
||||
case "windows":
|
||||
rootfsSize := config.GetWindows().GetResources().GetRootfsSizeInBytes()
|
||||
if rootfsSize != 0 {
|
||||
sizeStr := fmt.Sprintf("%d", rootfsSize)
|
||||
labels := map[string]string{
|
||||
"containerd.io/snapshot/windows/rootfs.sizebytes": sizeStr,
|
||||
"containerd.io/snapshot/windows/rootfs.sizebytes": strconv.FormatInt(rootfsSize, 10),
|
||||
}
|
||||
opts = append(opts, snapshots.WithLabels(labels))
|
||||
}
|
||||
|
@ -138,7 +138,7 @@ func makeSandboxName(s *runtime.PodSandboxMetadata) string {
|
||||
s.Name, // 0
|
||||
s.Namespace, // 1
|
||||
s.Uid, // 2
|
||||
fmt.Sprintf("%d", s.Attempt), // 3
|
||||
strconv.FormatUint(uint64(s.Attempt), 10), // 3
|
||||
}, nameDelimiter)
|
||||
}
|
||||
|
||||
@ -151,7 +151,7 @@ func makeContainerName(c *runtime.ContainerMetadata, s *runtime.PodSandboxMetada
|
||||
s.Name, // 1: pod name
|
||||
s.Namespace, // 2: pod namespace
|
||||
s.Uid, // 3: pod uid
|
||||
fmt.Sprintf("%d", c.Attempt), // 4: attempt number of creating the container
|
||||
strconv.FormatUint(uint64(c.Attempt), 10), // 4: attempt number of creating the container
|
||||
}, nameDelimiter)
|
||||
}
|
||||
|
||||
|
@ -18,7 +18,6 @@ package server
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"strconv"
|
||||
|
||||
imagespec "github.com/opencontainers/image-spec/specs-go/v1"
|
||||
@ -147,9 +146,8 @@ func snapshotterOpts(snapshotterName string, config *runtime.ContainerConfig) ([
|
||||
case "windows":
|
||||
rootfsSize := config.GetWindows().GetResources().GetRootfsSizeInBytes()
|
||||
if rootfsSize != 0 {
|
||||
sizeStr := fmt.Sprintf("%d", rootfsSize)
|
||||
labels := map[string]string{
|
||||
"containerd.io/snapshot/windows/rootfs.sizebytes": sizeStr,
|
||||
"containerd.io/snapshot/windows/rootfs.sizebytes": strconv.FormatInt(rootfsSize, 10),
|
||||
}
|
||||
opts = append(opts, snapshots.WithLabels(labels))
|
||||
}
|
||||
|
@ -99,7 +99,7 @@ func makeSandboxName(s *runtime.PodSandboxMetadata) string {
|
||||
s.Name, // 0
|
||||
s.Namespace, // 1
|
||||
s.Uid, // 2
|
||||
fmt.Sprintf("%d", s.Attempt), // 3
|
||||
strconv.Itoa(int(s.Attempt)), // 3
|
||||
}, nameDelimiter)
|
||||
}
|
||||
|
||||
@ -112,7 +112,7 @@ func makeContainerName(c *runtime.ContainerMetadata, s *runtime.PodSandboxMetada
|
||||
s.Name, // 1: pod name
|
||||
s.Namespace, // 2: pod namespace
|
||||
s.Uid, // 3: pod uid
|
||||
fmt.Sprintf("%d", c.Attempt), // 4: attempt number of creating the container
|
||||
strconv.FormatUint(uint64(c.Attempt), 10), // 4: attempt number of creating the container
|
||||
}, nameDelimiter)
|
||||
}
|
||||
|
||||
|
@ -36,6 +36,7 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
apierrors "k8s.io/apimachinery/pkg/api/errors"
|
||||
@ -76,7 +77,7 @@ func ServeExec(w http.ResponseWriter, req *http.Request, executor Executor, podN
|
||||
Causes: []metav1.StatusCause{
|
||||
{
|
||||
Type: remotecommandconsts.ExitCodeCauseType,
|
||||
Message: fmt.Sprintf("%d", rc),
|
||||
Message: strconv.Itoa(rc),
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -25,6 +25,7 @@ import (
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"net/url"
|
||||
"strconv"
|
||||
|
||||
refDocker "github.com/containerd/containerd/reference/docker"
|
||||
)
|
||||
@ -37,7 +38,7 @@ func FuzzFetcher(data []byte) int {
|
||||
|
||||
s := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
|
||||
rw.Header().Set("content-range", fmt.Sprintf("bytes %d-%d/%d", 0, dataLen-1, dataLen))
|
||||
rw.Header().Set("content-length", fmt.Sprintf("%d", dataLen))
|
||||
rw.Header().Set("content-length", strconv.Itoa(dataLen))
|
||||
rw.Write(data)
|
||||
}))
|
||||
defer s.Close()
|
||||
|
@ -25,6 +25,7 @@ import (
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"net/url"
|
||||
"strconv"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
@ -39,8 +40,8 @@ func TestFetcherOpen(t *testing.T) {
|
||||
if start > 0 {
|
||||
rw.Header().Set("content-range", fmt.Sprintf("bytes %d-127/128", start))
|
||||
}
|
||||
rw.Header().Set("content-length", fmt.Sprintf("%d", len(content[start:])))
|
||||
rw.Write(content[start:])
|
||||
rw.Header().Set("content-length", strconv.Itoa(len(content[start:])))
|
||||
_, _ = rw.Write(content[start:])
|
||||
}))
|
||||
defer s.Close()
|
||||
|
||||
|
@ -21,6 +21,7 @@ import (
|
||||
"encoding/binary"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@ -89,7 +90,7 @@ func GetInfo(ctx context.Context, key string) (string, snapshots.Info, snapshots
|
||||
return "", snapshots.Info{}, snapshots.Usage{}, err
|
||||
}
|
||||
|
||||
return fmt.Sprintf("%d", id), si, su, nil
|
||||
return strconv.FormatUint(id, 10), si, su, nil
|
||||
}
|
||||
|
||||
// UpdateInfo updates an existing snapshot info's data
|
||||
@ -184,7 +185,7 @@ func GetSnapshot(ctx context.Context, key string) (s Snapshot, err error) {
|
||||
return fmt.Errorf("snapshot does not exist: %w", errdefs.ErrNotFound)
|
||||
}
|
||||
|
||||
s.ID = fmt.Sprintf("%d", readID(sbkt))
|
||||
s.ID = strconv.FormatUint(readID(sbkt), 10)
|
||||
s.Kind = readKind(sbkt)
|
||||
|
||||
if s.Kind != snapshots.KindActive && s.Kind != snapshots.KindView {
|
||||
@ -279,7 +280,7 @@ func CreateSnapshot(ctx context.Context, kind snapshots.Kind, key, parent string
|
||||
}
|
||||
}
|
||||
|
||||
s.ID = fmt.Sprintf("%d", id)
|
||||
s.ID = strconv.FormatUint(id, 10)
|
||||
s.Kind = kind
|
||||
return nil
|
||||
})
|
||||
@ -336,7 +337,7 @@ func Remove(ctx context.Context, key string) (string, snapshots.Kind, error) {
|
||||
return "", 0, err
|
||||
}
|
||||
|
||||
return fmt.Sprintf("%d", id), si.Kind, nil
|
||||
return strconv.FormatUint(id, 10), si.Kind, nil
|
||||
}
|
||||
|
||||
// CommitActive renames the active snapshot transaction referenced by `key`
|
||||
@ -411,7 +412,7 @@ func CommitActive(ctx context.Context, key, name string, usage snapshots.Usage,
|
||||
return "", err
|
||||
}
|
||||
|
||||
return fmt.Sprintf("%d", id), nil
|
||||
return strconv.FormatUint(id, 10), nil
|
||||
}
|
||||
|
||||
// IDMap returns all the IDs mapped to their key
|
||||
@ -424,7 +425,7 @@ func IDMap(ctx context.Context) (map[string]string, error) {
|
||||
return nil
|
||||
}
|
||||
id := readID(bkt.Bucket(k))
|
||||
m[fmt.Sprintf("%d", id)] = string(k)
|
||||
m[strconv.FormatUint(id, 10)] = string(k)
|
||||
return nil
|
||||
})
|
||||
}); err != nil {
|
||||
@ -490,7 +491,7 @@ func createBucketIfNotExists(ctx context.Context, fn func(context.Context, *bolt
|
||||
|
||||
func parents(bkt, pbkt *bolt.Bucket, parent uint64) (parents []string, err error) {
|
||||
for {
|
||||
parents = append(parents, fmt.Sprintf("%d", parent))
|
||||
parents = append(parents, strconv.FormatUint(parent, 10))
|
||||
|
||||
parentKey := pbkt.Get(bucketKeyParent)
|
||||
if len(parentKey) == 0 {
|
||||
|
Loading…
Reference in New Issue
Block a user