Skip to content

Commit d6c45fc

Browse files
committed
feat: add environment variable support for etcd adapter address and APISIX key prefix
1 parent f50f708 commit d6c45fc

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

internal/adc/client/kind_executor.go

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,30 @@ import (
3434
)
3535

3636
const (
37-
// etcdAdapterAddr is the address for the local etcd adapter
38-
etcdAdapterAddr = "127.0.0.1:12379"
39-
// apisixKeyPrefix is the prefix for all APISIX resources in etcd
40-
apisixKeyPrefix = "/apisix"
37+
// Default values for environment variables
38+
defaultEtcdAdapterAddr = "127.0.0.1:12379"
39+
defaultApisixKeyPrefix = "/apisix"
40+
41+
// Environment variable names
42+
envEtcdAdapterAddr = "ETCD_ADAPTER_ADDR"
43+
envApisixKeyPrefix = "APISIX_KEY_PREFIX"
4144
)
4245

46+
// getConfig returns configuration values from environment variables with defaults
47+
func getConfig() (etcdAdapterAddr, apisixKeyPrefix string) {
48+
etcdAdapterAddr = os.Getenv(envEtcdAdapterAddr)
49+
if etcdAdapterAddr == "" {
50+
etcdAdapterAddr = defaultEtcdAdapterAddr
51+
}
52+
53+
apisixKeyPrefix = os.Getenv(envApisixKeyPrefix)
54+
if apisixKeyPrefix == "" {
55+
apisixKeyPrefix = defaultApisixKeyPrefix
56+
}
57+
58+
return
59+
}
60+
4361
// KindExecutor implements ADCExecutor interface using Kine to sync resources
4462
type KindExecutor struct {
4563
log logr.Logger
@@ -52,6 +70,7 @@ type KindExecutor struct {
5270
func newEtcdAdapter(log logr.Logger) adapter.Adapter {
5371
a := adapter.NewEtcdAdapter(nil)
5472

73+
etcdAdapterAddr, _ := getConfig()
5574
ln, err := net.Listen("tcp", etcdAdapterAddr)
5675
if err != nil {
5776
panic(err)
@@ -200,6 +219,7 @@ func (e *KindExecutor) applyCacheChange(event kine.Event) error {
200219
// convertToAdapterEvent converts a kine event to an adapter event
201220
func (e *KindExecutor) convertToAdapterEvent(event kine.Event) (*adapter.Event, error) {
202221
// Build key with /apisix prefix
222+
_, apisixKeyPrefix := getConfig()
203223
key := fmt.Sprintf("%s/%s/%s", apisixKeyPrefix, event.ResourceType, event.ResourceID)
204224

205225
adapterEvent := &adapter.Event{

0 commit comments

Comments
 (0)