Skip to content

Commit 397c927

Browse files
authored
Fixed pixiu proxy request 502 (#864)
1 parent a6fa4da commit 397c927

File tree

22 files changed

+346
-1044
lines changed

22 files changed

+346
-1044
lines changed

.asf.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ notifications:
2020
jira_options: link label
2121

2222
github:
23-
homepage: https://dubbo.apache.org
23+
homepage: ""
2424
description: "Dubbo Service Mesh for Kubernetes."
2525
features:
2626
# Enable wiki for documentation

dubbod/discovery/docker/dockerfile.discovery

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,29 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515

16-
FROM gcr.io/distroless/static:debug
17-
COPY bin/dubbo-discovery /usr/local/bin/dubbo-discovery
18-
USER 9999:9999
16+
FROM golang:1.25 AS builder
17+
18+
ARG TARGETOS
19+
ARG TARGETARCH
20+
21+
WORKDIR /src
22+
23+
ENV CGO_ENABLED=0 \
24+
GOOS=${TARGETOS} \
25+
GOARCH=${TARGETARCH}
26+
27+
COPY go.mod go.sum ./
28+
RUN go mod download
29+
30+
COPY . .
31+
32+
RUN go build -v -trimpath -ldflags="-s -w" \
33+
-o /out/dubbo-discovery \
34+
./dubbod/discovery/cmd/dubbo-discover/main.go
35+
36+
FROM scratch
37+
38+
COPY --from=builder /out/dubbo-discovery /usr/local/bin/dubbo-discovery
39+
40+
USER 65532:65532
1941
ENTRYPOINT ["/usr/local/bin/dubbo-discovery"]

dubbod/discovery/docker/dockerfile.proxy

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,36 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515

16-
FROM gcr.io/distroless/static:debug
17-
COPY bin/dubbo-agent /usr/local/bin/dubbo-agent
18-
COPY bin/pixiu-gateway /usr/local/bin/pixiu-gateway
19-
USER 9999:9999
20-
ENTRYPOINT ["/usr/local/bin/dubbo-agent"]
16+
FROM golang:1.25 AS builder
17+
18+
ARG TARGETOS
19+
ARG TARGETARCH
20+
21+
WORKDIR /src
22+
23+
ENV CGO_ENABLED=0 \
24+
GOOS=${TARGETOS} \
25+
GOARCH=${TARGETARCH}
26+
27+
COPY go.mod go.sum ./
28+
RUN go mod download
29+
30+
COPY . .
31+
32+
RUN go build -v -trimpath -ldflags="-s -w" \
33+
-o /out/dubbo-agent \
34+
./dubbod/discovery/cmd/dubbo-agent/main.go
35+
36+
RUN git clone --depth=1 https://github.com/apache/dubbo-go-pixiu.git && \
37+
cd dubbo-go-pixiu && \
38+
go build -v -trimpath -ldflags="-s -w" \
39+
-o /out/pixiu-proxy \
40+
./cmd/pixiu/pixiu.go
41+
42+
FROM scratch
43+
44+
COPY --from=builder /out/dubbo-agent /usr/local/bin/dubbo-agent
45+
COPY --from=builder /out/pixiu-proxy /usr/local/bin/pixiu-proxy
46+
47+
USER 65532:65532
48+
ENTRYPOINT ["/usr/local/bin/dubbo-agent"]

dubbod/discovery/pkg/config/kube/gateway/controller.go

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,9 @@ type Controller struct {
6262
inputs Inputs
6363
}
6464

65-
type Outputs struct{}
65+
type Outputs struct {
66+
Gateways krt.Collection[Gateway]
67+
}
6668

6769
type Inputs struct {
6870
Services krt.Collection[*corev1.Service]
@@ -99,11 +101,23 @@ func NewController(kc kube.Client, waitForCRD func(class schema.GroupVersionReso
99101
HTTPRoutes: buildClient[*gateway.HTTPRoute](c, kc, gvr.HTTPRoute, opts, "informer/HTTPRoutes"),
100102
}
101103

102-
GatewayClassStatus, _ := GatewayClassesCollection(inputs.GatewayClasses, opts)
104+
GatewayClassStatus, GatewayClasses := GatewayClassesCollection(inputs.GatewayClasses, opts)
103105
status.RegisterStatus(c.status, GatewayClassStatus, GetStatus)
104106

107+
GatewaysStatus, Gateways := GatewaysCollection(
108+
inputs.Gateways,
109+
GatewayClasses,
110+
opts,
111+
)
112+
113+
GatewayFinalStatus := FinalGatewayStatusCollection(GatewaysStatus, opts)
114+
status.RegisterStatus(c.status, GatewayFinalStatus, GetStatus)
115+
105116
handlers := []krt.HandlerRegistration{}
106-
outputs := Outputs{}
117+
outputs := Outputs{
118+
Gateways: Gateways,
119+
}
120+
107121
c.outputs = outputs
108122
c.handlers = handlers
109123
c.inputs = inputs

dubbod/discovery/pkg/config/kube/gateway/deployment_controller.go

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -727,7 +727,6 @@ func (d *DeploymentController) generatePixiuConfig(gw *gateway.Gateway, httpRout
727727
Name: "dgp.filter.httpconnectionmanager",
728728
Config: map[string]interface{}{
729729
"route_config": map[string]interface{}{
730-
"name": fmt.Sprintf("route-%s", listener.Name),
731730
"routes": d.convertHTTPRoutesToPixiuRoutes(httpRoutes, listener),
732731
},
733732
"http_filters": []map[string]interface{}{
@@ -759,6 +758,24 @@ func (d *DeploymentController) generatePixiuConfig(gw *gateway.Gateway, httpRout
759758
backendPort = int(*backendRef.Port)
760759
}
761760

761+
// Prefer Service ClusterIP to avoid DNS dependency inside the gateway pod.
762+
backendAddr := fmt.Sprintf("%s.%s.svc.cluster.local", backendName, backendNamespace)
763+
if d.services != nil {
764+
if svc := d.services.Get(backendName, backendNamespace); svc != nil {
765+
if ip := svc.Spec.ClusterIP; ip != "" && ip != corev1.ClusterIPNone {
766+
backendAddr = ip
767+
}
768+
}
769+
}
770+
// Fallback: if informer filtering prevented us from seeing the Service, read it directly.
771+
if backendAddr == fmt.Sprintf("%s.%s.svc.cluster.local", backendName, backendNamespace) && d.client != nil {
772+
if svc, err := d.client.Kube().CoreV1().Services(backendNamespace).Get(context.Background(), backendName, metav1.GetOptions{}); err == nil {
773+
if ip := svc.Spec.ClusterIP; ip != "" && ip != corev1.ClusterIPNone {
774+
backendAddr = ip
775+
}
776+
}
777+
}
778+
762779
clusterName := fmt.Sprintf("%s-%s-%d", backendNamespace, backendName, backendPort)
763780
if _, exists := clusterMap[clusterName]; !exists {
764781
clusterMap[clusterName] = &PixiuCluster{
@@ -769,7 +786,7 @@ func (d *DeploymentController) generatePixiuConfig(gw *gateway.Gateway, httpRout
769786
{
770787
ID: 1,
771788
SocketAddress: PixiuSocketAddress{
772-
Address: fmt.Sprintf("%s.%s.svc.cluster.local", backendName, backendNamespace),
789+
Address: backendAddr,
773790
Port: backendPort,
774791
},
775792
},
@@ -844,6 +861,11 @@ func (d *DeploymentController) convertHTTPRoutesToPixiuRoutes(httpRoutes []*gate
844861
pathMatch["regex"] = match.Path.Value
845862
}
846863
}
864+
865+
if match.Method == nil {
866+
pathMatch["methods"] = []string{}
867+
}
868+
847869
route["match"] = pathMatch
848870
}
849871

dubbod/discovery/pkg/config/kube/gateway/gateway_collection.go

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

dubbod/discovery/pkg/config/kube/gateway/gatewayclass_collection.go

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,7 @@ func getKnownControllerNames() []string {
3939
return names
4040
}
4141

42-
func GatewayClassesCollection(
43-
gatewayClasses krt.Collection[*gateway.GatewayClass],
44-
opts krt.OptionsBuilder,
45-
) (
42+
func GatewayClassesCollection(gatewayClasses krt.Collection[*gateway.GatewayClass], opts krt.OptionsBuilder) (
4643
krt.StatusCollection[*gateway.GatewayClass, gatewayv1.GatewayClassStatus],
4744
krt.Collection[GatewayClass],
4845
) {
@@ -67,3 +64,19 @@ func GatewayClassesCollection(
6764
}
6865
}, opts.WithName("GatewayClasses")...)
6966
}
67+
68+
func fetchClass(ctx krt.HandlerContext, gatewayClasses krt.Collection[GatewayClass], gc gatewayv1.ObjectName) *GatewayClass {
69+
class := krt.FetchOne(ctx, gatewayClasses, krt.FilterKey(string(gc)))
70+
if class == nil {
71+
if bc, f := builtinClasses[gc]; f {
72+
// We allow some classes to exist without being in the cluster
73+
return &GatewayClass{
74+
Name: string(gc),
75+
Controller: bc,
76+
}
77+
}
78+
// No gateway class found, this may be meant for another controller; should be skipped.
79+
return nil
80+
}
81+
return class
82+
}
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
//
2+
// Licensed to the Apache Software Foundation (ASF) under one or more
3+
// contributor license agreements. See the NOTICE file distributed with
4+
// this work for additional information regarding copyright ownership.
5+
// The ASF licenses this file to You under the Apache License, Version 2.0
6+
// (the "License"); you may not use this file except in compliance with
7+
// the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing, software
12+
// distributed under the License is distributed on an "AS IS" BASIS,
13+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
// See the License for the specific language governing permissions and
15+
// limitations under the License.
16+
17+
package gateway
18+
19+
import (
20+
"github.com/apache/dubbo-kubernetes/pkg/config"
21+
"github.com/apache/dubbo-kubernetes/pkg/kube/krt"
22+
"github.com/apache/dubbo-kubernetes/dubbod/discovery/pkg/model/kstatus"
23+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
24+
gateway "sigs.k8s.io/gateway-api/apis/v1"
25+
)
26+
27+
type Gateway struct {
28+
*config.Config `json:"config"`
29+
}
30+
31+
func (g Gateway) ResourceName() string {
32+
return config.NamespacedName(g.Config).String()
33+
}
34+
35+
func GatewaysCollection(
36+
gateways krt.Collection[*gateway.Gateway],
37+
gatewayClasses krt.Collection[GatewayClass],
38+
opts krt.OptionsBuilder,
39+
) (
40+
krt.StatusCollection[*gateway.Gateway, gateway.GatewayStatus],
41+
krt.Collection[Gateway],
42+
) {
43+
statusCol, gw := krt.NewStatusManyCollection(gateways, func(ctx krt.HandlerContext, obj *gateway.Gateway) (*gateway.GatewayStatus, []Gateway) {
44+
result := []Gateway{}
45+
kgw := obj.Spec
46+
status := obj.Status.DeepCopy()
47+
class := fetchClass(ctx, gatewayClasses, kgw.GatewayClassName)
48+
if class == nil {
49+
return nil, nil
50+
}
51+
controllerName := class.Controller
52+
classInfo, f := classInfos[controllerName]
53+
if !f {
54+
return nil, nil
55+
}
56+
if classInfo.disableRouteGeneration {
57+
// For now we still mark the Gateway as accepted, but let higher layers control route generation.
58+
status = setGatewayConditions(status, obj.Generation, true, true)
59+
return status, result
60+
}
61+
62+
// Default behavior: GatewayClass is known and managed by this controller.
63+
// Mark Accepted/Programmed to ensure status no longer stays at "Waiting for controller".
64+
status = setGatewayConditions(status, obj.Generation, true, true)
65+
return status, result
66+
}, opts.WithName("KubernetesGateway")...)
67+
68+
return statusCol, gw
69+
}
70+
71+
func setGatewayConditions(
72+
existing *gateway.GatewayStatus,
73+
gen int64,
74+
accepted, programmed bool,
75+
) *gateway.GatewayStatus {
76+
boolToConditionStatus := func(b bool) metav1.ConditionStatus {
77+
if b {
78+
return metav1.ConditionTrue
79+
}
80+
return metav1.ConditionFalse
81+
}
82+
83+
msg := "Handled by Dubbo controller"
84+
conds := kstatus.UpdateConditionIfChanged(existing.Conditions, metav1.Condition{
85+
Type: string(gateway.GatewayConditionAccepted),
86+
Status: boolToConditionStatus(accepted),
87+
ObservedGeneration: gen,
88+
LastTransitionTime: metav1.Now(),
89+
Reason: "Accepted",
90+
Message: msg,
91+
})
92+
conds = kstatus.UpdateConditionIfChanged(conds, metav1.Condition{
93+
Type: string(gateway.GatewayConditionProgrammed),
94+
Status: boolToConditionStatus(programmed),
95+
ObservedGeneration: gen,
96+
LastTransitionTime: metav1.Now(),
97+
Reason: "Programmed",
98+
Message: msg,
99+
})
100+
existing.Conditions = conds
101+
return existing
102+
}
103+
104+
func FinalGatewayStatusCollection(
105+
gatewayStatuses krt.StatusCollection[*gateway.Gateway, gateway.GatewayStatus],
106+
opts krt.OptionsBuilder,
107+
) krt.StatusCollection[*gateway.Gateway, gateway.GatewayStatus] {
108+
return krt.NewCollection(
109+
gatewayStatuses,
110+
func(ctx krt.HandlerContext, i krt.ObjectWithStatus[*gateway.Gateway, gateway.GatewayStatus]) *krt.ObjectWithStatus[*gateway.Gateway, gateway.GatewayStatus] {
111+
status := i.Status.DeepCopy()
112+
return &krt.ObjectWithStatus[*gateway.Gateway, gateway.GatewayStatus]{
113+
Obj: i.Obj,
114+
Status: *status,
115+
}
116+
}, opts.WithName("GatewayFinalStatus")...)
117+
}

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
module github.com/apache/dubbo-kubernetes
1717

18-
go 1.24.0
18+
go 1.25.0
1919

2020
require (
2121
k8s.io/apimachinery v0.34.1

manifests/charts/dubbo-control/dubbo-discovery/files/kube-gateway.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ spec:
4646
serviceAccountName: {{ .ServiceAccount }}
4747
containers:
4848
- name: dubbo-proxy
49-
image: mfordjody/dubbo-proxy:0.3.5
49+
image: dubboregistry/dubbo-proxy:0.3.5
5050
imagePullPolicy: Always
5151
ports:
5252
- containerPort: 15020

0 commit comments

Comments
 (0)