Skip to content

Commit f29f356

Browse files
authored
Merge pull request #1860 from mythi/PR-2024-022
qat: drop AppArmor annotations
2 parents 2b42d41 + fe3eaee commit f29f356

File tree

9 files changed

+25
-83
lines changed

9 files changed

+25
-83
lines changed

cmd/qat_plugin/README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,6 @@ There's also a possibility for a node specific congfiguration through passing a
149149

150150
Existing DaemonSet annotations can be updated through CR annotations in [deviceplugin_v1_qatdeviceplugin.yaml](../../deployments/operator/samples/deviceplugin_v1_qatdeviceplugin.yaml).
151151

152-
By default, the operator based deployment sets AppArmor policy to `"unconfined"` but this can be overridden by setting the AppArmor annotation to a new value in the CR annotations.
153-
154152
For non-operator plugin deployments such annotations can be dropped with the kustomization if required.
155153

156154
### Verify Plugin Registration

cmd/qat_plugin/dpdkdrv/dpdkdrv.go

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ const (
4444
pciDriverDirectory = "/sys/bus/pci/drivers"
4545
uioSuffix = "uio"
4646
iommuGroupSuffix = "iommu_group"
47-
vendorPrefix = "8086 "
4847
envVarPrefix = "QAT"
4948

5049
igbUio = "igb_uio"
@@ -187,31 +186,10 @@ func newDevicePlugin(pciDriverDir, pciDeviceDir string, maxDevices int, kernelVf
187186
}
188187
}
189188

