Skip to content

Commit 39da3da

Browse files
committed
seamless upgrades cli flag + kubeletplugin yaml accounts for updateStrategy values
1 parent 9ba4490 commit 39da3da

File tree

4 files changed

+29
-8
lines changed

4 files changed

+29
-8
lines changed

cmd/dra-example-kubeletplugin/driver.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ func NewDriver(ctx context.Context, config *Config) (*driver, error) {
5757
kubeletplugin.PluginDataDirectoryPath(config.DriverPluginPath()),
5858
}
5959

60-
// Enable seamless upgrades when POD_UID is available (which gets set by Helm when seamlessUpgrades.enabled=true)
61-
if config.flags.podUID != "" {
60+
// Enable seamless upgrades when both seamless upgrades are enabled and POD_UID is available
61+
if config.flags.seamlessUpgrades && config.flags.podUID != "" {
6262
kubeletPluginOptions = append(kubeletPluginOptions,
6363
kubeletplugin.RollingUpdate(types.UID(config.flags.podUID)),
6464
)

cmd/dra-example-kubeletplugin/health.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ func startHealthcheck(ctx context.Context, config *Config) (*healthcheck, error)
6464
regSockPath := (&url.URL{
6565
Scheme: "unix",
6666
Path: func() string {
67-
if config.flags.podUID != "" {
67+
if config.flags.seamlessUpgrades && config.flags.podUID != "" {
6868
return path.Join(config.flags.kubeletRegistrarDirectoryPath, consts.DriverName+"-"+config.flags.podUID+"-reg.sock")
6969
}
7070
return path.Join(config.flags.kubeletRegistrarDirectoryPath, consts.DriverName+"-reg.sock")
@@ -82,7 +82,7 @@ func startHealthcheck(ctx context.Context, config *Config) (*healthcheck, error)
8282
draSockPath := (&url.URL{
8383
Scheme: "unix",
8484
Path: func() string {
85-
if config.flags.podUID != "" {
85+
if config.flags.seamlessUpgrades && config.flags.podUID != "" {
8686
return path.Join(config.DriverPluginPath(), "dra-"+config.flags.podUID+".sock")
8787
}
8888
return path.Join(config.DriverPluginPath(), "dra.sock")

cmd/dra-example-kubeletplugin/main.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ type Flags struct {
5050
kubeletPluginsDirectoryPath string
5151
healthcheckPort int
5252
podUID string
53+
seamlessUpgrades bool
5354
}
5455

5556
type Config struct {
@@ -121,6 +122,12 @@ func newApp() *cli.App {
121122
Destination: &flags.podUID,
122123
EnvVars: []string{"POD_UID"},
123124
},
125+
&cli.BoolFlag{
126+
Name: "seamless-upgrades",
127+
Usage: "Enable seamless upgrades support. When enabled, the driver will use rolling update mode if pod-uid is available.",
128+
Destination: &flags.seamlessUpgrades,
129+
EnvVars: []string{"SEAMLESS_UPGRADES"},
130+
},
124131
}
125132
cliFlags = append(cliFlags, flags.kubeClientConfig.Flags()...)
126133
cliFlags = append(cliFlags, flags.loggingConfig.Flags()...)

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

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,26 @@ spec:
1414
app.kubernetes.io/component: kubeletplugin
1515
{{- if .Values.kubeletPlugin.seamlessUpgrades.enabled }}
1616
updateStrategy:
17-
type: RollingUpdate
17+
type: {{ .Values.kubeletPlugin.updateStrategy.type | default "RollingUpdate" }}
18+
{{- if or .Values.kubeletPlugin.updateStrategy.rollingUpdate (eq (.Values.kubeletPlugin.updateStrategy.type | default "RollingUpdate") "RollingUpdate") }}
1819
rollingUpdate:
19-
maxSurge: 1
20-
maxUnavailable: 0
20+
maxSurge: {{ .Values.kubeletPlugin.updateStrategy.rollingUpdate.maxSurge | default 1 }}
21+
maxUnavailable: {{ .Values.kubeletPlugin.updateStrategy.rollingUpdate.maxUnavailable | default 0 }}
22+
{{- with .Values.kubeletPlugin.updateStrategy.rollingUpdate }}
23+
{{- range $key, $value := . }}
24+
{{- if and (ne $key "maxSurge") (ne $key "maxUnavailable") }}
25+
{{ $key }}: {{ $value }}
26+
{{- end }}
27+
{{- end }}
28+
{{- end }}
29+
{{- end }}
2130
{{- else }}
2231
{{- with .Values.kubeletPlugin.updateStrategy }}
2332
updateStrategy:
2433
{{- toYaml . | nindent 4 }}
34+
{{- else }}
35+
updateStrategy:
36+
type: RollingUpdate
2537
{{- end }}
2638
{{- end }}
2739
template:
@@ -88,11 +100,13 @@ spec:
88100
- name: HEALTHCHECK_PORT
89101
value: {{ .Values.kubeletPlugin.containers.plugin.healthcheckPort | quote }}
90102
{{- end }}
91-
{{- if .Values.kubeletPlugin.seamlessUpgrades.enabled }}
92103
- name: POD_UID
93104
valueFrom:
94105
fieldRef:
95106
fieldPath: metadata.uid
107+
{{- if .Values.kubeletPlugin.seamlessUpgrades.enabled }}
108+
- name: SEAMLESS_UPGRADES
109+
value: "true"
96110
{{- end }}
97111
volumeMounts:
98112
- name: plugins-registry

0 commit comments

Comments
 (0)