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"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"text/tabwriter"
|
"text/tabwriter"
|
||||||
"time"
|
"time"
|
||||||
@ -207,7 +208,7 @@ var usageCommand = cli.Command{
|
|||||||
var displaySize func(int64) string
|
var displaySize func(int64) string
|
||||||
if context.Bool("b") {
|
if context.Bool("b") {
|
||||||
displaySize = func(s int64) string {
|
displaySize = func(s int64) string {
|
||||||
return fmt.Sprintf("%d", s)
|
return strconv.FormatInt(s, 10)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
displaySize = func(s int64) string {
|
displaySize = func(s int64) string {
|
||||||
|
@ -18,9 +18,9 @@ package client
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"fmt"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
"testing"
|
"testing"
|
||||||
@ -133,7 +133,7 @@ func TestDaemonCustomCgroup(t *testing.T) {
|
|||||||
t.Skip("skip TestDaemonCustomCgroup since no cgroup path available")
|
t.Skip("skip TestDaemonCustomCgroup since no cgroup path available")
|
||||||
}
|
}
|
||||||
|
|
||||||
customCgroup := fmt.Sprintf("%d", time.Now().Nanosecond())
|
customCgroup := strconv.Itoa(time.Now().Nanosecond())
|
||||||
configTOML := `
|
configTOML := `
|
||||||
version = 2
|
version = 2
|
||||||
[cgroup]
|
[cgroup]
|
||||||
|
@ -602,7 +602,7 @@ func (tc *nriTest) setup() {
|
|||||||
tc.prefix = strings.ToLower(tc.name)
|
tc.prefix = strings.ToLower(tc.name)
|
||||||
}
|
}
|
||||||
if tc.namespace == "" {
|
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)
|
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 {
|
if err := WithUser(config.User)(ctx, client, c, s); err != nil {
|
||||||
return err
|
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
|
// we should query the image's /etc/group for additional GIDs
|
||||||
// even if there is no specified user in the image config
|
// even if there is no specified user in the image config
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
package sbserver
|
package sbserver
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"strconv"
|
||||||
|
|
||||||
imagespec "github.com/opencontainers/image-spec/specs-go/v1"
|
imagespec "github.com/opencontainers/image-spec/specs-go/v1"
|
||||||
runtime "k8s.io/cri-api/pkg/apis/runtime/v1"
|
runtime "k8s.io/cri-api/pkg/apis/runtime/v1"
|
||||||
@ -39,9 +39,8 @@ func snapshotterOpts(snapshotterName string, config *runtime.ContainerConfig) ([
|
|||||||
case "windows":
|
case "windows":
|
||||||
rootfsSize := config.GetWindows().GetResources().GetRootfsSizeInBytes()
|
rootfsSize := config.GetWindows().GetResources().GetRootfsSizeInBytes()
|
||||||
if rootfsSize != 0 {
|
if rootfsSize != 0 {
|
||||||
sizeStr := fmt.Sprintf("%d", rootfsSize)
|
|
||||||
labels := map[string]string{
|
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))
|
opts = append(opts, snapshots.WithLabels(labels))
|
||||||
}
|
}
|
||||||
|
@ -135,10 +135,10 @@ func (c *criService) getSandboxDevShm(id string) string {
|
|||||||
// generated is unique as long as sandbox metadata is unique.
|
// generated is unique as long as sandbox metadata is unique.
|
||||||
func makeSandboxName(s *runtime.PodSandboxMetadata) string {
|
func makeSandboxName(s *runtime.PodSandboxMetadata) string {
|
||||||
return strings.Join([]string{
|
return strings.Join([]string{
|
||||||
s.Name, // 0
|
s.Name, // 0
|
||||||
s.Namespace, // 1
|
s.Namespace, // 1
|
||||||
s.Uid, // 2
|
s.Uid, // 2
|
||||||
fmt.Sprintf("%d", s.Attempt), // 3
|
strconv.FormatUint(uint64(s.Attempt), 10), // 3
|
||||||
}, nameDelimiter)
|
}, nameDelimiter)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -147,11 +147,11 @@ func makeSandboxName(s *runtime.PodSandboxMetadata) string {
|
|||||||
// unique.
|
// unique.
|
||||||
func makeContainerName(c *runtime.ContainerMetadata, s *runtime.PodSandboxMetadata) string {
|
func makeContainerName(c *runtime.ContainerMetadata, s *runtime.PodSandboxMetadata) string {
|
||||||
return strings.Join([]string{
|
return strings.Join([]string{
|
||||||
c.Name, // 0: container name
|
c.Name, // 0: container name
|
||||||
s.Name, // 1: pod name
|
s.Name, // 1: pod name
|
||||||
s.Namespace, // 2: pod namespace
|
s.Namespace, // 2: pod namespace
|
||||||
s.Uid, // 3: pod uid
|
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)
|
}, nameDelimiter)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,7 +18,6 @@ package server
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
imagespec "github.com/opencontainers/image-spec/specs-go/v1"
|
imagespec "github.com/opencontainers/image-spec/specs-go/v1"
|
||||||
@ -147,9 +146,8 @@ func snapshotterOpts(snapshotterName string, config *runtime.ContainerConfig) ([
|
|||||||
case "windows":
|
case "windows":
|
||||||
rootfsSize := config.GetWindows().GetResources().GetRootfsSizeInBytes()
|
rootfsSize := config.GetWindows().GetResources().GetRootfsSizeInBytes()
|
||||||
if rootfsSize != 0 {
|
if rootfsSize != 0 {
|
||||||
sizeStr := fmt.Sprintf("%d", rootfsSize)
|
|
||||||
labels := map[string]string{
|
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))
|
opts = append(opts, snapshots.WithLabels(labels))
|
||||||
}
|
}
|
||||||
|
@ -99,7 +99,7 @@ func makeSandboxName(s *runtime.PodSandboxMetadata) string {
|
|||||||
s.Name, // 0
|
s.Name, // 0
|
||||||
s.Namespace, // 1
|
s.Namespace, // 1
|
||||||
s.Uid, // 2
|
s.Uid, // 2
|
||||||
fmt.Sprintf("%d", s.Attempt), // 3
|
strconv.Itoa(int(s.Attempt)), // 3
|
||||||
}, nameDelimiter)
|
}, nameDelimiter)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -108,11 +108,11 @@ func makeSandboxName(s *runtime.PodSandboxMetadata) string {
|
|||||||
// unique.
|
// unique.
|
||||||
func makeContainerName(c *runtime.ContainerMetadata, s *runtime.PodSandboxMetadata) string {
|
func makeContainerName(c *runtime.ContainerMetadata, s *runtime.PodSandboxMetadata) string {
|
||||||
return strings.Join([]string{
|
return strings.Join([]string{
|
||||||
c.Name, // 0: container name
|
c.Name, // 0: container name
|
||||||
s.Name, // 1: pod name
|
s.Name, // 1: pod name
|
||||||
s.Namespace, // 2: pod namespace
|
s.Namespace, // 2: pod namespace
|
||||||
s.Uid, // 3: pod uid
|
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)
|
}, nameDelimiter)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,6 +36,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
apierrors "k8s.io/apimachinery/pkg/api/errors"
|
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{
|
Causes: []metav1.StatusCause{
|
||||||
{
|
{
|
||||||
Type: remotecommandconsts.ExitCodeCauseType,
|
Type: remotecommandconsts.ExitCodeCauseType,
|
||||||
Message: fmt.Sprintf("%d", rc),
|
Message: strconv.Itoa(rc),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -25,6 +25,7 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
refDocker "github.com/containerd/containerd/reference/docker"
|
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) {
|
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-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)
|
rw.Write(data)
|
||||||
}))
|
}))
|
||||||
defer s.Close()
|
defer s.Close()
|
||||||
|
@ -25,6 +25,7 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
"strconv"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
@ -39,8 +40,8 @@ func TestFetcherOpen(t *testing.T) {
|
|||||||
if start > 0 {
|
if start > 0 {
|
||||||
rw.Header().Set("content-range", fmt.Sprintf("bytes %d-127/128", start))
|
rw.Header().Set("content-range", fmt.Sprintf("bytes %d-127/128", start))
|
||||||
}
|
}
|
||||||
rw.Header().Set("content-length", fmt.Sprintf("%d", len(content[start:])))
|
rw.Header().Set("content-length", strconv.Itoa(len(content[start:])))
|
||||||
rw.Write(content[start:])
|
_, _ = rw.Write(content[start:])
|
||||||
}))
|
}))
|
||||||
defer s.Close()
|
defer s.Close()
|
||||||
|
|
||||||
|
@ -21,6 +21,7 @@ import (
|
|||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -89,7 +90,7 @@ func GetInfo(ctx context.Context, key string) (string, snapshots.Info, snapshots
|
|||||||
return "", snapshots.Info{}, snapshots.Usage{}, err
|
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
|
// 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)
|
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)
|
s.Kind = readKind(sbkt)
|
||||||
|
|
||||||
if s.Kind != snapshots.KindActive && s.Kind != snapshots.KindView {
|
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
|
s.Kind = kind
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
@ -336,7 +337,7 @@ func Remove(ctx context.Context, key string) (string, snapshots.Kind, error) {
|
|||||||
return "", 0, err
|
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`
|
// 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 "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
return fmt.Sprintf("%d", id), nil
|
return strconv.FormatUint(id, 10), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// IDMap returns all the IDs mapped to their key
|
// IDMap returns all the IDs mapped to their key
|
||||||
@ -424,7 +425,7 @@ func IDMap(ctx context.Context) (map[string]string, error) {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
id := readID(bkt.Bucket(k))
|
id := readID(bkt.Bucket(k))
|
||||||
m[fmt.Sprintf("%d", id)] = string(k)
|
m[strconv.FormatUint(id, 10)] = string(k)
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
}); err != 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) {
|
func parents(bkt, pbkt *bolt.Bucket, parent uint64) (parents []string, err error) {
|
||||||
for {
|
for {
|
||||||
parents = append(parents, fmt.Sprintf("%d", parent))
|
parents = append(parents, strconv.FormatUint(parent, 10))
|
||||||
|
|
||||||
parentKey := pbkt.Get(bucketKeyParent)
|
parentKey := pbkt.Get(bucketKeyParent)
|
||||||
if len(parentKey) == 0 {
|
if len(parentKey) == 0 {
|
||||||
|
Loading…
Reference in New Issue
Block a user