operator: dsa: Add InitImage for initcontainer

Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
This commit is contained in:
Oleg Zhurakivskyy 2021-08-26 22:23:15 +03:00
parent 3a6aa55858
commit 94a13fc96f
4 changed files with 53 additions and 4 deletions

View File

@ -51,6 +51,10 @@ spec:
spec:
description: DsaDevicePluginSpec defines the desired state of DsaDevicePlugin.
properties:
InitImage:
description: InitImage is an initcontainer image to configure and
enable DSA devices and workqueues with accel-config utility
type: string
image:
description: Image is a container image with DSA device plugin executable.
type: string

View File

@ -1,4 +1,4 @@
// Copyright 2020 Intel Corporation. All Rights Reserved.
// Copyright 2020-2021 Intel Corporation. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@ -31,6 +31,9 @@ type DsaDevicePluginSpec struct {
// Image is a container image with DSA device plugin executable.
Image string `json:"image,omitempty"`
// InitImage is an initcontainer image to configure and enable DSA devices and workqueues with accel-config utility
InitImage string `json:"InitImage,omitempty"`
// SharedDevNum is a number of containers that can share the same DSA device.
// +kubebuilder:validation:Minimum=1
SharedDevNum int `json:"sharedDevNum,omitempty"`

View File

@ -1,4 +1,4 @@
// Copyright 2020 Intel Corporation. All Rights Reserved.
// Copyright 2020-2021 Intel Corporation. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@ -86,5 +86,13 @@ func (r *DsaDevicePlugin) ValidateDelete() error {
}
func (r *DsaDevicePlugin) validatePlugin() error {
return validatePluginImage(r.Spec.Image, "intel-dsa-plugin", dsaMinVersion)
if err := validatePluginImage(r.Spec.Image, "intel-dsa-plugin", dsaMinVersion); err != nil {
return err
}
if len(r.Spec.InitImage) > 0 {
return validatePluginImage(r.Spec.InitImage, "intel-dsa-initcontainer", dsaMinVersion)
}
return nil
}

View File

@ -1,4 +1,4 @@
// Copyright 2020 Intel Corporation. All Rights Reserved.
// Copyright 2020-2021 Intel Corporation. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// 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
return len(list.Items), nil
}
func setInitContainer(spec *v1.PodSpec, imageName string) {
yes := true
spec.InitContainers = []v1.Container{
{
Image: imageName,
ImagePullPolicy: "IfNotPresent",
Name: "intel-dsa-initcontainer",
SecurityContext: &v1.SecurityContext{
Privileged: &yes,
},
VolumeMounts: []v1.VolumeMount{
{
Name: "sys-devices",
MountPath: "/sys/devices",
},
},
}}
}
func (c *controller) NewDaemonSet(rawObj client.Object) *apps.DaemonSet {
devicePlugin := rawObj.(*devicepluginv1.DsaDevicePlugin)
@ -193,6 +212,21 @@ func (c *controller) NewDaemonSet(rawObj client.Object) *apps.DaemonSet {
},
},
}
// add the optional InitImage
if devicePlugin.Spec.InitImage != "" {
setInitContainer(&daemonSet.Spec.Template.Spec, devicePlugin.Spec.InitImage)
daemonSet.Spec.Template.Spec.Volumes = append(daemonSet.Spec.Template.Spec.Volumes, v1.Volume{
Name: "sys-devices",
VolumeSource: v1.VolumeSource{
HostPath: &v1.HostPathVolumeSource{
Path: "/sys/devices",
},
},
})
}
return &daemonSet
}