Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error for bad PVC specification #46

Merged
merged 2 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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