|
| 1 | +package v1alpha1 |
| 2 | + |
| 3 | +import ( |
| 4 | + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 5 | + |
| 6 | + gatewayv1alpha2 "sigs.k8s.io/gateway-api/apis/v1alpha2" |
| 7 | +) |
| 8 | + |
| 9 | +// +kubebuilder:object:root=true |
| 10 | +// +kubebuilder:subresource:status |
| 11 | +type BackendTrafficPolicy struct { |
| 12 | + metav1.TypeMeta `json:",inline"` |
| 13 | + metav1.ObjectMeta `json:"metadata,omitempty"` |
| 14 | + |
| 15 | + Spec BackendTrafficPolicySpec `json:"spec,omitempty"` |
| 16 | + Status gatewayv1alpha2.PolicyStatus `json:"status,omitempty"` |
| 17 | +} |
| 18 | + |
| 19 | +type BackendTrafficPolicySpec struct { |
| 20 | + // TargetRef identifies an API object to apply policy to. |
| 21 | + // Currently, Backends (i.e. Service, ServiceImport, or any |
| 22 | + // implementation-specific backendRef) are the only valid API |
| 23 | + // target references. |
| 24 | + // +listType=map |
| 25 | + // +listMapKey=group |
| 26 | + // +listMapKey=kind |
| 27 | + // +listMapKey=name |
| 28 | + // +kubebuilder:validation:MinItems=1 |
| 29 | + // +kubebuilder:validation:MaxItems=16 |
| 30 | + TargetRefs []gatewayv1alpha2.LocalPolicyTargetReferenceWithSectionName `json:"targetRefs"` |
| 31 | + // LoadBalancer represents the load balancer configuration for Kubernetes Service. |
| 32 | + // The default strategy is round robin. |
| 33 | + LoadBalancer *LoadBalancer `json:"loadbalancer,omitempty" yaml:"loadbalancer,omitempty"` |
| 34 | + // The scheme used to talk with the upstream. |
| 35 | + // |
| 36 | + // +kubebuilder:validation:Enum=http;https;grpc;grpcs; |
| 37 | + // +kubebuilder:default=http |
| 38 | + Scheme string `json:"scheme,omitempty" yaml:"scheme,omitempty"` |
| 39 | + |
| 40 | + // How many times that the proxy (Apache APISIX) should do when |
| 41 | + // errors occur (error, timeout or bad http status codes like 500, 502). |
| 42 | + // +optional |
| 43 | + Retries *int `json:"retries,omitempty" yaml:"retries,omitempty"` |
| 44 | + |
| 45 | + // Timeout settings for the read, send and connect to the upstream. |
| 46 | + Timeout *Timeout `json:"timeout,omitempty" yaml:"timeout,omitempty"` |
| 47 | + |
| 48 | + // Configures the host when the request is forwarded to the upstream. |
| 49 | + // Can be one of pass, node or rewrite. |
| 50 | + // |
| 51 | + // +kubebuilder:validation:Enum=pass;node;rewrite; |
| 52 | + // +kubebuilder:default=pass |
| 53 | + PassHost string `json:"pass_host,omitempty" yaml:"pass_host,omitempty"` |
| 54 | + |
| 55 | + // Specifies the host of the Upstream request. This is only valid if |
| 56 | + // the pass_host is set to rewrite |
| 57 | + Host Hostname `json:"upstream_host,omitempty" yaml:"upstream_host,omitempty"` |
| 58 | +} |
| 59 | + |
| 60 | +// LoadBalancer describes the load balancing parameters. |
| 61 | +// +kubebuilder:validation:XValidation:rule="!(has(self.key) && self.type != 'chash')" |
| 62 | +type LoadBalancer struct { |
| 63 | + // +kubebuilder:validation:Enum=roundrobin;chash;ewma;least_conn; |
| 64 | + // +kubebuilder:default=roundrobin |
| 65 | + // +kubebuilder:validation:Required |
| 66 | + Type string `json:"type" yaml:"type"` |
| 67 | + // The HashOn and Key fields are required when Type is "chash". |
| 68 | + // HashOn represents the key fetching scope. |
| 69 | + // +kubebuilder:validation:Enum=vars;header;cookie;consumer;vars_combinations; |
| 70 | + // +kubebuilder:default=vars |
| 71 | + HashOn string `json:"hashOn,omitempty" yaml:"hashOn,omitempty"` |
| 72 | + // Key represents the hash key. |
| 73 | + Key string `json:"key,omitempty" yaml:"key,omitempty"` |
| 74 | +} |
| 75 | + |
| 76 | +type Timeout struct { |
| 77 | + Connect metav1.Duration `json:"connect,omitempty" yaml:"connect,omitempty"` |
| 78 | + Send metav1.Duration `json:"send,omitempty" yaml:"send,omitempty"` |
| 79 | + Read metav1.Duration `json:"read,omitempty" yaml:"read,omitempty"` |
| 80 | +} |
| 81 | + |
| 82 | +// +kubebuilder:object:root=true |
| 83 | +type BackendTrafficPolicyList struct { |
| 84 | + metav1.TypeMeta `json:",inline"` |
| 85 | + metav1.ListMeta `json:"metadata,omitempty"` |
| 86 | + Items []BackendTrafficPolicy `json:"items"` |
| 87 | +} |
| 88 | + |
| 89 | +func init() { |
| 90 | + SchemeBuilder.Register(&BackendTrafficPolicy{}, &BackendTrafficPolicyList{}) |
| 91 | +} |
0 commit comments