Skip to content

Commit 9fb1138

Browse files
committed
f:
1 parent f10df1d commit 9fb1138

File tree

7 files changed

+59
-28
lines changed

7 files changed

+59
-28
lines changed

internal/controller/gateway_controller.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ func (r *GatewayReconciler) SetupWithManager(mgr ctrl.Manager) error {
5454
}
5555
return ctrl.NewControllerManagedBy(mgr).
5656
For(&gatewayv1.Gateway{}).
57+
WithEventFilter(predicate.GenerationChangedPredicate{}).
5758
Watches(
5859
&gatewayv1.GatewayClass{},
5960
handler.EnqueueRequestsFromMapFunc(r.listGatewayForGatewayClass),
@@ -120,7 +121,7 @@ func (r *GatewayReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct
120121
Secrets: make(map[types.NamespacedName]*corev1.Secret),
121122
}
122123
r.processListenerConfig(tctx, gateway, ns)
123-
if err := r.processGatewayProxy(tctx, gateway, ns); err != nil {
124+
if err := r.processInfrastructure(tctx, gateway, ns); err != nil {
124125
acceptStatus = status{
125126
status: false,
126127
msg: err.Error(),
@@ -136,6 +137,7 @@ func (r *GatewayReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct
136137

137138
ListenerStatuses, err := getListenerStatus(ctx, r.Client, gateway)
138139
if err != nil {
140+
log.Error(err, "failed to get listener status", "gateway", gateway.GetName())
139141
return ctrl.Result{}, err
140142
}
141143

@@ -151,6 +153,7 @@ func (r *GatewayReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct
151153

152154
return ctrl.Result{}, r.Status().Update(ctx, gateway)
153155
}
156+
154157
return ctrl.Result{}, nil
155158
}
156159

@@ -272,7 +275,7 @@ func (r *GatewayReconciler) listGatewaysForHTTPRoute(_ context.Context, obj clie
272275
return recs
273276
}
274277

275-
func (r *GatewayReconciler) processGatewayProxy(tctx *provider.TranslateContext, gateway *gatewayv1.Gateway, ns string) error {
278+
func (r *GatewayReconciler) processInfrastructure(tctx *provider.TranslateContext, gateway *gatewayv1.Gateway, ns string) error {
276279
infra := gateway.Spec.Infrastructure
277280
if infra != nil && infra.ParametersRef != nil {
278281
paramRef := infra.ParametersRef

internal/controller/httproute_controller.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
ctrl "sigs.k8s.io/controller-runtime"
1515
"sigs.k8s.io/controller-runtime/pkg/client"
1616
"sigs.k8s.io/controller-runtime/pkg/handler"
17+
"sigs.k8s.io/controller-runtime/pkg/predicate"
1718
"sigs.k8s.io/controller-runtime/pkg/reconcile"
1819
gatewayv1 "sigs.k8s.io/gateway-api/apis/v1"
1920

@@ -42,6 +43,7 @@ func (r *HTTPRouteReconciler) SetupWithManager(mgr ctrl.Manager) error {
4243
}
4344
return ctrl.NewControllerManagedBy(mgr).
4445
For(&gatewayv1.HTTPRoute{}).
46+
WithEventFilter(predicate.GenerationChangedPredicate{}).
4547
Watches(&discoveryv1.EndpointSlice{},
4648
handler.EnqueueRequestsFromMapFunc(r.listHTTPRoutesByServiceBef),
4749
).
@@ -96,6 +98,7 @@ func (r *HTTPRouteReconciler) Reconcile(ctx context.Context, req ctrl.Request) (
9698
}
9799

98100
tctx := provider.NewDefaultTranslateContext()
101+
99102
if err := r.processHTTPRoute(tctx, hr); err != nil {
100103
acceptStatus.status = false
101104
acceptStatus.msg = err.Error()
@@ -113,8 +116,6 @@ func (r *HTTPRouteReconciler) Reconcile(ctx context.Context, req ctrl.Request) (
113116
acceptStatus.msg = err.Error()
114117
}
115118

116-
// process the HTTPRoute
117-
118119
// TODO: diff the old and new status
119120
hr.Status.Parents = make([]gatewayv1.RouteParentStatus, 0, len(gateways))
120121
for _, gateway := range gateways {
@@ -139,15 +140,15 @@ func (r *HTTPRouteReconciler) Reconcile(ctx context.Context, req ctrl.Request) (
139140
// SetupWithManager sets up the controller with the Manager.
140141
func (r *HTTPRouteReconciler) setupIndexer(mgr ctrl.Manager) error {
141142
if err := mgr.GetFieldIndexer().IndexField(
142-
context.TODO(),
143+
context.Background(),
143144
&gatewayv1.HTTPRoute{},
144145
indexer.ExtensionRef,
145146
indexer.HTTPRouteExtensionIndexFunc,
146147
); err != nil {
147148
return err
148149
}
149150
if err := mgr.GetFieldIndexer().IndexField(
150-
context.TODO(),
151+
context.Background(),
151152
&gatewayv1.HTTPRoute{},
152153
indexer.ServiceIndexRef,
153154
indexer.HTTPRouteServiceIndexFunc,

internal/controller/indexer/indexer.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ func GatewayParametersRefIndexFunc(rawObj client.Object) []string {
5757
if gw.Spec.Infrastructure != nil && gw.Spec.Infrastructure.ParametersRef != nil {
5858
// now we only care about kind: GatewayProxy
5959
if gw.Spec.Infrastructure.ParametersRef.Kind == "GatewayProxy" {
60-
return []string{GenIndexKey(gw.GetNamespace(), gw.Spec.Infrastructure.ParametersRef.Name)}
60+
name := gw.Spec.Infrastructure.ParametersRef.Name
61+
return []string{GenIndexKey(gw.GetNamespace(), name)}
6162
}
6263
}
6364
return nil

internal/provider/adc/adc.go

Lines changed: 41 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,31 @@ func New() (provider.Provider, error) {
4343
}
4444

4545
func (d *adcClient) Update(ctx context.Context, tctx *provider.TranslateContext, obj client.Object) error {
46-
var result *translator.TranslateResult
47-
var err error
46+
var (
47+
task = Task{
48+
Name: obj.GetName(),
49+
Labels: label.GenLabel(obj),
50+
}
51+
extraArgs []string
52+
result *translator.TranslateResult
53+
err error
54+
)
4855

4956
switch obj := obj.(type) {
5057
case *gatewayv1.HTTPRoute:
58+
extraArgs = append(extraArgs, "--include-resource-type", "service")
59+
log.Debugw("translating http route", zap.Any("http route", obj))
5160
result, err = d.translator.TranslateHTTPRoute(tctx, obj.DeepCopy())
5261
case *gatewayv1.Gateway:
62+
extraArgs = append(extraArgs, "--include-resource-type", "global_rule",
63+
"--include-resource-type", "plugin_metadata")
64+
log.Debugw("translating gateway", zap.Any("gateway", obj))
5365
result, err = d.translator.TranslateGateway(tctx, obj.DeepCopy())
5466
}
5567
if err != nil {
5668
return err
5769
}
70+
log.Debugw("translated result", zap.Any("result", result))
5871
if result == nil {
5972
return nil
6073
}
@@ -64,22 +77,33 @@ func (d *adcClient) Update(ctx context.Context, tctx *provider.TranslateContext,
6477
PluginMetadata: result.PluginMetadata,
6578
Services: result.Services,
6679
}
80+
log.Debugw("adc resources", zap.Any("resources", resources))
81+
82+
task.Resources = resources
6783

68-
return d.sync(Task{
69-
Name: obj.GetName(),
70-
Resources: resources,
71-
Labels: label.GenLabel(obj),
72-
})
84+
return d.sync(task, extraArgs...)
7385
}
7486

7587
func (d *adcClient) Delete(ctx context.Context, obj client.Object) error {
76-
return d.sync(Task{
88+
task := Task{
7789
Name: obj.GetName(),
7890
Labels: label.GenLabel(obj),
79-
})
91+
}
92+
93+
var extraArgs []string
94+
95+
switch obj.(type) {
96+
case *gatewayv1.HTTPRoute:
97+
extraArgs = append(extraArgs, "--include-resource-type", "service")
98+
case *gatewayv1.Gateway:
99+
extraArgs = append(extraArgs, "--include-resource-type", "global_rule",
100+
"--include-resource-type", "plugin_metadata")
101+
}
102+
103+
return d.sync(task, extraArgs...)
80104
}
81105

82-
func (d *adcClient) sync(task Task) error {
106+
func (d *adcClient) sync(task Task, extraArgs ...string) error {
83107
log.Debugw("syncing task", zap.Any("task", task))
84108

85109
data, err := yaml.Marshal(task.Resources)
@@ -104,12 +128,13 @@ func (d *adcClient) sync(task Task) error {
104128
args := []string{
105129
"sync",
106130
"-f", tmpFile.Name(),
107-
"--include-resource-type", "service",
108-
"--include-resource-type", "global_rule",
109-
"--include-resource-type", "plugin_metadata",
110131
"--tls-skip-verify",
111132
}
112133

134+
if len(extraArgs) > 0 {
135+
args = append(args, extraArgs...)
136+
}
137+
113138
for k, v := range task.Labels {
114139
args = append(args, "--label-selector", k+"="+v)
115140
}
@@ -134,5 +159,8 @@ func (d *adcClient) sync(task Task) error {
134159
)
135160
return err
136161
}
162+
163+
log.Debugw("adc sync success", zap.String("taskname", task.Name))
164+
137165
return nil
138166
}

internal/provider/adc/translator/gateway.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import (
77
gatewayv1 "sigs.k8s.io/gateway-api/apis/v1"
88
)
99

10-
// FillPluginsFromGatewayProxy fill plugins from GatewayProxy to given plugins
11-
func (t *Translator) FillPluginsFromGatewayProxy(plugins adctypes.Plugins, gatewayProxy *v1alpha1.GatewayProxy) {
10+
// fillPluginsFromGatewayProxy fill plugins from GatewayProxy to given plugins
11+
func (t *Translator) fillPluginsFromGatewayProxy(plugins adctypes.Plugins, gatewayProxy *v1alpha1.GatewayProxy) {
1212
if gatewayProxy == nil {
1313
return
1414
}
@@ -21,7 +21,7 @@ func (t *Translator) FillPluginsFromGatewayProxy(plugins adctypes.Plugins, gatew
2121
}
2222
}
2323

24-
func (t *Translator) FillPluginMetadataFromGatewayProxy(pluginMetadata adctypes.Plugins, gatewayProxy *v1alpha1.GatewayProxy) {
24+
func (t *Translator) fillPluginMetadataFromGatewayProxy(pluginMetadata adctypes.Plugins, gatewayProxy *v1alpha1.GatewayProxy) {
2525
if gatewayProxy == nil {
2626
return
2727
}
@@ -41,8 +41,8 @@ func (t *Translator) TranslateGateway(tctx *provider.TranslateContext, gateway *
4141
pluginMetadata = adctypes.Plugins{}
4242
)
4343
// apply plugins from GatewayProxy to global rules
44-
t.FillPluginsFromGatewayProxy(globalRules, tctx.GatewayProxy)
45-
t.FillPluginMetadataFromGatewayProxy(pluginMetadata, tctx.GatewayProxy)
44+
t.fillPluginsFromGatewayProxy(globalRules, tctx.GatewayProxy)
45+
t.fillPluginMetadataFromGatewayProxy(pluginMetadata, tctx.GatewayProxy)
4646
result.GlobalRules = globalRules
4747
result.PluginMetadata = pluginMetadata
4848
}

test/conformance/conformance_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ var skippedTestsForTraditionalRoutes = []string{
5656
tests.HTTPRouteInvalidReferenceGrant.ShortName,
5757
}
5858

59-
var gatewaySupportedFeatures = []features.SupportedFeature{
59+
var gatewaySupportedFeatures = []features.FeatureName{
6060
features.SupportGateway,
6161
features.SupportHTTPRoute,
6262
// features.SupportHTTPRouteMethodMatching,

test/e2e/gatewayapi/gatewayproxy.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,6 @@ spec:
137137
),
138138
fmt.Sprintf("checking %s condition status", resourceType),
139139
)
140-
time.Sleep(1 * time.Second)
141140
}
142141

143142
var (
@@ -177,7 +176,6 @@ spec:
177176
AfterEach(func() {
178177
By("Clean up resources")
179178
_ = s.DeleteResourceFromString(gatewayProxyWithEnabledPlugin)
180-
_ = s.DeleteResourceFromString(gatewayProxyWithDisabledPlugin)
181179
_ = s.DeleteResourceFromString(fmt.Sprintf(httpRouteForTest, "api7"))
182180
_ = s.DeleteResourceFromString(fmt.Sprintf(gatewayWithProxy, gatewayClassName))
183181
})

0 commit comments

Comments
 (0)