Skip to content

Commit d7030c1

Browse files
Merge pull request #53 from shivamerla/fix_external_pvc
Fix check for external PVC
2 parents 8a01783 + 1f5caa8 commit d7030c1

File tree

6 files changed

+17
-25
lines changed

6 files changed

+17
-25
lines changed

api/apps/v1alpha1/nimcache_types.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ type PersistentVolumeClaim struct {
124124
// Create indicates to create a new PVC
125125
Create *bool `json:"create,omitempty"`
126126
// Name is the name of the PVC
127-
Name *string `json:"name,omitempty"`
127+
Name string `json:"name,omitempty"`
128128
// StorageClass to be used for PVC creation. Leave it as empty if the PVC is already created.
129129
StorageClass string `json:"storageClass,omitempty"`
130130
// Size of the NIM cache in Gi, used during PVC creation
@@ -236,8 +236,8 @@ type NIMCache struct {
236236
// Prefers pvc.Name if explicitly set by the user in the NIMCache instance
237237
func (n *NIMCache) GetPVCName(pvc PersistentVolumeClaim) string {
238238
pvcName := fmt.Sprintf("%s-pvc", n.GetName())
239-
if pvc.Name != nil {
240-
pvcName = *pvc.Name
239+
if pvc.Name != "" {
240+
pvcName = pvc.Name
241241
}
242242
return pvcName
243243
}

api/apps/v1alpha1/nimservice_types.go

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,8 @@ type NIMServiceList struct {
120120
// Prefers pvc.Name if explicitly set by the user in the NIMService instance
121121
func (n *NIMService) GetPVCName(pvc PersistentVolumeClaim) string {
122122
pvcName := fmt.Sprintf("%s-pvc", n.GetName())
123-
if pvc.Name != nil {
124-
pvcName = *pvc.Name
123+
if pvc.Name != "" {
124+
pvcName = pvc.Name
125125
}
126126
return pvcName
127127
}
@@ -393,7 +393,7 @@ func (n *NIMService) GetVolumes(modelPVC PersistentVolumeClaim) []corev1.Volume
393393
Name: "model-store",
394394
VolumeSource: corev1.VolumeSource{
395395
PersistentVolumeClaim: &corev1.PersistentVolumeClaimVolumeSource{
396-
ClaimName: *modelPVC.Name,
396+
ClaimName: modelPVC.Name,
397397
},
398398
},
399399
},
@@ -434,11 +434,6 @@ func (n *NIMService) GetNIMCacheProfile() string {
434434
return n.Spec.NIMCache.Profile
435435
}
436436

437-
// GetExternalPVC returns the external PVC name to use for the NIMService deployment
438-
func (n *NIMService) GetExternalPVC() *PersistentVolumeClaim {
439-
return &n.Spec.Storage.PVC
440-
}
441-
442437
// GetHPA returns the HPA spec for the NIMService deployment
443438
func (n *NIMService) GetHPA() HorizontalPodAutoscalerSpec {
444439
return n.Spec.Scale.HPA

api/apps/v1alpha1/zz_generated.deepcopy.go

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

internal/controller/nimcache_controller.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -574,8 +574,8 @@ func getJobName(nimCache *appsv1alpha1.NIMCache) string {
574574

575575
func getPvcName(parent client.Object, pvc appsv1alpha1.PersistentVolumeClaim) string {
576576
pvcName := fmt.Sprintf("%s-pvc", parent.GetName())
577-
if pvc.Name != nil {
578-
pvcName = *pvc.Name
577+
if pvc.Name != "" {
578+
pvcName = pvc.Name
579579
}
580580
return pvcName
581581
}

internal/controller/platform/standalone/nimservice.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ func (r *NIMServiceReconciler) reconcileNIMService(ctx context.Context, nimServi
136136
var modelPVC *appsv1alpha1.PersistentVolumeClaim
137137
modelProfile := ""
138138

139-
// If external PVC is provided, use that as model-store
139+
// Select PVC for model store
140140
if nimService.GetNIMCacheName() != "" {
141141
// Fetch PVC for the associated NIMCache instance and mount it
142142
nimCachePVC, err := r.getNIMCachePVC(ctx, nimService)
@@ -151,16 +151,18 @@ func (r *NIMServiceReconciler) reconcileNIMService(ctx context.Context, nimServi
151151
logger.Info("overriding model profile", "profile", profile)
152152
modelProfile = profile
153153
}
154-
} else if externalPVC := nimService.GetExternalPVC(); externalPVC != nil {
155-
modelPVC = externalPVC
156154
} else if nimService.Spec.Storage.PVC.Create != nil && *nimService.Spec.Storage.PVC.Create {
155+
// Create a new PVC
157156
modelPVC, err = r.reconcilePVC(ctx, nimService)
158157
if err != nil {
159158
logger.Error(err, "unable to create pvc")
160159
return ctrl.Result{}, err
161160
}
161+
} else if nimService.Spec.Storage.PVC.Name != "" {
162+
// Use an existing PVC
163+
modelPVC = &nimService.Spec.Storage.PVC
162164
} else {
163-
err := fmt.Errorf("neither external PVC or NIMCache volume is provided")
165+
err := fmt.Errorf("neither external PVC name or NIMCache volume is provided")
164166
logger.Error(err, "failed to determine PVC for model-store")
165167
return ctrl.Result{}, err
166168
}
@@ -334,8 +336,8 @@ func (r *NIMServiceReconciler) getNIMCachePVC(ctx context.Context, nimService *a
334336
return nil, fmt.Errorf("missing PVC for the nimcache instance %s, nimservice %s", nimCache.GetName(), nimService.GetName())
335337
}
336338

337-
if nimCache.Spec.Storage.PVC.Name == nil {
338-
nimCache.Spec.Storage.PVC.Name = &nimCache.Status.PVC
339+
if nimCache.Spec.Storage.PVC.Name == "" {
340+
nimCache.Spec.Storage.PVC.Name = nimCache.Status.PVC
339341
}
340342
// Get the underlying PVC for the NIMCache instance
341343
return &nimCache.Spec.Storage.PVC, nil

internal/controller/platform/standalone/nimservice_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ var _ = Describe("NIMServiceReconciler for a standalone platform", func() {
110110
Image: appsv1alpha1.Image{Repository: "nvcr.io/nvidia/nim-llm", PullPolicy: "IfNotPresent", Tag: "v0.1.0", PullSecrets: []string{"ngc-secret"}},
111111
Storage: appsv1alpha1.Storage{
112112
PVC: appsv1alpha1.PersistentVolumeClaim{
113-
Name: &pvcName,
113+
Name: pvcName,
114114
},
115115
},
116116
NIMCache: appsv1alpha1.NIMCacheVolSpec{

0 commit comments

Comments
 (0)