Skip to content

Commit 70d37e3

Browse files
authored
fix: resolve externalName when gatewayproxy provider is service (#228)
Signed-off-by: Ashing Zheng <[email protected]>
1 parent 054207d commit 70d37e3

File tree

13 files changed

+83
-72
lines changed

13 files changed

+83
-72
lines changed

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

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -35,27 +35,8 @@ permissions:
3535
pull-requests: write
3636

3737
jobs:
38-
prepare:
39-
name: Prepare
40-
runs-on: buildjet-2vcpu-ubuntu-2204
41-
steps:
42-
- name: Checkout
43-
uses: actions/checkout@v4
44-
45-
- name: Setup Go Env
46-
id: go
47-
uses: actions/setup-go@v4
48-
with:
49-
go-version: "1.23"
50-
51-
- name: Install kind
52-
run: |
53-
go install sigs.k8s.io/[email protected]
54-
5538
conformance-test:
5639
timeout-minutes: 60
57-
needs:
58-
- prepare
5940
strategy:
6041
matrix:
6142
provider_type:
@@ -72,6 +53,9 @@ jobs:
7253
uses: actions/setup-go@v4
7354
with:
7455
go-version: "1.23"
56+
- name: Install kind
57+
run: |
58+
go install sigs.k8s.io/[email protected]
7559
7660
- name: Login to Registry
7761
uses: docker/login-action@v1

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

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -32,26 +32,7 @@ concurrency:
3232
cancel-in-progress: true
3333

3434
jobs:
35-
prepare:
36-
name: Prepare
37-
runs-on: buildjet-2vcpu-ubuntu-2204
38-
steps:
39-
- name: Checkout
40-
uses: actions/checkout@v4
41-
42-
- name: Setup Go Env
43-
id: go
44-
uses: actions/setup-go@v4
45-
with:
46-
go-version: "1.23"
47-
48-
- name: Install kind
49-
run: |
50-
go install sigs.k8s.io/[email protected]
51-
5235
e2e-test:
53-
needs:
54-
- prepare
5536
strategy:
5637
matrix:
5738
provider_type:
@@ -73,6 +54,10 @@ jobs:
7354
with:
7455
go-version: "1.23"
7556

57+
- name: Install kind
58+
run: |
59+
go install sigs.k8s.io/[email protected]
60+
7661
- name: Login to Registry
7762
uses: docker/login-action@v1
7863
with:
@@ -118,5 +103,6 @@ jobs:
118103
TEST_DIR: "./test/e2e/apisix/"
119104
PROVIDER_TYPE: ${{ matrix.provider_type }}
120105
TEST_LABEL: ${{ matrix.cases_subset }}
106+
TEST_ENV: CI
121107
run: |
122108
make e2e-test

.github/workflows/e2e-test.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,5 +124,6 @@ jobs:
124124
env:
125125
API7_EE_LICENSE: ${{ secrets.API7_EE_LICENSE }}
126126
PROVIDER_TYPE: api7ee
127+
TEST_ENV: CI
127128
run: |
128129
make e2e-test

internal/provider/adc/adc.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,12 @@ func New(updater status.Updater, readier readiness.ReadinessManager, opts ...Opt
115115
o := Options{}
116116
o.ApplyOptions(opts)
117117

118-
executor := NewHTTPADCExecutor("http://127.0.0.1:3000")
119-
log.Infow("using HTTP ADC Executor", zap.String("server_url", "http://127.0.0.1:3000"))
118+
serverURL := os.Getenv("ADC_SERVER_URL")
119+
if serverURL == "" {
120+
serverURL = "http://127.0.0.1:3000"
121+
}
122+
executor := NewHTTPADCExecutor(serverURL, o.SyncTimeout)
123+
log.Infow("using HTTP ADC Executor", zap.String("server_url", serverURL))
120124

121125
return &adcClient{
122126
Options: o,

internal/provider/adc/config.go

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626

2727
"github.com/api7/gopkg/pkg/log"
2828
"go.uber.org/zap"
29+
corev1 "k8s.io/api/core/v1"
2930
discoveryv1 "k8s.io/api/discovery/v1"
3031
k8stypes "k8s.io/apimachinery/pkg/types"
3132
"k8s.io/utils/ptr"
@@ -120,8 +121,24 @@ func (d *adcClient) getConfigsForGatewayProxy(tctx *provider.TranslateContext, g
120121
config.ServerAddrs = append(config.ServerAddrs, "http://"+net.JoinHostPort(node.Host, strconv.Itoa(node.Port)))
121122
}
122123
} else {
123-
config.ServerAddrs = []string{
124-
fmt.Sprintf("http://%s.%s:%d", provider.ControlPlane.Service.Name, gatewayProxy.Namespace, provider.ControlPlane.Service.Port),
124+
key := k8stypes.NamespacedName{
125+
Namespace: gatewayProxy.Namespace,
126+
Name: provider.ControlPlane.Service.Name,
127+
}
128+
service, ok := tctx.Services[key]
129+
if !ok {
130+
return nil, fmt.Errorf("service %s not found", key)
131+
}
132+
refPort := provider.ControlPlane.Service.Port
133+
// if the service is external name, we should use the external name as the server address
134+
if service.Spec.Type == corev1.ServiceTypeExternalName {
135+
config.ServerAddrs = []string{
136+
fmt.Sprintf("http://%s:%d", service.Spec.ExternalName, refPort),
137+
}
138+
} else {
139+
config.ServerAddrs = []string{
140+
fmt.Sprintf("http://%s.%s:%d", key.Name, key.Namespace, refPort),
141+
}
125142
}
126143
}
127144

internal/provider/adc/executor.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -227,10 +227,10 @@ type HTTPADCExecutor struct {
227227
}
228228

229229
// NewHTTPADCExecutor creates a new HTTPADCExecutor with the specified ADC Server URL
230-
func NewHTTPADCExecutor(serverURL string) *HTTPADCExecutor {
230+
func NewHTTPADCExecutor(serverURL string, timeout time.Duration) *HTTPADCExecutor {
231231
return &HTTPADCExecutor{
232232
httpClient: &http.Client{
233-
Timeout: 30 * time.Second,
233+
Timeout: timeout,
234234
},
235235
serverURL: serverURL,
236236
}
@@ -272,7 +272,7 @@ func (e *HTTPADCExecutor) runHTTPSync(ctx context.Context, mode string, config a
272272

273273
// runHTTPSyncForSingleServer performs HTTP sync to a single ADC Server
274274
func (e *HTTPADCExecutor) runHTTPSyncForSingleServer(ctx context.Context, serverAddr, mode string, config adcConfig, args []string) error {
275-
ctx, cancel := context.WithTimeout(ctx, 15*time.Second)
275+
ctx, cancel := context.WithTimeout(ctx, e.httpClient.Timeout)
276276
defer cancel()
277277

278278
// Parse args to extract labels, types, and file path
@@ -383,6 +383,8 @@ func (e *HTTPADCExecutor) buildHTTPRequest(ctx context.Context, serverAddr, mode
383383
return nil, fmt.Errorf("failed to marshal request body: %w", err)
384384
}
385385

386+
log.Debugw("request body", zap.String("body", string(jsonData)))
387+
386388
log.Debugw("sending HTTP request to ADC Server",
387389
zap.String("url", e.serverURL+"/sync"),
388390
zap.String("server", serverAddr),

test/e2e/crds/v2/basic.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ spec:
137137

138138
By("create IngressClass")
139139
ingressClass := fmt.Sprintf(ingressClassYaml, framework.IngressVersion, s.Namespace())
140-
err = s.CreateResourceFromString(ingressClass)
140+
err = s.CreateResourceFromStringWithNamespace(ingressClass, "")
141141
Expect(err).NotTo(HaveOccurred(), "creating IngressClass")
142142
time.Sleep(5 * time.Second)
143143

test/e2e/crds/v2/route.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ spec:
6666

6767
By("create IngressClass")
6868
ingressClass := fmt.Sprintf(ingressClassYaml, framework.IngressVersion, s.Namespace())
69-
err = s.CreateResourceFromString(ingressClass)
69+
err = s.CreateResourceFromStringWithNamespace(ingressClass, "")
7070
Expect(err).NotTo(HaveOccurred(), "creating IngressClass")
7171
time.Sleep(5 * time.Second)
7272
})

test/e2e/crds/v2/status.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ var _ = Describe("Test apisix.apache.org/v2 Status", Label("apisix.apache.org",
3939
var (
4040
s = scaffold.NewScaffold(&scaffold.Options{
4141
ControllerName: "apisix.apache.org/apisix-ingress-controller",
42+
// for triggering the sync
43+
SyncPeriod: 3 * time.Second,
4244
})
4345
applier = framework.NewApplier(s.GinkgoT, s.K8sClient, s.CreateResourceFromString)
4446
)
@@ -66,7 +68,7 @@ spec:
6668
name: "apisix-proxy-config"
6769
`
6870
ingressClass := fmt.Sprintf(ingressClassYaml, framework.IngressVersion, s.Namespace())
69-
err = s.CreateResourceFromString(ingressClass)
71+
err = s.CreateResourceFromStringWithNamespace(ingressClass, "")
7072
Expect(err).NotTo(HaveOccurred(), "creating IngressClass")
7173
time.Sleep(5 * time.Second)
7274
})
@@ -157,8 +159,8 @@ spec:
157159
})
158160

159161
It("dataplane unavailable", func() {
160-
if os.Getenv("PROVIDER_TYPE") != adc.BackendModeAPISIXStandalone {
161-
Skip("only for apisix standalone mode")
162+
if os.Getenv("PROVIDER_TYPE") == adc.BackendModeAPI7EE {
163+
Skip("skip for api7ee mode because it use dashboard admin api")
162164
}
163165
By("apply ApisixRoute")
164166
applier.MustApplyAPIv2(types.NamespacedName{Namespace: s.Namespace(), Name: "default"}, &apiv2.ApisixRoute{}, ar)
@@ -192,7 +194,7 @@ spec:
192194
s.RetryAssertion(func() string {
193195
output, _ := s.GetOutputFromString("ar", "default", "-o", "yaml")
194196
return output
195-
}).WithTimeout(80 * time.Second).
197+
}).WithTimeout(60 * time.Second).
196198
Should(
197199
And(
198200
ContainSubstring(`status: "False"`),
@@ -215,7 +217,7 @@ spec:
215217
s.RetryAssertion(func() string {
216218
output, _ := s.GetOutputFromString("ar", "default", "-o", "yaml")
217219
return output
218-
}).WithTimeout(80 * time.Second).
220+
}).WithTimeout(60 * time.Second).
219221
Should(
220222
And(
221223
ContainSubstring(`status: "True"`),

test/e2e/framework/manifests/ingress.yaml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -455,11 +455,7 @@ spec:
455455
port: 3001
456456
initialDelaySeconds: 5
457457
periodSeconds: 5
458-
securityContext:
459-
allowPrivilegeEscalation: false
460-
capabilities:
461-
drop:
462-
- ALL
458+
securityContext: {}
463459
volumes:
464460
- name: ingress-config
465461
configMap:

0 commit comments

Comments
 (0)