Skip to content

Commit 85d4858

Browse files
varunrsekarshivamerla
authored andcommitted
set ingress endpoints in status when available
Signed-off-by: Varun Ramachandra Sekar <vsekar@nvidia.com>
1 parent 3b03d5c commit 85d4858

File tree

6 files changed

+44
-27
lines changed

6 files changed

+44
-27
lines changed

api/apps/v1alpha1/nimservice_types.go

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,6 @@ type NIMCacheVolSpec struct {
8787
Profile string `json:"profile,omitempty"`
8888
}
8989

90-
type ModelEngine string
91-
92-
const (
93-
ModelEngineNIM ModelEngine = "nim"
94-
)
95-
9690
// NIMServiceStatus defines the observed state of NIMService
9791
type NIMServiceStatus struct {
9892
Conditions []metav1.Condition `json:"conditions,omitempty"`
@@ -103,10 +97,9 @@ type NIMServiceStatus struct {
10397

10498
// ModelStatus defines the configuration of the NIMService model.
10599
type ModelStatus struct {
106-
Name string `json:"name"`
107-
ClusterEndpoint string `json:"clusterEndpoint"`
108-
ExternalEndpoint string `json:"externalEndpoint"`
109-
Engine ModelEngine `json:"engine"`
100+
Name string `json:"name"`
101+
ClusterEndpoint string `json:"clusterEndpoint"`
102+
ExternalEndpoint string `json:"externalEndpoint"`
110103
}
111104

112105
// +genclient

bundle/manifests/apps.nvidia.com_nimservices.yaml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2290,15 +2290,12 @@ spec:
22902290
properties:
22912291
clusterEndpoint:
22922292
type: string
2293-
engine:
2294-
type: string
22952293
externalEndpoint:
22962294
type: string
22972295
name:
22982296
type: string
22992297
required:
23002298
- clusterEndpoint
2301-
- engine
23022299
- externalEndpoint
23032300
- name
23042301
type: object

config/crd/bases/apps.nvidia.com_nimservices.yaml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2290,15 +2290,12 @@ spec:
22902290
properties:
22912291
clusterEndpoint:
22922292
type: string
2293-
engine:
2294-
type: string
22952293
externalEndpoint:
22962294
type: string
22972295
name:
22982296
type: string
22992297
required:
23002298
- clusterEndpoint
2301-
- engine
23022299
- externalEndpoint
23032300
- name
23042301
type: object

deployments/helm/k8s-nim-operator/crds/apps.nvidia.com_nimservices.yaml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2290,15 +2290,12 @@ spec:
22902290
properties:
22912291
clusterEndpoint:
22922292
type: string
2293-
engine:
2294-
type: string
22952293
externalEndpoint:
22962294
type: string
22972295
name:
22982296
type: string
22992297
required:
23002298
- clusterEndpoint
2301-
- engine
23022299
- externalEndpoint
23032300
- name
23042301
type: object

internal/controller/platform/standalone/nimservice.go

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,6 @@ func (r *NIMServiceReconciler) updateModelStatus(ctx context.Context, nimService
296296
Name: modelName,
297297
ClusterEndpoint: clusterEndpoint,
298298
ExternalEndpoint: externalEndpoint,
299-
Engine: v1alpha1.ModelEngineNIM,
300299
}
301300

302301
return nil
@@ -333,12 +332,36 @@ func (r *NIMServiceReconciler) getNIMModelEndpoints(ctx context.Context, nimServ
333332
return "", "", err
334333
}
335334

336-
var externalIP string
337-
if svc.Spec.Type == corev1.ServiceTypeLoadBalancer {
338-
externalIP = svc.Spec.LoadBalancerIP
339-
}
335+
var externalEndpoint string
340336
port := nimService.GetServicePort()
341-
return utils.FormatEndpoint(svc.Spec.ClusterIP, port), utils.FormatEndpoint(externalIP, port), nil
337+
if nimService.IsIngressEnabled() {
338+
ingress := &networkingv1.Ingress{}
339+
if err := r.Get(ctx, types.NamespacedName{Name: nimService.GetName(), Namespace: nimService.GetNamespace()}, ingress); err != nil {
340+
logger.Error(err, "unable to fetch ingress", "nimservice", nimService.GetName())
341+
return "", "", err
342+
}
343+
344+
var found bool
345+
for _, rule := range ingress.Spec.Rules {
346+
if rule.HTTP == nil {
347+
continue
348+
}
349+
for _, path := range rule.HTTP.Paths {
350+
if path.Backend.Service != nil && path.Backend.Service.Name == nimService.GetName() {
351+
externalEndpoint = rule.Host
352+
found = true
353+
break
354+
}
355+
}
356+
if found {
357+
break
358+
}
359+
}
360+
} else if svc.Spec.Type == corev1.ServiceTypeLoadBalancer {
361+
externalEndpoint = utils.FormatEndpoint(svc.Spec.LoadBalancerIP, port)
362+
}
363+
364+
return utils.FormatEndpoint(svc.Spec.ClusterIP, port), externalEndpoint, nil
342365
}
343366

344367
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 {

internal/controller/platform/standalone/nimservice_test.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -707,6 +707,16 @@ var _ = Describe("NIMServiceReconciler for a standalone platform", func() {
707707
})
708708

709709
Describe("update model status on NIMService", func() {
710+
BeforeEach(func() {
711+
ingress := &networkingv1.Ingress{
712+
ObjectMeta: metav1.ObjectMeta{
713+
Name: "test-nimservice",
714+
Namespace: "default",
715+
},
716+
Spec: nimService.GetIngressSpec(),
717+
}
718+
_ = client.Create(context.TODO(), ingress)
719+
})
710720
AfterEach(func() {
711721
// Clean up the Service instance
712722
svc := &corev1.Service{
@@ -822,8 +832,8 @@ var _ = Describe("NIMServiceReconciler for a standalone platform", func() {
822832
modelStatus := nimService.Status.Model
823833
Expect(modelStatus).ToNot(BeNil())
824834
Expect(modelStatus.ClusterEndpoint).To(Equal("127.0.0.1:8123"))
835+
Expect(modelStatus.ExternalEndpoint).To(Equal("test-nimservice.default.example.com"))
825836
Expect(modelStatus.Name).To(Equal("dummy-model"))
826-
Expect(modelStatus.Engine).To(Equal(appsv1alpha1.ModelEngineNIM))
827837
})
828838

829839
It("should succeed when nimservice has lora adapter models attached", func() {
@@ -855,8 +865,8 @@ var _ = Describe("NIMServiceReconciler for a standalone platform", func() {
855865
modelStatus := nimService.Status.Model
856866
Expect(modelStatus).ToNot(BeNil())
857867
Expect(modelStatus.ClusterEndpoint).To(Equal("127.0.0.1:8123"))
868+
Expect(modelStatus.ExternalEndpoint).To(Equal("test-nimservice.default.example.com"))
858869
Expect(modelStatus.Name).To(Equal("dummy-model"))
859-
Expect(modelStatus.Engine).To(Equal(appsv1alpha1.ModelEngineNIM))
860870
})
861871

862872
})

0 commit comments

Comments
 (0)