Skip to content

Commit 215748b

Browse files
committed
fix: r
Signed-off-by: ashing <[email protected]>
1 parent 364200f commit 215748b

File tree

3 files changed

+35
-30
lines changed

3 files changed

+35
-30
lines changed

internal/controller/gateway_controller.go

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -277,20 +277,22 @@ func (r *GatewayReconciler) listGatewaysForHTTPRoute(_ context.Context, obj clie
277277

278278
func (r *GatewayReconciler) processInfrastructure(tctx *provider.TranslateContext, gateway *gatewayv1.Gateway, ns string) error {
279279
infra := gateway.Spec.Infrastructure
280-
if infra != nil && infra.ParametersRef != nil {
281-
paramRef := infra.ParametersRef
282-
if string(paramRef.Group) == v1alpha1.GroupVersion.Group && string(paramRef.Kind) == "GatewayProxy" {
283-
gatewayProxy := &v1alpha1.GatewayProxy{}
284-
if err := r.Get(context.Background(), client.ObjectKey{
285-
Namespace: ns,
286-
Name: paramRef.Name,
287-
}, gatewayProxy); err != nil {
288-
log.Error(err, "failed to get GatewayProxy", "namespace", ns, "name", paramRef.Name)
289-
return err
290-
} else {
291-
log.Info("found GatewayProxy for Gateway", "gateway", gateway.Name, "gatewayproxy", gatewayProxy.Name)
292-
tctx.GatewayProxy = gatewayProxy
293-
}
280+
if infra == nil || infra.ParametersRef == nil {
281+
return nil
282+
}
283+
284+
paramRef := infra.ParametersRef
285+
if string(paramRef.Group) == v1alpha1.GroupVersion.Group && string(paramRef.Kind) == "GatewayProxy" {
286+
gatewayProxy := &v1alpha1.GatewayProxy{}
287+
if err := r.Get(context.Background(), client.ObjectKey{
288+
Namespace: ns,
289+
Name: paramRef.Name,
290+
}, gatewayProxy); err != nil {
291+
log.Error(err, "failed to get GatewayProxy", "namespace", ns, "name", paramRef.Name)
292+
return err
293+
} else {
294+
log.Info("found GatewayProxy for Gateway", "gateway", gateway.Name, "gatewayproxy", gatewayProxy.Name)
295+
tctx.GatewayProxy = gatewayProxy
294296
}
295297
}
296298

internal/provider/adc/adc.go

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func (d *adcClient) Update(ctx context.Context, tctx *provider.TranslateContext,
4646
var result *translator.TranslateResult
4747
var err error
4848

49-
var task Task = Task{
49+
var task = Task{
5050
Name: obj.GetName(),
5151
Labels: label.GenLabel(obj),
5252
}
@@ -102,7 +102,7 @@ func (d *adcClient) Delete(ctx context.Context, obj client.Object) error {
102102
func (d *adcClient) sync(task Task, extraArgs ...string) error {
103103
log.Debugw("syncing task", zap.Any("task", task))
104104

105-
yaml, err := yaml.Marshal(task.Resources)
105+
data, err := yaml.Marshal(task.Resources)
106106
if err != nil {
107107
return err
108108
}
@@ -116,20 +116,17 @@ func (d *adcClient) sync(task Task, extraArgs ...string) error {
116116
_ = os.Remove(tmpFile.Name())
117117
}()
118118

119-
log.Debugw("syncing resources", zap.String("file", tmpFile.Name()), zap.String("yaml", string(yaml)))
119+
log.Debugw("syncing resources", zap.String("file", tmpFile.Name()), zap.String("yaml", string(data)))
120120

121-
if _, err := tmpFile.Write(yaml); err != nil {
121+
if _, err := tmpFile.Write(data); err != nil {
122122
return err
123123
}
124124
args := []string{
125125
"sync",
126126
"-f", tmpFile.Name(),
127127
"--tls-skip-verify",
128128
}
129-
130-
if len(extraArgs) > 0 {
131-
args = append(args, extraArgs...)
132-
}
129+
args = append(args, extraArgs...)
133130

134131
for k, v := range task.Labels {
135132
args = append(args, "--label-selector", k+"="+v)

test/e2e/gatewayapi/gatewayproxy.go

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -173,11 +173,7 @@ spec:
173173
Status(200)
174174

175175
resp.Header("X-Proxy-Test").IsEqual("enabled")
176-
})
177-
})
178176

179-
Context("Test Gateway with disabled GatewayProxy plugin", func() {
180-
It("Should not apply plugin configuration when disabled", func() {
181177
By("Update GatewayProxy with disabled plugin")
182178
err := s.CreateResourceFromString(gatewayProxyWithDisabledPlugin)
183179
Expect(err).NotTo(HaveOccurred(), "updating GatewayProxy with disabled plugin")
@@ -187,18 +183,28 @@ spec:
187183
ResourceApplied("HTTPRoute", "test-route", fmt.Sprintf(httpRouteForTest, "api7"), 1)
188184

189185
By("Check if the plugin is not applied")
190-
resp := s.NewAPISIXClient().
186+
resp = s.NewAPISIXClient().
191187
GET("/get").
192188
WithHost("example.com").
193189
Expect().
194190
Status(200)
195191

196192
resp.Header("X-Proxy-Test").IsEmpty()
197193
})
198-
})
199194

200-
Context("Test Gateway without GatewayProxy", func() {
201195
It("Should work normally without GatewayProxy", func() {
196+
By("Create HTTPRoute for Gateway with GatewayProxy")
197+
ResourceApplied("HTTPRoute", "test-route", fmt.Sprintf(httpRouteForTest, "api7"), 1)
198+
199+
By("Check if the plugin is applied")
200+
resp := s.NewAPISIXClient().
201+
GET("/get").
202+
WithHost("example.com").
203+
Expect().
204+
Status(200)
205+
206+
resp.Header("X-Proxy-Test").IsEqual("enabled")
207+
202208
By("Update Gateway without GatewayProxy")
203209
err := s.CreateResourceFromString(fmt.Sprintf(gatewayWithoutProxy, gatewayClassName))
204210
Expect(err).NotTo(HaveOccurred(), "updating Gateway without GatewayProxy")
@@ -208,7 +214,7 @@ spec:
208214
ResourceApplied("HTTPRoute", "test-route", fmt.Sprintf(httpRouteForTest, "api7"), 1)
209215

210216
By("Check if the route works without plugin")
211-
resp := s.NewAPISIXClient().
217+
resp = s.NewAPISIXClient().
212218
GET("/get").
213219
WithHost("example.com").
214220
Expect().

0 commit comments

Comments
 (0)