Skip to content

Commit

Permalink
Merge pull request #53 from shivamerla/fix_external_pvc
Browse files Browse the repository at this point in the history
Fix check for external PVC
  • Loading branch information
ArangoGutierrez authored Aug 16, 2024
2 parents 8a01783 + 1f5caa8 commit d7030c1
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 25 deletions.
6 changes: 3 additions & 3 deletions api/apps/v1alpha1/nimcache_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ type PersistentVolumeClaim struct {
// Create indicates to create a new PVC
Create *bool `json:"create,omitempty"`
// Name is the name of the PVC
Name *string `json:"name,omitempty"`
Name string `json:"name,omitempty"`
// StorageClass to be used for PVC creation. Leave it as empty if the PVC is already created.
StorageClass string `json:"storageClass,omitempty"`
// Size of the NIM cache in Gi, used during PVC creation
Expand Down Expand Up @@ -236,8 +236,8 @@ type NIMCache struct {
// Prefers pvc.Name if explicitly set by the user in the NIMCache instance
func (n *NIMCache) GetPVCName(pvc PersistentVolumeClaim) string {
pvcName := fmt.Sprintf("%s-pvc", n.GetName())
if pvc.Name != nil {
pvcName = *pvc.Name
if pvc.Name != "" {
pvcName = pvc.Name
}
return pvcName
}
Expand Down
11 changes: 3 additions & 8 deletions api/apps/v1alpha1/nimservice_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ type NIMServiceList struct {
// Prefers pvc.Name if explicitly set by the user in the NIMService instance
func (n *NIMService) GetPVCName(pvc PersistentVolumeClaim) string {
pvcName := fmt.Sprintf("%s-pvc", n.GetName())
if pvc.Name != nil {
pvcName = *pvc.Name
if pvc.Name != "" {
pvcName = pvc.Name
}
return pvcName
}
Expand Down Expand Up @@ -393,7 +393,7 @@ func (n *NIMService) GetVolumes(modelPVC PersistentVolumeClaim) []corev1.Volume
Name: "model-store",
VolumeSource: corev1.VolumeSource{
PersistentVolumeClaim: &corev1.PersistentVolumeClaimVolumeSource{
ClaimName: *modelPVC.Name,
ClaimName: modelPVC.Name,
},
},
},
Expand Down Expand Up @@ -434,11 +434,6 @@ func (n *NIMService) GetNIMCacheProfile() string {
return n.Spec.NIMCache.Profile
}

// GetExternalPVC returns the external PVC name to use for the NIMService deployment
func (n *NIMService) GetExternalPVC() *PersistentVolumeClaim {
return &n.Spec.Storage.PVC
}

// GetHPA returns the HPA spec for the NIMService deployment
func (n *NIMService) GetHPA() HorizontalPodAutoscalerSpec {
return n.Spec.Scale.HPA
Expand Down
5 changes: 0 additions & 5 deletions api/apps/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions internal/controller/nimcache_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -574,8 +574,8 @@ func getJobName(nimCache *appsv1alpha1.NIMCache) string {

func getPvcName(parent client.Object, pvc appsv1alpha1.PersistentVolumeClaim) string {
pvcName := fmt.Sprintf("%s-pvc", parent.GetName())
if pvc.Name != nil {
pvcName = *pvc.Name
if pvc.Name != "" {
pvcName = pvc.Name
}
return pvcName
}
Expand Down
14 changes: 8 additions & 6 deletions internal/controller/platform/standalone/nimservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func (r *NIMServiceReconciler) reconcileNIMService(ctx context.Context, nimServi
var modelPVC *appsv1alpha1.PersistentVolumeClaim
modelProfile := ""

// If external PVC is provided, use that as model-store
// Select PVC for model store
if nimService.GetNIMCacheName() != "" {
// Fetch PVC for the associated NIMCache instance and mount it
nimCachePVC, err := r.getNIMCachePVC(ctx, nimService)
Expand All @@ -151,16 +151,18 @@ func (r *NIMServiceReconciler) reconcileNIMService(ctx context.Context, nimServi
logger.Info("overriding model profile", "profile", profile)
modelProfile = profile
}
} else if externalPVC := nimService.GetExternalPVC(); externalPVC != nil {
modelPVC = externalPVC
} else if nimService.Spec.Storage.PVC.Create != nil && *nimService.Spec.Storage.PVC.Create {
// Create a new PVC
modelPVC, err = r.reconcilePVC(ctx, nimService)
if err != nil {
logger.Error(err, "unable to create pvc")
return ctrl.Result{}, err
}
} else if nimService.Spec.Storage.PVC.Name != "" {
// Use an existing PVC
modelPVC = &nimService.Spec.Storage.PVC
} else {
err := fmt.Errorf("neither external PVC or NIMCache volume is provided")
err := fmt.Errorf("neither external PVC name or NIMCache volume is provided")
logger.Error(err, "failed to determine PVC for model-store")
return ctrl.Result{}, err
}
Expand Down Expand Up @@ -334,8 +336,8 @@ func (r *NIMServiceReconciler) getNIMCachePVC(ctx context.Context, nimService *a
return nil, fmt.Errorf("missing PVC for the nimcache instance %s, nimservice %s", nimCache.GetName(), nimService.GetName())
}

if nimCache.Spec.Storage.PVC.Name == nil {
nimCache.Spec.Storage.PVC.Name = &nimCache.Status.PVC
if nimCache.Spec.Storage.PVC.Name == "" {
nimCache.Spec.Storage.PVC.Name = nimCache.Status.PVC
}
// Get the underlying PVC for the NIMCache instance
return &nimCache.Spec.Storage.PVC, nil
Expand Down
2 changes: 1 addition & 1 deletion internal/controller/platform/standalone/nimservice_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ var _ = Describe("NIMServiceReconciler for a standalone platform", func() {
Image: appsv1alpha1.Image{Repository: "nvcr.io/nvidia/nim-llm", PullPolicy: "IfNotPresent", Tag: "v0.1.0", PullSecrets: []string{"ngc-secret"}},
Storage: appsv1alpha1.Storage{
PVC: appsv1alpha1.PersistentVolumeClaim{
Name: &pvcName,
Name: pvcName,
},
},
NIMCache: appsv1alpha1.NIMCacheVolSpec{
Expand Down

0 comments on commit d7030c1

Please sign in to comment.