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
74 changes: 70 additions & 4 deletions api/apps/v1alpha1/common_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
corev1 "k8s.io/api/core/v1"
networkingv1 "k8s.io/api/networking/v1"
"k8s.io/utils/ptr"
gatewayv1 "sigs.k8s.io/gateway-api/apis/v1"
)

const (
Expand All @@ -37,8 +38,9 @@ const (

// Expose defines attributes to expose the service.
type Expose struct {
Service Service `json:"service,omitempty"`
Ingress Ingress `json:"ingress,omitempty"`
Service Service `json:"service,omitempty"`
Ingress Ingress `json:"ingress,omitempty"`
HTTPRoute HTTPRoute `json:"httpRoute,omitempty"`
}

// Service defines attributes to create a service.
Expand Down Expand Up @@ -69,8 +71,9 @@ type Service struct {

// ExposeV1 defines attributes to expose the service.
type ExposeV1 struct {
Service Service `json:"service,omitempty"`
Ingress IngressV1 `json:"ingress,omitempty"`
Service Service `json:"service,omitempty"`
Ingress IngressV1 `json:"ingress,omitempty"`
HTTPRoute HTTPRoute `json:"httpRoute,omitempty"`
}

// Metrics defines attributes to setup metrics collection.
Expand Down Expand Up @@ -119,6 +122,32 @@ type Ingress struct {
Spec networkingv1.IngressSpec `json:"spec,omitempty"`
}

// HTTPRoute defines attributes to HTTPRoute in Gateway API.
type HTTPRoute struct {
Enabled *bool `json:"enabled,omitempty"`
Annotations map[string]string `json:"annotations,omitempty"`
Spec *HTTPRouteSpec `json:"spec,omitempty"`
}

type HTTPRouteSpec struct {
gatewayv1.CommonRouteSpec `json:",inline"`
Host gatewayv1.Hostname `json:"host,omitempty"`
Paths []HTTPPathMatch `json:"paths,omitempty"`
}

type HTTPPathMatch struct {
// Type specifies how to match against the path Value.
// +optional
// +kubebuilder:default=PathPrefix
Type *gatewayv1.PathMatchType `json:"type,omitempty"`

// Value of the HTTP path to match against.
// +optional
// +kubebuilder:default="/"
// +kubebuilder:validation:MaxLength=1024
Value *string `json:"value,omitempty"`
}

// IngressV1 defines attributes for ingress
//
// +kubebuilder:validation:XValidation:rule="(has(self.spec) && has(self.enabled) && self.enabled) || !has(self.enabled) || !self.enabled", message="spec cannot be nil when ingress is enabled"
Expand All @@ -142,6 +171,43 @@ type ResourceRequirements struct {
Requests corev1.ResourceList `json:"requests,omitempty" protobuf:"bytes,2,rep,name=requests,casttype=ResourceList,castkey=ResourceName"`
}

func (i *HTTPRoute) GenerateGatewayHTTPRouteSpec(name string) gatewayv1.HTTPRouteSpec {
if i.Spec == nil {
return gatewayv1.HTTPRouteSpec{}
}

port := gatewayv1.PortNumber(DefaultAPIPort)
httpRouteMatches := []gatewayv1.HTTPRouteMatch{}
for _, path := range i.Spec.Paths {
httpRouteMatches = append(httpRouteMatches, gatewayv1.HTTPRouteMatch{
Path: &gatewayv1.HTTPPathMatch{
Type: path.Type,
Value: path.Value,
},
})
}

return gatewayv1.HTTPRouteSpec{
CommonRouteSpec: i.Spec.CommonRouteSpec,
Hostnames: []gatewayv1.Hostname{i.Spec.Host},
Rules: []gatewayv1.HTTPRouteRule{
{
BackendRefs: []gatewayv1.HTTPBackendRef{
{
BackendRef: gatewayv1.BackendRef{
BackendObjectReference: gatewayv1.BackendObjectReference{
Name: gatewayv1.ObjectName(name),
Port: &port,
},
},
},
},
Matches: httpRouteMatches,
},
},
}
}

func (i *IngressV1) GenerateNetworkingV1IngressSpec(name string) networkingv1.IngressSpec {
if i.Spec == nil {
return networkingv1.IngressSpec{}
Expand Down
32 changes: 32 additions & 0 deletions api/apps/v1alpha1/nemo_customizer_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"
"k8s.io/utils/ptr"
gatewayv1 "sigs.k8s.io/gateway-api/apis/v1"

rendertypes "github.com/NVIDIA/k8s-nim-operator/internal/render/types"
utils "github.com/NVIDIA/k8s-nim-operator/internal/utils"
Expand Down Expand Up @@ -643,6 +644,14 @@ func (n *NemoCustomizer) GetIngressSpec() networkingv1.IngressSpec {
return n.Spec.Expose.Ingress.GenerateNetworkingV1IngressSpec(n.GetName())
}

func (n *NemoCustomizer) IsHTTPRouteEnabled() bool {
return n.Spec.Expose.HTTPRoute.Enabled != nil && *n.Spec.Expose.HTTPRoute.Enabled
}

func (n *NemoCustomizer) GetHTTPRouteSpec() gatewayv1.HTTPRouteSpec {
return n.Spec.Expose.HTTPRoute.GenerateGatewayHTTPRouteSpec(n.GetName())
}

// IsServiceMonitorEnabled returns true if servicemonitor is enabled for NemoCustomizer deployment.
func (n *NemoCustomizer) IsServiceMonitorEnabled() bool {
return n.Spec.Metrics.Enabled != nil && *n.Spec.Metrics.Enabled
Expand Down Expand Up @@ -839,6 +848,20 @@ func (n *NemoCustomizer) GetIngressParams() *rendertypes.IngressParams {
return params
}

// GetHTTPRouteParams returns params to render HTTPRoute from templates.
func (n *NemoCustomizer) GetHTTPRouteParams() *rendertypes.HTTPRouteParams {
params := &rendertypes.HTTPRouteParams{}
params.Enabled = n.IsHTTPRouteEnabled()

// Set metadata
params.Name = n.GetName()
params.Namespace = n.GetNamespace()
params.Labels = n.GetServiceLabels()
params.Annotations = n.GetHTTPRouteAnnotations()
params.Spec = n.GetHTTPRouteSpec()
return params
}

// GetRoleParams returns params to render Role from templates.
func (n *NemoCustomizer) GetRoleParams() *rendertypes.RoleParams {
params := &rendertypes.RoleParams{}
Expand Down Expand Up @@ -1023,6 +1046,15 @@ func (n *NemoCustomizer) GetIngressAnnotations() map[string]string {
return NemoCustomizerAnnotations
}

func (n *NemoCustomizer) GetHTTPRouteAnnotations() map[string]string {
annotations := n.GetNemoCustomizerAnnotations()

if n.Spec.Expose.HTTPRoute.Annotations != nil {
return utils.MergeMaps(annotations, n.Spec.Expose.HTTPRoute.Annotations)
}
return annotations
}

// GetServiceAnnotations return standard and customized service annotations.
func (n *NemoCustomizer) GetServiceAnnotations() map[string]string {
NemoCustomizerAnnotations := n.GetNemoCustomizerAnnotations()
Expand Down
32 changes: 32 additions & 0 deletions api/apps/v1alpha1/nemo_datastore_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"
"k8s.io/utils/ptr"
gatewayv1 "sigs.k8s.io/gateway-api/apis/v1"

rendertypes "github.com/NVIDIA/k8s-nim-operator/internal/render/types"
utils "github.com/NVIDIA/k8s-nim-operator/internal/utils"
Expand Down Expand Up @@ -767,11 +768,19 @@ func (n *NemoDatastore) IsIngressEnabled() bool {
return n.Spec.Expose.Ingress.Enabled != nil && *n.Spec.Expose.Ingress.Enabled
}

func (n *NemoDatastore) IsHTTPRouteEnabled() bool {
return n.Spec.Expose.HTTPRoute.Enabled != nil && *n.Spec.Expose.HTTPRoute.Enabled
}

// GetIngressSpec returns the Ingress spec NemoDatastore deployment.
func (n *NemoDatastore) GetIngressSpec() networkingv1.IngressSpec {
return n.Spec.Expose.Ingress.GenerateNetworkingV1IngressSpec(n.GetName())
}

func (n *NemoDatastore) GetHTTPRouteSpec() gatewayv1.HTTPRouteSpec {
return n.Spec.Expose.HTTPRoute.GenerateGatewayHTTPRouteSpec(n.GetName())
}

// IsServiceMonitorEnabled returns true if servicemonitor is enabled for NemoDatastore deployment.
func (n *NemoDatastore) IsServiceMonitorEnabled() bool {
return n.Spec.Metrics.Enabled != nil && *n.Spec.Metrics.Enabled
Expand Down Expand Up @@ -967,6 +976,20 @@ func (n *NemoDatastore) GetIngressParams() *rendertypes.IngressParams {
return params
}

// GetHTTPRouteParams returns params to render HTTPRoute from templates.
func (n *NemoDatastore) GetHTTPRouteParams() *rendertypes.HTTPRouteParams {
params := &rendertypes.HTTPRouteParams{}
params.Enabled = n.IsHTTPRouteEnabled()

// Set metadata
params.Name = n.GetName()
params.Namespace = n.GetNamespace()
params.Labels = n.GetServiceLabels()
params.Annotations = n.GetHTTPRouteAnnotations()
params.Spec = n.GetHTTPRouteSpec()
return params
}

// GetRoleParams returns params to render Role from templates.
func (n *NemoDatastore) GetRoleParams() *rendertypes.RoleParams {
params := &rendertypes.RoleParams{}
Expand Down Expand Up @@ -1077,6 +1100,15 @@ func (n *NemoDatastore) GetIngressAnnotations() map[string]string {
return NemoDatastoreAnnotations
}

func (n *NemoDatastore) GetHTTPRouteAnnotations() map[string]string {
annotations := n.GetNemoDatastoreAnnotations()

if n.Spec.Expose.HTTPRoute.Annotations != nil {
return utils.MergeMaps(annotations, n.Spec.Expose.HTTPRoute.Annotations)
}
return annotations
}

func (n *NemoDatastore) GetServiceAnnotations() map[string]string {
NemoDatastoreAnnotations := n.GetNemoDatastoreAnnotations()

Expand Down
32 changes: 32 additions & 0 deletions api/apps/v1alpha1/nemo_entitystore_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"
"k8s.io/utils/ptr"
gatewayv1 "sigs.k8s.io/gateway-api/apis/v1"

rendertypes "github.com/NVIDIA/k8s-nim-operator/internal/render/types"
utils "github.com/NVIDIA/k8s-nim-operator/internal/utils"
Expand Down Expand Up @@ -399,6 +400,14 @@ func (n *NemoEntitystore) GetIngressSpec() networkingv1.IngressSpec {
return n.Spec.Expose.Ingress.GenerateNetworkingV1IngressSpec(n.GetName())
}

func (n *NemoEntitystore) IsHTTPRouteEnabled() bool {
return n.Spec.Expose.HTTPRoute.Enabled != nil && *n.Spec.Expose.HTTPRoute.Enabled
}

func (n *NemoEntitystore) GetHTTPRouteSpec() gatewayv1.HTTPRouteSpec {
return n.Spec.Expose.HTTPRoute.GenerateGatewayHTTPRouteSpec(n.GetName())
}

// IsServiceMonitorEnabled returns true if servicemonitor is enabled for NemoEntitystore deployment.
func (n *NemoEntitystore) IsServiceMonitorEnabled() bool {
return n.Spec.Metrics.Enabled != nil && *n.Spec.Metrics.Enabled
Expand Down Expand Up @@ -601,6 +610,20 @@ func (n *NemoEntitystore) GetIngressParams() *rendertypes.IngressParams {
return params
}

// GetHTTPRouteParams returns params to render HTTPRoute from templates.
func (n *NemoEntitystore) GetHTTPRouteParams() *rendertypes.HTTPRouteParams {
params := &rendertypes.HTTPRouteParams{}
params.Enabled = n.IsHTTPRouteEnabled()

// Set metadata
params.Name = n.GetName()
params.Namespace = n.GetNamespace()
params.Labels = n.GetServiceLabels()
params.Annotations = n.GetHTTPRouteAnnotations()
params.Spec = n.GetHTTPRouteSpec()
return params
}

// GetRoleParams returns params to render Role from templates.
func (n *NemoEntitystore) GetRoleParams() *rendertypes.RoleParams {
params := &rendertypes.RoleParams{}
Expand Down Expand Up @@ -711,6 +734,15 @@ func (n *NemoEntitystore) GetIngressAnnotations() map[string]string {
return NemoEntitystoreAnnotations
}

func (n *NemoEntitystore) GetHTTPRouteAnnotations() map[string]string {
annotations := n.GetNemoEntitystoreAnnotations()

if n.Spec.Expose.HTTPRoute.Annotations != nil {
return utils.MergeMaps(annotations, n.Spec.Expose.HTTPRoute.Annotations)
}
return annotations
}

func (n *NemoEntitystore) GetServiceAnnotations() map[string]string {
NemoEntitystoreAnnotations := n.GetNemoEntitystoreAnnotations()

Expand Down
32 changes: 32 additions & 0 deletions api/apps/v1alpha1/nemo_evaluator_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"
"k8s.io/utils/ptr"
gatewayv1 "sigs.k8s.io/gateway-api/apis/v1"

rendertypes "github.com/NVIDIA/k8s-nim-operator/internal/render/types"
utils "github.com/NVIDIA/k8s-nim-operator/internal/utils"
Expand Down Expand Up @@ -584,11 +585,19 @@ func (n *NemoEvaluator) IsIngressEnabled() bool {
return n.Spec.Expose.Ingress.Enabled != nil && *n.Spec.Expose.Ingress.Enabled
}

func (n *NemoEvaluator) IsHTTPRouteEnabled() bool {
return n.Spec.Expose.HTTPRoute.Enabled != nil && *n.Spec.Expose.HTTPRoute.Enabled
}

// GetIngressSpec returns the Ingress spec NemoEvaluator deployment.
func (n *NemoEvaluator) GetIngressSpec() networkingv1.IngressSpec {
return n.Spec.Expose.Ingress.GenerateNetworkingV1IngressSpec(n.GetName())
}

func (n *NemoEvaluator) GetHTTPRouteSpec() gatewayv1.HTTPRouteSpec {
return n.Spec.Expose.HTTPRoute.GenerateGatewayHTTPRouteSpec(n.GetName())
}

// IsServiceMonitorEnabled returns true if servicemonitor is enabled for NemoEvaluator deployment.
func (n *NemoEvaluator) IsServiceMonitorEnabled() bool {
return n.Spec.Metrics.Enabled != nil && *n.Spec.Metrics.Enabled
Expand Down Expand Up @@ -784,6 +793,20 @@ func (n *NemoEvaluator) GetIngressParams() *rendertypes.IngressParams {
return params
}

// GetHTTPRouteParams returns params to render HTTPRoute from templates.
func (n *NemoEvaluator) GetHTTPRouteParams() *rendertypes.HTTPRouteParams {
params := &rendertypes.HTTPRouteParams{}
params.Enabled = n.IsHTTPRouteEnabled()

// Set metadata
params.Name = n.GetName()
params.Namespace = n.GetNamespace()
params.Labels = n.GetServiceLabels()
params.Annotations = n.GetHTTPRouteAnnotations()
params.Spec = n.GetHTTPRouteSpec()
return params
}

// GetRoleParams returns params to render Role from templates.
func (n *NemoEvaluator) GetRoleParams() *rendertypes.RoleParams {
params := &rendertypes.RoleParams{}
Expand Down Expand Up @@ -899,6 +922,15 @@ func (n *NemoEvaluator) GetIngressAnnotations() map[string]string {
return NemoEvaluatorAnnotations
}

func (n *NemoEvaluator) GetHTTPRouteAnnotations() map[string]string {
annotations := n.GetNemoEvaluatorAnnotations()

if n.Spec.Expose.HTTPRoute.Annotations != nil {
return utils.MergeMaps(annotations, n.Spec.Expose.HTTPRoute.Annotations)
}
return annotations
}

func (n *NemoEvaluator) GetServiceAnnotations() map[string]string {
NemoEvaluatorAnnotations := n.GetNemoEvaluatorAnnotations()

Expand Down
Loading
Loading