Skip to content

Commit 94a13fc

Browse files
committed
operator: dsa: Add InitImage for initcontainer
Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
1 parent 3a6aa55 commit 94a13fc

File tree

4 files changed

+53
-4
lines changed

4 files changed

+53
-4
lines changed

deployments/operator/crd/bases/deviceplugin.intel.com_dsadeviceplugins.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ spec:
5151
spec:
5252
description: DsaDevicePluginSpec defines the desired state of DsaDevicePlugin.
5353
properties:
54+
InitImage:
55+
description: InitImage is an initcontainer image to configure and
56+
enable DSA devices and workqueues with accel-config utility
57+
type: string
5458
image:
5559
description: Image is a container image with DSA device plugin executable.
5660
type: string

pkg/apis/deviceplugin/v1/dsadeviceplugin_types.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2020 Intel Corporation. All Rights Reserved.
1+
// Copyright 2020-2021 Intel Corporation. All Rights Reserved.
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -31,6 +31,9 @@ type DsaDevicePluginSpec struct {
3131
// Image is a container image with DSA device plugin executable.
3232
Image string `json:"image,omitempty"`
3333

34+
// InitImage is an initcontainer image to configure and enable DSA devices and workqueues with accel-config utility
35+
InitImage string `json:"InitImage,omitempty"`
36+
3437
// SharedDevNum is a number of containers that can share the same DSA device.
3538
// +kubebuilder:validation:Minimum=1
3639
SharedDevNum int `json:"sharedDevNum,omitempty"`

pkg/apis/deviceplugin/v1/dsadeviceplugin_webhook.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2020 Intel Corporation. All Rights Reserved.
1+
// Copyright 2020-2021 Intel Corporation. All Rights Reserved.
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -86,5 +86,13 @@ func (r *DsaDevicePlugin) ValidateDelete() error {
8686
}
8787

8888
func (r *DsaDevicePlugin) validatePlugin() error {
89-
return validatePluginImage(r.Spec.Image, "intel-dsa-plugin", dsaMinVersion)
89+
if err := validatePluginImage(r.Spec.Image, "intel-dsa-plugin", dsaMinVersion); err != nil {
90+
return err
91+
}
92+
93+
if len(r.Spec.InitImage) > 0 {
94+
return validatePluginImage(r.Spec.InitImage, "intel-dsa-initcontainer", dsaMinVersion)
95+
}
96+
97+
return nil
9098
}

pkg/controllers/dsa/controller.go

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2020 Intel Corporation. All Rights Reserved.
1+
// Copyright 2020-2021 Intel Corporation. All Rights Reserved.
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -75,6 +75,25 @@ func (c *controller) GetTotalObjectCount(ctx context.Context, clnt client.Client
7575
return len(list.Items), nil
7676
}
7777

78+
func setInitContainer(spec *v1.PodSpec, imageName string) {
79+
yes := true
80+
spec.InitContainers = []v1.Container{
81+
{
82+
Image: imageName,
83+
ImagePullPolicy: "IfNotPresent",
84+
Name: "intel-dsa-initcontainer",
85+
SecurityContext: &v1.SecurityContext{
86+
Privileged: &yes,
87+
},
88+
VolumeMounts: []v1.VolumeMount{
89+
{
90+
Name: "sys-devices",
91+
MountPath: "/sys/devices",
92+
},
93+
},
94+
}}
95+
}
96+
7897
func (c *controller) NewDaemonSet(rawObj client.Object) *apps.DaemonSet {
7998
devicePlugin := rawObj.(*devicepluginv1.DsaDevicePlugin)
8099

@@ -193,6 +212,21 @@ func (c *controller) NewDaemonSet(rawObj client.Object) *apps.DaemonSet {
193212
},
194213
},
195214
}
215+
216+
// add the optional InitImage
217+
if devicePlugin.Spec.InitImage != "" {
218+
setInitContainer(&daemonSet.Spec.Template.Spec, devicePlugin.Spec.InitImage)
219+
220+
daemonSet.Spec.Template.Spec.Volumes = append(daemonSet.Spec.Template.Spec.Volumes, v1.Volume{
221+
Name: "sys-devices",
222+
VolumeSource: v1.VolumeSource{
223+
HostPath: &v1.HostPathVolumeSource{
224+
Path: "/sys/devices",
225+
},
226+
},
227+
})
228+
}
229+
196230
return &daemonSet
197231
}
198232

0 commit comments

Comments
 (0)