Skip to content

Commit d07c436

Browse files
authored
feat: add L4RoutePolicy CRD for attaching stream plugins to Gateway API L4 routes (#416)
1 parent ecbb5d5 commit d07c436

27 files changed

Lines changed: 1643 additions & 15 deletions
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
package v1alpha1
19+
20+
import (
21+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
22+
gatewayv1alpha2 "sigs.k8s.io/gateway-api/apis/v1alpha2"
23+
)
24+
25+
// L4RoutePolicySpec defines the desired state of L4RoutePolicy.
26+
type L4RoutePolicySpec struct {
27+
// TargetRefs identifies the L4 route resources (TCPRoute, UDPRoute, or TLSRoute)
28+
// to which this policy applies. Only same-namespace targets are supported.
29+
//
30+
// +kubebuilder:validation:MinItems=1
31+
// +kubebuilder:validation:MaxItems=16
32+
// +kubebuilder:validation:XValidation:rule="self.all(r, r.kind == 'TCPRoute' || r.kind == 'UDPRoute' || r.kind == 'TLSRoute')",message="targetRefs kind must be TCPRoute, UDPRoute, or TLSRoute"
33+
// +kubebuilder:validation:XValidation:rule="self.all(r, r.group == 'gateway.networking.k8s.io')",message="targetRefs group must be gateway.networking.k8s.io"
34+
TargetRefs []gatewayv1alpha2.LocalPolicyTargetReferenceWithSectionName `json:"targetRefs"`
35+
36+
// Plugins is the list of APISIX stream plugins to attach to the targeted L4 routes.
37+
// Plugin names should be valid APISIX stream plugin names (e.g., limit-conn, ip-restriction).
38+
//
39+
// +optional
40+
Plugins []Plugin `json:"plugins,omitempty"`
41+
}
42+
43+
// +kubebuilder:object:root=true
44+
// +kubebuilder:subresource:status
45+
46+
// L4RoutePolicy defines plugin configuration for Gateway API L4 routes (TCPRoute, UDPRoute, TLSRoute).
47+
// It follows the Gateway API Policy Attachment pattern and attaches APISIX stream plugins
48+
// to the targeted L4 route resources.
49+
type L4RoutePolicy struct {
50+
metav1.TypeMeta `json:",inline"`
51+
metav1.ObjectMeta `json:"metadata,omitempty"`
52+
53+
// Spec defines the desired state of L4RoutePolicy.
54+
Spec L4RoutePolicySpec `json:"spec,omitempty"`
55+
Status PolicyStatus `json:"status,omitempty"`
56+
}
57+
58+
// +kubebuilder:object:root=true
59+
60+
// L4RoutePolicyList contains a list of L4RoutePolicy.
61+
type L4RoutePolicyList struct {
62+
metav1.TypeMeta `json:",inline"`
63+
metav1.ListMeta `json:"metadata,omitempty"`
64+
Items []L4RoutePolicy `json:"items"`
65+
}
66+
67+
func init() {
68+
SchemeBuilder.Register(&L4RoutePolicy{}, &L4RoutePolicyList{})
69+
}

api/v1alpha1/zz_generated.deepcopy.go

Lines changed: 88 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/v2/zz_generated.deepcopy.go

Lines changed: 15 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)