Skip to content

Commit 9ba4490

Browse files
committed
feat: helm chart value + conditional POD_UID env var for seamless upgrades
1 parent 836fe72 commit 9ba4490

File tree

5 files changed

+40
-62
lines changed

5 files changed

+40
-62
lines changed

cmd/dra-example-kubeletplugin/driver.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,22 @@ func NewDriver(ctx context.Context, config *Config) (*driver, error) {
4949
}
5050
driver.state = state
5151

52-
helper, err := kubeletplugin.Start(
53-
ctx,
54-
driver,
52+
kubeletPluginOptions := []kubeletplugin.Option{
5553
kubeletplugin.KubeClient(config.coreclient),
5654
kubeletplugin.NodeName(config.flags.nodeName),
5755
kubeletplugin.DriverName(consts.DriverName),
5856
kubeletplugin.RegistrarDirectoryPath(config.flags.kubeletRegistrarDirectoryPath),
5957
kubeletplugin.PluginDataDirectoryPath(config.DriverPluginPath()),
60-
)
58+
}
59+
60+
// Enable seamless upgrades when POD_UID is available (which gets set by Helm when seamlessUpgrades.enabled=true)
61+
if config.flags.podUID != "" {
62+
kubeletPluginOptions = append(kubeletPluginOptions,
63+
kubeletplugin.RollingUpdate(types.UID(config.flags.podUID)),
64+
)
65+
}
66+
67+
helper, err := kubeletplugin.Start(ctx, driver, kubeletPluginOptions...)
6168
if err != nil {
6269
return nil, err
6370
}

cmd/dra-example-kubeletplugin/health.go

Lines changed: 6 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -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-
}

cmd/dra-example-kubeletplugin/main.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ type Flags struct {
4949
kubeletRegistrarDirectoryPath string
5050
kubeletPluginsDirectoryPath string
5151
healthcheckPort int
52+
podUID string
5253
}
5354

5455
type Config struct {
@@ -114,6 +115,12 @@ func newApp() *cli.App {
114115
Destination: &flags.healthcheckPort,
115116
EnvVars: []string{"HEALTHCHECK_PORT"},
116117
},
118+
&cli.StringFlag{
119+
Name: "pod-uid",
120+
Usage: "UID of the pod (used for seamless upgrades to create unique socket names).",
121+
Destination: &flags.podUID,
122+
EnvVars: []string{"POD_UID"},
123+
},
117124
}
118125
cliFlags = append(cliFlags, flags.kubeClientConfig.Flags()...)
119126
cliFlags = append(cliFlags, flags.loggingConfig.Flags()...)

deployments/helm/dra-example-driver/templates/kubeletplugin.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,18 @@ spec:
1212
matchLabels:
1313
{{- include "dra-example-driver.selectorLabels" . | nindent 6 }}
1414
app.kubernetes.io/component: kubeletplugin
15+
{{- if .Values.kubeletPlugin.seamlessUpgrades.enabled }}
16+
updateStrategy:
17+
type: RollingUpdate
18+
rollingUpdate:
19+
maxSurge: 1
20+
maxUnavailable: 0
21+
{{- else }}
1522
{{- with .Values.kubeletPlugin.updateStrategy }}
1623
updateStrategy:
1724
{{- toYaml . | nindent 4 }}
1825
{{- end }}
26+
{{- end }}
1927
template:
2028
metadata:
2129
{{- with .Values.kubeletPlugin.podAnnotations }}
@@ -80,6 +88,12 @@ spec:
8088
- name: HEALTHCHECK_PORT
8189
value: {{ .Values.kubeletPlugin.containers.plugin.healthcheckPort | quote }}
8290
{{- end }}
91+
{{- if .Values.kubeletPlugin.seamlessUpgrades.enabled }}
92+
- name: POD_UID
93+
valueFrom:
94+
fieldRef:
95+
fieldPath: metadata.uid
96+
{{- end }}
8397
volumeMounts:
8498
- name: plugins-registry
8599
mountPath: {{ .Values.kubeletPlugin.kubeletRegistrarDirectoryPath | quote }}

deployments/helm/dra-example-driver/values.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ controller:
4646

4747
kubeletPlugin:
4848
priorityClassName: "system-node-critical"
49+
seamlessUpgrades:
50+
enabled: false
4951
updateStrategy:
5052
type: RollingUpdate
5153
podAnnotations: {}

0 commit comments

Comments
 (0)