Skip to content

Commit 5af85a7

Browse files
committed
qat: copy annotations
Signed-off-by: Ed Bartosh <eduard.bartosh@intel.com>
1 parent fe19450 commit 5af85a7

File tree

3 files changed

+36
-1
lines changed

3 files changed

+36
-1
lines changed

deployments/operator/samples/deviceplugin_v1_qatdeviceplugin.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@ 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
511
spec:
612
image: intel/intel-qat-plugin:0.21.0
713
dpdkDriver: vfio-pci

pkg/controllers/qat/controller.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,15 @@ func (c *controller) GetTotalObjectCount(ctx context.Context, clnt client.Client
7878
func (c *controller) NewDaemonSet(rawObj client.Object) *apps.DaemonSet {
7979
devicePlugin := rawObj.(*devicepluginv1.QatDevicePlugin)
8080
yes := true
81+
pluginAnnotations := devicePlugin.ObjectMeta.DeepCopy().Annotations
8182
return &apps.DaemonSet{
8283
ObjectMeta: metav1.ObjectMeta{
8384
Namespace: c.ns,
8485
GenerateName: devicePlugin.Name + "-",
8586
Labels: map[string]string{
8687
"app": appLabel,
8788
},
89+
Annotations: pluginAnnotations,
8890
},
8991
Spec: apps.DaemonSetSpec{
9092
Selector: &metav1.LabelSelector{
@@ -97,6 +99,7 @@ func (c *controller) NewDaemonSet(rawObj client.Object) *apps.DaemonSet {
9799
Labels: map[string]string{
98100
"app": appLabel,
99101
},
102+
Annotations: pluginAnnotations,
100103
},
101104
Spec: v1.PodSpec{
102105
Containers: []v1.Container{
@@ -161,6 +164,13 @@ func (c *controller) NewDaemonSet(rawObj client.Object) *apps.DaemonSet {
161164
func (c *controller) UpdateDaemonSet(rawObj client.Object, ds *apps.DaemonSet) (updated bool) {
162165
dp := rawObj.(*devicepluginv1.QatDevicePlugin)
163166

167+
if !reflect.DeepEqual(ds.ObjectMeta.Annotations, dp.ObjectMeta.Annotations) {
168+
pluginAnnotations := dp.ObjectMeta.DeepCopy().Annotations
169+
ds.ObjectMeta.Annotations = pluginAnnotations
170+
ds.Spec.Template.Annotations = pluginAnnotations
171+
updated = true
172+
}
173+
164174
if ds.Spec.Template.Spec.Containers[0].Image != dp.Spec.Image {
165175
ds.Spec.Template.Spec.Containers[0].Image = dp.Spec.Image
166176
updated = true

test/envtest/qatdeviceplugin_controller_test.go

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,14 @@ 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+
4953
toCreate := &devicepluginv1.QatDevicePlugin{
5054
ObjectMeta: metav1.ObjectMeta{
51-
Name: key.Name,
55+
Name: key.Name,
56+
Annotations: annotations,
5257
},
5358
Spec: spec,
5459
}
@@ -63,6 +68,20 @@ var _ = Describe("QatDevicePlugin Controller", func() {
6368
return len(fetched.Status.ControlledDaemonSet.UID) > 0
6469
}, timeout, interval).Should(BeTrue())
6570

71+
By("copy annotations successfully")
72+
Expect(&(fetched.Annotations) == &annotations).ShouldNot(BeTrue())
73+
Eventually(fetched.Annotations).Should(Equal(annotations))
74+
75+
By("updating annotations successfully")
76+
updatedAnnotations := map[string]string{"key": "value"}
77+
fetched.Annotations = updatedAnnotations
78+
Expect(k8sClient.Update(context.Background(), fetched)).Should(Succeed())
79+
updated := &devicepluginv1.QatDevicePlugin{}
80+
Eventually(func() map[string]string {
81+
_ = k8sClient.Get(context.Background(), key, updated)
82+
return updated.Annotations
83+
}, timeout, interval).Should(Equal(updatedAnnotations))
84+
6685
By("updating image name successfully")
6786
updatedImage := "updated-testimage"
6887
fetched.Spec.Image = updatedImage

0 commit comments

Comments
 (0)