Skip to content

Commit d0dca13

Browse files
Adding support for hostpath on NIMService (#699)
* Adding support for hostpath on NIMService Signed-off-by: Vishesh Tanksale <[email protected]> * Adding OCP security context Signed-off-by: Vishesh Tanksale <[email protected]> --------- Signed-off-by: Vishesh Tanksale <[email protected]>
1 parent 7350000 commit d0dca13

File tree

3 files changed

+44
-8
lines changed

3 files changed

+44
-8
lines changed

api/apps/v1alpha1/nimservice_types.go

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,8 @@ func (n *NIMService) GetStandardAnnotations() map[string]string {
499499
}
500500
if n.GetProxyCertConfigMap() != "" {
501501
standardAnnotations["openshift.io/required-scc"] = "anyuid"
502+
} else if n.GetHostPath() != "" {
503+
standardAnnotations["openshift.io/required-scc"] = "hostmount-anyuid"
502504
}
503505
return standardAnnotations
504506
}
@@ -709,7 +711,8 @@ func (n *NIMService) GetVolumes(modelPVC *PersistentVolumeClaim) []corev1.Volume
709711
},
710712
},
711713
}
712-
if modelPVC != nil {
714+
switch {
715+
case modelPVC != nil:
713716
volumes = append(volumes, corev1.Volume{
714717
Name: "model-store",
715718
VolumeSource: corev1.VolumeSource{
@@ -719,7 +722,7 @@ func (n *NIMService) GetVolumes(modelPVC *PersistentVolumeClaim) []corev1.Volume
719722
},
720723
},
721724
})
722-
} else if n.Spec.Storage.EmptyDir != nil {
725+
case n.Spec.Storage.EmptyDir != nil:
723726
volumes = append(volumes, corev1.Volume{
724727
Name: "model-store",
725728
VolumeSource: corev1.VolumeSource{
@@ -728,6 +731,17 @@ func (n *NIMService) GetVolumes(modelPVC *PersistentVolumeClaim) []corev1.Volume
728731
},
729732
},
730733
})
734+
case n.GetHostPath() != "":
735+
hostPathType := corev1.HostPathDirectoryOrCreate
736+
volumes = append(volumes, corev1.Volume{
737+
Name: "model-store",
738+
VolumeSource: corev1.VolumeSource{
739+
HostPath: &corev1.HostPathVolumeSource{
740+
Path: *n.Spec.Storage.HostPath,
741+
Type: &hostPathType,
742+
},
743+
},
744+
})
731745
}
732746

733747
if n.GetProxyCertConfigMap() != "" {
@@ -1417,7 +1431,8 @@ func (n *NIMService) GetRoleParams() *rendertypes.RoleParams {
14171431
params.Namespace = n.GetNamespace()
14181432

14191433
// Set rules to use SCC
1420-
if n.GetProxySpec() != nil {
1434+
switch {
1435+
case n.GetProxySpec() != nil:
14211436
params.Rules = []rbacv1.PolicyRule{
14221437
{
14231438
APIGroups: []string{"security.openshift.io"},
@@ -1426,7 +1441,16 @@ func (n *NIMService) GetRoleParams() *rendertypes.RoleParams {
14261441
Verbs: []string{"use"},
14271442
},
14281443
}
1429-
} else {
1444+
case n.GetHostPath() != "":
1445+
params.Rules = []rbacv1.PolicyRule{
1446+
{
1447+
APIGroups: []string{"security.openshift.io"},
1448+
Resources: []string{"securitycontextconstraints"},
1449+
ResourceNames: []string{"hostmount-anyuid"},
1450+
Verbs: []string{"use"},
1451+
},
1452+
}
1453+
default:
14301454
params.Rules = []rbacv1.PolicyRule{
14311455
{
14321456
APIGroups: []string{"security.openshift.io"},
@@ -1591,6 +1615,14 @@ func (n *NIMService) GetProxyCertConfigMap() string {
15911615
return ""
15921616
}
15931617

1618+
// GetHostPath returns the host path for the NIMService deployment.
1619+
func (n *NIMService) GetHostPath() string {
1620+
if n.Spec.Storage.HostPath != nil && *n.Spec.Storage.HostPath != "" {
1621+
return *n.Spec.Storage.HostPath
1622+
}
1623+
return ""
1624+
}
1625+
15941626
// GetInferenceServiceParams returns params to render InferenceService from templates.
15951627
func (n *NIMService) GetInferenceServiceParams(
15961628
deploymentMode kserveconstants.DeploymentModeType) *rendertypes.InferenceServiceParams {

internal/controller/platform/kserve/nimservice.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -342,9 +342,11 @@ func (r *NIMServiceReconciler) renderAndSyncCache(ctx context.Context,
342342
modelPVC = &nimService.Spec.Storage.PVC
343343
} else if nimService.Spec.Storage.EmptyDir != nil {
344344
modelPVC = nil
345+
} else if nimService.Spec.Storage.HostPath != nil && *nimService.Spec.Storage.HostPath != "" {
346+
modelPVC = nil
345347
} else {
346-
err := fmt.Errorf("neither external PVC name or NIMCache volume is provided")
347-
logger.Error(err, "failed to determine PVC for model-store")
348+
err := fmt.Errorf("neither external PVC name, NIMCache volume, empty dir or local host path should be provided")
349+
logger.Error(err, "failed to determine PVC , NIMCache volume, empty dir or local host path for model-store")
348350
return nil, "", nil, err
349351
}
350352

internal/controller/platform/standalone/nimservice.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -372,9 +372,11 @@ func (r *NIMServiceReconciler) reconcileNIMService(ctx context.Context, nimServi
372372
modelPVC = &nimService.Spec.Storage.PVC
373373
} else if nimService.Spec.Storage.EmptyDir != nil {
374374
modelPVC = nil
375+
} else if nimService.Spec.Storage.HostPath != nil && *nimService.Spec.Storage.HostPath != "" {
376+
modelPVC = nil
375377
} else {
376-
err = fmt.Errorf("neither external PVC name, NIMCache volume or empty dir is provided")
377-
logger.Error(err, "failed to determine PVC , NIMCache volume or empty dir for model-store")
378+
err = fmt.Errorf("neither external PVC name, NIMCache volume, empty dir or local host path should be provided")
379+
logger.Error(err, "failed to determine PVC , NIMCache volume, empty dir or local host path for model-store")
378380
return ctrl.Result{}, err
379381
}
380382

0 commit comments

Comments
 (0)