@@ -40,8 +40,6 @@ import (
4040// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.
4141
4242const (
43- // NIMAPIPort is the default port that the NIM serves on.
44- NIMAPIPort = 8000
4543 // NIMServiceConditionReady indicates that the NIM deployment is ready.
4644 NIMServiceConditionReady = "NIM_SERVICE_READY"
4745 // NIMServiceConditionFailed indicates that the NIM deployment has failed.
@@ -199,7 +197,11 @@ func (n *NIMService) GetStandardEnv() []corev1.EnvVar {
199197 },
200198 {
201199 Name : "NIM_SERVER_PORT" ,
202- Value : fmt .Sprintf ("%d" , NIMAPIPort ),
200+ Value : fmt .Sprintf ("%d" , * n .Spec .Expose .Service .Port ),
201+ },
202+ {
203+ Name : "NIM_HTTP_API_PORT" ,
204+ Value : fmt .Sprintf ("%d" , * n .Spec .Expose .Service .Port ),
203205 },
204206 {
205207 Name : "NIM_JSONL_LOGGING" ,
@@ -210,6 +212,21 @@ func (n *NIMService) GetStandardEnv() []corev1.EnvVar {
210212 Value : "INFO" ,
211213 },
212214 }
215+ if n .Spec .Expose .Service .GRPCPort != nil {
216+ envVars = append (envVars , corev1.EnvVar {
217+ Name : "NIM_GRPC_API_PORT" ,
218+ Value : fmt .Sprintf ("%d" , * n .Spec .Expose .Service .GRPCPort ),
219+ }, corev1.EnvVar {
220+ Name : "NIM_TRITON_GRPC_PORT" ,
221+ Value : fmt .Sprintf ("%d" , * n .Spec .Expose .Service .GRPCPort ),
222+ })
223+ }
224+ if n .Spec .Expose .Service .MetricsPort != nil {
225+ envVars = append (envVars , corev1.EnvVar {
226+ Name : "NIM_TRITON_METRICS_PORT" ,
227+ Value : fmt .Sprintf ("%d" , * n .Spec .Expose .Service .MetricsPort ),
228+ })
229+ }
213230
214231 return envVars
215232}
@@ -681,10 +698,23 @@ func (n *NIMService) GetDeploymentParams() *rendertypes.DeploymentParams {
681698 {
682699 Name : DefaultNamedPortAPI ,
683700 Protocol : corev1 .ProtocolTCP ,
684- ContainerPort : NIMAPIPort ,
701+ ContainerPort : * n . Spec . Expose . Service . Port ,
685702 },
686703 }
687-
704+ if n .Spec .Expose .Service .GRPCPort != nil {
705+ params .Ports = append (params .Ports , corev1.ContainerPort {
706+ Name : DefaultNamedPortGRPC ,
707+ Protocol : corev1 .ProtocolTCP ,
708+ ContainerPort : * n .Spec .Expose .Service .GRPCPort ,
709+ })
710+ }
711+ if n .Spec .Expose .Service .MetricsPort != nil {
712+ params .Ports = append (params .Ports , corev1.ContainerPort {
713+ Name : DefaultNamedPortMetrics ,
714+ Protocol : corev1 .ProtocolTCP ,
715+ ContainerPort : * n .Spec .Expose .Service .MetricsPort ,
716+ })
717+ }
688718 return params
689719}
690720
@@ -759,6 +789,23 @@ func (n *NIMService) GetServiceParams() *rendertypes.ServiceParams {
759789 Protocol : corev1 .ProtocolTCP ,
760790 },
761791 }
792+ if n .Spec .Expose .Service .GRPCPort != nil {
793+ params .Ports = append (params .Ports , corev1.ServicePort {
794+ Name : DefaultNamedPortGRPC ,
795+ Port : * n .Spec .Expose .Service .GRPCPort ,
796+ TargetPort : intstr .FromString (DefaultNamedPortGRPC ),
797+ Protocol : corev1 .ProtocolTCP ,
798+ })
799+ }
800+ if n .Spec .Expose .Service .MetricsPort != nil {
801+ params .Ports = append (params .Ports , corev1.ServicePort {
802+ Name : DefaultNamedPortMetrics ,
803+ Port : * n .Spec .Expose .Service .MetricsPort ,
804+ TargetPort : intstr .FromString (DefaultNamedPortMetrics ),
805+ Protocol : corev1 .ProtocolTCP ,
806+ })
807+ }
808+
762809 return params
763810}
764811
@@ -885,6 +932,14 @@ func (n *NIMService) GetServiceMonitorParams() *rendertypes.ServiceMonitorParams
885932 },
886933 },
887934 }
935+ if n .Spec .Expose .Service .MetricsPort != nil {
936+ smSpec .Endpoints = append (smSpec .Endpoints , monitoringv1.Endpoint {
937+ Path : "/metrics" ,
938+ Port : DefaultNamedPortMetrics ,
939+ ScrapeTimeout : serviceMonitor .ScrapeTimeout ,
940+ Interval : serviceMonitor .Interval ,
941+ })
942+ }
888943 params .SMSpec = smSpec
889944 return params
890945}
0 commit comments