Skip to content
Open
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 cmd/gpud/command/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ sudo rm /etc/systemd/system/gpud.service
&cli.StringFlag{
Name: "listen-address",
Usage: "set the listen address",
Value: fmt.Sprintf("0.0.0.0:%d", pkgconfig.DefaultGPUdPort),
Value: fmt.Sprintf("0.0.0.0:%d", pkgconfig.GPUdPortNumber()),
},
&cli.BoolFlag{
Name: "pprof",
Expand Down
4 changes: 2 additions & 2 deletions cmd/gpud/compact/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ func Command(cliContext *cli.Context) error {
}
}

portOpen := isPortOpen(config.DefaultGPUdPort)
portOpen := isPortOpen(config.GPUdPortNumber())
if portOpen {
return fmt.Errorf("gpud is running on port %d (must be stopped before running compact)", config.DefaultGPUdPort)
return fmt.Errorf("gpud is running on port %d (must be stopped before running compact)", config.GPUdPortNumber())
}

log.Logger.Infow("successfully checked gpud is not running")
Expand Down
2 changes: 1 addition & 1 deletion cmd/gpud/compact/command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func TestCommand_ReturnsErrorWhenPortOpen(t *testing.T) {

err := Command(cliContext)
require.Error(t, err)
assert.Equal(t, fmt.Sprintf("gpud is running on port %d (must be stopped before running compact)", config.DefaultGPUdPort), err.Error())
assert.Equal(t, fmt.Sprintf("gpud is running on port %d (must be stopped before running compact)", config.GPUdPortNumber()), err.Error())
}

func TestCommand_Success(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion cmd/gpud/list-plugins/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func Command(cliContext *cli.Context) error {
// Get the server address from the flag, default to http://localhost:<Default GPUd port>
serverAddr := cliContext.String("server")
if serverAddr == "" {
serverAddr = fmt.Sprintf("https://localhost:%d", config.DefaultGPUdPort)
serverAddr = fmt.Sprintf("https://localhost:%d", config.GPUdPortNumber())
}

// Get custom plugins
Expand Down
2 changes: 1 addition & 1 deletion cmd/gpud/run-plugin-group/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func Command(cliContext *cli.Context) error {
// Get the server address from the flag, default to http://localhost:<Default GPUd port>
serverAddr := cliContext.String("server")
if serverAddr == "" {
serverAddr = fmt.Sprintf("https://localhost:%d", config.DefaultGPUdPort)
serverAddr = fmt.Sprintf("https://localhost:%d", config.GPUdPortNumber())
}

// Create a context with timeout
Expand Down
2 changes: 1 addition & 1 deletion cmd/gpud/set-healthy/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func CreateCommand() func(*cli.Context) error {
// Get the server address from the flag, default to https://localhost:<Default GPUd port>
serverAddr := cliContext.String("server")
if serverAddr == "" {
serverAddr = fmt.Sprintf("https://localhost:%d", config.DefaultGPUdPort)
serverAddr = fmt.Sprintf("https://localhost:%d", config.GPUdPortNumber())
}

// Get the components from the positional argument
Expand Down
4 changes: 2 additions & 2 deletions cmd/gpud/status/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func Command(cliContext *cli.Context) error {

if err := clientv1.BlockUntilServerReady(
rootCtx,
fmt.Sprintf("https://localhost:%d", config.DefaultGPUdPort),
fmt.Sprintf("https://localhost:%d", config.GPUdPortNumber()),
); err != nil {
return err
}
Expand All @@ -118,7 +118,7 @@ func Command(cliContext *cli.Context) error {
for {
var err error
cctx, ccancel := context.WithTimeout(rootCtx, 15*time.Second)
lastPackageStatus, err = clientv1.GetPackageStatus(cctx, fmt.Sprintf("https://localhost:%d%s", config.DefaultGPUdPort, server.URLPathAdminPackages))
lastPackageStatus, err = clientv1.GetPackageStatus(cctx, fmt.Sprintf("https://localhost:%d%s", config.GPUdPortNumber(), server.URLPathAdminPackages))
ccancel()
if err != nil {
fmt.Printf("%s failed to get package status: %v\n", cmdcommon.WarningSign, err)
Expand Down
19 changes: 17 additions & 2 deletions pkg/config/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
stdos "os"
"path/filepath"
"strconv"
"time"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand All @@ -14,8 +15,8 @@ import (

const (
DefaultAPIVersion = "v1"
DefaultGPUdPort = 15132
DefaultDataDir = "/var/lib/gpud"
DefaultGPUdPort = 15132
)

var (
Expand Down Expand Up @@ -43,7 +44,7 @@ func DefaultConfig(ctx context.Context, opts ...OpOption) (*Config, error) {

cfg := &Config{
APIVersion: DefaultAPIVersion,
Address: fmt.Sprintf(":%d", DefaultGPUdPort),
Address: fmt.Sprintf(":%d", GPUdPortNumber()),
DataDir: dataDir,
RetentionPeriod: DefaultRetentionPeriod,
CompactPeriod: DefaultCompactPeriod,
Expand Down Expand Up @@ -141,3 +142,17 @@ func PackagesDir(dataDir string) string {
func VersionFilePath(dataDir string) string {
return filepath.Join(dataDir, "target_version")
}

func GPUdPortNumber() int {
portStr, found := stdos.LookupEnv("GPUD_PORT")
if !found {
return DefaultGPUdPort
}

port, err := strconv.Atoi(portStr)
if err != nil {
return DefaultGPUdPort
}

return port
}
2 changes: 1 addition & 1 deletion pkg/config/default_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func TestDefaultConfig(t *testing.T) {

// Check basic properties that don't depend on the environment
assert.Equal(t, DefaultAPIVersion, cfg.APIVersion)
assert.Equal(t, fmt.Sprintf(":%d", DefaultGPUdPort), cfg.Address)
assert.Equal(t, fmt.Sprintf(":%d", GPUdPortNumber()), cfg.Address)
assert.Equal(t, DefaultRetentionPeriod, cfg.RetentionPeriod)
assert.Equal(t, DefaultCompactPeriod, cfg.CompactPeriod)
assert.False(t, cfg.Pprof)
Expand Down
Loading