Skip to content
20 changes: 13 additions & 7 deletions api/apps/v1alpha1/common_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ import (
networkingv1 "k8s.io/api/networking/v1"
)

const (
// DefaultAPIPort is the default api port
DefaultAPIPort = 8000
// DefaultNamedPortAPI is the default name for api port
DefaultNamedPortAPI = "api"
)

// Expose defines attributes to expose the service
type Expose struct {
Service Service `json:"service,omitempty"`
Expand All @@ -34,13 +41,12 @@ type Service struct {
Type corev1.ServiceType `json:"type,omitempty"`
// override the default service name
Name string `json:"name,omitempty"`
// Deprecated: Use Ports instead.
// +kubebuilder:deprecatedversion
// +kubebuilder:default=8000
Port int32 `json:"port,omitempty"`
// Defines multiple ports for the service
Ports []corev1.ServicePort `json:"ports,omitempty"`
Annotations map[string]string `json:"annotations,omitempty"`
// Port is the main api serving port (default: 8000)
// +kubebuilder:validation:Minimum=1
// +kubebuilder:validation:Maximum=65535
// +kubebuilder:default:=8000
Port *int32 `json:"port,omitempty"`
Annotations map[string]string `json:"annotations,omitempty"`
}

// Metrics defines attributes to setup metrics collection
Expand Down
121 changes: 53 additions & 68 deletions api/apps/v1alpha1/nemo_customizer_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ import (
)

const (
// CustomizerAPIPort is the default port that customizer serves on
CustomizerAPIPort = 8000
// DefaultNamedPortInternal is the default name for customizer internal port
DefaultNamedPortInternal = "internal"
// CustomizerInternalPort is the default port used for syncing training progress
CustomizerInternalPort = 9009
// NemoCustomizerConditionReady indicates that the NEMO CustomizerService is ready.
NemoCustomizerConditionReady = "Ready"
// NemoCustomizerConditionFailed indicates that the NEMO CustomizerService has failed.
Expand Down Expand Up @@ -67,7 +73,7 @@ type NemoCustomizerSpec struct {
Tolerations []corev1.Toleration `json:"tolerations,omitempty"`
PodAffinity *corev1.PodAffinity `json:"podAffinity,omitempty"`
Resources *corev1.ResourceRequirements `json:"resources,omitempty"`
Expose Expose `json:"expose"`
Expose Expose `json:"expose,omitempty"`
LivenessProbe Probe `json:"livenessProbe,omitempty"`
ReadinessProbe Probe `json:"readinessProbe,omitempty"`
StartupProbe Probe `json:"startupProbe,omitempty"`
Expand Down Expand Up @@ -177,7 +183,7 @@ func (n *NemoCustomizer) GetStandardEnv() []corev1.EnvVar {
},
{
Name: "CUSTOMIZATIONS_CALLBACK_URL",
Value: fmt.Sprintf("http://%s.%s.svc.cluster.local:%d", n.GetName(), n.GetNamespace(), n.GetInternalServicePort()),
Value: fmt.Sprintf("http://%s.%s.svc.cluster.local:%d", n.GetName(), n.GetNamespace(), CustomizerInternalPort),
},
{
Name: "LOG_LEVEL",
Expand Down Expand Up @@ -435,18 +441,15 @@ func (n *NemoCustomizer) GetStartupProbe() *corev1.Probe {
// GetDefaultStartupProbe returns the default startup probe for the NemoCustomizer container
func (n *NemoCustomizer) GetDefaultStartupProbe() *corev1.Probe {
Comment thread
shivamerla marked this conversation as resolved.
probe := corev1.Probe{
FailureThreshold: 5,
InitialDelaySeconds: 10,
FailureThreshold: 30,
InitialDelaySeconds: 30,
PeriodSeconds: 10,
SuccessThreshold: 1,
TimeoutSeconds: 1,
ProbeHandler: corev1.ProbeHandler{
HTTPGet: &corev1.HTTPGetAction{
Path: "/v1/health/ready",
Port: intstr.IntOrString{
Type: intstr.Type(1),
StrVal: "api",
},
Port: intstr.FromString(DefaultNamedPortAPI),
},
},
}
Expand All @@ -473,11 +476,7 @@ func (n *NemoCustomizer) GetDefaultLivenessProbe() *corev1.Probe {
ProbeHandler: corev1.ProbeHandler{
HTTPGet: &corev1.HTTPGetAction{
Path: "/v1/health/live",
Port: intstr.IntOrString{
Type: intstr.Type(1),
StrVal: "api",
},
Scheme: "HTTP",
Port: intstr.FromString(DefaultNamedPortAPI),
},
},
}
Expand All @@ -503,10 +502,7 @@ func (n *NemoCustomizer) GetDefaultReadinessProbe() *corev1.Probe {
ProbeHandler: corev1.ProbeHandler{
HTTPGet: &corev1.HTTPGetAction{
Path: "/v1/health/ready",
Port: intstr.IntOrString{
Type: intstr.Type(1),
StrVal: "api",
},
Port: intstr.FromString(DefaultNamedPortAPI),
},
},
}
Expand Down Expand Up @@ -567,28 +563,6 @@ func (n *NemoCustomizer) IsServiceMonitorEnabled() bool {
return n.Spec.Metrics.Enabled != nil && *n.Spec.Metrics.Enabled
}

// GetInternalServicePort returns the internal service port number for the NemoCustomizer deployment
func (n *NemoCustomizer) GetInternalServicePort() int32 {
for _, port := range n.Spec.Expose.Service.Ports {
if port.Name == "internal" {
return port.Port
}
}

// Default to 9009 if no internal port is found
return 9009
}

// GetServicePorts returns the service ports for the NemoCustomizer deployment
func (n *NemoCustomizer) GetServicePorts() []corev1.ServicePort {
return n.Spec.Expose.Service.Ports
}

// GetServicePort returns the service port for the NemoCustomizer deployment
func (n *NemoCustomizer) GetServicePort() int32 {
return n.Spec.Expose.Service.Port
}

// GetServiceType returns the service type for the NemoCustomizer deployment
func (n *NemoCustomizer) GetServiceType() string {
return string(n.Spec.Expose.Service.Type)
Expand Down Expand Up @@ -668,25 +642,19 @@ func (n *NemoCustomizer) GetDeploymentParams() *rendertypes.DeploymentParams {
// Set runtime class
params.RuntimeClassName = n.GetRuntimeClass()

// Extract ports from spec and update rendering params
if len(n.GetServicePorts()) > 0 {
var containerPorts []corev1.ContainerPort
for _, svcPort := range n.GetServicePorts() {
containerPorts = append(containerPorts, corev1.ContainerPort{
Name: svcPort.Name,
Protocol: svcPort.Protocol,
ContainerPort: svcPort.Port,
})
}
params.Ports = containerPorts
} else {
params.Ports = []corev1.ContainerPort{{
Name: "api",
// Setup container ports for customizer
params.Ports = []corev1.ContainerPort{
{
Name: DefaultNamedPortAPI,
Protocol: corev1.ProtocolTCP,
ContainerPort: n.GetServicePort(),
}}
ContainerPort: CustomizerAPIPort,
},
{
Name: DefaultNamedPortInternal,
Protocol: corev1.ProtocolTCP,
ContainerPort: CustomizerInternalPort,
},
}

return params
}

Expand Down Expand Up @@ -752,19 +720,21 @@ func (n *NemoCustomizer) GetServiceParams() *rendertypes.ServiceParams {
// Set service type
params.Type = n.GetServiceType()

servicePorts := n.GetServicePorts()
if len(servicePorts) != 0 {
params.Ports = servicePorts
} else {
// Use corev1.ServicePort instead of deprecated params.Port
params.Ports = []corev1.ServicePort{{
Name: "api",
Port: 8000,
TargetPort: intstr.FromInt(8000),
// Set service ports
params.Ports = []corev1.ServicePort{
{
Name: DefaultNamedPortAPI,
Port: n.GetServicePort(),
TargetPort: intstr.FromString((DefaultNamedPortAPI)),
Protocol: corev1.ProtocolTCP,
}}
},
{
Name: DefaultNamedPortInternal,
Port: CustomizerInternalPort,
TargetPort: intstr.FromString((DefaultNamedPortInternal)),
Protocol: corev1.ProtocolTCP,
},
}

return params
}

Expand Down Expand Up @@ -903,12 +873,27 @@ func (n *NemoCustomizer) GetServiceMonitorParams() *rendertypes.ServiceMonitorPa
smSpec := monitoringv1.ServiceMonitorSpec{
NamespaceSelector: monitoringv1.NamespaceSelector{MatchNames: []string{n.Namespace}},
Selector: metav1.LabelSelector{MatchLabels: n.GetServiceLabels()},
Endpoints: []monitoringv1.Endpoint{{Port: "service-port", ScrapeTimeout: serviceMonitor.ScrapeTimeout, Interval: serviceMonitor.Interval}},
Endpoints: []monitoringv1.Endpoint{
{
Port: DefaultNamedPortAPI,
ScrapeTimeout: serviceMonitor.ScrapeTimeout,
Interval: serviceMonitor.Interval,
},
},
}
params.SMSpec = smSpec
return params
}

// GetServicePort returns the service port for the NemoCustomizer deployment or default port
func (n *NemoCustomizer) GetServicePort() int32 {
if n.Spec.Expose.Service.Port == nil {
return DefaultAPIPort
}

return *n.Spec.Expose.Service.Port
}

// GetIngressAnnotations return standard and customized ingress annotations
func (n *NemoCustomizer) GetIngressAnnotations() map[string]string {
NemoCustomizerAnnotations := n.GetNemoCustomizerAnnotations()
Expand Down
62 changes: 42 additions & 20 deletions api/apps/v1alpha1/nemo_datastore_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ import (
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.

const (
// DatastoreAPIPort is the default port that the datastore serves on
DatastoreAPIPort = 3000
// NemoDatastoreConditionReady indicates that the NEMO datastore service is ready.
NemoDatastoreConditionReady = "Ready"
// NemoDatastoreConditionFailed indicates that the NEMO datastore service has failed.
Expand Down Expand Up @@ -65,7 +67,7 @@ type NemoDatastoreSpec struct {
Tolerations []corev1.Toleration `json:"tolerations,omitempty"`
PodAffinity *corev1.PodAffinity `json:"podAffinity,omitempty"`
Resources *corev1.ResourceRequirements `json:"resources,omitempty"`
Expose Expose `json:"expose"`
Expose Expose `json:"expose,omitempty"`
LivenessProbe Probe `json:"livenessProbe,omitempty"`
ReadinessProbe Probe `json:"readinessProbe,omitempty"`
StartupProbe Probe `json:"startupProbe,omitempty"`
Expand Down Expand Up @@ -590,10 +592,7 @@ func (n *NemoDatastore) GetDefaultLivenessProbe() *corev1.Probe {
ProbeHandler: corev1.ProbeHandler{
HTTPGet: &corev1.HTTPGetAction{
Path: "/v1/health",
Port: intstr.IntOrString{
Type: intstr.Type(0),
IntVal: n.Spec.Expose.Service.Port,
},
Port: intstr.FromString(DefaultNamedPortAPI),
},
},
}
Expand All @@ -620,10 +619,7 @@ func (n *NemoDatastore) GetDefaultReadinessProbe() *corev1.Probe {
ProbeHandler: corev1.ProbeHandler{
HTTPGet: &corev1.HTTPGetAction{
Path: "/v1/health",
Port: intstr.IntOrString{
Type: intstr.Type(0),
IntVal: n.Spec.Expose.Service.Port,
},
Port: intstr.FromString(DefaultNamedPortAPI),
},
},
}
Expand All @@ -633,24 +629,24 @@ func (n *NemoDatastore) GetDefaultReadinessProbe() *corev1.Probe {

// GetStartupProbe returns startup probe for the NemoDatastore container
func (n *NemoDatastore) GetStartupProbe() *corev1.Probe {
if n.Spec.StartupProbe.Probe == nil {
return n.GetDefaultStartupProbe()
}
return n.Spec.StartupProbe.Probe
}

// GetDefaultStartupProbe returns the default startup probe for the NemoDatastore container
func (n *NemoDatastore) GetDefaultStartupProbe() *corev1.Probe {
probe := corev1.Probe{
InitialDelaySeconds: 40,
InitialDelaySeconds: 30,
TimeoutSeconds: 1,
PeriodSeconds: 10,
SuccessThreshold: 1,
FailureThreshold: 180,
FailureThreshold: 30,
ProbeHandler: corev1.ProbeHandler{
HTTPGet: &corev1.HTTPGetAction{
Path: "/v1/health",
Port: intstr.IntOrString{
Type: intstr.Type(0),
IntVal: n.Spec.Expose.Service.Port,
},
Port: intstr.FromString(DefaultNamedPortAPI),
},
},
}
Expand Down Expand Up @@ -804,9 +800,12 @@ func (n *NemoDatastore) IsServiceMonitorEnabled() bool {
return n.Spec.Metrics.Enabled != nil && *n.Spec.Metrics.Enabled
}

// GetServicePort returns the service port for the NemoDatastore deployment
// GetServicePort returns the service port for the NemoDatastore deployment or default port
func (n *NemoDatastore) GetServicePort() int32 {
return n.Spec.Expose.Service.Port
if n.Spec.Expose.Service.Port == nil {
return DefaultAPIPort
}
return *n.Spec.Expose.Service.Port
}

// GetServiceType returns the service type for the NemoDatastore deployment
Expand Down Expand Up @@ -891,6 +890,16 @@ func (n *NemoDatastore) GetDeploymentParams() *rendertypes.DeploymentParams {

// Set runtime class
params.RuntimeClassName = n.GetRuntimeClass()

// Setup container ports for datastore
params.Ports = []corev1.ContainerPort{
{
Name: DefaultNamedPortAPI,
Protocol: corev1.ProtocolTCP,
ContainerPort: DatastoreAPIPort,
},
}

return params
}

Expand Down Expand Up @@ -957,8 +966,15 @@ func (n *NemoDatastore) GetServiceParams() *rendertypes.ServiceParams {
params.Type = n.GetServiceType()

// Set service ports
params.Port = n.GetServicePort()
params.PortName = "service-port"
params.Ports = []corev1.ServicePort{
{
Name: DefaultNamedPortAPI,
Port: n.GetServicePort(),
TargetPort: intstr.FromString((DefaultNamedPortAPI)),
Protocol: corev1.ProtocolTCP,
},
}

return params
}

Expand Down Expand Up @@ -1065,7 +1081,13 @@ func (n *NemoDatastore) GetServiceMonitorParams() *rendertypes.ServiceMonitorPar
smSpec := monitoringv1.ServiceMonitorSpec{
NamespaceSelector: monitoringv1.NamespaceSelector{MatchNames: []string{n.Namespace}},
Selector: metav1.LabelSelector{MatchLabels: n.GetServiceLabels()},
Endpoints: []monitoringv1.Endpoint{{Port: "service-port", ScrapeTimeout: serviceMonitor.ScrapeTimeout, Interval: serviceMonitor.Interval}},
Endpoints: []monitoringv1.Endpoint{
{
Port: DefaultNamedPortAPI,
ScrapeTimeout: serviceMonitor.ScrapeTimeout,
Interval: serviceMonitor.Interval,
},
},
}
params.SMSpec = smSpec
return params
Expand Down
Loading