Skip to content

Commit

Permalink
Merge pull request #46 from NVIDIA/pvc-wo-size-panic
Browse files Browse the repository at this point in the history
Error for bad PVC specification
  • Loading branch information
mikemckiernan authored Aug 13, 2024
2 parents 55b6e7c + a57125c commit 378eb2f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
8 changes: 4 additions & 4 deletions internal/controller/nimcache_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,20 +237,20 @@ func (r *NIMCacheReconciler) reconcilePVC(ctx context.Context, nimCache *appsv1a
if nimCache.Spec.Storage.PVC.Create != nil && *nimCache.Spec.Storage.PVC.Create {
pvc, err = shared.ConstructPVC(nimCache.Spec.Storage.PVC, metav1.ObjectMeta{Name: pvcName, Namespace: nimCache.GetNamespace()})
if err != nil {
logger.Error(err, "Failed to construct pvc", "name", pvc.Name)
logger.Error(err, "Failed to construct pvc", "name", pvcName)
return err
}
if err := controllerutil.SetControllerReference(nimCache, pvc, r.GetScheme()); err != nil {
return err
}
err = r.Create(ctx, pvc)
if err != nil {
logger.Error(err, "Failed to create pvc", "name", pvc.Name)
logger.Error(err, "Failed to create pvc", "name", pvcName)
return err
}
logger.Info("Created PVC for NIM Cache", "pvc", pvcName)
logger.Info("Created PVC for NIM Cache", "pvc", pvc.Name)

conditions.UpdateCondition(&nimCache.Status.Conditions, appsv1alpha1.NimCacheConditionPVCCreated, metav1.ConditionTrue, "PVCCreated", "The PVC has been created for caching NIM")
conditions.UpdateCondition(&nimCache.Status.Conditions, appsv1alpha1.NimCacheConditionPVCCreated, metav1.ConditionTrue, "PVCCreated", "The PVC has been created for caching NIM model")
nimCache.Status.State = appsv1alpha1.NimCacheStatusPVCCreated
if err := r.Status().Update(ctx, nimCache); err != nil {
logger.Error(err, "Failed to update status", "NIMCache", nimCache.Name)
Expand Down
23 changes: 23 additions & 0 deletions internal/controller/nimcache_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,29 @@ var _ = Describe("NIMCache Controller", func() {
return client.Get(ctx, pvcName, pvc)
}, time.Second*10).Should(Succeed())
})

It("should return an error if the PVC size is not specified", func() {
ctx := context.TODO()
NIMCache := &appsv1alpha1.NIMCache{
ObjectMeta: metav1.ObjectMeta{
Name: "test-nimcache",
Namespace: "default",
},
Spec: appsv1alpha1.NIMCacheSpec{
Source: appsv1alpha1.NIMSource{NGC: &appsv1alpha1.NGCSource{ModelPuller: "test-container", PullSecret: "my-secret"}},
Storage: appsv1alpha1.Storage{PVC: appsv1alpha1.PersistentVolumeClaim{Create: ptr.To[bool](true), StorageClass: "standard"}},
},
Status: appsv1alpha1.NIMCacheStatus{
State: appsv1alpha1.NimCacheStatusNotReady,
},
}
Expect(client.Create(ctx, NIMCache)).To(Succeed())

// Reconcile the resource
_, err := reconciler.reconcileNIMCache(ctx, NIMCache)
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("failed to parse size for pvc creation"))
})
})

Context("When the Job completes", func() {
Expand Down

0 comments on commit 378eb2f

Please sign in to comment.