Skip to content

Commit 154df57

Browse files
github-actions[bot]AlinsRanronething
authored
feat: add Unix socket support for inter-container communication (#2587) (dc8b662) (#297)
Co-authored-by: AlinsRan <[email protected]> Co-authored-by: Ashing Zheng <[email protected]>
1 parent 3587ba2 commit 154df57

File tree

4 files changed

+40
-22
lines changed

4 files changed

+40
-22
lines changed

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,6 @@ jobs:
6464
username: ${{ secrets.DOCKER_USERNAME }}
6565
password: ${{ secrets.DOCKER_PASSWORD }}
6666

67-
- name: Install kind
68-
run: |
69-
go install sigs.k8s.io/[email protected]
70-
7167
- name: Build images
7268
env:
7369
TAG: dev
@@ -85,7 +81,7 @@ jobs:
8581
8682
- name: Install And Run Cloud Provider KIND
8783
run: |
88-
go install sigs.k8s.io/cloud-provider-kind@latest
84+
go install sigs.k8s.io/cloud-provider-kind@v0.8.0
8985
nohup cloud-provider-kind > /tmp/kind-loadbalancer.log 2>&1 &
9086
9187
- name: Install Gateway API And CRDs

.github/workflows/conformance-test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ jobs:
8686
8787
- name: Install And Run Cloud Provider KIND
8888
run: |
89-
go install sigs.k8s.io/cloud-provider-kind@latest
89+
go install sigs.k8s.io/cloud-provider-kind@v0.8.0
9090
nohup cloud-provider-kind > /tmp/kind-loadbalancer.log 2>&1 &
9191
9292
- name: Install Gateway API And CRDs

internal/adc/client/executor.go

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"errors"
2525
"fmt"
2626
"io"
27+
"net"
2728
"net/http"
2829
"os"
2930
"os/exec"
@@ -227,13 +228,32 @@ type HTTPADCExecutor struct {
227228
serverURL string
228229
}
229230

230-
// NewHTTPADCExecutor creates a new HTTPADCExecutor with the specified ADC Server URL
231+
// NewHTTPADCExecutor creates a new HTTPADCExecutor with the specified ADC Server URL.
232+
// serverURL can be "http(s)://host:port" or "unix:///path/to/socket" or "unix:/path/to/socket".
231233
func NewHTTPADCExecutor(serverURL string, timeout time.Duration) *HTTPADCExecutor {
234+
httpClient := &http.Client{
235+
Timeout: timeout,
236+
}
237+
238+
if strings.HasPrefix(serverURL, "unix:") {
239+
var socketPath string
240+
if strings.HasPrefix(serverURL, "unix:///") {
241+
socketPath = strings.TrimPrefix(serverURL, "unix://")
242+
} else {
243+
socketPath = strings.TrimPrefix(serverURL, "unix:")
244+
}
245+
transport := &http.Transport{
246+
DialContext: func(ctx context.Context, _, _ string) (net.Conn, error) {
247+
return (&net.Dialer{}).DialContext(ctx, "unix", socketPath)
248+
},
249+
}
250+
httpClient.Transport = transport
251+
serverURL = "http://unix"
252+
}
253+
232254
return &HTTPADCExecutor{
233-
httpClient: &http.Client{
234-
Timeout: timeout,
235-
},
236-
serverURL: serverURL,
255+
httpClient: httpClient,
256+
serverURL: serverURL,
237257
}
238258
}
239259

test/e2e/framework/manifests/ingress.yaml

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,8 @@ spec:
348348
app: apisix-ingress-controller
349349
control-plane: controller-manager
350350
spec:
351+
securityContext:
352+
fsGroup: 2000
351353
containers:
352354
- image: api7/api7-ingress-controller:dev
353355
env:
@@ -359,10 +361,14 @@ spec:
359361
valueFrom:
360362
fieldRef:
361363
fieldPath: metadata.name
364+
- name: ADC_SERVER_URL
365+
value: "unix:/sockets/adc.sock"
362366
volumeMounts:
363367
- name: ingress-config
364368
mountPath: /app/conf/config.yaml
365369
subPath: config.yaml
370+
- name: socket-volume
371+
mountPath: /sockets
366372
{{ if .WebhookEnable -}}
367373
- name: webhook-certs
368374
mountPath: /tmp/certs
@@ -387,12 +393,7 @@ spec:
387393
path: /readyz
388394
port: 8081
389395
initialDelaySeconds: 5
390-
periodSeconds: 10
391-
securityContext:
392-
allowPrivilegeEscalation: false
393-
capabilities:
394-
drop:
395-
- ALL
396+
periodSeconds: 10
396397
- image: ghcr.io/api7/adc:dev
397398
env:
398399
- name: ADC_RUNNING_MODE
@@ -405,13 +406,10 @@ spec:
405406
args:
406407
- "server"
407408
- "--listen"
408-
- "http://127.0.0.1:3000"
409+
- "unix:/sockets/adc.sock"
409410
- "--listen-status"
410411
- "3001"
411412
ports:
412-
- name: http
413-
containerPort: 3000
414-
protocol: TCP
415413
- name: http-status
416414
containerPort: 3001
417415
protocol: TCP
@@ -428,11 +426,15 @@ spec:
428426
port: 3001
429427
initialDelaySeconds: 5
430428
periodSeconds: 5
431-
securityContext: {}
429+
volumeMounts:
430+
- name: socket-volume
431+
mountPath: /sockets
432432
volumes:
433433
- name: ingress-config
434434
configMap:
435435
name: ingress-config
436+
- name: socket-volume
437+
emptyDir: {}
436438
{{ if .WebhookEnable -}}
437439
- name: webhook-certs
438440
secret:

0 commit comments

Comments
 (0)