Skip to content

Commit cb24675

Browse files
committed
operator: fix setting QAT provisioning config volumeMount
setInitContainer() adds "init-sriov-numvfs" to initContainers but uses initcontainerName constant to search where to add the QAT configMap volumeMount. Fix by moving all code to use the const. It was also noticed in the controller logs that setting Pod Volumes is not idempotent but broken DaemonSet gets created: ""intel-device-plugins-manager: Reconciler error "err="DaemonSet.apps \"intel-qat-plugin\" is invalid: spec.template.spec.volumes[6].name: Duplicate value: \"qat-config\"" controller="qatdeviceplugin" controllerGroup="deviceplugin.intel.com" Finally, change 'qat-config' to 'intel-qat-config-volume' to better describe that it's a volume. Signed-off-by: Mikko Ylinen <[email protected]>
1 parent e49e89e commit cb24675

File tree

2 files changed

+23
-11
lines changed

2 files changed

+23
-11
lines changed

pkg/controllers/qat/controller.go

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,7 @@ func (c *controller) NewDaemonSet(rawObj client.Object) *apps.DaemonSet {
9696
daemonSet.Spec.Template.Spec.NodeSelector = devicePlugin.Spec.NodeSelector
9797
}
9898

99-
if devicePlugin.Spec.InitImage == "" {
100-
daemonSet.Spec.Template.Spec.InitContainers = nil
101-
daemonSet.Spec.Template.Spec.Volumes = removeVolume(daemonSet.Spec.Template.Spec.Volumes, "sysfs")
102-
} else {
99+
if devicePlugin.Spec.InitImage != "" {
103100
setInitContainer(&daemonSet.Spec.Template.Spec, devicePlugin.Spec)
104101
}
105102

@@ -129,7 +126,7 @@ func (c *controller) UpdateDaemonSet(rawObj client.Object, ds *apps.DaemonSet) (
129126
if ds.Spec.Template.Spec.InitContainers != nil {
130127
ds.Spec.Template.Spec.InitContainers = nil
131128
ds.Spec.Template.Spec.Volumes = removeVolume(ds.Spec.Template.Spec.Volumes, "sysfs")
132-
ds.Spec.Template.Spec.Volumes = removeVolume(ds.Spec.Template.Spec.Volumes, "qat-config")
129+
ds.Spec.Template.Spec.Volumes = removeVolume(ds.Spec.Template.Spec.Volumes, "intel-qat-config-volume")
133130
updated = true
134131
}
135132
} else {
@@ -220,7 +217,7 @@ func setInitContainer(dsSpec *v1.PodSpec, dpSpec devicepluginv1.QatDevicePluginS
220217
{
221218
Image: dpSpec.InitImage,
222219
ImagePullPolicy: "IfNotPresent",
223-
Name: "init-sriov-numvfs",
220+
Name: initcontainerName,
224221
Env: []v1.EnvVar{
225222
{
226223
Name: "ENABLED_QAT_PF_PCIIDS",
@@ -254,20 +251,35 @@ func setInitContainer(dsSpec *v1.PodSpec, dpSpec devicepluginv1.QatDevicePluginS
254251
mode := int32(0440)
255252

256253
if dpSpec.ProvisioningConfig != "" {
257-
dsSpec.Volumes = append(dsSpec.Volumes, v1.Volume{
258-
Name: "qat-config",
254+
qatVol := v1.Volume{
255+
Name: "intel-qat-config-volume",
259256
VolumeSource: v1.VolumeSource{
260257
ConfigMap: &v1.ConfigMapVolumeSource{
261258
LocalObjectReference: v1.LocalObjectReference{Name: dpSpec.ProvisioningConfig},
262259
DefaultMode: &mode,
263260
},
264261
},
265-
})
262+
}
263+
264+
volumeUpdated := false
265+
266+
// update ProvisioningConfig volume
267+
for idx, vol := range dsSpec.Volumes {
268+
if vol.Name == "intel-qat-config-volume" {
269+
dsSpec.Volumes[idx] = qatVol
270+
volumeUpdated = true
271+
}
272+
}
273+
274+
// or add if it's completely missing
275+
if !volumeUpdated {
276+
dsSpec.Volumes = append(dsSpec.Volumes, qatVol)
277+
}
266278

267279
for i, initcontainer := range dsSpec.InitContainers {
268280
if initcontainer.Name == initcontainerName {
269281
dsSpec.InitContainers[i].VolumeMounts = append(dsSpec.InitContainers[i].VolumeMounts, v1.VolumeMount{
270-
Name: "qat-config",
282+
Name: "intel-qat-config-volume",
271283
MountPath: "/qat-init/conf",
272284
})
273285
}

test/envtest/qatdeviceplugin_controller_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ var _ = Describe("QatDevicePlugin Controller", func() {
136136
}
137137
mode := int32(0440)
138138
expectedVolume := v1.Volume{
139-
Name: "qat-config",
139+
Name: "intel-qat-config-volume",
140140
VolumeSource: v1.VolumeSource{
141141
ConfigMap: &v1.ConfigMapVolumeSource{
142142
LocalObjectReference: v1.LocalObjectReference{Name: updatedProvisioningConfig},

0 commit comments

Comments
 (0)