@@ -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
2728const (
@@ -37,8 +38,11 @@ const (
3738
3839// Expose defines attributes to expose the service.
3940type Expose struct {
40- Service Service `json:"service,omitempty"`
41- Ingress Ingress `json:"ingress,omitempty"`
41+ // common field between ingress and httproute
42+ // deprecate Ingress
43+ Service Service `json:"service,omitempty"`
44+ Ingress Ingress `json:"ingress,omitempty"`
45+ HTTPRoute HTTPRoute `json:"httpRoute,omitempty"`
4246}
4347
4448// Service defines attributes to create a service.
@@ -69,8 +73,9 @@ type Service struct {
6973
7074// ExposeV1 defines attributes to expose the service.
7175type ExposeV1 struct {
72- Service Service `json:"service,omitempty"`
73- Ingress IngressV1 `json:"ingress,omitempty"`
76+ Service Service `json:"service,omitempty"`
77+ Ingress IngressV1 `json:"ingress,omitempty"`
78+ HTTPRoute HTTPRoute `json:"httpRoute,omitempty"`
7479}
7580
7681// Metrics defines attributes to setup metrics collection.
@@ -119,6 +124,39 @@ type Ingress struct {
119124 Spec networkingv1.IngressSpec `json:"spec,omitempty"`
120125}
121126
127+ // HTTPRoute defines attributes to HTTPRoute in Gateway API
128+ type HTTPRoute struct {
129+ Enabled * bool `json:"enabled,omitempty"`
130+ Annotations map [string ]string `json:"annotations,omitempty"`
131+ Spec * HTTPRouteSpec `json:"spec,omitempty"`
132+ }
133+
134+ type HTTPRouteSpec struct {
135+ gatewayv1.CommonRouteSpec `json:",inline"`
136+ Host gatewayv1.Hostname `json:"host,omitempty"`
137+ // +kubebuilder:validation:MaxItems=2
138+ Paths []HTTPPathMatch `json:"paths,omitempty"`
139+ }
140+
141+ type HTTPPathMatch struct {
142+ // Type specifies how to match against the path Value.
143+ //
144+ // Support: Core (Exact, PathPrefix)
145+ //
146+ // Support: Implementation-specific (RegularExpression)
147+ //
148+ // +optional
149+ // +kubebuilder:default=PathPrefix
150+ Type * gatewayv1.PathMatchType `json:"type,omitempty"`
151+
152+ // Value of the HTTP path to match against.
153+ //
154+ // +optional
155+ // +kubebuilder:default="/"
156+ // +kubebuilder:validation:MaxLength=1024
157+ Value * string `json:"value,omitempty"`
158+ }
159+
122160// IngressV1 defines attributes for ingress
123161//
124162// +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 +180,43 @@ type ResourceRequirements struct {
142180 Requests corev1.ResourceList `json:"requests,omitempty" protobuf:"bytes,2,rep,name=requests,casttype=ResourceList,castkey=ResourceName"`
143181}
144182
183+ func (i * HTTPRoute ) GenerateGatewayHTTPRouteSpec (name string ) gatewayv1.HTTPRouteSpec {
184+ if i .Spec == nil {
185+ return gatewayv1.HTTPRouteSpec {}
186+ }
187+
188+ httpRouteSpec := gatewayv1.HTTPRouteSpec {
189+ CommonRouteSpec : i .Spec .CommonRouteSpec ,
190+ Hostnames : []gatewayv1.Hostname {i .Spec .Host },
191+ Rules : []gatewayv1.HTTPRouteRule {},
192+ }
193+
194+ port := gatewayv1 .PortNumber (DefaultAPIPort )
195+ for _ , path := range i .Spec .Paths {
196+ httpRouteSpec .Rules = append (httpRouteSpec .Rules , gatewayv1.HTTPRouteRule {
197+ BackendRefs : []gatewayv1.HTTPBackendRef {
198+ {
199+ BackendRef : gatewayv1.BackendRef {
200+ BackendObjectReference : gatewayv1.BackendObjectReference {
201+ Name : gatewayv1 .ObjectName (name ),
202+ Port : & port ,
203+ },
204+ },
205+ },
206+ },
207+ Matches : []gatewayv1.HTTPRouteMatch {
208+ {
209+ Path : & gatewayv1.HTTPPathMatch {
210+ Type : path .Type ,
211+ Value : path .Value ,
212+ },
213+ },
214+ },
215+ })
216+ }
217+ return httpRouteSpec
218+ }
219+
145220func (i * IngressV1 ) GenerateNetworkingV1IngressSpec (name string ) networkingv1.IngressSpec {
146221 if i .Spec == nil {
147222 return networkingv1.IngressSpec {}
0 commit comments