Skip to content

Commit c17b53d

Browse files
authored
Merge pull request #604 from shengnuo/gateway-api
Gateway API coupling
2 parents 1243ea9 + 0669140 commit c17b53d

File tree

118 files changed

+15506
-1827
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

118 files changed

+15506
-1827
lines changed

api/apps/v1alpha1/common_types.go

Lines changed: 70 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
corev1 "k8s.io/api/core/v1"
2323
networkingv1 "k8s.io/api/networking/v1"
2424
"k8s.io/utils/ptr"
25+
gatewayv1 "sigs.k8s.io/gateway-api/apis/v1"
2526
)
2627

2728
const (
@@ -37,8 +38,9 @@ const (
3738

3839
// Expose defines attributes to expose the service.
3940
type Expose struct {
40-
Service Service `json:"service,omitempty"`
41-
Ingress Ingress `json:"ingress,omitempty"`
41+
Service Service `json:"service,omitempty"`
42+
Ingress Ingress `json:"ingress,omitempty"`
43+
HTTPRoute HTTPRoute `json:"httpRoute,omitempty"`
4244
}
4345

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

7072
// ExposeV1 defines attributes to expose the service.
7173
type ExposeV1 struct {
72-
Service Service `json:"service,omitempty"`
73-
Ingress IngressV1 `json:"ingress,omitempty"`
74+
Service Service `json:"service,omitempty"`
75+
Ingress IngressV1 `json:"ingress,omitempty"`
76+
HTTPRoute HTTPRoute `json:"httpRoute,omitempty"`
7477
}
7578

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

125+
// HTTPRoute defines attributes to HTTPRoute in Gateway API.
126+
type HTTPRoute struct {
127+
Enabled *bool `json:"enabled,omitempty"`
128+
Annotations map[string]string `json:"annotations,omitempty"`
129+
Spec *HTTPRouteSpec `json:"spec,omitempty"`
130+
}
131+
132+
type HTTPRouteSpec struct {
133+
gatewayv1.CommonRouteSpec `json:",inline"`
134+
Host gatewayv1.Hostname `json:"host,omitempty"`
135+
Paths []HTTPPathMatch `json:"paths,omitempty"`
136+
}
137+
138+
type HTTPPathMatch struct {
139+
// Type specifies how to match against the path Value.
140+
// +optional
141+
// +kubebuilder:default=PathPrefix
142+
Type *gatewayv1.PathMatchType `json:"type,omitempty"`
143+
144+
// Value of the HTTP path to match against.
145+
// +optional
146+
// +kubebuilder:default="/"
147+
// +kubebuilder:validation:MaxLength=1024
148+
Value *string `json:"value,omitempty"`
149+
}
150+
122151
// IngressV1 defines attributes for ingress
123152
//
124153
// +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"
@@ -142,6 +171,43 @@ type ResourceRequirements struct {
142171
Requests corev1.ResourceList `json:"requests,omitempty" protobuf:"bytes,2,rep,name=requests,casttype=ResourceList,castkey=ResourceName"`
143172
}
144173

174+
func (i *HTTPRoute) GenerateGatewayHTTPRouteSpec(name string) gatewayv1.HTTPRouteSpec {
175+
if i.Spec == nil {
176+
return gatewayv1.HTTPRouteSpec{}
177+
}
178+
179+
port := gatewayv1.PortNumber(DefaultAPIPort)
180+
httpRouteMatches := []gatewayv1.HTTPRouteMatch{}
181+
for _, path := range i.Spec.Paths {
182+
httpRouteMatches = append(httpRouteMatches, gatewayv1.HTTPRouteMatch{
183+
Path: &gatewayv1.HTTPPathMatch{
184+
Type: path.Type,
185+
Value: path.Value,
186+
},
187+
})
188+
}
189+
190+
return gatewayv1.HTTPRouteSpec{
191+
CommonRouteSpec: i.Spec.CommonRouteSpec,
192+
Hostnames: []gatewayv1.Hostname{i.Spec.Host},
193+
Rules: []gatewayv1.HTTPRouteRule{
194+
{
195+
BackendRefs: []gatewayv1.HTTPBackendRef{
196+
{
197+
BackendRef: gatewayv1.BackendRef{
198+
BackendObjectReference: gatewayv1.BackendObjectReference{
199+
Name: gatewayv1.ObjectName(name),
200+
Port: &port,
201+
},
202+
},
203+
},
204+
},
205+
Matches: httpRouteMatches,
206+
},
207+
},
208+
}
209+
}
210+
145211
func (i *IngressV1) GenerateNetworkingV1IngressSpec(name string) networkingv1.IngressSpec {
146212
if i.Spec == nil {
147213
return networkingv1.IngressSpec{}

api/apps/v1alpha1/nemo_customizer_types.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import (
3333
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3434
"k8s.io/apimachinery/pkg/util/intstr"
3535
"k8s.io/utils/ptr"
36+
gatewayv1 "sigs.k8s.io/gateway-api/apis/v1"
3637

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

647+
func (n *NemoCustomizer) IsHTTPRouteEnabled() bool {
648+
return n.Spec.Expose.HTTPRoute.Enabled != nil && *n.Spec.Expose.HTTPRoute.Enabled
649+
}
650+
651+
func (n *NemoCustomizer) GetHTTPRouteSpec() gatewayv1.HTTPRouteSpec {
652+
return n.Spec.Expose.HTTPRoute.GenerateGatewayHTTPRouteSpec(n.GetName())
653+
}
654+
646655
// IsServiceMonitorEnabled returns true if servicemonitor is enabled for NemoCustomizer deployment.
647656
func (n *NemoCustomizer) IsServiceMonitorEnabled() bool {
648657
return n.Spec.Metrics.Enabled != nil && *n.Spec.Metrics.Enabled
@@ -839,6 +848,20 @@ func (n *NemoCustomizer) GetIngressParams() *rendertypes.IngressParams {
839848
return params
840849
}
841850

851+
// GetHTTPRouteParams returns params to render HTTPRoute from templates.
852+
func (n *NemoCustomizer) GetHTTPRouteParams() *rendertypes.HTTPRouteParams {
853+
params := &rendertypes.HTTPRouteParams{}
854+
params.Enabled = n.IsHTTPRouteEnabled()
855+
856+
// Set metadata
857+
params.Name = n.GetName()
858+
params.Namespace = n.GetNamespace()
859+
params.Labels = n.GetServiceLabels()
860+
params.Annotations = n.GetHTTPRouteAnnotations()
861+
params.Spec = n.GetHTTPRouteSpec()
862+
return params
863+
}
864+
842865
// GetRoleParams returns params to render Role from templates.
843866
func (n *NemoCustomizer) GetRoleParams() *rendertypes.RoleParams {
844867
params := &rendertypes.RoleParams{}
@@ -1023,6 +1046,15 @@ func (n *NemoCustomizer) GetIngressAnnotations() map[string]string {
10231046
return NemoCustomizerAnnotations
10241047
}
10251048

1049+
func (n *NemoCustomizer) GetHTTPRouteAnnotations() map[string]string {
1050+
annotations := n.GetNemoCustomizerAnnotations()
1051+
1052+
if n.Spec.Expose.HTTPRoute.Annotations != nil {
1053+
return utils.MergeMaps(annotations, n.Spec.Expose.HTTPRoute.Annotations)
1054+
}
1055+
return annotations
1056+
}
1057+
10261058
// GetServiceAnnotations return standard and customized service annotations.
10271059
func (n *NemoCustomizer) GetServiceAnnotations() map[string]string {
10281060
NemoCustomizerAnnotations := n.GetNemoCustomizerAnnotations()

api/apps/v1alpha1/nemo_datastore_types.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3131
"k8s.io/apimachinery/pkg/util/intstr"
3232
"k8s.io/utils/ptr"
33+
gatewayv1 "sigs.k8s.io/gateway-api/apis/v1"
3334

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

771+
func (n *NemoDatastore) IsHTTPRouteEnabled() bool {
772+
return n.Spec.Expose.HTTPRoute.Enabled != nil && *n.Spec.Expose.HTTPRoute.Enabled
773+
}
774+
770775
// GetIngressSpec returns the Ingress spec NemoDatastore deployment.
771776
func (n *NemoDatastore) GetIngressSpec() networkingv1.IngressSpec {
772777
return n.Spec.Expose.Ingress.GenerateNetworkingV1IngressSpec(n.GetName())
773778
}
774779

780+
func (n *NemoDatastore) GetHTTPRouteSpec() gatewayv1.HTTPRouteSpec {
781+
return n.Spec.Expose.HTTPRoute.GenerateGatewayHTTPRouteSpec(n.GetName())
782+
}
783+
775784
// IsServiceMonitorEnabled returns true if servicemonitor is enabled for NemoDatastore deployment.
776785
func (n *NemoDatastore) IsServiceMonitorEnabled() bool {
777786
return n.Spec.Metrics.Enabled != nil && *n.Spec.Metrics.Enabled
@@ -967,6 +976,20 @@ func (n *NemoDatastore) GetIngressParams() *rendertypes.IngressParams {
967976
return params
968977
}
969978

979+
// GetHTTPRouteParams returns params to render HTTPRoute from templates.
980+
func (n *NemoDatastore) GetHTTPRouteParams() *rendertypes.HTTPRouteParams {
981+
params := &rendertypes.HTTPRouteParams{}
982+
params.Enabled = n.IsHTTPRouteEnabled()
983+
984+
// Set metadata
985+
params.Name = n.GetName()
986+
params.Namespace = n.GetNamespace()
987+
params.Labels = n.GetServiceLabels()
988+
params.Annotations = n.GetHTTPRouteAnnotations()
989+
params.Spec = n.GetHTTPRouteSpec()
990+
return params
991+
}
992+
970993
// GetRoleParams returns params to render Role from templates.
971994
func (n *NemoDatastore) GetRoleParams() *rendertypes.RoleParams {
972995
params := &rendertypes.RoleParams{}
@@ -1077,6 +1100,15 @@ func (n *NemoDatastore) GetIngressAnnotations() map[string]string {
10771100
return NemoDatastoreAnnotations
10781101
}
10791102

1103+
func (n *NemoDatastore) GetHTTPRouteAnnotations() map[string]string {
1104+
annotations := n.GetNemoDatastoreAnnotations()
1105+
1106+
if n.Spec.Expose.HTTPRoute.Annotations != nil {
1107+
return utils.MergeMaps(annotations, n.Spec.Expose.HTTPRoute.Annotations)
1108+
}
1109+
return annotations
1110+
}
1111+
10801112
func (n *NemoDatastore) GetServiceAnnotations() map[string]string {
10811113
NemoDatastoreAnnotations := n.GetNemoDatastoreAnnotations()
10821114

api/apps/v1alpha1/nemo_entitystore_types.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import (
3131
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3232
"k8s.io/apimachinery/pkg/util/intstr"
3333
"k8s.io/utils/ptr"
34+
gatewayv1 "sigs.k8s.io/gateway-api/apis/v1"
3435

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

403+
func (n *NemoEntitystore) IsHTTPRouteEnabled() bool {
404+
return n.Spec.Expose.HTTPRoute.Enabled != nil && *n.Spec.Expose.HTTPRoute.Enabled
405+
}
406+
407+
func (n *NemoEntitystore) GetHTTPRouteSpec() gatewayv1.HTTPRouteSpec {
408+
return n.Spec.Expose.HTTPRoute.GenerateGatewayHTTPRouteSpec(n.GetName())
409+
}
410+
402411
// IsServiceMonitorEnabled returns true if servicemonitor is enabled for NemoEntitystore deployment.
403412
func (n *NemoEntitystore) IsServiceMonitorEnabled() bool {
404413
return n.Spec.Metrics.Enabled != nil && *n.Spec.Metrics.Enabled
@@ -601,6 +610,20 @@ func (n *NemoEntitystore) GetIngressParams() *rendertypes.IngressParams {
601610
return params
602611
}
603612

613+
// GetHTTPRouteParams returns params to render HTTPRoute from templates.
614+
func (n *NemoEntitystore) GetHTTPRouteParams() *rendertypes.HTTPRouteParams {
615+
params := &rendertypes.HTTPRouteParams{}
616+
params.Enabled = n.IsHTTPRouteEnabled()
617+
618+
// Set metadata
619+
params.Name = n.GetName()
620+
params.Namespace = n.GetNamespace()
621+
params.Labels = n.GetServiceLabels()
622+
params.Annotations = n.GetHTTPRouteAnnotations()
623+
params.Spec = n.GetHTTPRouteSpec()
624+
return params
625+
}
626+
604627
// GetRoleParams returns params to render Role from templates.
605628
func (n *NemoEntitystore) GetRoleParams() *rendertypes.RoleParams {
606629
params := &rendertypes.RoleParams{}
@@ -711,6 +734,15 @@ func (n *NemoEntitystore) GetIngressAnnotations() map[string]string {
711734
return NemoEntitystoreAnnotations
712735
}
713736

737+
func (n *NemoEntitystore) GetHTTPRouteAnnotations() map[string]string {
738+
annotations := n.GetNemoEntitystoreAnnotations()
739+
740+
if n.Spec.Expose.HTTPRoute.Annotations != nil {
741+
return utils.MergeMaps(annotations, n.Spec.Expose.HTTPRoute.Annotations)
742+
}
743+
return annotations
744+
}
745+
714746
func (n *NemoEntitystore) GetServiceAnnotations() map[string]string {
715747
NemoEntitystoreAnnotations := n.GetNemoEntitystoreAnnotations()
716748

api/apps/v1alpha1/nemo_evaluator_types.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import (
3232
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3333
"k8s.io/apimachinery/pkg/util/intstr"
3434
"k8s.io/utils/ptr"
35+
gatewayv1 "sigs.k8s.io/gateway-api/apis/v1"
3536

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

588+
func (n *NemoEvaluator) IsHTTPRouteEnabled() bool {
589+
return n.Spec.Expose.HTTPRoute.Enabled != nil && *n.Spec.Expose.HTTPRoute.Enabled
590+
}
591+
587592
// GetIngressSpec returns the Ingress spec NemoEvaluator deployment.
588593
func (n *NemoEvaluator) GetIngressSpec() networkingv1.IngressSpec {
589594
return n.Spec.Expose.Ingress.GenerateNetworkingV1IngressSpec(n.GetName())
590595
}
591596

597+
func (n *NemoEvaluator) GetHTTPRouteSpec() gatewayv1.HTTPRouteSpec {
598+
return n.Spec.Expose.HTTPRoute.GenerateGatewayHTTPRouteSpec(n.GetName())
599+
}
600+
592601
// IsServiceMonitorEnabled returns true if servicemonitor is enabled for NemoEvaluator deployment.
593602
func (n *NemoEvaluator) IsServiceMonitorEnabled() bool {
594603
return n.Spec.Metrics.Enabled != nil && *n.Spec.Metrics.Enabled
@@ -784,6 +793,20 @@ func (n *NemoEvaluator) GetIngressParams() *rendertypes.IngressParams {
784793
return params
785794
}
786795

796+
// GetHTTPRouteParams returns params to render HTTPRoute from templates.
797+
func (n *NemoEvaluator) GetHTTPRouteParams() *rendertypes.HTTPRouteParams {
798+
params := &rendertypes.HTTPRouteParams{}
799+
params.Enabled = n.IsHTTPRouteEnabled()
800+
801+
// Set metadata
802+
params.Name = n.GetName()
803+
params.Namespace = n.GetNamespace()
804+
params.Labels = n.GetServiceLabels()
805+
params.Annotations = n.GetHTTPRouteAnnotations()
806+
params.Spec = n.GetHTTPRouteSpec()
807+
return params
808+
}
809+
787810
// GetRoleParams returns params to render Role from templates.
788811
func (n *NemoEvaluator) GetRoleParams() *rendertypes.RoleParams {
789812
params := &rendertypes.RoleParams{}
@@ -899,6 +922,15 @@ func (n *NemoEvaluator) GetIngressAnnotations() map[string]string {
899922
return NemoEvaluatorAnnotations
900923
}
901924

925+
func (n *NemoEvaluator) GetHTTPRouteAnnotations() map[string]string {
926+
annotations := n.GetNemoEvaluatorAnnotations()
927+
928+
if n.Spec.Expose.HTTPRoute.Annotations != nil {
929+
return utils.MergeMaps(annotations, n.Spec.Expose.HTTPRoute.Annotations)
930+
}
931+
return annotations
932+
}
933+
902934
func (n *NemoEvaluator) GetServiceAnnotations() map[string]string {
903935
NemoEvaluatorAnnotations := n.GetNemoEvaluatorAnnotations()
904936

0 commit comments

Comments
 (0)