Skip to content

Commit d80c0f2

Browse files
committed
fix: add test case
Signed-off-by: ashing <[email protected]>
1 parent 2fc258a commit d80c0f2

File tree

7 files changed

+300
-14
lines changed

7 files changed

+300
-14
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,4 @@ api7-ingress-controller-conformance-report.yaml
3333

3434
*.mdx
3535
.cursor/
36-
36+
.env

Makefile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,15 @@ kind-load-images: pull-infra-images kind-load-ingress-image
140140
@kind load docker-image kennethreitz/httpbin:latest --name $(KIND_NAME)
141141
@kind load docker-image jmalloc/echo-server:latest --name $(KIND_NAME)
142142

143+
.PHONY: kind-load-gateway-image
144+
kind-load-gateway-image:
145+
@kind load docker-image hkccr.ccs.tencentyun.com/api7-dev/api7-ee-3-gateway:dev --name $(KIND_NAME)
146+
147+
.PHONY: kind-load-dashboard-images
148+
kind-load-dashboard-images:
149+
@kind load docker-image hkccr.ccs.tencentyun.com/api7-dev/api7-ee-dp-manager:$(DASHBOARD_VERSION) --name $(KIND_NAME)
150+
@kind load docker-image hkccr.ccs.tencentyun.com/api7-dev/api7-ee-3-integrated:$(DASHBOARD_VERSION) --name $(KIND_NAME)
151+
143152
.PHONY: kind-load-ingress-image
144153
kind-load-ingress-image:
145154
@kind load docker-image $(IMG) --name $(KIND_NAME)

