Skip to content

Commit 2c26672

Browse files
authored
Merge pull request #1591 from ozhuraki/qat-apparmor
qat: Add AppArmor unconfided anntotation configurability in the operator
2 parents 25fcc69 + ab0e8bc commit 2c26672

File tree

6 files changed

+24
-17
lines changed

6 files changed

+24
-17
lines changed

cmd/qat_plugin/README.md

+5
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,11 @@ When using the operator for deploying the plugin with provisioning config, use `
148148

149149
There's also a possibility for a node specific congfiguration through passing a nodename via `NODE_NAME` into initcontainer's environment and passing a node specific profile (`qat-$NODE_NAME.conf`) via ConfigMap volume mount.
150150

151+
Existing DaemonSet annotations can be updated through CR annotations in [deviceplugin_v1_qatdeviceplugin.yaml](../../deployments/operator/samples/deviceplugin_v1_qatdeviceplugin.yaml).
152+
153+
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.
154+
155+
For non-operator plugin deployments such annotations can be dropped with the kustomization if required.
151156

152157
### Verify Plugin Registration
153158

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

+4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ 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
79
spec:
810
selector:
911
matchLabels:
@@ -12,6 +14,8 @@ spec:
1214
metadata:
1315
labels:
1416
app: intel-qat-plugin
17+
annotations:
18+
container.apparmor.security.beta.kubernetes.io/intel-qat-plugin: unconfined
1519
spec:
1620
automountServiceAccountToken: false
1721
containers:

deployments/qat_plugin/overlays/apparmor_unconfined/kustomization.yaml

-4
This file was deleted.

deployments/qat_plugin/overlays/e2e/kustomization.yaml

-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
nameSuffix: -e2e
2-
commonAnnotations:
3-
container.apparmor.security.beta.kubernetes.io/intel-qat-plugin: unconfined
42

53
resources:
64
- ../qat_initcontainer

pkg/controllers/qat/controller.go

+7-10
Original file line numberDiff line numberDiff line change
@@ -103,16 +103,13 @@ func (c *controller) NewDaemonSet(rawObj client.Object) *apps.DaemonSet {
103103
func (c *controller) UpdateDaemonSet(rawObj client.Object, ds *apps.DaemonSet) (updated bool) {
104104
dp := rawObj.(*devicepluginv1.QatDevicePlugin)
105105

106-
// Remove always incrementing annotation so it doesn't cause the next DeepEqual
107-
// to return false every time.
108-
dsAnnotations := ds.ObjectMeta.DeepCopy().Annotations
109-
delete(dsAnnotations, "deprecated.daemonset.template.generation")
110-
111-
if !reflect.DeepEqual(dsAnnotations, dp.ObjectMeta.Annotations) {
112-
pluginAnnotations := dp.ObjectMeta.DeepCopy().Annotations
113-
ds.ObjectMeta.Annotations = pluginAnnotations
114-
ds.Spec.Template.Annotations = pluginAnnotations
115-
updated = true
106+
// Update only existing daemonset annotations
107+
for k, v := range ds.ObjectMeta.Annotations {
108+
if v2, ok := dp.ObjectMeta.Annotations[k]; ok && v2 != v {
109+
ds.ObjectMeta.Annotations[k] = v2
110+
ds.Spec.Template.Annotations[k] = v2
111+
updated = true
112+
}
116113
}
117114

118115
if ds.Spec.Template.Spec.Containers[0].Image != dp.Spec.Image {

pkg/controllers/qat/controller_test.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,16 @@ func (c *controller) newDaemonSetExpected(rawObj client.Object) *apps.DaemonSet
164164
func TestNewDaemonSetQAT(t *testing.T) {
165165
c := &controller{}
166166

167-
plugin := &devicepluginv1.QatDevicePlugin{}
167+
plugin := &devicepluginv1.QatDevicePlugin{
168+
ObjectMeta: metav1.ObjectMeta{
169+
Annotations: map[string]string{
170+
"container.apparmor.security.beta.kubernetes.io/intel-qat-plugin": "runtime/default",
171+
},
172+
},
173+
}
168174
plugin.Name = "testing"
169175
plugin.Spec.InitImage = "intel/intel-qat-initcontainer:" + controllers.ImageMinVersion.String()
176+
170177
expected := c.newDaemonSetExpected(plugin)
171178
actual := c.NewDaemonSet(plugin)
172179

0 commit comments

Comments
 (0)