Skip to content

Commit aa2fdfe

Browse files
committed
Merge branch 'release-v2-dev' into chore/build-multi-image
2 parents cb3fb92 + aea4dba commit aa2fdfe

27 files changed

+2052
-95
lines changed

PROJECT

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,12 @@ resources:
2626
kind: GatewayProxy
2727
path: github.com/api7/api7-ingress-controller/api/v1alpha1
2828
version: v1alpha1
29+
- api:
30+
crdVersion: v1
31+
namespaced: true
32+
domain: github.com
33+
group: gateway.apisix.io
34+
kind: HTTPRoutePolicy
35+
path: github.com/api7/api7-ingress-controller/api/v1alpha1
36+
version: v1alpha1
2937
version: "3"

api/adc/types.go

Lines changed: 12 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import (
1010
"time"
1111

1212
"github.com/incubator4/go-resty-expr/expr"
13+
14+
"github.com/api7/api7-ingress-controller/api/common"
1315
)
1416

1517
const (
@@ -113,16 +115,16 @@ type Service struct {
113115
type Route struct {
114116
Metadata `json:",inline" yaml:",inline"`
115117

116-
EnableWebsocket *bool `json:"enable_websocket,omitempty" yaml:"enable_websocket,omitempty"`
117-
FilterFunc string `json:"filter_func,omitempty" yaml:"filter_func,omitempty"`
118-
Hosts []string `json:"hosts,omitempty" yaml:"hosts,omitempty"`
119-
Methods []string `json:"methods,omitempty" yaml:"methods,omitempty"`
120-
Plugins Plugins `json:"plugins,omitempty" yaml:"plugins,omitempty"`
121-
Priority *int64 `json:"priority,omitempty" yaml:"priority,omitempty"`
122-
RemoteAddrs []string `json:"remote_addrs,omitempty" yaml:"remote_addrs,omitempty"`
123-
Timeout *Timeout `json:"timeout,omitempty" yaml:"timeout,omitempty"`
124-
Uris []string `json:"uris" yaml:"uris"`
125-
Vars Vars `json:"vars,omitempty" yaml:"vars,omitempty"`
118+
EnableWebsocket *bool `json:"enable_websocket,omitempty" yaml:"enable_websocket,omitempty"`
119+
FilterFunc string `json:"filter_func,omitempty" yaml:"filter_func,omitempty"`
120+
Hosts []string `json:"hosts,omitempty" yaml:"hosts,omitempty"`
121+
Methods []string `json:"methods,omitempty" yaml:"methods,omitempty"`
122+
Plugins Plugins `json:"plugins,omitempty" yaml:"plugins,omitempty"`
123+
Priority *int64 `json:"priority,omitempty" yaml:"priority,omitempty"`
124+
RemoteAddrs []string `json:"remote_addrs,omitempty" yaml:"remote_addrs,omitempty"`
125+
Timeout *Timeout `json:"timeout,omitempty" yaml:"timeout,omitempty"`
126+
Uris []string `json:"uris" yaml:"uris"`
127+
Vars common.Vars `json:"vars,omitempty" yaml:"vars,omitempty"`
126128
}
127129

128130
type Timeout struct {
@@ -325,62 +327,6 @@ func (n *UpstreamNodes) UnmarshalJSON(p []byte) error {
325327
return nil
326328
}
327329

328-
// Vars represents the route match expressions of APISIX.
329-
type Vars [][]StringOrSlice
330-
331-
// UnmarshalJSON implements json.Unmarshaler interface.
332-
// lua-cjson doesn't distinguish empty array and table,
333-
// and by default empty array will be encoded as '{}'.
334-
// We have to maintain the compatibility.
335-
func (vars *Vars) UnmarshalJSON(p []byte) error {
336-
if p[0] == '{' {
337-
if len(p) != 2 {
338-
return errors.New("unexpected non-empty object")
339-
}
340-
return nil
341-
}
342-
var data [][]StringOrSlice
343-
if err := json.Unmarshal(p, &data); err != nil {
344-
return err
345-
}
346-
*vars = data
347-
return nil
348-
}
349-
350-
// StringOrSlice represents a string or a string slice.
351-
// TODO Do not use interface{} to avoid the reflection overheads.
352-
type StringOrSlice struct {
353-
StrVal string `json:"-"`
354-
SliceVal []string `json:"-"`
355-
}
356-
357-
func (s *StringOrSlice) MarshalJSON() ([]byte, error) {
358-
var (
359-
p []byte
360-
err error
361-
)
362-
if s.SliceVal != nil {
363-
p, err = json.Marshal(s.SliceVal)
364-
} else {
365-
p, err = json.Marshal(s.StrVal)
366-
}
367-
return p, err
368-
}
369-
370-
func (s *StringOrSlice) UnmarshalJSON(p []byte) error {
371-
var err error
372-
373-
if len(p) == 0 {
374-
return errors.New("empty object")
375-
}
376-
if p[0] == '[' {
377-
err = json.Unmarshal(p, &s.SliceVal)
378-
} else {
379-
err = json.Unmarshal(p, &s.StrVal)
380-
}
381-
return err
382-
}
383-
384330
// ComposeRouteName uses namespace, name and rule name to compose
385331
// the route name.
386332
func ComposeRouteName(namespace, name string, rule string) string {

api/common/types.go

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
// +kubebuilder:object:generate=true
2+
3+
package common
4+
5+
import (
6+
"encoding/json"
7+
"errors"
8+
)
9+
10+
// Vars represents the route match expressions of APISIX.
11+
type Vars [][]StringOrSlice
12+
13+
// UnmarshalJSON implements json.Unmarshaler interface.
14+
// lua-cjson doesn't distinguish empty array and table,
15+
// and by default empty array will be encoded as '{}'.
16+
// We have to maintain the compatibility.
17+
func (vars *Vars) UnmarshalJSON(p []byte) error {
18+
if p[0] == '{' {
19+
if len(p) != 2 {
20+
return errors.New("unexpected non-empty object")
21+
}
22+
return nil
23+
}
24+
var data [][]StringOrSlice
25+
if err := json.Unmarshal(p, &data); err != nil {
26+
return err
27+
}
28+
*vars = data
29+
return nil
30+
}
31+
32+
// StringOrSlice represents a string or a string slice.
33+
// TODO Do not use interface{} to avoid the reflection overheads.
34+
type StringOrSlice struct {
35+
StrVal string `json:"-"`
36+
SliceVal []string `json:"-"`
37+
}
38+
39+
func (s *StringOrSlice) MarshalJSON() ([]byte, error) {
40+
var (
41+
p []byte
42+
err error
43+
)
44+
if s.SliceVal != nil {
45+
p, err = json.Marshal(s.SliceVal)
46+
} else {
47+
p, err = json.Marshal(s.StrVal)
48+
}
49+
return p, err
50+
}
51+
52+
func (s *StringOrSlice) UnmarshalJSON(p []byte) error {
53+
var err error
54+
55+
if len(p) == 0 {
56+
return errors.New("empty object")
57+
}
58+
if p[0] == '[' {
59+
err = json.Unmarshal(p, &s.SliceVal)
60+
} else {
61+
err = json.Unmarshal(p, &s.StrVal)
62+
}
63+
return err
64+
}

api/common/zz_generated.deepcopy.go

Lines changed: 70 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
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+
}

api/v1alpha1/consumer_types.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,6 @@ type SecretReference struct {
4646
Namespace *string `json:"namespace,omitempty"`
4747
}
4848

49-
type Status struct {
50-
Conditions []metav1.Condition `json:"conditions,omitempty"`
51-
}
52-
5349
// +kubebuilder:object:root=true
5450
type ConsumerList struct {
5551
metav1.TypeMeta `json:",inline"`

0 commit comments

Comments
 (0)