Skip to content

Commit 527f804

Browse files
authored
[Misc] remove the duplicated env functions (vllm-project#953)
Signed-off-by: Iceber Gu <[email protected]>
1 parent b248ee2 commit 527f804

File tree

5 files changed

+9
-58
lines changed

5 files changed

+9
-58
lines changed

pkg/controller/modeladapter/utils.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
"errors"
2121
"fmt"
2222
"net/url"
23-
"os"
2423
"strings"
2524

2625
"github.com/vllm-project/aibrix/pkg/config"
@@ -46,14 +45,6 @@ func equalStringSlices(a, b []string) bool {
4645
return true
4746
}
4847

49-
// getEnvKey retrieves the value of the environment variable named by the key.
50-
// If the variable is present, the function returns the value and a boolean true.
51-
// If the variable is not present, the function returns an empty string and a boolean false.
52-
func getEnvKey(key string) (string, bool) {
53-
value, exists := os.LookupEnv(key)
54-
return value, exists
55-
}
56-
5748
func extractHuggingFacePath(artifactURL string) (string, error) {
5849
parsedURL, err := url.Parse(artifactURL)
5950
if err != nil {

pkg/controller/modeladapter/utils_test.go

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ package modeladapter
1818

1919
import (
2020
"fmt"
21-
"os"
2221
"testing"
2322

2423
"github.com/stretchr/testify/assert"
@@ -50,27 +49,6 @@ func TestEqualStringSlices(t *testing.T) {
5049
})
5150
}
5251

53-
// Test for getEnvKey function
54-
func TestGetEnvKey(t *testing.T) {
55-
// Case 1: Environment variable exists
56-
t.Run("environment variable exists", func(t *testing.T) {
57-
err := os.Setenv("TEST_ENV", "test_value")
58-
assert.NoError(t, err)
59-
value, exists := getEnvKey("TEST_ENV")
60-
assert.True(t, exists)
61-
assert.Equal(t, "test_value", value)
62-
err = os.Unsetenv("TEST_ENV")
63-
assert.NoError(t, err)
64-
})
65-
66-
// Case 2: Environment variable does not exist
67-
t.Run("environment variable does not exist", func(t *testing.T) {
68-
value, exists := getEnvKey("NON_EXISTENT_ENV")
69-
assert.False(t, exists)
70-
assert.Equal(t, "", value)
71-
})
72-
}
73-
7452
func TestExtractHuggingFacePath(t *testing.T) {
7553
tests := []struct {
7654
name string

pkg/controller/podautoscaler/metrics/utils.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
"context"
2121
"fmt"
2222
"net/url"
23-
"os"
2423
"strconv"
2524
"strings"
2625
"time"
@@ -134,11 +133,3 @@ func GetMetricFromSource(ctx context.Context, fetcher MetricFetcher, source auto
134133
}
135134
return fetcher.FetchMetric(ctx, source.ProtocolType, endpoint, source.Path, source.TargetMetric)
136135
}
137-
138-
// getEnvKey retrieves the value of the environment variable named by the key.
139-
// If the variable is present, the function returns the value and a boolean true.
140-
// If the variable is not present, the function returns an empty string and a boolean false.
141-
func getEnvKey(key string) (string, bool) {
142-
value, exists := os.LookupEnv(key)
143-
return value, exists
144-
}

pkg/utils/redis.go

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,32 +19,16 @@ package utils
1919
import (
2020
"context"
2121
"fmt"
22-
"os"
2322

2423
"github.com/redis/go-redis/v9"
2524
"k8s.io/klog/v2"
2625
)
2726

2827
var (
29-
redis_host = GetEnv("REDIS_HOST", "localhost")
30-
redis_port = GetEnv("REDIS_PORT", "6379")
28+
redis_host = LoadEnv("REDIS_HOST", "localhost")
29+
redis_port = LoadEnv("REDIS_PORT", "6379")
3130
)
3231

33-
// CheckEnvExists checks if an environment variable exists.
34-
// It returns the value and a boolean indicating its existence.
35-
func CheckEnvExists(envVar string) (string, bool) {
36-
value, exists := os.LookupEnv(envVar)
37-
return value, exists
38-
}
39-
40-
func GetEnv(key, defaultValue string) string {
41-
value := os.Getenv(key)
42-
if value == "" {
43-
return defaultValue
44-
}
45-
return value
46-
}
47-
4832
func GetRedisClient() *redis.Client {
4933
// Connect to Redis
5034
client := redis.NewClient(&redis.Options{

pkg/utils/util.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,13 @@ func TrimMessage(message string) string {
7474
return message
7575
}
7676

77+
// CheckEnvExists checks if an environment variable exists.
78+
// It returns the value and a boolean indicating its existence.
79+
func CheckEnvExists(envVar string) (string, bool) {
80+
value, exists := os.LookupEnv(envVar)
81+
return value, exists
82+
}
83+
7784
// LoadEnv loads an environment variable or returns a default value if not set.
7885
func LoadEnv(key, defaultValue string) string {
7986
value := os.Getenv(key)

0 commit comments

Comments
 (0)