-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: [skip ci] add RateLimitPolicy CRD Signed-off-by: Lin Yang <[email protected]> * feat: [skip ci] add comments Signed-off-by: Lin Yang <[email protected]> * fix: json maker Signed-off-by: Lin Yang <[email protected]> * wip: [skip ci] RateLimitPolicy Signed-off-by: Lin Yang <[email protected]> * chore: initialize version v1.2.0-alpha.1 Signed-off-by: Lin Yang <[email protected]> * wip: [skip ci] Signed-off-by: Lin Yang <[email protected]> * feat: build config.json and enrich RateLimitPolicy Signed-off-by: Lin Yang <[email protected]> * fix: golang lint Signed-off-by: Lin Yang <[email protected]> * feat: detect conflicts Signed-off-by: Lin Yang <[email protected]> * feat: sort rate limits by timestamp Signed-off-by: Lin Yang <[email protected]> * fix: golang lint Signed-off-by: Lin Yang <[email protected]> * fix: ratelimitpolicies RBAC Signed-off-by: Lin Yang <[email protected]> * fix: ratelimitpolicies events Signed-off-by: Lin Yang <[email protected]> * fix: register ratelimitpolicies reconciler Signed-off-by: Lin Yang <[email protected]> * feat: enable the ratelimit policy matches multiple routes Signed-off-by: Lin Yang <[email protected]> * feat: enable the ratelimit policy matches multiple gateway ports Signed-off-by: Lin Yang <[email protected]> * feat: add feature flags to enable/disable validating hostnames of GatewayAPI resources (#83) * feat: bump fgw scripts and config chains (#85) Signed-off-by: Lin Yang <[email protected]> * wip: [skip ci] refactoring RateLimitPolicy Signed-off-by: Lin Yang <[email protected]> * cloud connector with gateway api (#86) * cloud connector with gateway api. * cloud connector with gateway api. * feat: new FGW options to control per-request/per-connection load balancing (#87) Signed-off-by: Lin Yang <[email protected]> * fix: package-scripts Signed-off-by: Lin Yang <[email protected]> * wip: [skip ci] Signed-off-by: Lin Yang <[email protected]> * feat: add more options to configure FGW (#89) * feat: add more options to configure FGW Signed-off-by: Lin Yang <[email protected]> * fix: make chart-readme Signed-off-by: Lin Yang <[email protected]> --------- Signed-off-by: Lin Yang <[email protected]> * fix: code checks [skip ci] Signed-off-by: Lin Yang <[email protected]> * docs: add testcases for RateLimitPolicy Signed-off-by: Lin Yang <[email protected]> * fix: register policy attachment scheme Signed-off-by: Lin Yang <[email protected]> --------- Signed-off-by: Lin Yang <[email protected]> Co-authored-by: Cybwan <[email protected]>
- Loading branch information
1 parent
4c05d89
commit 171ea46
Showing
58 changed files
with
4,273 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
652 changes: 652 additions & 0 deletions
652
cmd/fsm-bootstrap/crds/gateway.flomesh.io_ratelimitpolicies.yaml
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// +k8s:deepcopy-gen=package,register | ||
// +groupName=gateway.flomesh.io | ||
|
||
// Package v1alpha1 is the v1alpha3 version of the API. | ||
package v1alpha1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
package v1alpha1 | ||
|
||
import ( | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
gwv1alpha2 "sigs.k8s.io/gateway-api/apis/v1alpha2" | ||
gwv1beta1 "sigs.k8s.io/gateway-api/apis/v1beta1" | ||
) | ||
|
||
type RateLimitPolicyMode string | ||
|
||
const ( | ||
// RateLimitPolicyModeLocal is the local mode | ||
RateLimitPolicyModeLocal RateLimitPolicyMode = "Local" | ||
|
||
// RateLimitPolicyModeGlobal is the global mode | ||
RateLimitPolicyModeGlobal RateLimitPolicyMode = "Global" | ||
) | ||
|
||
// RateLimitPolicySpec defines the desired state of RateLimitPolicy | ||
type RateLimitPolicySpec struct { | ||
// TargetRef is the reference to the target resource to which the policy is applied | ||
TargetRef gwv1alpha2.PolicyTargetReference `json:"targetRef"` | ||
|
||
// +optional | ||
// Ports is the rate limit configuration for ports | ||
Ports []PortRateLimit `json:"ports,omitempty"` | ||
|
||
// +optional | ||
// DefaultBPS is the default rate limit for all ports | ||
DefaultBPS *int64 `json:"bps,omitempty"` | ||
|
||
// +optional | ||
// Hostnames is the rate limit configuration for hostnames | ||
Hostnames []HostnameRateLimit `json:"hostnames,omitempty"` | ||
|
||
// +optional | ||
// HTTPRateLimits is the rate limit configuration for HTTP routes | ||
HTTPRateLimits []HTTPRateLimit `json:"http,omitempty"` | ||
|
||
// +optional | ||
// GRPCRateLimits is the rate limit configuration for GRPC routes | ||
GRPCRateLimits []GRPCRateLimit `json:"grpc,omitempty"` | ||
|
||
// +optional | ||
// DefaultRateLimit is the default rate limit for all routes and hostnames | ||
DefaultL7RateLimit *L7RateLimit `json:"rateLimit,omitempty"` | ||
} | ||
|
||
// PortRateLimit defines the rate limit configuration for a port | ||
type PortRateLimit struct { | ||
Port gwv1beta1.PortNumber `json:"port"` | ||
BPS *int64 `json:"bps,omitempty"` | ||
} | ||
|
||
// HostnameRateLimit defines the rate limit configuration for a hostname | ||
type HostnameRateLimit struct { | ||
Hostname gwv1beta1.Hostname `json:"hostname"` | ||
RateLimit *L7RateLimit `json:"rateLimit,omitempty"` | ||
} | ||
|
||
// RouteRateLimitConfig defines the rate limit configuration for routes | ||
type RouteRateLimitConfig struct { | ||
HttpRateLimits []HTTPRateLimit `json:"http,omitempty"` | ||
GrpcRateLimits []GRPCRateLimit `json:"grpc,omitempty"` | ||
DefaultRateLimit *L7RateLimit `json:"rateLimit,omitempty"` | ||
} | ||
|
||
// HTTPRateLimit defines the rate limit configuration for a HTTP route | ||
type HTTPRateLimit struct { | ||
Match gwv1beta1.HTTPRouteMatch `json:"match"` | ||
RateLimit *L7RateLimit `json:"rateLimit,omitempty"` | ||
} | ||
|
||
// GRPCRateLimit defines the rate limit configuration for a GRPC route | ||
type GRPCRateLimit struct { | ||
Match gwv1alpha2.GRPCRouteMatch `json:"match"` | ||
RateLimit *L7RateLimit `json:"rateLimit,omitempty"` | ||
} | ||
|
||
// L7RateLimit defines the rate limit configuration for a route | ||
type L7RateLimit struct { | ||
// +optional | ||
// +kubebuilder:default=Local | ||
// +kubebuilder:validation:Enum=Local;Global | ||
// Mode is the mode of the rate limit policy, Local or Global, default is Local | ||
Mode *RateLimitPolicyMode `json:"mode"` | ||
|
||
// +optional | ||
// +kubebuilder:default=10 | ||
// Backlog is the number of requests allowed to wait in the queue | ||
Backlog *int `json:"backlog,omitempty"` | ||
|
||
// Requests is the number of requests allowed per statTimeWindow | ||
Requests int `json:"requests"` | ||
|
||
// Burst is the number of requests allowed to be bursted, if not specified, it will be the same as Requests | ||
// +optional | ||
Burst *int `json:"burst,omitempty"` | ||
|
||
// StatTimeWindow is the time window in seconds | ||
StatTimeWindow int `json:"statTimeWindow"` | ||
|
||
// ResponseStatusCode is the response status code to be returned when the rate limit is exceeded | ||
// +optional | ||
// +kubebuilder:default=429 | ||
ResponseStatusCode *int `json:"responseStatusCode"` | ||
|
||
// +optional | ||
// ResponseHeadersToAdd is the response headers to be added when the rate limit is exceeded | ||
ResponseHeadersToAdd map[string]string `json:"responseHeadersToAdd,omitempty"` | ||
} | ||
|
||
// RateLimitPolicyStatus defines the observed state of RateLimitPolicy | ||
type RateLimitPolicyStatus struct { | ||
// Conditions describe the current conditions of the RateLimitPolicy. | ||
// | ||
// +optional | ||
// +listType=map | ||
// +listMapKey=type | ||
// +kubebuilder:validation:MaxItems=8 | ||
Conditions []metav1.Condition `json:"conditions,omitempty"` | ||
} | ||
|
||
// +genclient | ||
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object | ||
// +k8s:openapi-gen=true | ||
// +kubebuilder:object:root=true | ||
// +kubebuilder:subresource:status | ||
// +kubebuilder:resource:scope=Namespaced | ||
// +kubebuilder:metadata:labels=app.kubernetes.io/name=flomesh.io | ||
|
||
// RateLimitPolicy is the Schema for the RateLimitPolicys API | ||
type RateLimitPolicy struct { | ||
metav1.TypeMeta `json:",inline"` | ||
metav1.ObjectMeta `json:"metadata,omitempty"` | ||
|
||
Spec RateLimitPolicySpec `json:"spec,omitempty"` | ||
Status RateLimitPolicyStatus `json:"status,omitempty"` | ||
} | ||
|
||
// +kubebuilder:object:root=true | ||
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object | ||
|
||
// RateLimitPolicyList contains a list of RateLimitPolicy | ||
type RateLimitPolicyList struct { | ||
metav1.TypeMeta `json:",inline"` | ||
metav1.ListMeta `json:"metadata,omitempty"` | ||
Items []RateLimitPolicy `json:"items"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// +k8s:deepcopy-gen=package,register | ||
// +groupName=gateway.flomesh.io | ||
|
||
// Package v1alpha1 contains API Schema definitions for the gateway.flomesh.io v1alpha1 API group | ||
package v1alpha1 | ||
|
||
import ( | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/runtime" | ||
"k8s.io/apimachinery/pkg/runtime/schema" | ||
) | ||
|
||
var ( | ||
// SchemeGroupVersion is group version used to register MeshConfig | ||
SchemeGroupVersion = schema.GroupVersion{ | ||
Group: "gateway.flomesh.io", | ||
Version: "v1alpha1", | ||
} | ||
|
||
// SchemeBuilder is used to add go types to the GroupVersionKind scheme | ||
SchemeBuilder = runtime.NewSchemeBuilder(addKnownTypes) | ||
|
||
// AddToScheme adds all Resources to the Scheme | ||
AddToScheme = SchemeBuilder.AddToScheme | ||
) | ||
|
||
// Kind takes an unqualified kind and returns back a Group qualified GroupKind | ||
func Kind(kind string) schema.GroupKind { | ||
return SchemeGroupVersion.WithKind(kind).GroupKind() | ||
} | ||
|
||
// Resource takes an unqualified resource and returns a Group qualified GroupResource | ||
func Resource(resource string) schema.GroupResource { | ||
return SchemeGroupVersion.WithResource(resource).GroupResource() | ||
} | ||
|
||
// Adds the list of known types to Scheme. | ||
func addKnownTypes(scheme *runtime.Scheme) error { | ||
scheme.AddKnownTypes(SchemeGroupVersion, | ||
&RateLimitPolicy{}, | ||
&RateLimitPolicyList{}, | ||
) | ||
|
||
metav1.AddToGroupVersion( | ||
scheme, | ||
SchemeGroupVersion, | ||
) | ||
return nil | ||
} |
Oops, something went wrong.