Skip to content

Commit

Permalink
Merge pull request #1431 from mythi/PR-2023-027
Browse files Browse the repository at this point in the history
operator: fix setting QAT provisioning config volumeMount
  • Loading branch information
tkatila authored May 25, 2023
2 parents 7f812e6 + 52d3d4a commit 819d302
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
33 changes: 23 additions & 10 deletions pkg/controllers/qat/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import (
const (
ownerKey = ".metadata.controller.qat"
initcontainerName = "intel-qat-initcontainer"
qatConfigVolume = "intel-qat-config-volume"
)

var defaultNodeSelector = deployments.QATPluginDaemonSet().Spec.Template.Spec.NodeSelector
Expand Down Expand Up @@ -96,10 +97,7 @@ func (c *controller) NewDaemonSet(rawObj client.Object) *apps.DaemonSet {
daemonSet.Spec.Template.Spec.NodeSelector = devicePlugin.Spec.NodeSelector
}

if devicePlugin.Spec.InitImage == "" {
daemonSet.Spec.Template.Spec.InitContainers = nil
daemonSet.Spec.Template.Spec.Volumes = removeVolume(daemonSet.Spec.Template.Spec.Volumes, "sysfs")
} else {
if devicePlugin.Spec.InitImage != "" {
setInitContainer(&daemonSet.Spec.Template.Spec, devicePlugin.Spec)
}

Expand Down Expand Up @@ -129,7 +127,7 @@ func (c *controller) UpdateDaemonSet(rawObj client.Object, ds *apps.DaemonSet) (
if ds.Spec.Template.Spec.InitContainers != nil {
ds.Spec.Template.Spec.InitContainers = nil
ds.Spec.Template.Spec.Volumes = removeVolume(ds.Spec.Template.Spec.Volumes, "sysfs")
ds.Spec.Template.Spec.Volumes = removeVolume(ds.Spec.Template.Spec.Volumes, "qat-config")
ds.Spec.Template.Spec.Volumes = removeVolume(ds.Spec.Template.Spec.Volumes, qatConfigVolume)
updated = true
}
} else {
Expand Down Expand Up @@ -220,7 +218,7 @@ func setInitContainer(dsSpec *v1.PodSpec, dpSpec devicepluginv1.QatDevicePluginS
{
Image: dpSpec.InitImage,
ImagePullPolicy: "IfNotPresent",
Name: "init-sriov-numvfs",
Name: initcontainerName,
Env: []v1.EnvVar{
{
Name: "ENABLED_QAT_PF_PCIIDS",
Expand Down Expand Up @@ -254,20 +252,35 @@ func setInitContainer(dsSpec *v1.PodSpec, dpSpec devicepluginv1.QatDevicePluginS
mode := int32(0440)

if dpSpec.ProvisioningConfig != "" {
dsSpec.Volumes = append(dsSpec.Volumes, v1.Volume{
Name: "qat-config",
qatVol := v1.Volume{
Name: qatConfigVolume,
VolumeSource: v1.VolumeSource{
ConfigMap: &v1.ConfigMapVolumeSource{
LocalObjectReference: v1.LocalObjectReference{Name: dpSpec.ProvisioningConfig},
DefaultMode: &mode,
},
},
})
}

volumeUpdated := false

// update ProvisioningConfig volume
for idx, vol := range dsSpec.Volumes {
if vol.Name == qatConfigVolume {
dsSpec.Volumes[idx] = qatVol
volumeUpdated = true
}
}

// or add if it's completely missing
if !volumeUpdated {
dsSpec.Volumes = append(dsSpec.Volumes, qatVol)
}

for i, initcontainer := range dsSpec.InitContainers {
if initcontainer.Name == initcontainerName {
dsSpec.InitContainers[i].VolumeMounts = append(dsSpec.InitContainers[i].VolumeMounts, v1.VolumeMount{
Name: "qat-config",
Name: qatConfigVolume,
MountPath: "/qat-init/conf",
})
}
Expand Down
2 changes: 1 addition & 1 deletion test/envtest/qatdeviceplugin_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ var _ = Describe("QatDevicePlugin Controller", func() {
}
mode := int32(0440)
expectedVolume := v1.Volume{
Name: "qat-config",
Name: "intel-qat-config-volume",
VolumeSource: v1.VolumeSource{
ConfigMap: &v1.ConfigMapVolumeSource{
LocalObjectReference: v1.LocalObjectReference{Name: updatedProvisioningConfig},
Expand Down

0 comments on commit 819d302

Please sign in to comment.