Skip to content

Commit c43d045

Browse files
committed
fix lint
1 parent 10fcca5 commit c43d045

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

internal/dcgm/dcgmhelper.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
package dcgm
22

33
import (
4+
"context"
45
"fmt"
56
"os/exec"
67
"regexp"
78
"strconv"
89
"strings"
10+
"time"
911
)
1012

1113
type Helper struct {
@@ -16,7 +18,10 @@ func NewDcgmHelper() *Helper {
1618
}
1719

1820
func (h *Helper) GetDCGMVersion() (string, error) {
19-
cmd := exec.Command("dcgmi", "-v")
21+
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
22+
defer cancel()
23+
24+
cmd := exec.CommandContext(ctx, "dcgmi", "-v")
2025
output, err := cmd.Output()
2126

2227
if err != nil {
@@ -27,7 +32,10 @@ func (h *Helper) GetDCGMVersion() (string, error) {
2732
}
2833

2934
func (h *Helper) GetGpuInfo() (model string, number int, err error) {
30-
cmd := exec.Command("dcgmi", "discovery", "-l")
35+
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
36+
defer cancel()
37+
38+
cmd := exec.CommandContext(ctx, "dcgmi", "discovery", "-l")
3139
output, err := cmd.Output()
3240

3341
if err != nil {

internal/metadata/metadata.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
package metadata
22

33
import (
4+
"context"
45
"fmt"
56
"log/slog"
67
"os"
78
"os/exec"
89
"strings"
10+
"time"
911
)
1012

1113
type Config struct {
@@ -30,7 +32,10 @@ func (r *Reader) GetParentId() (string, error) {
3032
}
3133

3234
func (r *Reader) GetInstanceId() (instanceId string, isFallback bool, err error) {
33-
cmd := exec.Command("cloud-init", "query", "instance-id")
35+
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
36+
defer cancel()
37+
38+
cmd := exec.CommandContext(ctx, "cloud-init", "query", "instance-id")
3439
output, err := cmd.Output()
3540
if err != nil {
3641
instanceId, err2 := r.readAndTrimFile(r.cfg.Path + "/" + r.cfg.InstanceIdFilename)

0 commit comments

Comments
 (0)