@@ -21,11 +21,8 @@ import (
2121 "fmt"
2222 "net"
2323 "net/url"
24- "os"
2524 "path"
26- "path/filepath"
2725 "strconv"
28- "strings"
2926 "sync"
3027
3128 "google.golang.org/grpc"
@@ -66,18 +63,11 @@ func startHealthcheck(ctx context.Context, config *Config) (*healthcheck, error)
6663
6764 regSockPath := (& url.URL {
6865 Scheme : "unix" ,
69- // Support both legacy and seamless upgrade socket naming conventions
7066 Path : func () string {
71- socketPath , err := findSocketPath (
72- config .flags .kubeletRegistrarDirectoryPath ,
73- consts .DriverName ,
74- "-reg.sock" ,
75- )
76- if err != nil {
77- // Fallback to legacy path name
78- return path .Join (config .flags .kubeletRegistrarDirectoryPath , consts .DriverName + "-reg.sock" )
67+ if config .flags .podUID != "" {
68+ return path .Join (config .flags .kubeletRegistrarDirectoryPath , consts .DriverName + "-" + config .flags .podUID + "-reg.sock" )
7969 }
80- return socketPath
70+ return path . Join ( config . flags . kubeletRegistrarDirectoryPath , consts . DriverName + "-reg.sock" )
8171 }(),
8272 }).String ()
8373 log .Info ("connecting to registration socket" , "path" , regSockPath )
@@ -92,16 +82,10 @@ func startHealthcheck(ctx context.Context, config *Config) (*healthcheck, error)
9282 draSockPath := (& url.URL {
9383 Scheme : "unix" ,
9484 Path : func () string {
95- socketPath , err := findSocketPath (
96- config .DriverPluginPath (),
97- "dra" ,
98- ".sock" ,
99- )
100- if err != nil {
101- // Fallback to legacy path name
102- return path .Join (config .DriverPluginPath (), "dra.sock" )
85+ if config .flags .podUID != "" {
86+ return path .Join (config .DriverPluginPath (), "dra-" + config .flags .podUID + ".sock" )
10387 }
104- return socketPath
88+ return path . Join ( config . DriverPluginPath (), "dra.sock" )
10589 }(),
10690 }).String ()
10791 log .Info ("connecting to DRA socket" , "path" , draSockPath )
@@ -171,39 +155,3 @@ func (h *healthcheck) Check(ctx context.Context, req *grpc_health_v1.HealthCheck
171155 status .Status = grpc_health_v1 .HealthCheckResponse_SERVING
172156 return status , nil
173157}
174-
175- // Finds driver's socket paths whether its legacy (fixed filename) or seamless upgrade (UID-based filename) formats.
176- func findSocketPath (dir , baseName , suffix string ) (string , error ) {
177- // First try the legacy path name: {baseName}{suffix}
178- legacyPath := filepath .Join (dir , baseName + suffix )
179- if _ , err := os .Stat (legacyPath ); err == nil {
180- return legacyPath , nil
181- }
182-
183- // Then try the seamless upgrade format: {baseName}-{uid}{suffix}
184- entries , err := os .ReadDir (dir )
185- if err != nil {
186- return "" , fmt .Errorf ("failed to read directory %s: %w" , dir , err )
187- }
188-
189- for _ , entry := range entries {
190- if entry .IsDir () {
191- continue
192- }
193- name := entry .Name ()
194-
195- // Look for files matching pattern: {baseName}-{uid}{suffix}
196- if strings .HasPrefix (name , baseName + "-" ) && strings .HasSuffix (name , suffix ) {
197- // Verify it's not the legacy format (which would be {baseName}{suffix})
198- if name != baseName + suffix {
199- socketPath := filepath .Join (dir , name )
200- klog .Info ("Found seamless upgrade socket" , "path" , socketPath , "uid" , strings .TrimPrefix (strings .TrimSuffix (name , suffix ), baseName + "-" ))
201- return socketPath , nil
202- }
203- }
204- }
205-
206- // If neither path name types are found, return the legacy path for error reporting
207- return legacyPath , fmt .Errorf ("socket file not found in dir %s (tried legacy path name %s and seamless upgrade with uid path name %s-*%s)" ,
208- dir , baseName + suffix , baseName , suffix )
209- }
0 commit comments