190-
func (dp *DevicePlugin) setupDeviceIDs() error {
191-
for devID, driver := range qatDeviceDriver {
192-
for _, enabledDriver := range dp.kernelVfDrivers {
193-
if driver != enabledDriver {
194-
continue
195-
}
196-
197-
err := writeToDriver(filepath.Join(dp.pciDriverDir, dp.dpdkDriver, "new_id"), vendorPrefix+devID)
198-
if err != nil && !errors.Is(err, os.ErrExist) {
199-
return errors.WithMessagef(err, "failed to set device ID %s for %s. Driver module not loaded?", devID, dp.dpdkDriver)
200-
}
201-
}
202-
}
203-
204-
return nil
205-
}
206-
207189
// Scan implements Scanner interface for vfio based QAT plugin.
208190
func (dp *DevicePlugin) Scan(notifier dpapi.Notifier) error {
209191
defer dp.scanTicker.Stop()
210192

211-
if err := dp.setupDeviceIDs(); err != nil {
212-
return err
213-
}
214-
215193
for {
216194
devTree, err := dp.scan()
217195
if err != nil {
@@ -629,6 +607,7 @@ func (dp *DevicePlugin) scan() (dpapi.DeviceTree, error) {
629607
for _, vfDevice := range dp.getVfDevices() {
630608
vfBdf := filepath.Base(vfDevice)
631609

610+
// TODO(mythi): can be dropped in a later release since the same is already done in qat-init.sh.
632611
if drv := getCurrentDriver(vfDevice); drv != dp.dpdkDriver {
633612
if drv != "" {
634613
err := writeToDriver(filepath.Join(dp.pciDriverDir, drv, "unbind"), vfBdf)

demo/qat-init.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,32 @@ enable_sriov() {
5858
echo "error: $NUMVFS is not found or not writable. Check if QAT driver module is loaded"
5959
exit 1
6060
fi
61+
if ! test -d /sys/bus/pci/drivers/vfio-pci; then
62+
echo "error: vfio-pci driver needed by QAT VFs must be loaded"
63+
exit 1
64+
fi
6165
if [ "$(cat "$NUMVFS")" -ne 0 ]; then
6266
echo "$DEVPATH already configured"
6367
else
6468
tee "$NUMVFS" < "$DEVPATH/sriov_totalvfs"
69+
VFDEVS=$(realpath -L "$DEVPATH"/virtfn*)
70+
for vfdev in $VFDEVS; do
71+
BSF=$(basename "$vfdev")
72+
VF_DEV="/sys/bus/pci/devices/$BSF"
73+
if test -e "$VF_DEV/driver"; then
74+
P=$(realpath -L "$VF_DEV/driver")
75+
VF_DRIVER=$(basename "$P")
76+
else
77+
VF_DRIVER=""
78+
fi
79+
if [ "$VF_DRIVER" != "vfio-pci" ]; then
80+
if [ "$VF_DRIVER" ]; then
81+
echo -n "$BSF" > /sys/bus/pci/drivers/"$VF_DRIVER"/unbind
82+
fi
83+
echo -n vfio-pci > /sys/bus/pci/devices/"$BSF"/driver_override
84+
echo -n "$BSF" > /sys/bus/pci/drivers/vfio-pci/bind
85+
fi
86+
done
6587
fi
6688
done
6789
}

deployments/operator/samples/deviceplugin_v1_dlbdeviceplugin.yaml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,6 @@ apiVersion: deviceplugin.intel.com/v1
22
kind: DlbDevicePlugin
33
metadata:
44
name: dlbdeviceplugin-sample
5-
# example apparmor annotation
6-
# see more details here:
7-
# - https://kubernetes.io/docs/tutorials/clusters/apparmor/#securing-a-pod
8-
# - https://github.com/intel/intel-device-plugins-for-kubernetes/issues/381
9-
# annotations:
10-
# container.apparmor.security.beta.kubernetes.io/intel-dlb-plugin: unconfined
115
spec:
126
image: intel/intel-dlb-plugin:0.31.1
137
initImage: intel/intel-dlb-initcontainer:0.31.1

deployments/operator/samples/deviceplugin_v1_qatdeviceplugin.yaml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,6 @@ apiVersion: deviceplugin.intel.com/v1
22
kind: QatDevicePlugin
33
metadata:
44
name: qatdeviceplugin-sample
5-
# example apparmor annotation
6-
# see more details here:
7-
# - https://kubernetes.io/docs/tutorials/clusters/apparmor/#securing-a-pod
8-
# - https://github.com/intel/intel-device-plugins-for-kubernetes/issues/381
9-
# annotations:
10-
# container.apparmor.security.beta.kubernetes.io/intel-qat-plugin: unconfined
115
spec:
126
image: intel/intel-qat-plugin:0.31.1
137
initImage: intel/intel-qat-initcontainer:0.31.1

deployments/qat_plugin/base/intel-qat-plugin.yaml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ metadata:
44
name: intel-qat-plugin
55
labels:
66
app: intel-qat-plugin
7-
annotations:
8-
container.apparmor.security.beta.kubernetes.io/intel-qat-plugin: unconfined
97
spec:
108
selector:
119
matchLabels:
@@ -19,8 +17,6 @@ spec:
1917
metadata:
2018
labels:
2119
app: intel-qat-plugin
22-
annotations:
23-
container.apparmor.security.beta.kubernetes.io/intel-qat-plugin: unconfined
2420
spec:
2521
automountServiceAccountToken: false
2622
containers:

pkg/controllers/qat/controller.go

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,8 @@ func (c *controller) Upgrade(ctx context.Context, obj client.Object) bool {
7878
func (c *controller) NewDaemonSet(rawObj client.Object) *apps.DaemonSet {
7979
devicePlugin := rawObj.(*devicepluginv1.QatDevicePlugin)
8080

81-
annotations := devicePlugin.ObjectMeta.DeepCopy().Annotations
82-
8381
daemonSet := deployments.QATPluginDaemonSet()
8482
daemonSet.Name = controllers.SuffixedName(daemonSet.Name, devicePlugin.Name)
85-
daemonSet.Annotations = annotations
86-
daemonSet.Spec.Template.Annotations = annotations
8783

8884
if devicePlugin.Spec.Tolerations != nil {
8985
daemonSet.Spec.Template.Spec.Tolerations = devicePlugin.Spec.Tolerations
@@ -107,15 +103,6 @@ func (c *controller) NewDaemonSet(rawObj client.Object) *apps.DaemonSet {
107103
func (c *controller) UpdateDaemonSet(rawObj client.Object, ds *apps.DaemonSet) (updated bool) {
108104
dp := rawObj.(*devicepluginv1.QatDevicePlugin)
109105

110-
// Update only existing daemonset annotations
111-
for k, v := range ds.ObjectMeta.Annotations {
112-
if v2, ok := dp.ObjectMeta.Annotations[k]; ok && v2 != v {
113-
ds.ObjectMeta.Annotations[k] = v2
114-
ds.Spec.Template.Annotations[k] = v2
115-
updated = true
116-
}
117-
}
118-
119106
if ds.Spec.Template.Spec.Containers[0].Image != dp.Spec.Image {
120107
ds.Spec.Template.Spec.Containers[0].Image = dp.Spec.Image
121108
updated = true

pkg/controllers/qat/controller_test.go

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ func (c *controller) newDaemonSetExpected(rawObj client.Object) *apps.DaemonSet
3939
devicePlugin := rawObj.(*devicepluginv1.QatDevicePlugin)
4040
yes := true
4141
no := false
42-
pluginAnnotations := devicePlugin.ObjectMeta.DeepCopy().Annotations
4342
maxUnavailable := intstr.FromInt(1)
4443
maxSurge := intstr.FromInt(0)
4544

@@ -54,7 +53,6 @@ func (c *controller) newDaemonSetExpected(rawObj client.Object) *apps.DaemonSet
5453
Labels: map[string]string{
5554
"app": appLabel,
5655
},
57-
Annotations: pluginAnnotations,
5856
},
5957
Spec: apps.DaemonSetSpec{
6058
Selector: &metav1.LabelSelector{
@@ -74,7 +72,6 @@ func (c *controller) newDaemonSetExpected(rawObj client.Object) *apps.DaemonSet
7472
Labels: map[string]string{
7573
"app": appLabel,
7674
},
77-
Annotations: pluginAnnotations,
7875
},
7976
Spec: v1.PodSpec{
8077
AutomountServiceAccountToken: &no,
@@ -187,13 +184,7 @@ func (c *controller) newDaemonSetExpected(rawObj client.Object) *apps.DaemonSet
187184
func TestNewDaemonSetQAT(t *testing.T) {
188185
c := &controller{}
189186

190-
plugin := &devicepluginv1.QatDevicePlugin{
191-
ObjectMeta: metav1.ObjectMeta{
192-
Annotations: map[string]string{
193-
"container.apparmor.security.beta.kubernetes.io/intel-qat-plugin": "runtime/default",
194-
},
195-
},
196-
}
187+
plugin := &devicepluginv1.QatDevicePlugin{}
197188
plugin.Name = "testing"
198189
plugin.Spec.InitImage = "intel/intel-qat-initcontainer:" + controllers.ImageMinVersion.String()
199190

test/envtest/qatdeviceplugin_controller_test.go

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,9 @@ var _ = Describe("QatDevicePlugin Controller", func() {
4646
Name: "qatdeviceplugin-test",
4747
}
4848

49-
annotations := map[string]string{
50-
"container.apparmor.security.beta.kubernetes.io/intel-qat-plugin": "unconfined",
51-
}
52-
5349
toCreate := &devicepluginv1.QatDevicePlugin{
5450
ObjectMeta: metav1.ObjectMeta{
55-
Name: key.Name,
56-
Annotations: annotations,
51+
Name: key.Name,
5752
},
5853
Spec: spec,
5954
}
@@ -80,20 +75,6 @@ var _ = Describe("QatDevicePlugin Controller", func() {
8075
Expect(ds.Spec.Template.Spec.NodeSelector).To(Equal(spec.NodeSelector))
8176
Expect(ds.Spec.Template.Spec.Tolerations).To(HaveLen(0))
8277

83-
By("copy annotations successfully")
84-
Expect(&(fetched.Annotations) == &annotations).ShouldNot(BeTrue())
85-
Eventually(fetched.Annotations).Should(Equal(annotations))
86-
87-
By("updating annotations successfully")
88-
updatedAnnotations := map[string]string{"key": "value"}
89-
fetched.Annotations = updatedAnnotations
90-
Expect(k8sClient.Update(context.Background(), fetched)).Should(Succeed())
91-
updated := &devicepluginv1.QatDevicePlugin{}
92-
Eventually(func() map[string]string {
93-
_ = k8sClient.Get(context.Background(), key, updated)
94-
return updated.Annotations
95-
}, timeout, interval).Should(Equal(updatedAnnotations))
96-
9778
By("updating QatDevicePlugin successfully")
9879
updatedImage := "updated-qat-testimage"
9980
updatedInitImage := "updated-qat-testinitimage"

0 commit comments

Comments
 (0)