@@ -31,10 +31,13 @@ import (
3131 networkingv1 "k8s.io/api/networking/v1"
3232 rbacv1 "k8s.io/api/rbac/v1"
3333 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
34- "k8s.io/apimachinery/pkg/util/intstr"
3534)
3635
3736const (
37+ // CustomizerAPIPort is the default port that customizer serves on
38+ CustomizerAPIPort = 8000
39+ // CustomizerInternalPort is the default port used for syncing training progress
40+ CustomizerInternalPort = 9009
3841 // NemoCustomizerConditionReady indicates that the NEMO CustomizerService is ready.
3942 NemoCustomizerConditionReady = "Ready"
4043 // NemoCustomizerConditionFailed indicates that the NEMO CustomizerService has failed.
@@ -57,7 +60,7 @@ const (
5760
5861// NemoCustomizerSpec defines the desired state of NemoCustomizer
5962type NemoCustomizerSpec struct {
60- Image Image `json:"image,omitempty "`
63+ Image Image `json:"image"`
6164 Command []string `json:"command,omitempty"`
6265 Args []string `json:"args,omitempty"`
6366 Env []corev1.EnvVar `json:"env,omitempty"`
@@ -67,7 +70,7 @@ type NemoCustomizerSpec struct {
6770 Tolerations []corev1.Toleration `json:"tolerations,omitempty"`
6871 PodAffinity * corev1.PodAffinity `json:"podAffinity,omitempty"`
6972 Resources * corev1.ResourceRequirements `json:"resources,omitempty"`
70- Expose Expose `json:"expose,omitempty "`
73+ Expose Expose `json:"expose"`
7174 LivenessProbe Probe `json:"livenessProbe,omitempty"`
7275 ReadinessProbe Probe `json:"readinessProbe,omitempty"`
7376 StartupProbe Probe `json:"startupProbe,omitempty"`
@@ -428,18 +431,15 @@ func (n *NemoCustomizer) GetStartupProbe() *corev1.Probe {
428431// GetDefaultStartupProbe returns the default startup probe for the NemoCustomizer container
429432func (n * NemoCustomizer ) GetDefaultStartupProbe () * corev1.Probe {
430433 probe := corev1.Probe {
431- FailureThreshold : 5 ,
432- InitialDelaySeconds : 10 ,
434+ FailureThreshold : 30 ,
435+ InitialDelaySeconds : 30 ,
433436 PeriodSeconds : 10 ,
434437 SuccessThreshold : 1 ,
435438 TimeoutSeconds : 1 ,
436439 ProbeHandler : corev1.ProbeHandler {
437440 HTTPGet : & corev1.HTTPGetAction {
438441 Path : "/v1/health/ready" ,
439- Port : intstr.IntOrString {
440- Type : intstr .Type (1 ),
441- StrVal : "api" ,
442- },
442+ Port : getProbePort (n .Spec .Expose .Service ),
443443 },
444444 },
445445 }
@@ -466,11 +466,7 @@ func (n *NemoCustomizer) GetDefaultLivenessProbe() *corev1.Probe {
466466 ProbeHandler : corev1.ProbeHandler {
467467 HTTPGet : & corev1.HTTPGetAction {
468468 Path : "/v1/health/live" ,
469- Port : intstr.IntOrString {
470- Type : intstr .Type (1 ),
471- StrVal : "api" ,
472- },
473- Scheme : "HTTP" ,
469+ Port : getProbePort (n .Spec .Expose .Service ),
474470 },
475471 },
476472 }
@@ -496,10 +492,7 @@ func (n *NemoCustomizer) GetDefaultReadinessProbe() *corev1.Probe {
496492 ProbeHandler : corev1.ProbeHandler {
497493 HTTPGet : & corev1.HTTPGetAction {
498494 Path : "/v1/health/ready" ,
499- Port : intstr.IntOrString {
500- Type : intstr .Type (1 ),
501- StrVal : "api" ,
502- },
495+ Port : getProbePort (n .Spec .Expose .Service ),
503496 },
504497 },
505498 }
@@ -569,19 +562,14 @@ func (n *NemoCustomizer) GetInternalServicePort() int32 {
569562 }
570563
571564 // Default to 9009 if no internal port is found
572- return 9009
565+ return CustomizerInternalPort
573566}
574567
575568// GetServicePorts returns the service ports for the NemoCustomizer deployment
576569func (n * NemoCustomizer ) GetServicePorts () []corev1.ServicePort {
577570 return n .Spec .Expose .Service .Ports
578571}
579572
580- // GetServicePort returns the service port for the NemoCustomizer deployment
581- func (n * NemoCustomizer ) GetServicePort () int32 {
582- return n .Spec .Expose .Service .Port
583- }
584-
585573// GetServiceType returns the service type for the NemoCustomizer deployment
586574func (n * NemoCustomizer ) GetServiceType () string {
587575 return string (n .Spec .Expose .Service .Type )
@@ -661,24 +649,22 @@ func (n *NemoCustomizer) GetDeploymentParams() *rendertypes.DeploymentParams {
661649 // Set runtime class
662650 params .RuntimeClassName = n .GetRuntimeClass ()
663651
664- // Extract ports from spec and update rendering params
665- if len (n .GetServicePorts ()) > 0 {
666- var containerPorts []corev1.ContainerPort
667- for _ , svcPort := range n .GetServicePorts () {
668- containerPorts = append (containerPorts , corev1.ContainerPort {
669- Name : svcPort .Name ,
670- Protocol : svcPort .Protocol ,
671- ContainerPort : svcPort .Port ,
672- })
673- }
674- params .Ports = containerPorts
675- } else {
676- params .Ports = []corev1.ContainerPort {{
677- Name : "api" ,
652+ // Setup container ports for customizer
653+ // TODO: set these to use defined values in the service spec
654+ // once that is allowed by the customizer through env variables
655+ containerPorts := []corev1.ContainerPort {
656+ {
657+ Name : DefaultNamedPortAPI ,
678658 Protocol : corev1 .ProtocolTCP ,
679- ContainerPort : n .GetServicePort (),
680- }}
659+ ContainerPort : CustomizerAPIPort ,
660+ },
661+ {
662+ Name : "internal" ,
663+ Protocol : corev1 .ProtocolTCP ,
664+ ContainerPort : CustomizerInternalPort ,
665+ },
681666 }
667+ params .Ports = containerPorts
682668
683669 return params
684670}
@@ -749,13 +735,19 @@ func (n *NemoCustomizer) GetServiceParams() *rendertypes.ServiceParams {
749735 if len (servicePorts ) != 0 {
750736 params .Ports = servicePorts
751737 } else {
752- // Use corev1.ServicePort instead of deprecated params.Port
753- params .Ports = []corev1.ServicePort {{
754- Name : "api" ,
755- Port : 8000 ,
756- TargetPort : intstr .FromInt (8000 ),
757- Protocol : corev1 .ProtocolTCP ,
758- }}
738+ // Set default ports
739+ params .Ports = []corev1.ServicePort {
740+ {
741+ Name : DefaultNamedPortAPI ,
742+ Port : CustomizerAPIPort ,
743+ Protocol : corev1 .ProtocolTCP ,
744+ },
745+ {
746+ Name : "internal" ,
747+ Port : CustomizerInternalPort ,
748+ Protocol : corev1 .ProtocolTCP ,
749+ },
750+ }
759751 }
760752
761753 return params
@@ -892,11 +884,20 @@ func (n *NemoCustomizer) GetServiceMonitorParams() *rendertypes.ServiceMonitorPa
892884 params .Labels = svcLabels
893885 params .Annotations = n .GetServiceMonitorAnnotations ()
894886
887+ // Determine the appropriate port for monitoring
888+ metricsPort := getMetricsPort (n .Spec .Expose .Service )
889+
895890 // Set Service Monitor spec
896891 smSpec := monitoringv1.ServiceMonitorSpec {
897892 NamespaceSelector : monitoringv1.NamespaceSelector {MatchNames : []string {n .Namespace }},
898893 Selector : metav1.LabelSelector {MatchLabels : n .GetServiceLabels ()},
899- Endpoints : []monitoringv1.Endpoint {{Port : "service-port" , ScrapeTimeout : serviceMonitor .ScrapeTimeout , Interval : serviceMonitor .Interval }},
894+ Endpoints : []monitoringv1.Endpoint {
895+ {
896+ Port : metricsPort .StrVal ,
897+ ScrapeTimeout : serviceMonitor .ScrapeTimeout ,
898+ Interval : serviceMonitor .Interval ,
899+ },
900+ },
900901 }
901902 params .SMSpec = smSpec
902903 return params
0 commit comments