Skip to content

Commit a840f92

Browse files
committed
feat: enhance provider_type support with etcd integration
- Introduced `EnvKeyProviderType` constant for environment variable reference. - Added support for dynamically configuring `config_provider` based on provider type. - Enabled etcd deployment for `apisix` provider type in E2E tests. - Embedded `etcd` manifests for streamlined test setup.
1 parent 73fa5ef commit a840f92

File tree

7 files changed

+86
-22
lines changed

7 files changed

+86
-22
lines changed

internal/provider/adc/adc.go

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -186,21 +186,11 @@ func (d *adcClient) Update(ctx context.Context, tctx *provider.TranslateContext,
186186
}
187187
}
188188

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
189+
// This mode is full synchronization,
190+
// which only needs to be saved in cache
191+
// and triggered by a timer for synchronization
192+
if d.BackendMode == BackendModeAPISIXStandalone || d.BackendMode == BackendModeAPISIX || apiv2.Is(obj) {
194193
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)
204194
}
205195

206196
return d.sync(ctx, Task{

internal/provider/adc/executor.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,19 @@ func (e *DefaultADCExecutor) Execute(ctx context.Context, mode string, config ad
4646

4747
func (e *DefaultADCExecutor) runADC(ctx context.Context, mode string, config adcConfig, args []string) error {
4848
for _, addr := range config.ServerAddrs {
49-
ctxWithTimeout, cancel := context.WithTimeout(ctx, 15*time.Second)
50-
defer cancel()
51-
if err := e.runForSingleServer(ctxWithTimeout, addr, mode, config, args); err != nil {
49+
if err := e.runForSingleServerWithTimeout(ctx, addr, mode, config, args); err != nil {
5250
return err
5351
}
5452
}
5553
return nil
5654
}
5755

56+
func (e *DefaultADCExecutor) runForSingleServerWithTimeout(ctx context.Context, serverAddr, mode string, config adcConfig, args []string) error {
57+
ctx, cancel := context.WithTimeout(ctx, 15*time.Second)
58+
defer cancel()
59+
return e.runForSingleServer(ctx, serverAddr, mode, config, args)
60+
}
61+
5862
func (e *DefaultADCExecutor) runForSingleServer(ctx context.Context, serverAddr, mode string, config adcConfig, args []string) error {
5963
cmdArgs := append([]string{}, args...)
6064
if !config.TlsVerify {

test/conformance/apisix/suite_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ func TestMain(m *testing.M) {
161161
Namespace: namespace,
162162
StatusAddress: address,
163163
InitSyncDelay: 1 * time.Minute,
164-
ProviderType: cmp.Or(os.Getenv("PROVIDER_TYPE"), "apisix-standalone"),
164+
ProviderType: cmp.Or(os.Getenv(framework.EnvKeyProviderType), "apisix-standalone"),
165165
ProviderSyncPeriod: 10 * time.Millisecond,
166166
})
167167

test/e2e/framework/apisix_consts.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,17 @@ import (
1919
"github.com/Masterminds/sprig/v3"
2020
)
2121

22+
const (
23+
EnvKeyProviderType = "PROVIDER_TYPE"
24+
)
25+
2226
var (
2327
//go:embed manifests/apisix-standalone.yaml
2428
apisixStandaloneTemplate string
2529
APISIXStandaloneTpl *template.Template
30+
31+
//go:embed manifests/etcd.yaml
32+
EtcdSpec string
2633
)
2734

2835
var (

test/e2e/framework/manifests/apisix-standalone.yaml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,21 @@ data:
77
deployment:
88
role: traditional
99
role_traditional:
10-
config_provider: yaml
10+
# on backend mode apisix-standalone, config_provider is "yaml"
11+
# on backend mode apisix, config_provider is "etcd"
12+
config_provider: {{ .ConfigProvider | default "yaml" }}
1113
admin:
1214
allow_admin:
1315
- 0.0.0.0/0
1416
admin_key:
1517
- key: {{ .AdminKey }}
1618
name: admin
1719
role: admin
20+
{{- if eq .ConfigProvider "etcd" }}
21+
etcd:
22+
host:
23+
- "http://etcd:2379"
24+
{{- end }}
1825
nginx_config:
1926
worker_processes: 2
2027
error_log_level: info
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
---
2+
apiVersion: apps/v1
3+
kind: Deployment
4+
metadata:
5+
name: etcd
6+
spec:
7+
replicas: 1
8+
selector:
9+
matchLabels:
10+
app: etcd
11+
template:
12+
metadata:
13+
labels:
14+
app: etcd
15+
spec:
16+
containers:
17+
- name: etcd
18+
image: quay.io/coreos/etcd:v3.5.0
19+
command:
20+
- etcd
21+
- --data-dir=/etcd-data
22+
- --name=node1
23+
- --initial-advertise-peer-urls=http://0.0.0.0:2380
24+
- --listen-peer-urls=http://0.0.0.0:2380
25+
- --advertise-client-urls=http://0.0.0.0:2379
26+
- --listen-client-urls=http://0.0.0.0:2379
27+
- --initial-cluster=node1=http://0.0.0.0:2380
28+
ports:
29+
- containerPort: 2379
30+
- containerPort: 2380
31+
---
32+
apiVersion: v1
33+
kind: Service
34+
metadata:
35+
name: etcd
36+
spec:
37+
ports:
38+
- port: 2379
39+
targetPort: 2379
40+
selector:
41+
app: etcd

test/e2e/scaffold/apisix_deployer.go

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
corev1 "k8s.io/api/core/v1"
2626
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2727

28+
"github.com/apache/apisix-ingress-controller/internal/provider/adc"
2829
"github.com/apache/apisix-ingress-controller/pkg/utils"
2930
"github.com/apache/apisix-ingress-controller/test/e2e/framework"
3031
)
@@ -37,6 +38,8 @@ type APISIXDeployOptions struct {
3738
ServiceType string
3839
ServiceHTTPPort int
3940
ServiceHTTPSPort int
41+
42+
ConfigProvider string
4043
}
4144

4245
type APISIXDeployer struct {
@@ -187,12 +190,24 @@ func (s *APISIXDeployer) deployDataplane(opts *APISIXDeployOptions) *corev1.Serv
187190
if opts.ServiceHTTPSPort == 0 {
188191
opts.ServiceHTTPSPort = 443
189192
}
193+
opts.ConfigProvider = "yaml"
194+
195+
kubectlOpts := k8s.NewKubectlOptions("", "", opts.Namespace)
196+
197+
if os.Getenv(framework.EnvKeyProviderType) == adc.BackendModeAPISIX {
198+
// deploy etcd
199+
opts.ConfigProvider = "etcd"
200+
k8s.KubectlApplyFromString(s.GinkgoT, kubectlOpts, framework.EtcdSpec)
201+
err := framework.WaitPodsAvailable(s.GinkgoT, kubectlOpts, metav1.ListOptions{
202+
LabelSelector: "app=etcd",
203+
})
204+
Expect(err).ToNot(HaveOccurred(), "waiting for etcd pod ready")
205+
}
190206

191207
buf := bytes.NewBuffer(nil)
192208
err := framework.APISIXStandaloneTpl.Execute(buf, opts)
193209
Expect(err).ToNot(HaveOccurred(), "executing template")
194210

195-
kubectlOpts := k8s.NewKubectlOptions("", "", opts.Namespace)
196211
k8s.KubectlApplyFromString(s.GinkgoT, kubectlOpts, buf.String())
197212

198213
err = framework.WaitPodsAvailable(s.GinkgoT, kubectlOpts, metav1.ListOptions{
@@ -220,7 +235,7 @@ func (s *APISIXDeployer) deployDataplane(opts *APISIXDeployOptions) *corev1.Serv
220235
func (s *APISIXDeployer) DeployIngress() {
221236
s.Framework.DeployIngress(framework.IngressDeployOpts{
222237
ControllerName: s.opts.ControllerName,
223-
ProviderType: cmp.Or(os.Getenv("PROVIDER_TYPE"), "apisix-standalone"),
238+
ProviderType: cmp.Or(os.Getenv(framework.EnvKeyProviderType), "apisix-standalone"),
224239
ProviderSyncPeriod: 200 * time.Millisecond,
225240
Namespace: s.namespace,
226241
Replicas: 1,
@@ -230,7 +245,7 @@ func (s *APISIXDeployer) DeployIngress() {
230245
func (s *APISIXDeployer) ScaleIngress(replicas int) {
231246
s.Framework.DeployIngress(framework.IngressDeployOpts{
232247
ControllerName: s.opts.ControllerName,
233-
ProviderType: cmp.Or(os.Getenv("PROVIDER_TYPE"), "apisix-standalone"),
248+
ProviderType: cmp.Or(os.Getenv(framework.EnvKeyProviderType), "apisix-standalone"),
234249
ProviderSyncPeriod: 200 * time.Millisecond,
235250
Namespace: s.namespace,
236251
Replicas: replicas,

0 commit comments

Comments
 (0)