Skip to content

Commit 7752729

Browse files
committed
Merge branch origin/release-v2-dev
2 parents 5c8aa78 + cb81148 commit 7752729

26 files changed

+1210
-105
lines changed

api/v1alpha1/backendtrafficpolicy_types.go

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ package v1alpha1
22

33
import (
44
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
5-
6-
gatewayv1alpha2 "sigs.k8s.io/gateway-api/apis/v1alpha2"
75
)
86

97
// +kubebuilder:object:root=true
@@ -12,22 +10,18 @@ type BackendTrafficPolicy struct {
1210
metav1.TypeMeta `json:",inline"`
1311
metav1.ObjectMeta `json:"metadata,omitempty"`
1412

15-
Spec BackendTrafficPolicySpec `json:"spec,omitempty"`
16-
Status gatewayv1alpha2.PolicyStatus `json:"status,omitempty"`
13+
Spec BackendTrafficPolicySpec `json:"spec,omitempty"`
14+
Status PolicyStatus `json:"status,omitempty"`
1715
}
1816

1917
type BackendTrafficPolicySpec struct {
2018
// TargetRef identifies an API object to apply policy to.
2119
// Currently, Backends (i.e. Service, ServiceImport, or any
2220
// implementation-specific backendRef) are the only valid API
2321
// target references.
24-
// +listType=map
25-
// +listMapKey=group
26-
// +listMapKey=kind
27-
// +listMapKey=name
2822
// +kubebuilder:validation:MinItems=1
2923
// +kubebuilder:validation:MaxItems=16
30-
TargetRefs []gatewayv1alpha2.LocalPolicyTargetReferenceWithSectionName `json:"targetRefs"`
24+
TargetRefs []BackendPolicyTargetReferenceWithSectionName `json:"targetRefs"`
3125
// LoadBalancer represents the load balancer configuration for Kubernetes Service.
3226
// The default strategy is round robin.
3327
LoadBalancer *LoadBalancer `json:"loadbalancer,omitempty" yaml:"loadbalancer,omitempty"`
@@ -74,9 +68,12 @@ type LoadBalancer struct {
7468
}
7569

7670
type Timeout struct {
71+
// +kubebuilder:default="60s"
7772
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"`
73+
// +kubebuilder:default="60s"
74+
Send metav1.Duration `json:"send,omitempty" yaml:"send,omitempty"`
75+
// +kubebuilder:default="60s"
76+
Read metav1.Duration `json:"read,omitempty" yaml:"read,omitempty"`
8077
}
8178

8279
// +kubebuilder:object:root=true

api/v1alpha1/gatewayproxy_types.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,10 @@ type ControlPlaneProvider struct {
113113
// +kubebuilder:validation:MinItems=1
114114
Endpoints []string `json:"endpoints"`
115115

116+
// TlsVerify specifies whether to verify the TLS certificate of the control plane
117+
// +optional
118+
TlsVerify *bool `json:"tlsVerify,omitempty"`
119+
116120
// Auth specifies the authentication configuration
117121
// +kubebuilder:validation:Required
118122
Auth ControlPlaneAuth `json:"auth"`

api/v1alpha1/policies_type.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package v1alpha1
2+
3+
import gatewayv1alpha2 "sigs.k8s.io/gateway-api/apis/v1alpha2"
4+
5+
type PolicyStatus gatewayv1alpha2.PolicyStatus
6+
7+
// +kubebuilder:validation:XValidation:rule="self.kind == 'Service' && self.group == \"\""
8+
type BackendPolicyTargetReferenceWithSectionName gatewayv1alpha2.LocalPolicyTargetReferenceWithSectionName

api/v1alpha1/zz_generated.deepcopy.go

Lines changed: 50 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/bases/gateway.apisix.io_backendtrafficpolicies.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -153,23 +153,23 @@ spec:
153153
- kind
154154
- name
155155
type: object
156+
x-kubernetes-validations:
157+
- rule: self.kind == 'Service' && self.group == ""
156158
maxItems: 16
157159
minItems: 1
158160
type: array
159-
x-kubernetes-list-map-keys:
160-
- group
161-
- kind
162-
- name
163-
x-kubernetes-list-type: map
164161
timeout:
165162
description: Timeout settings for the read, send and connect to the
166163
upstream.
167164
properties:
168165
connect:
166+
default: 60s
169167
type: string
170168
read:
169+
default: 60s
171170
type: string
172171
send:
172+
default: 60s
173173
type: string
174174
type: object
175175
upstream_host:

config/crd/bases/gateway.apisix.io_gatewayproxies.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,10 @@ spec:
108108
type: string
109109
minItems: 1
110110
type: array
111+
tlsVerify:
112+
description: TlsVerify specifies whether to verify the TLS
113+
certificate of the control plane
114+
type: boolean
111115
required:
112116
- auth
113117
- endpoints

config/samples/config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ gateway_configs: # The configuration of the API7 Gateway.
2424
control_plane:
2525
admin_key: "${ADMIN_KEY}" # The admin key of the control plane.
2626
endpoints:
27-
- ${ENDPOINT} # The endpoint of the control plane.
27+
- ${ENDPOINT} # The endpoint of the control plane.
2828
tls_verify: false
2929
addresses: # record the status address of the gateway-api gateway
3030
- "172.18.0.4" # The LB IP of the gateway service.

internal/controller/consumer_controller.go

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,24 @@ func (r *ConsumerReconciler) Reconcile(ctx context.Context, req ctrl.Request) (c
136136
}
137137

138138
var statusErr error
139-
tctx := provider.NewDefaultTranslateContext()
139+
tctx := provider.NewDefaultTranslateContext(ctx)
140+
141+
gateway, err := r.getGateway(ctx, consumer)
142+
if err != nil {
143+
r.Log.Error(err, "failed to get gateway", "consumer", consumer)
144+
statusErr = err
145+
}
146+
147+
rk := provider.ResourceKind{
148+
Kind: consumer.Kind,
149+
Namespace: consumer.Namespace,
150+
Name: consumer.Name,
151+
}
152+
153+
if err := ProcessGatewayProxy(r.Client, tctx, gateway, rk); err != nil {
154+
r.Log.Error(err, "failed to process gateway proxy", "gateway", gateway)
155+
statusErr = err
156+
}
140157

141158
if err := r.processSpec(ctx, tctx, consumer); err != nil {
142159
r.Log.Error(err, "failed to process consumer spec", "consumer", consumer)
@@ -201,6 +218,22 @@ func (r *ConsumerReconciler) updateStatus(ctx context.Context, consumer *v1alpha
201218
return nil
202219
}
203220

221+
func (r *ConsumerReconciler) getGateway(ctx context.Context, consumer *v1alpha1.Consumer) (*gatewayv1.Gateway, error) {
222+
ns := consumer.GetNamespace()
223+
if consumer.Spec.GatewayRef.Namespace != nil {
224+
ns = *consumer.Spec.GatewayRef.Namespace
225+
}
226+
gateway := &gatewayv1.Gateway{}
227+
if err := r.Get(ctx, client.ObjectKey{
228+
Name: consumer.Spec.GatewayRef.Name,
229+
Namespace: ns,
230+
}, gateway); err != nil {
231+
r.Log.Error(err, "failed to get gateway", "gateway", consumer.Spec.GatewayRef.Name)
232+
return nil, err
233+
}
234+
return gateway, nil
235+
}
236+
204237
func (r *ConsumerReconciler) checkGatewayRef(object client.Object) bool {
205238
consumer, ok := object.(*v1alpha1.Consumer)
206239
if !ok {

internal/controller/gateway_controller.go

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,10 @@ func (r *GatewayReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct
107107
status: true,
108108
msg: acceptedMessage("gateway"),
109109
}
110-
tctx := &provider.TranslateContext{
111-
Secrets: make(map[types.NamespacedName]*corev1.Secret),
112-
}
110+
111+
// create a translate context
112+
tctx := provider.NewDefaultTranslateContext(ctx)
113+
113114
r.processListenerConfig(tctx, gateway)
114115
if err := r.processInfrastructure(tctx, gateway); err != nil {
115116
acceptStatus = status{
@@ -267,28 +268,12 @@ func (r *GatewayReconciler) listGatewaysForHTTPRoute(_ context.Context, obj clie
267268
}
268269

269270
func (r *GatewayReconciler) processInfrastructure(tctx *provider.TranslateContext, gateway *gatewayv1.Gateway) error {
270-
infra := gateway.Spec.Infrastructure
271-
if infra == nil || infra.ParametersRef == nil {
272-
return nil
271+
rk := provider.ResourceKind{
272+
Kind: gateway.Kind,
273+
Namespace: gateway.Namespace,
274+
Name: gateway.Name,
273275
}
274-
275-
ns := gateway.GetNamespace()
276-
paramRef := infra.ParametersRef
277-
if string(paramRef.Group) == v1alpha1.GroupVersion.Group && string(paramRef.Kind) == "GatewayProxy" {
278-
gatewayProxy := &v1alpha1.GatewayProxy{}
279-
if err := r.Get(context.Background(), client.ObjectKey{
280-
Namespace: ns,
281-
Name: paramRef.Name,
282-
}, gatewayProxy); err != nil {
283-
log.Error(err, "failed to get GatewayProxy", "namespace", ns, "name", paramRef.Name)
284-
return err
285-
} else {
286-
log.Info("found GatewayProxy for Gateway", "gateway", gateway.Name, "gatewayproxy", gatewayProxy.Name)
287-
tctx.GatewayProxy = gatewayProxy
288-
}
289-
}
290-
291-
return nil
276+
return ProcessGatewayProxy(r.Client, tctx, gateway, rk)
292277
}
293278

294279
func (r *GatewayReconciler) processListenerConfig(tctx *provider.TranslateContext, gateway *gatewayv1.Gateway) {

internal/controller/httproute_controller.go

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,19 @@ func (r *HTTPRouteReconciler) Reconcile(ctx context.Context, req ctrl.Request) (
115115
return ctrl.Result{}, nil
116116
}
117117

118-
tctx := provider.NewDefaultTranslateContext()
118+
tctx := provider.NewDefaultTranslateContext(ctx)
119+
120+
rk := provider.ResourceKind{
121+
Kind: hr.Kind,
122+
Namespace: hr.Namespace,
123+
Name: hr.Name,
124+
}
125+
for _, gateway := range gateways {
126+
if err := ProcessGatewayProxy(r.Client, tctx, gateway.Gateway, rk); err != nil {
127+
acceptStatus.status = false
128+
acceptStatus.msg = err.Error()
129+
}
130+
}
119131

120132
if err := r.processHTTPRoute(tctx, hr); err != nil {
121133
acceptStatus.status = false
@@ -305,7 +317,7 @@ func (r *HTTPRouteReconciler) processHTTPRouteBackendRefs(tctx *provider.Transla
305317
}
306318

307319
var service corev1.Service
308-
if err := r.Get(context.TODO(), client.ObjectKey{
320+
if err := r.Get(tctx, client.ObjectKey{
309321
Namespace: namespace,
310322
Name: name,
311323
}, &service); err != nil {
@@ -324,9 +336,13 @@ func (r *HTTPRouteReconciler) processHTTPRouteBackendRefs(tctx *provider.Transla
324336
terr = fmt.Errorf("port %d not found in service %s", *backend.Port, name)
325337
continue
326338
}
339+
tctx.Services[client.ObjectKey{
340+
Namespace: namespace,
341+
Name: name,
342+
}] = &service
327343

328344
endpointSliceList := new(discoveryv1.EndpointSliceList)
329-
if err := r.List(context.TODO(), endpointSliceList,
345+
if err := r.List(tctx, endpointSliceList,
330346
client.InNamespace(namespace),
331347
client.MatchingLabels{
332348
discoveryv1.LabelServiceName: name,

0 commit comments

Comments
 (0)