Skip to content

Commit a6d199b

Browse files
committed
ON-15199: Add cplane parameters to Onload CRD
1 parent 2a9f04e commit a6d199b

File tree

9 files changed

+158
-13
lines changed

9 files changed

+158
-13
lines changed

api/v1alpha1/onload_types.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,18 @@ type OnloadSpec struct {
7676
// ImagePullPolicy is the policy used when pulling images.
7777
// More info: https://kubernetes.io/docs/concepts/containers/images#updating-images
7878
ImagePullPolicy v1.PullPolicy `json:"imagePullPolicy,omitempty"`
79+
80+
// +optional
81+
// ControlPlane allows fine-tuning of the Onload control plane server.
82+
ControlPlane *ControlPlaneSpec `json:"controlPlane,omitempty"`
83+
}
84+
85+
type ControlPlaneSpec struct {
86+
// +optional
87+
// Parameters is an optional list of parameters passed to the Onload
88+
// control plane server when launched by the Onload kernel module.
89+
// +kubebuilder:default:={"-K"}
90+
Parameters []string `json:"parameters"`
7991
}
8092

8193
// Currently unimplemented

api/v1alpha1/zz_generated.deepcopy.go

Lines changed: 25 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/worker/main.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ func main() {
3030
// A mount point with the Onload control plane server.
3131
onloadCPServerPath := os.Getenv("ONLOAD_CP_SERVER_PATH")
3232

33+
// Params the Onload kmod should pass to the Onload control plane server.
34+
onloadCPServerParams := os.Getenv("ONLOAD_CP_SERVER_PARAMS")
35+
3336
// There is a race condition when the container is starting, and the
3437
// Onload kernel module is loading at the same time, resulting in not
3538
// all files being available in the container.
@@ -59,8 +62,8 @@ func main() {
5962

6063
// Configure Onload kernel module to launch
6164
// Onload control plane within a container.
62-
err = control_plane.Configure(onloadCPServerPath, containerID,
63-
control_plane.NewKernelParametersWriter())
65+
err = control_plane.Configure(onloadCPServerPath, onloadCPServerParams,
66+
containerID, control_plane.NewKernelParametersWriter())
6467
if err != nil {
6568
glog.Fatal("Failed to configure Onload control plane: ", err)
6669
}

config/crd/bases/onload.amd.com_onloads.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,20 @@ spec:
9595
description: Onload is the specification of the version of Onload
9696
to be used by this CR
9797
properties:
98+
controlPlane:
99+
description: ControlPlane allows fine-tuning of the Onload control
100+
plane server.
101+
properties:
102+
parameters:
103+
default:
104+
- -K
105+
description: Parameters is an optional list of parameters
106+
passed to the Onload control plane server when launched
107+
by the Onload kernel module.
108+
items:
109+
type: string
110+
type: array
111+
type: object
98112
imagePullPolicy:
99113
description: 'ImagePullPolicy is the policy used when pulling
100114
images. More info: https://kubernetes.io/docs/concepts/containers/images#updating-images'

config/samples/onload/base/onload_v1alpha1_onload.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,15 @@ spec:
8080
# ImagePullPolicy is the policy used when pulling images. Optional.
8181
imagePullPolicy: Always
8282

83+
# ControlPlane allows fine-tuning of the Onload control plane server.
84+
# Optional.
85+
#controlPlane:
86+
87+
# Parameters is an optional list of parameters passed to the Onload
88+
# control plane server when launched by the Onload kernel module.
89+
#parameters:
90+
#- -K
91+
8392
# DevicePlugin is further specification for the Onload Device Plugin which
8493
# uses the device plugin framework to provide an `amd.com/onload` resource.
8594
# Image location is not configured here; see Onload Operator deployment.

controllers/onload_controller.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"context"
88
"fmt"
99
"slices"
10+
"strings"
1011
"time"
1112

1213
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -991,6 +992,11 @@ func (r *OnloadReconciler) createDevicePluginDaemonSet(
991992

992993
workerContainerName := "onload-worker"
993994

995+
cplaneParams := "-K" // log-to-kmsg
996+
if onload.Spec.Onload.ControlPlane != nil && onload.Spec.Onload.ControlPlane.Parameters != nil {
997+
cplaneParams = strings.Join(onload.Spec.Onload.ControlPlane.Parameters, " ")
998+
}
999+
9941000
workerContainerEnv := []corev1.EnvVar{
9951001
{
9961002
Name: "POD_NAME",
@@ -1016,6 +1022,10 @@ func (r *OnloadReconciler) createDevicePluginDaemonSet(
10161022
Name: "ONLOAD_CP_SERVER_PATH",
10171023
Value: "/mnt/onload/sbin/onload_cp_server",
10181024
},
1025+
{
1026+
Name: "ONLOAD_CP_SERVER_PARAMS",
1027+
Value: cplaneParams,
1028+
},
10191029
}
10201030

10211031
workerContainer := corev1.Container{

controllers/onload_controller_test.go

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ package controllers
44

55
import (
66
"errors"
7+
"slices"
78
"strconv"
89
"time"
910

@@ -871,5 +872,56 @@ var _ = Describe("onload controller", func() {
871872
"-libMountPath=qux",
872873
),
873874
)
875+
876+
DescribeTable("Testing Onload cplane parameters",
877+
func(cplane *onloadv1alpha1.ControlPlaneSpec, expectedParams string) {
878+
devicePlugin := appsv1.DaemonSet{}
879+
devicePluginName := types.NamespacedName{
880+
Name: onload.Name + "-onload-device-plugin-ds",
881+
Namespace: onload.Namespace,
882+
}
883+
884+
if cplane != nil {
885+
onload.Spec.Onload.ControlPlane = cplane
886+
}
887+
888+
Expect(k8sClient.Create(ctx, onload)).To(BeNil())
889+
890+
Eventually(func() bool {
891+
err := k8sClient.Get(ctx, devicePluginName, &devicePlugin)
892+
return err == nil
893+
}, timeout, pollingInterval).Should(BeTrue())
894+
895+
// Find the worker container.
896+
workerIdx := slices.IndexFunc(devicePlugin.Spec.Template.Spec.Containers,
897+
func(c corev1.Container) bool { return c.Name == "onload-worker" })
898+
899+
Expect(workerIdx).NotTo(Equal(-1))
900+
workerContainer := devicePlugin.Spec.Template.Spec.Containers[workerIdx]
901+
902+
// Find the ONLOAD_CP_SERVER_PARAMS env.
903+
envIdx := slices.IndexFunc(workerContainer.Env,
904+
func(e corev1.EnvVar) bool { return e.Name == "ONLOAD_CP_SERVER_PARAMS" })
905+
Expect(envIdx).NotTo(Equal(-1))
906+
envValue := workerContainer.Env[envIdx].Value
907+
908+
// Compare actual vs. expected.
909+
Expect(envValue).To(Equal(expectedParams))
910+
911+
},
912+
Entry( /*It*/ "should use the default parameters", nil, "-K"),
913+
Entry( /*It*/ "should pass an empty list of parameters",
914+
&onloadv1alpha1.ControlPlaneSpec{Parameters: []string{}}, "",
915+
),
916+
Entry( /*It*/ "should pass a custom list of parameters",
917+
&onloadv1alpha1.ControlPlaneSpec{
918+
Parameters: []string{
919+
"-K",
920+
"--llap-max=100",
921+
},
922+
}, "-K --llap-max=100",
923+
),
924+
)
925+
874926
})
875927
})

pkg/control_plane/control_plane.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ import (
1212
// Configure the loaded Onload kernel module to launch
1313
// the Onload control plane process within a container.
1414
func Configure(
15-
onloadCPServerPath string, containerID string, kpw KernelParametersWriter,
15+
onloadCPServerPath string, onloadCPServerParams string,
16+
containerID string, kpw KernelParametersWriter,
1617
) error {
1718
// Split the container runtime type from identifier.
1819
containerID, found := strings.CutPrefix(containerID, "cri-o://")
@@ -31,8 +32,14 @@ func Configure(
3132

3233
glog.Info("Updated Onload control plane server path to ", crictlPath)
3334

35+
// Prepend the whitespace to non-empty cplane parameters.
36+
if onloadCPServerParams != "" {
37+
onloadCPServerParams = " " + onloadCPServerParams
38+
}
39+
3440
// Set the Onload control plane params.
35-
params := fmt.Sprintf("exec %s %s -K", containerID, onloadCPServerPath)
41+
params := fmt.Sprintf("exec %s %s%s", containerID,
42+
onloadCPServerPath, onloadCPServerParams)
3643
err = kpw.SetControlPlaneServerParams(params)
3744
if err != nil {
3845
return err

pkg/control_plane/control_plane_test.go

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,39 +8,52 @@ import (
88
)
99

1010
const (
11-
mockOnloadCPServerPath = "/mock/sbin/onload_cp_server"
11+
mockOnloadCPServerPath = "/mock/sbin/onload_cp_server"
12+
mockOnloadCPServerParams = "-mock -foo -bar"
1213

1314
mockCRIOContainerID = "cri-o://0123456789abcdef"
1415
mockContainerdContainerID = "containerd://fedcba9876543210"
1516
)
1617

1718
type mockKernelParametersWriter struct {
19+
expectedParams string
1820
}
1921

20-
func NewMockKernelParametersWriter() KernelParametersWriter {
21-
return &mockKernelParametersWriter{}
22+
func NewMockKernelParametersWriter(expectedParams string) KernelParametersWriter {
23+
return &mockKernelParametersWriter{
24+
expectedParams: expectedParams,
25+
}
2226
}
2327

2428
func (*mockKernelParametersWriter) SetControlPlaneServerPath(path string) error {
2529
Expect(path).To(Equal("/usr/bin/crictl"))
2630
return nil
2731
}
2832

29-
func (*mockKernelParametersWriter) SetControlPlaneServerParams(params string) error {
30-
Expect(params).To(Equal("exec 0123456789abcdef /mock/sbin/onload_cp_server -K"))
33+
func (mkpw *mockKernelParametersWriter) SetControlPlaneServerParams(params string) error {
34+
Expect(params).To(Equal(mkpw.expectedParams))
3135
return nil
3236
}
3337

3438
var _ = Describe("Configure Onload to launch the control plane process within a container", func() {
3539
It("Should work with the CRI-O runtime", func() {
36-
err := Configure(mockOnloadCPServerPath, mockCRIOContainerID,
37-
NewMockKernelParametersWriter())
40+
expectedParams := "exec 0123456789abcdef /mock/sbin/onload_cp_server -mock -foo -bar"
41+
err := Configure(mockOnloadCPServerPath, mockOnloadCPServerParams,
42+
mockCRIOContainerID, NewMockKernelParametersWriter(expectedParams))
43+
Expect(err).Should(Succeed())
44+
})
45+
46+
It("Should work with the CRI-O runtime and empty parameter list", func() {
47+
expectedParams := "exec 0123456789abcdef /mock/sbin/onload_cp_server"
48+
err := Configure(mockOnloadCPServerPath, "", mockCRIOContainerID,
49+
NewMockKernelParametersWriter(expectedParams))
3850
Expect(err).Should(Succeed())
3951
})
4052

4153
It("Should fail with non CRI-O runtime, e.g. containerd", func() {
42-
err := Configure(mockOnloadCPServerPath, mockContainerdContainerID,
43-
NewMockKernelParametersWriter())
54+
notUsed := ""
55+
err := Configure(mockOnloadCPServerPath, mockOnloadCPServerParams,
56+
mockContainerdContainerID, NewMockKernelParametersWriter(notUsed))
4457
Expect(err).Should(HaveOccurred())
4558
})
4659
})

0 commit comments

Comments
 (0)