Skip to content
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: 8 additions & 0 deletions api/apps/v1alpha1/nimservice_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,14 @@ type NIMServiceStatus struct {
Conditions []metav1.Condition `json:"conditions,omitempty"`
AvailableReplicas int32 `json:"availableReplicas,omitempty"`
State string `json:"state,omitempty"`
Model *ModelStatus `json:"model,omitempty"`
}

// ModelStatus defines the configuration of the NIMService model.
type ModelStatus struct {
Name string `json:"name"`
ClusterEndpoint string `json:"clusterEndpoint"`
ExternalEndpoint string `json:"externalEndpoint"`
}

// +genclient
Expand Down
20 changes: 20 additions & 0 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.

15 changes: 15 additions & 0 deletions bundle/manifests/apps.nvidia.com_nimservices.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2284,6 +2284,21 @@ spec:
- type
type: object
type: array
model:
description: ModelStatus defines the configuration of the NIMService
model.
properties:
clusterEndpoint:
type: string
externalEndpoint:
type: string
name:
type: string
required:
- clusterEndpoint
- externalEndpoint
- name
type: object
state:
type: string
type: object
Expand Down
15 changes: 15 additions & 0 deletions config/crd/bases/apps.nvidia.com_nimservices.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2284,6 +2284,21 @@ spec:
- type
type: object
type: array
model:
description: ModelStatus defines the configuration of the NIMService
model.
properties:
clusterEndpoint:
type: string
externalEndpoint:
type: string
name:
type: string
required:
- clusterEndpoint
- externalEndpoint
- name
type: object
state:
type: string
type: object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2284,6 +2284,21 @@ spec:
- type
type: object
type: array
model:
description: ModelStatus defines the configuration of the NIMService
model.
properties:
clusterEndpoint:
type: string
externalEndpoint:
type: string
name:
type: string
required:
- clusterEndpoint
- externalEndpoint
- name
type: object
state:
type: string
type: object
Expand Down
89 changes: 89 additions & 0 deletions internal/controller/platform/standalone/nimservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ import (
"context"
"fmt"

"github.com/NVIDIA/k8s-nim-operator/api/apps/v1alpha1"
appsv1alpha1 "github.com/NVIDIA/k8s-nim-operator/api/apps/v1alpha1"
"github.com/NVIDIA/k8s-nim-operator/internal/conditions"
"github.com/NVIDIA/k8s-nim-operator/internal/k8sutil"
"github.com/NVIDIA/k8s-nim-operator/internal/nimmodels"
"github.com/NVIDIA/k8s-nim-operator/internal/render"
rendertypes "github.com/NVIDIA/k8s-nim-operator/internal/render/types"
"github.com/NVIDIA/k8s-nim-operator/internal/shared"
Expand Down Expand Up @@ -261,6 +263,12 @@ func (r *NIMServiceReconciler) reconcileNIMService(ctx context.Context, nimServi
r.GetEventRecorder().Eventf(nimService, corev1.EventTypeNormal, conditions.NotReady,
"NIMService %s not ready yet, msg: %s", nimService.Name, msg)
} else {
// Update NIMServiceStatus with model config.
err = r.updateModelStatus(ctx, nimService)
if err != nil {
return ctrl.Result{}, err
}

// Update status as ready
err = r.updater.SetConditionsReady(ctx, nimService, conditions.Ready, msg)
r.GetEventRecorder().Eventf(nimService, corev1.EventTypeNormal, conditions.Ready,
Expand All @@ -275,6 +283,87 @@ func (r *NIMServiceReconciler) reconcileNIMService(ctx context.Context, nimServi
return ctrl.Result{}, nil
}

func (r *NIMServiceReconciler) updateModelStatus(ctx context.Context, nimService *v1alpha1.NIMService) error {
clusterEndpoint, externalEndpoint, err := r.getNIMModelEndpoints(ctx, nimService)
if err != nil {
return err
}
modelName, err := r.getNIMModelName(ctx, clusterEndpoint)
if err != nil {
return err
}
nimService.Status.Model = &v1alpha1.ModelStatus{
Name: modelName,
ClusterEndpoint: clusterEndpoint,
ExternalEndpoint: externalEndpoint,
}

return nil
}

func (r *NIMServiceReconciler) getNIMModelName(ctx context.Context, nimServiceEndpoint string) (string, error) {
modelsList, err := nimmodels.ListModelsV1(ctx, nimServiceEndpoint)
if err != nil {
return "", err
}

if modelsList.Object == nimmodels.ObjectTypeList {
for _, model := range modelsList.Data {
if model.Object != nimmodels.ObjectTypeModel {
continue
}
if model.Root == nil || *model.Root != model.Id {
continue
}
return model.Id, nil
}
}

return "", fmt.Errorf("failed to detect model name from nimservice endpoint '%s'", nimServiceEndpoint)
}

func (r *NIMServiceReconciler) getNIMModelEndpoints(ctx context.Context, nimService *appsv1alpha1.NIMService) (string, string, error) {
logger := log.FromContext(ctx)

// Lookup NIMCache instance in the same namespace as the NIMService instance
svc := &corev1.Service{}
if err := r.Get(ctx, types.NamespacedName{Name: nimService.GetName(), Namespace: nimService.GetNamespace()}, svc); err != nil {
logger.Error(err, "unable to fetch k8s service", "nimservice", nimService.GetName())
return "", "", err
}

var externalEndpoint string
port := nimService.GetServicePort()
if nimService.IsIngressEnabled() {
ingress := &networkingv1.Ingress{}
if err := r.Get(ctx, types.NamespacedName{Name: nimService.GetName(), Namespace: nimService.GetNamespace()}, ingress); err != nil {
logger.Error(err, "unable to fetch ingress", "nimservice", nimService.GetName())
return "", "", err
}

var found bool
for _, rule := range ingress.Spec.Rules {
if rule.HTTP == nil {
continue
}
for _, path := range rule.HTTP.Paths {
if path.Backend.Service != nil && path.Backend.Service.Name == nimService.GetName() {
externalEndpoint = rule.Host
found = true
break
}
}
if found {
break
}
}
} else if svc.Spec.Type == corev1.ServiceTypeLoadBalancer {
externalEndpoint = utils.FormatEndpoint(svc.Spec.LoadBalancerIP, port)
}

return utils.FormatEndpoint(svc.Spec.ClusterIP, port), externalEndpoint, nil
}

func (r *NIMServiceReconciler) renderAndSyncResource(ctx context.Context, nimService *appsv1alpha1.NIMService, renderer *render.Renderer, obj client.Object, renderFunc func() (client.Object, error), conditionType string, reason string) error {
logger := log.FromContext(ctx)

Expand Down
Loading