internal/provider/adc/adc.go

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,7 @@ type adcConfig struct {
3232
type adcClient struct {
3333
sync.Mutex
3434

35-
translator *translator.Translator
36-
ServerAddr string
37-
Token string
38-
GatewayGroup string
35+
translator *translator.Translator
3936
// gateway/ingressclass -> adcConfig
4037
configs map[provider.ResourceKind]adcConfig
4138
// httproute/consumer/ingress/gateway -> gateway/ingressclass
@@ -164,6 +161,7 @@ func (d *adcClient) Delete(ctx context.Context, obj client.Object) error {
164161
}
165162

166163
configs := d.getConfigs(rk)
164+
defer d.deleteConfigs(rk)
167165

168166
err := d.sync(ctx, Task{
169167
Name: obj.GetName(),
@@ -175,7 +173,6 @@ func (d *adcClient) Delete(ctx context.Context, obj client.Object) error {
175173
return err
176174
}
177175

178-
d.deleteConfigs(rk)
179176
return nil
180177
}
181178

@@ -233,14 +230,8 @@ func (d *adcClient) execADC(ctx context.Context, config adcConfig, args []string
233230
ctxWithTimeout, cancel := context.WithTimeout(ctx, d.syncTimeout)
234231
defer cancel()
235232
// todo: use adc config
236-
serverAddr := d.ServerAddr
237-
if config.ServerAddr != "" {
238-
serverAddr = config.ServerAddr
239-
}
240-
token := d.Token
241-
if config.Token != "" {
242-
token = config.Token
243-
}
233+
serverAddr := config.ServerAddr
234+
token := config.Token
244235

245236
adcEnv := []string{
246237
"ADC_EXPERIMENTAL_FEATURE_FLAGS=remote-state-file,parallel-backend-request",

test/e2e/crds/consumer.go

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
package gatewayapi
22

33
import (
4+
"fmt"
45
"time"
56

67
. "github.com/onsi/ginkgo/v2"
78
. "github.com/onsi/gomega"
89

10+
"github.com/api7/api7-ingress-controller/test/e2e/framework"
911
"github.com/api7/api7-ingress-controller/test/e2e/scaffold"
1012
)
1113

@@ -376,4 +378,89 @@ spec:
376378
Status(401)
377379
})
378380
})
381+
382+
Context("Consumer with GatewayProxy Update", func() {
383+
var additionalGatewayGroupID string
384+
385+
var defaultCredential = `
386+
apiVersion: apisix.apache.org/v1alpha1
387+
kind: Consumer
388+
metadata:
389+
name: consumer-sample
390+
spec:
391+
gatewayRef:
392+
name: api7ee
393+
credentials:
394+
- type: basic-auth
395+
name: basic-auth-sample
396+
config:
397+
username: sample-user
398+
password: sample-password
399+
`
400+
var updatedGatewayProxy = `
401+
apiVersion: apisix.apache.org/v1alpha1
402+
kind: GatewayProxy
403+
metadata:
404+
name: api7-proxy-config
405+
spec:
406+
provider:
407+
type: ControlPlane
408+
controlPlane:
409+
endpoints:
410+
- %s
411+
auth:
412+
type: AdminKey
413+
adminKey:
414+
value: "%s"
415+
`
416+
417+
BeforeEach(func() {
418+
s.ApplyDefaultGatewayResource(defaultGatewayProxy, defaultGatewayClass, defaultGateway, defaultHTTPRoute)
419+
})
420+
421+
It("Should sync consumer when GatewayProxy is updated", func() {
422+
s.ResourceApplied("Consumer", "consumer-sample", defaultCredential, 1)
423+
424+
// verify basic-auth works
425+
s.NewAPISIXClient().
426+
GET("/get").
427+
WithBasicAuth("sample-user", "sample-password").
428+
WithHost("httpbin.org").
429+
Expect().
430+
Status(200)
431+
432+
By("create additional gateway group to get new admin key")
433+
var err error
434+
additionalGatewayGroupID, _, err = s.CreateAdditionalGatewayGroup("gateway-proxy-update")
435+
Expect(err).NotTo(HaveOccurred(), "creating additional gateway group")
436+
437+
resources, exists := s.GetAdditionalGatewayGroup(additionalGatewayGroupID)
438+
Expect(exists).To(BeTrue(), "additional gateway group should exist")
439+
440+
client, err := s.NewAPISIXClientForGatewayGroup(additionalGatewayGroupID)
441+
Expect(err).NotTo(HaveOccurred(), "creating APISIX client for additional gateway group")
442+
443+
By("Consumer not found for additional gateway group")
444+
client.
445+
GET("/get").
446+
WithBasicAuth("sample-user", "sample-password").
447+
WithHost("httpbin.org").
448+
Expect().
449+
Status(404)
450+
451+
By("update GatewayProxy with new admin key")
452+
updatedProxy := fmt.Sprintf(updatedGatewayProxy, framework.DashboardTLSEndpoint, resources.AdminAPIKey)
453+
err = s.CreateResourceFromString(updatedProxy)
454+
Expect(err).NotTo(HaveOccurred(), "updating GatewayProxy")
455+
time.Sleep(30 * time.Second)
456+
457+
By("verify Consumer works for additional gateway group")
458+
client.
459+
GET("/get").
460+
WithBasicAuth("sample-user", "sample-password").
461+
WithHost("httpbin.org").
462+
Expect().
463+
Status(200)
464+
})
465+
})
379466
})

test/e2e/framework/dashboard.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,7 @@ func (f *Framework) GetDataplaneCertificates(gatewayGroupID string) *v1.Dataplan
367367
POST("/api/gateway_groups/"+gatewayGroupID+"/dp_client_certificates").
368368
WithBasicAuth("admin", "admin").
369369
WithHeader("Content-Type", "application/json").
370+
WithBytes([]byte(`{}`)).
370371
Expect()
371372

372373
f.Logger.Logf(f.GinkgoT, "dataplane certificates issuer response: %s", respExp.Body().Raw())

test/e2e/gatewayapi/httproute.go

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1394,6 +1394,92 @@ spec:
13941394
})
13951395
})
13961396

