Skip to content

Commit 6efdc28

Browse files
committed
e2e
1 parent 57f1aa9 commit 6efdc28

File tree

2 files changed

+53
-23
lines changed

2 files changed

+53
-23
lines changed

internal/provider/adc/translator/gateway.go

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
package translator
22

33
import (
4-
"encoding/json"
5-
64
adctypes "github.com/api7/api7-ingress-controller/api/adc"
75
"github.com/api7/api7-ingress-controller/api/v1alpha1"
86
"github.com/api7/api7-ingress-controller/internal/provider"
9-
"github.com/api7/gopkg/pkg/log"
10-
"go.uber.org/zap"
117
gatewayv1 "sigs.k8s.io/gateway-api/apis/v1"
128
)
139

@@ -19,19 +15,9 @@ func (t *Translator) FillPluginsFromGatewayProxy(plugins adctypes.Plugins, gatew
1915

2016
for _, plugin := range gatewayProxy.Spec.Plugins {
2117
// only apply enabled plugins
22-
if !plugin.Enabled {
23-
continue
24-
}
25-
26-
pluginName := plugin.Name
27-
var pluginConfig map[string]any
28-
if err := json.Unmarshal(plugin.Config.Raw, &pluginConfig); err != nil {
29-
log.Errorw("gateway proxy plugin config unmarshal failed", zap.Error(err), zap.String("plugin", pluginName))
30-
continue
18+
if plugin.Enabled {
19+
plugins[plugin.Name] = plugin.Config
3120
}
32-
33-
log.Debugw("fill plugin from gateway proxy", zap.String("plugin", pluginName), zap.Any("config", pluginConfig))
34-
plugins[pluginName] = pluginConfig
3521
}
3622
}
3723

@@ -58,6 +44,7 @@ func (t *Translator) TranslateGateway(tctx *provider.TranslateContext, gateway *
5844
t.FillPluginsFromGatewayProxy(globalRules, tctx.GatewayProxy)
5945
t.FillPluginMetadataFromGatewayProxy(pluginMetadata, tctx.GatewayProxy)
6046
result.GlobalRules = globalRules
47+
result.PluginMetadata = pluginMetadata
6148
}
6249

6350
return result, nil

test/e2e/gatewayapi/gatewayproxy.go

Lines changed: 50 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package gatewayapi
22

33
import (
44
"fmt"
5+
"net/http"
56
"time"
67

78
. "github.com/onsi/ginkgo/v2"
@@ -10,7 +11,7 @@ import (
1011
"github.com/api7/api7-ingress-controller/test/e2e/scaffold"
1112
)
1213

13-
var _ = FDescribe("Test GatewayProxy", func() {
14+
var _ = Describe("Test GatewayProxy", func() {
1415
s := scaffold.NewDefaultScaffold()
1516

1617
var defaultGatewayClass = `
@@ -80,6 +81,25 @@ spec:
8081
headers:
8182
X-Proxy-Test: "disabled"
8283
`
84+
var gatewayProxyWithPluginMetadata = `
85+
apiVersion: gateway.apisix.io/v1alpha1
86+
kind: GatewayProxy
87+
metadata:
88+
name: api7-proxy-config
89+
spec:
90+
plugins:
91+
- name: error_page
92+
enabled: true
93+
config: {}
94+
pluginMetadata:
95+
error_page: {
96+
"enable": true,
97+
"error_404": {
98+
"body": "404 from plugin metadata",
99+
"content-type": "text/plain"
100+
}
101+
}
102+
`
83103

84104
var httpRouteForTest = `
85105
apiVersion: gateway.networking.k8s.io/v1
@@ -101,21 +121,21 @@ spec:
101121
port: 80
102122
`
103123

104-
var ResourceApplied = func(resourType, resourceName, resourceRaw string, observedGeneration int) {
124+
var ResourceApplied = func(resourceType, resourceName, resourceRaw string, observedGeneration int) {
105125
Expect(s.CreateResourceFromString(resourceRaw)).
106-
NotTo(HaveOccurred(), fmt.Sprintf("creating %s", resourType))
126+
NotTo(HaveOccurred(), fmt.Sprintf("creating %s", resourceType))
107127

108128
Eventually(func() string {
109-
hryaml, err := s.GetResourceYaml(resourType, resourceName)
110-
Expect(err).NotTo(HaveOccurred(), fmt.Sprintf("getting %s yaml", resourType))
129+
hryaml, err := s.GetResourceYaml(resourceType, resourceName)
130+
Expect(err).NotTo(HaveOccurred(), fmt.Sprintf("getting %s yaml", resourceType))
111131
return hryaml
112-
}, "8s", "2s").
132+
}).WithTimeout(8*time.Second).ProbeEvery(2*time.Second).
113133
Should(
114134
SatisfyAll(
115135
ContainSubstring(`status: "True"`),
116136
ContainSubstring(fmt.Sprintf("observedGeneration: %d", observedGeneration)),
117137
),
118-
fmt.Sprintf("checking %s condition status", resourType),
138+
fmt.Sprintf("checking %s condition status", resourceType),
119139
)
120140
time.Sleep(1 * time.Second)
121141
}
@@ -220,4 +240,27 @@ spec:
220240
})
221241
})
222242

243+
FContext("Test Gateway with PluginMetadata", func() {
244+
var (
245+
err error
246+
)
247+
248+
It("Should work OK with error_page", func() {
249+
By("Update GatewayProxy with PluginMetadata")
250+
err = s.CreateResourceFromString(gatewayProxyWithPluginMetadata)
251+
Ω(err).ShouldNot(HaveOccurred())
252+
time.Sleep(5 * time.Second)
253+
254+
By("Create HTTPRoute for Gateway with GatewayProxy")
255+
ResourceApplied("HTTPRoute", "test-route", fmt.Sprintf(httpRouteForTest, "api7"), 1)
256+
257+
By("Check PluginMetadata working")
258+
s.NewAPISIXClient().
259+
GET("/get").
260+
WithHost("example.com").
261+
Expect().
262+
Status(http.StatusNotFound).
263+
Body().Contains("404 from plugin metadata")
264+
})
265+
})
223266
})

0 commit comments

Comments
 (0)