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
12 changes: 10 additions & 2 deletions pkg/resources/resources_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ import (
"github.com/Mellanox/k8s-rdma-shared-dev-plugin/pkg/utils"
)

// getSocketDir returns the socket directory path, checking environment variable first
func getSocketDir(defaultPath string) string {
if envPath := os.Getenv("DP_SOCK_PATH"); envPath != "" {
return envPath
}
return defaultPath
}

const (
// General constants
DefaultConfigFilePath = "/k8s-rdma-shared-dev-plugin/config.json"
Expand All @@ -71,8 +79,8 @@ const (
)

var (
activeSockDir = "/var/lib/kubelet/plugins_registry"
deprecatedSockDir = "/var/lib/kubelet/device-plugins"
activeSockDir = getSocketDir("/var/lib/kubelet/plugins_registry")
deprecatedSockDir = getSocketDir("/var/lib/kubelet/device-plugins")
)

// resourceManager for plugin
Expand Down
25 changes: 25 additions & 0 deletions pkg/resources/resources_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,31 @@ var _ = Describe("ResourcesManger", func() {
Expect(rm.watchMode).To(Equal(false))
})
})
Context("getSocketDir", func() {
It("returns environment variable when DP_SOCK_PATH is set", func() {
customPath := "/custom/socket/path"
os.Setenv("DP_SOCK_PATH", customPath)
defer os.Unsetenv("DP_SOCK_PATH")

result := getSocketDir("/default/path")
Expect(result).To(Equal(customPath))
})
It("returns default path when DP_SOCK_PATH is not set", func() {
os.Unsetenv("DP_SOCK_PATH")
defaultPath := "/default/path"

result := getSocketDir(defaultPath)
Expect(result).To(Equal(defaultPath))
})
It("returns environment variable even when it's empty string", func() {
os.Setenv("DP_SOCK_PATH", "")
defer os.Unsetenv("DP_SOCK_PATH")
defaultPath := "/default/path"

result := getSocketDir(defaultPath)
Expect(result).To(Equal(defaultPath))
})
})
//nolint:dupl
Context("ReadConfig", func() {
It("Read valid config file with non default periodic update", func() {
Expand Down