1397+
Context("HTTPRoute with GatewayProxy Update", func() {
1398+
var additionalGatewayGroupID string
1399+
1400+
var exactRouteByGet = `
1401+
apiVersion: gateway.networking.k8s.io/v1
1402+
kind: HTTPRoute
1403+
metadata:
1404+
name: httpbin
1405+
spec:
1406+
parentRefs:
1407+
- name: api7ee
1408+
hostnames:
1409+
- httpbin.example
1410+
rules:
1411+
- matches:
1412+
- path:
1413+
type: Exact
1414+
value: /get
1415+
backendRefs:
1416+
- name: httpbin-service-e2e-test
1417+
port: 80
1418+
`
1419+
1420+
var updatedGatewayProxy = `
1421+
apiVersion: apisix.apache.org/v1alpha1
1422+
kind: GatewayProxy
1423+
metadata:
1424+
name: api7-proxy-config
1425+
spec:
1426+
provider:
1427+
type: ControlPlane
1428+
controlPlane:
1429+
endpoints:
1430+
- %s
1431+
auth:
1432+
type: AdminKey
1433+
adminKey:
1434+
value: "%s"
1435+
`
1436+
1437+
BeforeEach(beforeEachHTTP)
1438+
1439+
It("Should sync HTTPRoute when GatewayProxy is updated", func() {
1440+
By("create HTTPRoute")
1441+
ResourceApplied("HTTPRoute", "httpbin", exactRouteByGet, 1)
1442+
1443+
By("verify HTTPRoute works")
1444+
s.NewAPISIXClient().
1445+
GET("/get").
1446+
WithHost("httpbin.example").
1447+
Expect().
1448+
Status(200)
1449+
1450+
By("create additional gateway group to get new admin key")
1451+
var err error
1452+
additionalGatewayGroupID, _, err = s.CreateAdditionalGatewayGroup("gateway-proxy-update")
1453+
Expect(err).NotTo(HaveOccurred(), "creating additional gateway group")
1454+
1455+
resources, exists := s.GetAdditionalGatewayGroup(additionalGatewayGroupID)
1456+
Expect(exists).To(BeTrue(), "additional gateway group should exist")
1457+
1458+
client, err := s.NewAPISIXClientForGatewayGroup(additionalGatewayGroupID)
1459+
Expect(err).NotTo(HaveOccurred(), "creating APISIX client for additional gateway group")
1460+
1461+
By("HTTPRoute not found for additional gateway group")
1462+
client.
1463+
GET("/get").
1464+
WithHost("httpbin.example").
1465+
Expect().
1466+
Status(404)
1467+
1468+
By("update GatewayProxy with new admin key")
1469+
updatedProxy := fmt.Sprintf(updatedGatewayProxy, framework.DashboardTLSEndpoint, resources.AdminAPIKey)
1470+
err = s.CreateResourceFromString(updatedProxy)
1471+
Expect(err).NotTo(HaveOccurred(), "updating GatewayProxy")
1472+
time.Sleep(5 * time.Second)
1473+
1474+
By("verify HTTPRoute works for additional gateway group")
1475+
client.
1476+
GET("/get").
1477+
WithHost("httpbin.example").
1478+
Expect().
1479+
Status(200)
1480+
})
1481+
})
1482+
13971483
/*
13981484
Context("HTTPRoute Status Updated", func() {
13991485
})

test/e2e/ingress/ingress.go

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -638,4 +638,116 @@ spec:
638638
WithTimeout(8 * time.Second).ProbeEvery(time.Second).Should(Equal(http.StatusOK))
639639
})
640640
})
641+
642+
Context("Ingress with GatewayProxy Update", func() {
643+
var additionalGatewayGroupID string
644+
645+
var ingressClass = `
646+
apiVersion: networking.k8s.io/v1
647+
kind: IngressClass
648+
metadata:
649+
name: api7-ingress-class
650+
spec:
651+
controller: "apisix.apache.org/api7-ingress-controller"
652+
parameters:
653+
apiGroup: "apisix.apache.org"
654+
kind: "GatewayProxy"
655+
name: "api7-proxy-config"
656+
namespace: "default"
657+
scope: "Namespace"
658+
`
659+
var ingress = `
660+
apiVersion: networking.k8s.io/v1
661+
kind: Ingress
662+
metadata:
663+
name: api7-ingress
664+
spec:
665+
ingressClassName: api7-ingress-class
666+
rules:
667+
- host: ingress.example.com
668+
http:
669+
paths:
670+
- path: /
671+
pathType: Prefix
672+
backend:
673+
service:
674+
name: httpbin-service-e2e-test
675+
port:
676+
number: 80
677+
`
678+
var updatedGatewayProxy = `
679+
apiVersion: apisix.apache.org/v1alpha1
680+
kind: GatewayProxy
681+
metadata:
682+
name: api7-proxy-config
683+
namespace: default
684+
spec:
685+
provider:
686+
type: ControlPlane
687+
controlPlane:
688+
endpoints:
689+
- %s
690+
auth:
691+
type: AdminKey
692+
adminKey:
693+
value: "%s"
694+
`
695+
696+
BeforeEach(func() {
697+
By("create GatewayProxy")
698+
gatewayProxy := fmt.Sprintf(gatewayProxyYaml, framework.DashboardTLSEndpoint, s.AdminKey())
699+
err := s.CreateResourceFromStringWithNamespace(gatewayProxy, "default")
700+
Expect(err).NotTo(HaveOccurred(), "creating GatewayProxy")
701+
time.Sleep(5 * time.Second)
702+
703+
By("create IngressClass")
704+
err = s.CreateResourceFromStringWithNamespace(ingressClass, "")
705+
Expect(err).NotTo(HaveOccurred(), "creating IngressClass")
706+
time.Sleep(5 * time.Second)
707+
})
708+
709+
It("Should sync Ingress when GatewayProxy is updated", func() {
710+
By("create Ingress")
711+
err := s.CreateResourceFromString(ingress)
712+
Expect(err).NotTo(HaveOccurred(), "creating Ingress")
713+
time.Sleep(5 * time.Second)
714+
715+
By("verify Ingress works")
716+
s.NewAPISIXClient().
717+
GET("/get").
718+
WithHost("ingress.example.com").
719+
Expect().
720+
Status(200)
721+
722+
By("create additional gateway group to get new admin key")
723+
additionalGatewayGroupID, _, err = s.CreateAdditionalGatewayGroup("gateway-proxy-update")
724+
Expect(err).NotTo(HaveOccurred(), "creating additional gateway group")
725+
726+
client, err := s.NewAPISIXClientForGatewayGroup(additionalGatewayGroupID)
727+
Expect(err).NotTo(HaveOccurred(), "creating APISIX client for additional gateway group")
728+
729+
By("Ingress not found for additional gateway group")
730+
client.
731+
GET("/get").
732+
WithHost("ingress.example.com").
733+
Expect().
734+
Status(404)
735+
736+
resources, exists := s.GetAdditionalGatewayGroup(additionalGatewayGroupID)
737+
Expect(exists).To(BeTrue(), "additional gateway group should exist")
738+
739+
By("update GatewayProxy with new admin key")
740+
updatedProxy := fmt.Sprintf(updatedGatewayProxy, framework.DashboardTLSEndpoint, resources.AdminAPIKey)
741+
err = s.CreateResourceFromStringWithNamespace(updatedProxy, "default")
742+
Expect(err).NotTo(HaveOccurred(), "updating GatewayProxy")
743+
time.Sleep(5 * time.Second)
744+
745+
By("verify Ingress works for additional gateway group")
746+
client.
747+
GET("/get").
748+
WithHost("ingress.example.com").
749+
Expect().
750+
Status(200)
751+
})
752+
})
641753
})

0 commit comments

Comments
 (0)