Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replace some basic uses of fmt.Sprintf() #8672

Merged
merged 1 commit into from
Jun 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion client.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ func NewWithConn(conn *grpc.ClientConn, opts ...ClientOpt) (*Client, error) {
c := &Client{
defaultns: copts.defaultns,
conn: conn,
runtime: fmt.Sprintf("%s.%s", plugin.RuntimePlugin, runtime.GOOS),
runtime: plugin.RuntimePlugin.String() + "." + runtime.GOOS,
}

if copts.defaultPlatform != nil {
Expand Down
2 changes: 1 addition & 1 deletion integration/client/container_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ func TestContainerStart(t *testing.T) {
}

func readShimPath(taskID string) (string, error) {
runtime := fmt.Sprintf("%s.%s", plugin.RuntimePluginV2, "task")
runtime := plugin.RuntimePluginV2.String() + ".task"
shimBinaryNamePath := filepath.Join(defaultState, runtime, testNamespace, taskID, "shim-binary-path")

shimPath, err := os.ReadFile(shimBinaryNamePath)
Expand Down
2 changes: 1 addition & 1 deletion pkg/cri/sbserver/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ func (c *criService) register(s *grpc.Server) error {
// imageFSPath returns containerd image filesystem path.
// Note that if containerd changes directory layout, we also needs to change this.
func imageFSPath(rootDir, snapshotter string) string {
return filepath.Join(rootDir, fmt.Sprintf("%s.%s", plugin.SnapshotPlugin, snapshotter))
return filepath.Join(rootDir, plugin.SnapshotPlugin.String()+"."+snapshotter)
}

func loadOCISpec(filename string) (*oci.Spec, error) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/cri/server/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ func (c *criService) register(s *grpc.Server) error {
// imageFSPath returns containerd image filesystem path.
// Note that if containerd changes directory layout, we also needs to change this.
func imageFSPath(rootDir, snapshotter string) string {
return filepath.Join(rootDir, fmt.Sprintf("%s.%s", plugin.SnapshotPlugin, snapshotter))
return filepath.Join(rootDir, plugin.SnapshotPlugin.String()+"."+snapshotter)
}

func loadOCISpec(filename string) (*oci.Spec, error) {
Expand Down
2 changes: 1 addition & 1 deletion plugin/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ func (r *Registration) Init(ic *InitContext) *Plugin {

// URI returns the full plugin URI
func (r *Registration) URI() string {
return fmt.Sprintf("%s.%s", r.Type, r.ID)
return r.Type.String() + "." + r.ID
}

var register = struct {
Expand Down
2 changes: 1 addition & 1 deletion remotes/docker/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func appendDistributionSourceLabel(originLabel, repo string) string {
}

func distributionSourceLabelKey(source string) string {
return fmt.Sprintf("%s.%s", labels.LabelDistributionSource, source)
return labels.LabelDistributionSource + "." + source
}

// selectRepositoryMountCandidate will select the repo which has longest
Expand Down
4 changes: 2 additions & 2 deletions runtime/v2/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ type ShimManager struct {

// ID of the shim manager
func (m *ShimManager) ID() string {
return fmt.Sprintf("%s.%s", plugin.RuntimePluginV2, "shim")
return plugin.RuntimePluginV2.String() + ".shim"
}

// Start launches a new shim instance
Expand Down Expand Up @@ -413,7 +413,7 @@ func NewTaskManager(shims *ShimManager) *TaskManager {

// ID of the task manager
func (m *TaskManager) ID() string {
return fmt.Sprintf("%s.%s", plugin.RuntimePluginV2, "task")
return plugin.RuntimePluginV2.String() + ".task"
}

// Create launches new shim instance and creates new task
Expand Down
4 changes: 2 additions & 2 deletions task.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ func (t *task) Delete(ctx context.Context, opts ...ProcessDeleteOpts) (*ExitStat
switch status.Status {
case Stopped, Unknown, "":
case Created:
if t.client.runtime == fmt.Sprintf("%s.%s", plugin.RuntimePlugin, "windows") {
if t.client.runtime == plugin.RuntimePlugin.String()+".windows" {
// On windows Created is akin to Stopped
break
}
Expand All @@ -328,7 +328,7 @@ func (t *task) Delete(ctx context.Context, opts ...ProcessDeleteOpts) (*ExitStat
// io.Wait locks for restored tasks on Windows unless we call
// io.Close first (https://github.com/containerd/containerd/issues/5621)
// in other cases, preserve the contract and let IO finish before closing
if t.client.runtime == fmt.Sprintf("%s.%s", plugin.RuntimePlugin, "windows") {
if t.client.runtime == plugin.RuntimePlugin.String()+".windows" {
t.io.Close()
}
// io.Cancel is used to cancel the io goroutine while it is in
Expand Down