Skip to content

Commit 15c62e5

Browse files
committed
fix: r
Signed-off-by: ashing <[email protected]>
1 parent e70a2f8 commit 15c62e5

File tree

6 files changed

+81
-36
lines changed

6 files changed

+81
-36
lines changed

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,11 +196,11 @@ endif
196196

197197
.PHONY: install-gateway-api
198198
install-gateway-api: ## Install Gateway API CRDs into the K8s cluster specified in ~/.kube/config.
199-
kubectl apply -f https://github.com/kubernetes-sigs/gateway-api/releases/download/$(GATEAY_API_VERSION)/standard-install.yaml
199+
kubectl apply -f https://github.com/kubernetes-sigs/gateway-api/releases/download/$(GATEAY_API_VERSION)/experimental-install.yaml
200200

201201
.PHONY: uninstall-gateway-api
202202
uninstall-gateway-api: ## Uninstall Gateway API CRDs from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
203-
kubectl delete -f https://github.com/kubernetes-sigs/gateway-api/releases/download/$(GATEAY_API_VERSION)/standard-install.yaml
203+
kubectl delete -f https://github.com/kubernetes-sigs/gateway-api/releases/download/$(GATEAY_API_VERSION)/experimental-install.yaml
204204

205205
.PHONY: install
206206
install: manifests kustomize install-gateway-api ## Install CRDs into the K8s cluster specified in ~/.kube/config.

config/rbac/role.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,14 @@ rules:
5555
- get
5656
- list
5757
- watch
58+
- apiGroups:
59+
- gateway.apisix.io
60+
resources:
61+
- gatewayproxies
62+
verbs:
63+
- get
64+
- list
65+
- watch
5866
- apiGroups:
5967
- gateway.apisix.io
6068
resources:

internal/controller/gateway_controller.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,12 @@ func (r *GatewayReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct
120120
Secrets: make(map[types.NamespacedName]*corev1.Secret),
121121
}
122122
r.processListenerConfig(tctx, gateway, ns)
123-
r.processGatewayProxy(tctx, gateway, ns)
123+
if err := r.processGatewayProxy(tctx, gateway, ns); err != nil {
124+
acceptStatus = status{
125+
status: false,
126+
msg: err.Error(),
127+
}
128+
}
124129

