From b322edb9006617aedd7e486d59ba645deb8ffb45 Mon Sep 17 00:00:00 2001 From: Vishesh Tanksale Date: Thu, 7 Nov 2024 16:42:44 -0800 Subject: [PATCH] Adding check for empty runtimeclassname to NIMCache (#225) Signed-off-by: Vishesh Tanksale --- api/apps/v1alpha1/nimcache_types.go | 7 +++++-- internal/controller/nimcache_controller.go | 6 ++---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/api/apps/v1alpha1/nimcache_types.go b/api/apps/v1alpha1/nimcache_types.go index 3d2867e4..5231d103 100644 --- a/api/apps/v1alpha1/nimcache_types.go +++ b/api/apps/v1alpha1/nimcache_types.go @@ -275,8 +275,11 @@ func (n *NIMCache) GetNodeSelectors() map[string]string { } // GetRuntimeClassName return the runtime class name for the NIMCache Job -func (n *NIMCache) GetRuntimeClassName() string { - return n.Spec.RuntimeClassName +func (n *NIMCache) GetRuntimeClassName() *string { + if n.Spec.RuntimeClassName == "" { + return nil + } + return &n.Spec.RuntimeClassName } // +kubebuilder:object:root=true diff --git a/internal/controller/nimcache_controller.go b/internal/controller/nimcache_controller.go index c230292e..482cd7b1 100644 --- a/internal/controller/nimcache_controller.go +++ b/internal/controller/nimcache_controller.go @@ -914,7 +914,6 @@ func constructPodSpec(nimCache *appsv1alpha1.NIMCache, platformType k8sutil.Orch "app.kubernetes.io/name": nimCache.Name, "app.kubernetes.io/managed-by": "k8s-nim-operator", } - runtimeClassName := nimCache.GetRuntimeClassName() annotations := make(map[string]string) if platformType == k8sutil.OpenShift { @@ -931,7 +930,7 @@ func constructPodSpec(nimCache *appsv1alpha1.NIMCache, platformType k8sutil.Orch Annotations: annotations, }, Spec: corev1.PodSpec{ - RuntimeClassName: &runtimeClassName, + RuntimeClassName: nimCache.GetRuntimeClassName(), Containers: []corev1.Container{ { Name: NIMCacheContainerName, @@ -1005,7 +1004,6 @@ func (r *NIMCacheReconciler) getPodLogs(ctx context.Context, pod *corev1.Pod) (s func (r *NIMCacheReconciler) constructJob(ctx context.Context, nimCache *appsv1alpha1.NIMCache, platformType k8sutil.OrchestratorType) (*batchv1.Job, error) { logger := r.GetLogger() pvcName := getPvcName(nimCache, nimCache.Spec.Storage.PVC) - runtimeClassName := nimCache.GetRuntimeClassName() labels := map[string]string{ "app": "k8s-nim-operator", "app.kubernetes.io/name": nimCache.Name, @@ -1032,7 +1030,7 @@ func (r *NIMCacheReconciler) constructJob(ctx context.Context, nimCache *appsv1a Annotations: annotations, }, Spec: corev1.PodSpec{ - RuntimeClassName: &runtimeClassName, + RuntimeClassName: nimCache.GetRuntimeClassName(), SecurityContext: &corev1.PodSecurityContext{ RunAsUser: nimCache.GetUserID(), FSGroup: nimCache.GetGroupID(),