Skip to content

qat: Add AppArmor unconfided anntotation configurability in the operator #1591

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions cmd/qat_plugin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,11 @@ When using the operator for deploying the plugin with provisioning config, use `

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.

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

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.

For non-operator plugin deployments such annotations can be dropped with the kustomization if required.

### Verify Plugin Registration

Expand Down
4 changes: 4 additions & 0 deletions deployments/qat_plugin/base/intel-qat-plugin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ metadata:
name: intel-qat-plugin
labels:
app: intel-qat-plugin
annotations:
container.apparmor.security.beta.kubernetes.io/intel-qat-plugin: unconfined
spec:
selector:
matchLabels:
Expand All @@ -12,6 +14,8 @@ spec:
metadata:
labels:
app: intel-qat-plugin
annotations:
container.apparmor.security.beta.kubernetes.io/intel-qat-plugin: unconfined
spec:
automountServiceAccountToken: false
containers:
Expand Down

This file was deleted.

2 changes: 0 additions & 2 deletions deployments/qat_plugin/overlays/e2e/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
nameSuffix: -e2e
commonAnnotations:
container.apparmor.security.beta.kubernetes.io/intel-qat-plugin: unconfined

resources:
- ../qat_initcontainer
Expand Down
17 changes: 7 additions & 10 deletions pkg/controllers/qat/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,16 +103,13 @@ func (c *controller) NewDaemonSet(rawObj client.Object) *apps.DaemonSet {
func (c *controller) UpdateDaemonSet(rawObj client.Object, ds *apps.DaemonSet) (updated bool) {
dp := rawObj.(*devicepluginv1.QatDevicePlugin)

// Remove always incrementing annotation so it doesn't cause the next DeepEqual
// to return false every time.
dsAnnotations := ds.ObjectMeta.DeepCopy().Annotations
delete(dsAnnotations, "deprecated.daemonset.template.generation")

if !reflect.DeepEqual(dsAnnotations, dp.ObjectMeta.Annotations) {
pluginAnnotations := dp.ObjectMeta.DeepCopy().Annotations
ds.ObjectMeta.Annotations = pluginAnnotations
ds.Spec.Template.Annotations = pluginAnnotations
updated = true
// Update only existing daemonset annotations
for k, v := range ds.ObjectMeta.Annotations {
if v2, ok := dp.ObjectMeta.Annotations[k]; ok && v2 != v {
ds.ObjectMeta.Annotations[k] = v2
ds.Spec.Template.Annotations[k] = v2
updated = true
}
}

if ds.Spec.Template.Spec.Containers[0].Image != dp.Spec.Image {
Expand Down
9 changes: 8 additions & 1 deletion pkg/controllers/qat/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,16 @@ func (c *controller) newDaemonSetExpected(rawObj client.Object) *apps.DaemonSet
func TestNewDaemonSetQAT(t *testing.T) {
c := &controller{}

plugin := &devicepluginv1.QatDevicePlugin{}
plugin := &devicepluginv1.QatDevicePlugin{
ObjectMeta: metav1.ObjectMeta{
Annotations: map[string]string{
"container.apparmor.security.beta.kubernetes.io/intel-qat-plugin": "runtime/default",
},
},
}
plugin.Name = "testing"
plugin.Spec.InitImage = "intel/intel-qat-initcontainer:" + controllers.ImageMinVersion.String()

expected := c.newDaemonSetExpected(plugin)
actual := c.NewDaemonSet(plugin)

Expand Down