125130
if err := r.Provider.Update(ctx, tctx, gateway); err != nil {
126131
acceptStatus = status{
@@ -267,7 +272,7 @@ func (r *GatewayReconciler) listGatewaysForHTTPRoute(_ context.Context, obj clie
267272
return recs
268273
}
269274

270-
func (r *GatewayReconciler) processGatewayProxy(tctx *provider.TranslateContext, gateway *gatewayv1.Gateway, ns string) {
275+
func (r *GatewayReconciler) processGatewayProxy(tctx *provider.TranslateContext, gateway *gatewayv1.Gateway, ns string) error {
271276
infra := gateway.Spec.Infrastructure
272277
if infra != nil && infra.ParametersRef != nil {
273278
paramRef := infra.ParametersRef
@@ -278,12 +283,15 @@ func (r *GatewayReconciler) processGatewayProxy(tctx *provider.TranslateContext,
278283
Name: paramRef.Name,
279284
}, gatewayProxy); err != nil {
280285
log.Error(err, "failed to get GatewayProxy", "namespace", ns, "name", paramRef.Name)
286+
return err
281287
} else {
282288
log.Info("found GatewayProxy for Gateway", "gateway", gateway.Name, "gatewayproxy", gatewayProxy.Name)
283289
tctx.GatewayProxy = gatewayProxy
284290
}
285291
}
286292
}
293+
294+
return nil
287295
}
288296

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

internal/manager/controllers.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
// +kubebuilder:rbac:groups="",resources=secrets,verbs=get;list;watch
1818
// +kubebuilder:rbac:groups="",resources=namespaces,verbs=get;list;watch
1919
// +kubebuilder:rbac:groups=gateway.apisix.io,resources=pluginconfigs,verbs=get;list;watch
20+
// +kubebuilder:rbac:groups=gateway.apisix.io,resources=gatewayproxies,verbs=get;list;watch
2021

2122
type Controller interface {
2223
SetupWithManager(mgr manager.Manager) error

test/e2e/framework/manifests/ingress.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ rules:
160160
- gateway.apisix.io
161161
resources:
162162
- pluginconfigs
163+
- gatewayproxies
163164
verbs:
164165
- get
165166
- list

test/e2e/gatewayapi/gatewayproxy.go

Lines changed: 59 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ spec:
4444
apiVersion: gateway.networking.k8s.io/v1
4545
kind: Gateway
4646
metadata:
47-
name: api7-no-proxy
47+
name: api7
4848
spec:
4949
gatewayClassName: %s
5050
listeners:
@@ -95,51 +95,81 @@ spec:
9595
- matches:
9696
- path:
9797
type: Exact
98-
value: /test
98+
value: /get
9999
backendRefs:
100100
- name: httpbin-service-e2e-test
101101
port: 80
102102
`
103103

104+
var ResourceApplied = func(resourType, resourceName, resourceRaw string, observedGeneration int) {
105+
Expect(s.CreateResourceFromString(resourceRaw)).
106+
NotTo(HaveOccurred(), fmt.Sprintf("creating %s", resourType))
107+
108+
Eventually(func() string {
109+
hryaml, err := s.GetResourceYaml(resourType, resourceName)
110+
Expect(err).NotTo(HaveOccurred(), fmt.Sprintf("getting %s yaml", resourType))
111+
return hryaml
112+
}, "8s", "2s").
113+
Should(
114+
SatisfyAll(
115+
ContainSubstring(`status: "True"`),
116+
ContainSubstring(fmt.Sprintf("observedGeneration: %d", observedGeneration)),
117+
),
118+
fmt.Sprintf("checking %s condition status", resourType),
119+
)
120+
time.Sleep(1 * time.Second)
121+
}
122+
123+
var (
124+
gatewayClassName string
125+
)
126+
104127
BeforeEach(func() {
105128
By("Create GatewayClass")
106-
gatewayClassName := fmt.Sprintf("api7-%d", time.Now().Unix())
129+
gatewayClassName = fmt.Sprintf("api7-%d", time.Now().Unix())
107130
err := s.CreateResourceFromStringWithNamespace(fmt.Sprintf(defaultGatewayClass, gatewayClassName, s.GetControllerName()), "")
108131
Expect(err).NotTo(HaveOccurred(), "creating GatewayClass")
109-
time.Sleep(3 * time.Second)
132+
time.Sleep(5 * time.Second)
110133

111134
By("Check GatewayClass condition")
112135
gcYaml, err := s.GetResourceYaml("GatewayClass", gatewayClassName)
113136
Expect(err).NotTo(HaveOccurred(), "getting GatewayClass yaml")
114137
Expect(gcYaml).To(ContainSubstring(`status: "True"`), "checking GatewayClass condition status")
115138
Expect(gcYaml).To(ContainSubstring("message: the gatewayclass has been accepted by the api7-ingress-controller"), "checking GatewayClass condition message")
116139

140+
By("Create GatewayProxy with enabled plugin")
141+
err = s.CreateResourceFromString(gatewayProxyWithEnabledPlugin)
142+
Expect(err).NotTo(HaveOccurred(), "creating GatewayProxy with enabled plugin")
143+
time.Sleep(5 * time.Second)
144+
117145
By("Create Gateway with GatewayProxy")
118146
err = s.CreateResourceFromString(fmt.Sprintf(gatewayWithProxy, gatewayClassName))
119147
Expect(err).NotTo(HaveOccurred(), "creating Gateway with GatewayProxy")
120-
time.Sleep(3 * time.Second)
148+
time.Sleep(5 * time.Second)
121149

122-
By("Create Gateway without GatewayProxy")
123-
err = s.CreateResourceFromString(fmt.Sprintf(gatewayWithoutProxy, gatewayClassName))
124-
Expect(err).NotTo(HaveOccurred(), "creating Gateway without GatewayProxy")
125-
time.Sleep(3 * time.Second)
150+
By("check Gateway condition")
151+
gwyaml, err := s.GetResourceYaml("Gateway", "api7")
152+
Expect(err).NotTo(HaveOccurred(), "getting Gateway yaml")
153+
Expect(gwyaml).To(ContainSubstring(`status: "True"`), "checking Gateway condition status")
154+
Expect(gwyaml).To(ContainSubstring("message: the gateway has been accepted by the api7-ingress-controller"), "checking Gateway condition message")
155+
})
156+
157+
AfterEach(func() {
158+
By("Clean up resources")
159+
_ = s.DeleteResourceFromString(gatewayProxyWithEnabledPlugin)
160+
_ = s.DeleteResourceFromString(gatewayProxyWithDisabledPlugin)
161+
_ = s.DeleteResourceFromString(fmt.Sprintf(httpRouteForTest, "api7"))
162+
_ = s.DeleteResourceFromString(fmt.Sprintf(gatewayWithProxy, gatewayClassName))
126163
})
127164

128165
Context("Test Gateway with enabled GatewayProxy plugin", func() {
129166
It("Should apply plugin configuration when enabled", func() {
130-
By("Create GatewayProxy with enabled plugin")
131-
err := s.CreateResourceFromString(gatewayProxyWithEnabledPlugin)
132-
Expect(err).NotTo(HaveOccurred(), "creating GatewayProxy with enabled plugin")
133-
time.Sleep(5 * time.Second)
134-
135167
By("Create HTTPRoute for Gateway with GatewayProxy")
136-
err = s.CreateResourceFromString(fmt.Sprintf(httpRouteForTest, "api7"))
137-
Expect(err).NotTo(HaveOccurred(), "creating HTTPRoute for Gateway with GatewayProxy")
138-
time.Sleep(5 * time.Second)
168+
ResourceApplied("HTTPRoute", "test-route", fmt.Sprintf(httpRouteForTest, "api7"), 1)
139169

140170
By("Check if the plugin is applied")
141171
resp := s.NewAPISIXClient().
142-
GET("/test").
172+
GET("/get").
143173
WithHost("example.com").
144174
Expect().
145175
Status(200)
@@ -155,9 +185,12 @@ spec:
155185
Expect(err).NotTo(HaveOccurred(), "updating GatewayProxy with disabled plugin")
156186
time.Sleep(5 * time.Second)
157187

188+
By("Create HTTPRoute for Gateway with GatewayProxy")
189+
ResourceApplied("HTTPRoute", "test-route", fmt.Sprintf(httpRouteForTest, "api7"), 1)
190+
158191
By("Check if the plugin is not applied")
159192
resp := s.NewAPISIXClient().
160-
GET("/test").
193+
GET("/get").
161194
WithHost("example.com").
162195
Expect().
163196
Status(200)
@@ -168,14 +201,17 @@ spec:
168201

169202
Context("Test Gateway without GatewayProxy", func() {
170203
It("Should work normally without GatewayProxy", func() {
171-
By("Create HTTPRoute for Gateway without GatewayProxy")
172-
err := s.CreateResourceFromString(fmt.Sprintf(httpRouteForTest, "api7-no-proxy"))
173-
Expect(err).NotTo(HaveOccurred(), "creating HTTPRoute for Gateway without GatewayProxy")
204+
By("Update Gateway without GatewayProxy")
205+
err := s.CreateResourceFromString(fmt.Sprintf(gatewayWithoutProxy, gatewayClassName))
206+
Expect(err).NotTo(HaveOccurred(), "updating Gateway without GatewayProxy")
174207
time.Sleep(5 * time.Second)
175208

209+
By("Create HTTPRoute for Gateway without GatewayProxy")
210+
ResourceApplied("HTTPRoute", "test-route", fmt.Sprintf(httpRouteForTest, "api7"), 1)
211+
176212
By("Check if the route works without plugin")
177213
resp := s.NewAPISIXClient().
178-
GET("/test").
214+
GET("/get").
179215
WithHost("example.com").
180216
Expect().
181217
Status(200)
@@ -184,13 +220,4 @@ spec:
184220
})
185221
})
186222

187-
AfterEach(func() {
188-
By("Clean up resources")
189-
_ = s.DeleteResourceFromString(gatewayProxyWithEnabledPlugin)
190-
_ = s.DeleteResourceFromString(fmt.Sprintf(httpRouteForTest, "api7"))
191-
_ = s.DeleteResourceFromString(fmt.Sprintf(httpRouteForTest, "api7-no-proxy"))
192-
_ = s.DeleteResourceFromString(fmt.Sprintf(gatewayWithProxy, "dummy"))
193-
_ = s.DeleteResourceFromString(fmt.Sprintf(gatewayWithoutProxy, "dummy"))
194-
time.Sleep(3 * time.Second)
195-
})
196223
})

0 commit comments

Comments
 (0)