Skip to content

Commit 73fa5ef

Browse files
committed
feat: add support for "apisix" provider_type
1 parent 4ee2596 commit 73fa5ef

File tree

11 files changed

+49
-67
lines changed

11 files changed

+49
-67
lines changed

.github/workflows/apisix-conformance-test.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ jobs:
3636
timeout-minutes: 60
3737
needs:
3838
- prepare
39+
strategy:
40+
matrix:
41+
provider_type:
42+
- apisix-standalone
43+
- apisix
3944
runs-on: buildjet-2vcpu-ubuntu-2204
4045
steps:
4146
- name: Checkout
@@ -79,6 +84,8 @@ jobs:
7984
- name: Run Conformance Test
8085
shell: bash
8186
continue-on-error: true
87+
env:
88+
PROVIDER_TYPE: ${{ matrix.provider_type }}
8289
run: |
8390
make conformance-test-standalone
8491

.github/workflows/apisix-e2e-test.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ jobs:
3535
e2e-test:
3636
needs:
3737
- prepare
38+
strategy:
39+
matrix:
40+
provider_type:
41+
- apisix-standalone
42+
- apisix
3843
runs-on: buildjet-2vcpu-ubuntu-2204
3944
steps:
4045
- name: Checkout
@@ -83,5 +88,6 @@ jobs:
8388
shell: bash
8489
env:
8590
TEST_DIR: "./test/e2e/apisix/"
91+
PROVIDER_TYPE: ${{ matrix.provider_type }}
8692
run: |
8793
make e2e-test

config/rbac/gatewayproxy_editor_role.yaml

Lines changed: 0 additions & 31 deletions
This file was deleted.

config/rbac/gatewayproxy_viewer_role.yaml

Lines changed: 0 additions & 27 deletions
This file was deleted.

config/rbac/role.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ rules:
9191
- gatewayclasses/status
9292
- gateways/status
9393
- httproutes/status
94+
- referencegrants/status
9495
verbs:
9596
- get
9697
- update
@@ -102,6 +103,14 @@ rules:
102103
- get
103104
- list
104105
- watch
106+
- apiGroups:
107+
- gateway.networking.k8s.io
108+
resources:
109+
- referencegrants
110+
verbs:
111+
- list
112+
- update
113+
- watch
105114
- apiGroups:
106115
- networking.k8s.io
107116
resources:

internal/controller/config/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ func validateProvider(config ProviderConfig) error {
118118
return fmt.Errorf("sync_period must be greater than 0 for standalone provider")
119119
}
120120
return nil
121-
case ProviderTypeAPI7EE:
121+
case ProviderTypeAPI7EE, ProviderTypeAPISIX:
122122
return nil
123123
default:
124124
return fmt.Errorf("unsupported provider type: %s", config.Type)

internal/controller/config/types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ type ProviderType string
2121
const (
2222
ProviderTypeStandalone ProviderType = "apisix-standalone"
2323
ProviderTypeAPI7EE ProviderType = "api7ee"
24+
ProviderTypeAPISIX ProviderType = "apisix"
2425
)
2526

2627
const (

internal/manager/controllers.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ import (
6666
// +kubebuilder:rbac:groups=gateway.networking.k8s.io,resources=gateways/status,verbs=get;update
6767
// +kubebuilder:rbac:groups=gateway.networking.k8s.io,resources=httproutes,verbs=get;list;watch
6868
// +kubebuilder:rbac:groups=gateway.networking.k8s.io,resources=httproutes/status,verbs=get;update
69+
// +kubebuilder:rbac:groups=gateway.networking.k8s.io,resources=referencegrants,verbs=list;watch;update
70+
// +kubebuilder:rbac:groups=gateway.networking.k8s.io,resources=referencegrants/status,verbs=get;update
6971

7072
// Networking
7173
// +kubebuilder:rbac:groups=networking.k8s.io,resources=ingresses,verbs=get;list;watch;update

internal/provider/adc/adc.go

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ package adc
1515
import (
1616
"context"
1717
"encoding/json"
18-
"errors"
1918
"os"
2019
"sync"
2120
"time"
2221

2322
"github.com/api7/gopkg/pkg/log"
23+
"github.com/pkg/errors"
2424
"go.uber.org/zap"
2525
networkingv1 "k8s.io/api/networking/v1"
2626
"sigs.k8s.io/controller-runtime/pkg/client"
@@ -48,6 +48,7 @@ type BackendMode string
4848
const (
4949
BackendModeAPISIXStandalone string = "apisix-standalone"
5050
BackendModeAPI7EE string = "api7ee"
51+
BackendModeAPISIX string = "apisix"
5152
)
5253

5354
type adcClient struct {
@@ -185,11 +186,21 @@ func (d *adcClient) Update(ctx context.Context, tctx *provider.TranslateContext,
185186
}
186187
}
187188

188-
// This mode is full synchronization,
189-
// which only needs to be saved in cache
190-
// and triggered by a timer for synchronization
191-
if d.BackendMode == BackendModeAPISIXStandalone || apiv2.Is(obj) {
189+
switch d.BackendMode {
190+
case BackendModeAPISIXStandalone:
191+
// This mode is full synchronization,
192+
// which only needs to be saved in cache
193+
// and triggered by a timer for synchronization
192194
return nil
195+
case BackendModeAPISIX:
196+
// sync by apisix admin api
197+
case BackendModeAPI7EE:
198+
// apiv2 is not support on api7ee mode
199+
if apiv2.Is(obj) {
200+
return nil
201+
}
202+
default:
203+
return errors.Errorf("unknown backend mode: %s", d.BackendMode)
193204
}
194205

195206
return d.sync(ctx, Task{

test/conformance/apisix/suite_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
package conformance
1313

1414
import (
15+
"cmp"
1516
"context"
1617
"fmt"
1718
"os"
@@ -160,7 +161,7 @@ func TestMain(m *testing.M) {
160161
Namespace: namespace,
161162
StatusAddress: address,
162163
InitSyncDelay: 1 * time.Minute,
163-
ProviderType: "apisix-standalone",
164+
ProviderType: cmp.Or(os.Getenv("PROVIDER_TYPE"), "apisix-standalone"),
164165
ProviderSyncPeriod: 10 * time.Millisecond,
165166
})
166167

0 commit comments

Comments
 (0)