Skip to content

Commit 836fe72

Browse files
committed
fix: supports seamless upgrade socket path name with uid
1 parent fd1da0b commit 836fe72

1 file changed

Lines changed: 64 additions & 4 deletions

File tree

cmd/dra-example-kubeletplugin/health.go

Lines changed: 64 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,11 @@ import (
2121
"fmt"
2222
"net"
2323
"net/url"
24+
"os"
2425
"path"
26+
"path/filepath"
2527
"strconv"
28+
"strings"
2629
"sync"
2730

2831
"google.golang.org/grpc"
@@ -63,9 +66,19 @@ func startHealthcheck(ctx context.Context, config *Config) (*healthcheck, error)
6366

6467
regSockPath := (&url.URL{
6568
Scheme: "unix",
66-
// TODO: this needs to adapt when seamless upgrades
67-
// are enabled and the filename includes a uid.
68-
Path: path.Join(config.flags.kubeletRegistrarDirectoryPath, consts.DriverName+"-reg.sock"),
69+
// Support both legacy and seamless upgrade socket naming conventions
70+
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")
79+
}
80+
return socketPath
81+
}(),
6982
}).String()
7083
log.Info("connecting to registration socket", "path", regSockPath)
7184
regConn, err := grpc.NewClient(
@@ -78,7 +91,18 @@ func startHealthcheck(ctx context.Context, config *Config) (*healthcheck, error)
7891

7992
draSockPath := (&url.URL{
8093
Scheme: "unix",
81-
Path: path.Join(config.DriverPluginPath(), "dra.sock"),
94+
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")
103+
}
104+
return socketPath
105+
}(),
82106
}).String()
83107
log.Info("connecting to DRA socket", "path", draSockPath)
84108
draConn, err := grpc.NewClient(
@@ -147,3 +171,39 @@ func (h *healthcheck) Check(ctx context.Context, req *grpc_health_v1.HealthCheck
147171
status.Status = grpc_health_v1.HealthCheckResponse_SERVING
148172
return status, nil
149173
}
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

Comments
 (0)