@@ -25,6 +25,7 @@ import (
2525 "k8s.io/utils/ptr"
2626
2727 "github.com/NVIDIA/k8s-nim-operator/internal/k8sutil"
28+ rendertypes "github.com/NVIDIA/k8s-nim-operator/internal/render/types"
2829)
2930
3031// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
@@ -132,23 +133,6 @@ type NIMCacheStorage struct {
132133 HostPath * string `json:"hostPath,omitempty"`
133134}
134135
135- // PersistentVolumeClaim defines the attributes of PVC used as a source for caching NIM model.
136- type PersistentVolumeClaim struct {
137- // Create indicates to create a new PVC
138- Create * bool `json:"create,omitempty"`
139- // Name is the name of the PVC
140- Name string `json:"name,omitempty"`
141- // StorageClass to be used for PVC creation. Leave it as empty if the PVC is already created or
142- // a default storage class is set in the cluster.
143- StorageClass string `json:"storageClass,omitempty"`
144- // Size of the NIM cache in Gi, used during PVC creation
145- Size string `json:"size,omitempty"`
146- // VolumeAccessMode is the volume access mode of the PVC
147- VolumeAccessMode corev1.PersistentVolumeAccessMode `json:"volumeAccessMode,omitempty"`
148- // SubPath is the path inside the PVC that should be mounted
149- SubPath string `json:"subPath,omitempty"`
150- }
151-
152136// NIMCacheStatus defines the observed state of NIMCache.
153137type NIMCacheStatus struct {
154138 State string `json:"state,omitempty"`
@@ -247,10 +231,10 @@ type NIMCache struct {
247231
248232// GetPVCName returns the name to be used for the PVC based on the custom spec
249233// Prefers pvc.Name if explicitly set by the user in the NIMCache instance.
250- func (n * NIMCache ) GetPVCName (pvc PersistentVolumeClaim ) string {
234+ func (n * NIMCache ) GetPVCName () string {
251235 pvcName := fmt .Sprintf ("%s-pvc" , n .GetName ())
252- if pvc .Name != "" {
253- pvcName = pvc .Name
236+ if n . Spec . Storage . PVC .Name != "" {
237+ pvcName = n . Spec . Storage . PVC .Name
254238 }
255239 return pvcName
256240}
@@ -351,6 +335,24 @@ func (n *NIMCache) GetInitContainers() []corev1.Container {
351335 return []corev1.Container {}
352336}
353337
338+ // GetPVCParams returns parameters to render a PersistentVolumeClaim from templates.
339+ func (n * NIMCache ) GetPVCParams () * rendertypes.PVCParams {
340+ params := & rendertypes.PVCParams {}
341+
342+ // Set metadata
343+ params .Enabled = ptr .Deref (n .Spec .Storage .PVC .Create , false )
344+ params .Name = n .GetPVCName ()
345+ params .Namespace = n .GetNamespace ()
346+ params .Annotations = n .Spec .Storage .PVC .Annotations
347+
348+ // PVC-specific config
349+ params .AccessMode = n .Spec .Storage .PVC .VolumeAccessMode
350+ params .Storage = n .Spec .Storage .PVC .Size
351+ params .StorageClassName = n .Spec .Storage .PVC .StorageClass
352+
353+ return params
354+ }
355+
354356// +kubebuilder:object:root=true
355357
356358// NIMCacheList contains a list of NIMCache.
0 commit comments