From d2f7f3e9dd0f2211dfe2b1163eed39e02c362a79 Mon Sep 17 00:00:00 2001 From: Pradipta Banerjee Date: Thu, 19 Dec 2024 21:07:33 +0530 Subject: [PATCH] Add runtimeClass support to modelmesh deployment This allows the deployment to use different container runtimes or configuration exposed by K8s runtimeClass. Signed-off-by: Pradipta Banerjee --- config/default/config-defaults.yaml | 1 + controllers/modelmesh/modelmesh.go | 10 ++++++++++ controllers/servingruntime_controller.go | 1 + docs/configuration/README.md | 1 + pkg/config/config.go | 2 ++ 5 files changed, 15 insertions(+) diff --git a/config/default/config-defaults.yaml b/config/default/config-defaults.yaml index 4a4c7e42..83c49336 100644 --- a/config/default/config-defaults.yaml +++ b/config/default/config-defaults.yaml @@ -49,6 +49,7 @@ storageHelperResources: cpu: "2" memory: "512Mi" serviceAccountName: "" +runtimeClassName: "" metrics: enabled: true builtInServerTypes: diff --git a/controllers/modelmesh/modelmesh.go b/controllers/modelmesh/modelmesh.go index cf136a7d..bccab3d3 100644 --- a/controllers/modelmesh/modelmesh.go +++ b/controllers/modelmesh/modelmesh.go @@ -67,6 +67,7 @@ type Deployment struct { PullerImageCommand []string PullerResources *corev1.ResourceRequirements Replicas uint16 + RuntimeClassName string Port uint16 TLSSecretName string TLSClientAuth string @@ -131,6 +132,7 @@ func (m *Deployment) Apply(ctx context.Context) error { m.configureRuntimePodSpecLabels, m.ensureMMContainerIsLast, m.configureRuntimePodSpecImagePullSecrets, + m.addRuntimeClassToDeployment, ); tErr != nil { return tErr } @@ -313,3 +315,11 @@ func (m *Deployment) setConfigMap() error { m.AnnotationConfigMap = annotationConfigMap return nil } + +// Add runtimeClassName to the deployment spec +func (m *Deployment) addRuntimeClassToDeployment(deployment *appsv1.Deployment) error { + if m.RuntimeClassName != "" { + deployment.Spec.Template.Spec.RuntimeClassName = &m.RuntimeClassName + } + return nil +} diff --git a/controllers/servingruntime_controller.go b/controllers/servingruntime_controller.go index 28144afd..c850ef38 100644 --- a/controllers/servingruntime_controller.go +++ b/controllers/servingruntime_controller.go @@ -259,6 +259,7 @@ func (r *ServingRuntimeReconciler) Reconcile(ctx context.Context, req ctrl.Reque AnnotationsMap: cfg.RuntimePodAnnotations, LabelsMap: cfg.RuntimePodLabels, ImagePullSecrets: cfg.ImagePullSecrets, + RuntimeClassName: cfg.RuntimeClassName, } // if the runtime is disabled, delete the deployment if spec.IsDisabled() || !spec.IsMultiModelRuntime() || !mmEnabled { diff --git a/docs/configuration/README.md b/docs/configuration/README.md index c8f78178..b538f2cd 100644 --- a/docs/configuration/README.md +++ b/docs/configuration/README.md @@ -54,6 +54,7 @@ The following parameters are currently supported. _Note_ the keys are expressed | `runtimePodAnnotations` | `metadata.annotations` to be added to all `ServingRuntime` pods | (\*\*\*\*\*) See default annotations below | | `imagePullSecrets` | The image pull secrets to use for runtime Pods | | | `allowAnyPVC` | Allows any PVC in predictor to configure PVC for runtime pods when it's not in storage secret | `false` | +| `runtimeClassName` | The K8s runtimeClassName to use for the runtime | (\*) Currently requires a controller restart to take effect diff --git a/pkg/config/config.go b/pkg/config/config.go index ca2db8a0..1506201c 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -89,6 +89,8 @@ type Config struct { ImagePullSecrets []corev1.LocalObjectReference + RuntimeClassName string + // For internal use only InternalModelMeshEnvVars EnvVarList }