Skip to content

Commit 378eb2f

Browse files
Merge pull request #46 from NVIDIA/pvc-wo-size-panic
Error for bad PVC specification
2 parents 55b6e7c + a57125c commit 378eb2f

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

internal/controller/nimcache_controller.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -237,20 +237,20 @@ func (r *NIMCacheReconciler) reconcilePVC(ctx context.Context, nimCache *appsv1a
237237
if nimCache.Spec.Storage.PVC.Create != nil && *nimCache.Spec.Storage.PVC.Create {
238238
pvc, err = shared.ConstructPVC(nimCache.Spec.Storage.PVC, metav1.ObjectMeta{Name: pvcName, Namespace: nimCache.GetNamespace()})
239239
if err != nil {
240-
logger.Error(err, "Failed to construct pvc", "name", pvc.Name)
240+
logger.Error(err, "Failed to construct pvc", "name", pvcName)
241241
return err
242242
}
243243
if err := controllerutil.SetControllerReference(nimCache, pvc, r.GetScheme()); err != nil {
244244
return err
245245
}
246246
err = r.Create(ctx, pvc)
247247
if err != nil {
248-
logger.Error(err, "Failed to create pvc", "name", pvc.Name)
248+
logger.Error(err, "Failed to create pvc", "name", pvcName)
249249
return err
250250
}
251-
logger.Info("Created PVC for NIM Cache", "pvc", pvcName)
251+
logger.Info("Created PVC for NIM Cache", "pvc", pvc.Name)
252252

253-
conditions.UpdateCondition(&nimCache.Status.Conditions, appsv1alpha1.NimCacheConditionPVCCreated, metav1.ConditionTrue, "PVCCreated", "The PVC has been created for caching NIM")
253+
conditions.UpdateCondition(&nimCache.Status.Conditions, appsv1alpha1.NimCacheConditionPVCCreated, metav1.ConditionTrue, "PVCCreated", "The PVC has been created for caching NIM model")
254254
nimCache.Status.State = appsv1alpha1.NimCacheStatusPVCCreated
255255
if err := r.Status().Update(ctx, nimCache); err != nil {
256256
logger.Error(err, "Failed to update status", "NIMCache", nimCache.Name)

internal/controller/nimcache_controller_test.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,29 @@ var _ = Describe("NIMCache Controller", func() {
109109
return client.Get(ctx, pvcName, pvc)
110110
}, time.Second*10).Should(Succeed())
111111
})
112+
113+
It("should return an error if the PVC size is not specified", func() {
114+
ctx := context.TODO()
115+
NIMCache := &appsv1alpha1.NIMCache{
116+
ObjectMeta: metav1.ObjectMeta{
117+
Name: "test-nimcache",
118+
Namespace: "default",
119+
},
120+
Spec: appsv1alpha1.NIMCacheSpec{
121+
Source: appsv1alpha1.NIMSource{NGC: &appsv1alpha1.NGCSource{ModelPuller: "test-container", PullSecret: "my-secret"}},
122+
Storage: appsv1alpha1.Storage{PVC: appsv1alpha1.PersistentVolumeClaim{Create: ptr.To[bool](true), StorageClass: "standard"}},
123+
},
124+
Status: appsv1alpha1.NIMCacheStatus{
125+
State: appsv1alpha1.NimCacheStatusNotReady,
126+
},
127+
}
128+
Expect(client.Create(ctx, NIMCache)).To(Succeed())
129+
130+
// Reconcile the resource
131+
_, err := reconciler.reconcileNIMCache(ctx, NIMCache)
132+
Expect(err).To(HaveOccurred())
133+
Expect(err.Error()).To(ContainSubstring("failed to parse size for pvc creation"))
134+
})
112135
})
113136

114137
Context("When the Job completes", func() {

0 commit comments

Comments
 (0)