Skip to content

Commit 1d44757

Browse files
authored
Merge pull request #366 from doringeman/debug-log-ascend-mounts
fix(standalone): use StatusPrinter in tryGetBindAscendMounts
2 parents 0d652d4 + 21aa3c7 commit 1d44757

File tree

3 files changed

+18
-6
lines changed

3 files changed

+18
-6
lines changed

cmd/cli/commands/utils.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ func (cp *commandPrinter) Println(args ...any) {
5858
cp.cmd.Println(args...)
5959
}
6060

61+
// PrintErrf implements StatusPrinter.PrintErrf by delegating to cobra.Command.PrintErrf
62+
func (cp *commandPrinter) PrintErrf(format string, args ...any) {
63+
cp.cmd.PrintErrf(format, args...)
64+
}
65+
6166
// Write implements StatusPrinter.Write by delegating to cobra.Command's output writer
6267
func (cp *commandPrinter) Write(p []byte) (n int, err error) {
6368
return cp.cmd.OutOrStdout().Write(p)

cmd/cli/pkg/standalone/containers.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ func isRootless(ctx context.Context, dockerClient *client.Client) bool {
233233
}
234234

235235
// Check whether the host Ascend driver path exists. If so, create the corresponding mount configuration.
236-
func tryGetBindAscendMounts() []mount.Mount {
236+
func tryGetBindAscendMounts(printer StatusPrinter) []mount.Mount {
237237
hostPaths := []string{
238238
"/usr/local/dcmi",
239239
"/usr/local/bin/npu-smi",
@@ -245,7 +245,7 @@ func tryGetBindAscendMounts() []mount.Mount {
245245
for _, hostPath := range hostPaths {
246246
matches, err := filepath.Glob(hostPath)
247247
if err != nil {
248-
fmt.Errorf("Error checking glob pattern for %s: %v", hostPath, err)
248+
printer.PrintErrf("Error checking glob pattern for %s: %v\n", hostPath, err)
249249
continue
250250
}
251251

@@ -258,7 +258,9 @@ func tryGetBindAscendMounts() []mount.Mount {
258258
}
259259
newMounts = append(newMounts, newMount)
260260
} else {
261-
fmt.Printf(" [NOT FOUND] Ascend driver path does not exist, skipping: %s\n", hostPath)
261+
if os.Getenv("DEBUG") == "1" {
262+
printer.Printf("[NOT FOUND] Ascend driver path does not exist, skipping: %s\n", hostPath)
263+
}
262264
}
263265
}
264266

@@ -309,7 +311,7 @@ func CreateControllerContainer(ctx context.Context, dockerClient *client.Client,
309311
Name: "always",
310312
},
311313
}
312-
ascendMounts := tryGetBindAscendMounts()
314+
ascendMounts := tryGetBindAscendMounts(printer)
313315
if len(ascendMounts) > 0 {
314316
hostConfig.Mounts = append(hostConfig.Mounts, ascendMounts...)
315317
}

cmd/cli/pkg/standalone/status.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@ package standalone
22

33
// StatusPrinter is the interface used to print status updates.
44
type StatusPrinter interface {
5-
// Printf should perform formatted printing.
5+
// Printf should perform formatted printing to stdout.
66
Printf(format string, args ...any)
7-
// Println should perform line-based printing.
7+
// Println should perform line-based printing to stdout.
88
Println(args ...any)
9+
// PrintErrf should perform formatted printing to stderr.
10+
PrintErrf(format string, args ...any)
911
// Write implements io.Writer for stream-based output.
1012
Write(p []byte) (n int, err error)
1113
// GetFdInfo returns the file descriptor and terminal status for the output.
@@ -21,6 +23,9 @@ func (*noopPrinter) Printf(format string, args ...any) {}
2123
// Println implements StatusPrinter.Println.
2224
func (*noopPrinter) Println(args ...any) {}
2325

26+
// PrintErrf implements StatusPrinter.PrintErrf.
27+
func (*noopPrinter) PrintErrf(format string, args ...any) {}
28+
2429
// Write implements StatusPrinter.Write.
2530
func (*noopPrinter) Write(p []byte) (n int, err error) {
2631
return len(p), nil

0 commit comments

Comments
 (0)