Skip to content

Commit 865efe0

Browse files
committed
fix proxy grpcClient: set default http2 DialTLSContext
1 parent 1bf6de0 commit 865efe0

File tree

7 files changed

+22
-8
lines changed

7 files changed

+22
-8
lines changed

artifacts/images/manager.Dockerfile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@ RUN CGO_ENABLED=0 GO111MODULE=on GOOS=linux GOARCH=amd64 go build -mod=vendor -a
1515
FROM ubuntu:focal
1616
# This is required by daemon connnecting with cri
1717
RUN ln -s /usr/bin/* /usr/sbin/ && apt-get update -y \
18-
&& apt-get install --no-install-recommends -y ca-certificates \
18+
&& apt-get install --no-install-recommends -y \
19+
sudo \
20+
net-tools \
21+
curl \
22+
ca-certificates \
1923
&& apt-get clean && rm -rf /var/log/*log /var/lib/apt/lists/* /var/log/apt/* /var/lib/dpkg/*-old /var/cache/debconf/*-old
2024
WORKDIR /
2125
COPY --from=builder /workspace/ctrlmesh-manager .

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ go 1.20
55
require (
66
connectrpc.com/connect v1.11.1
77
github.com/go-logr/zapr v1.2.3
8-
github.com/gogo/protobuf v1.3.2
98
github.com/onsi/ginkgo v1.16.5
109
github.com/onsi/gomega v1.24.1
1110
github.com/prometheus/client_golang v1.14.0
@@ -52,6 +51,7 @@ require (
5251
github.com/go-openapi/jsonpointer v0.19.5 // indirect
5352
github.com/go-openapi/jsonreference v0.20.0 // indirect
5453
github.com/go-openapi/swag v0.19.14 // indirect
54+
github.com/gogo/protobuf v1.3.2 // indirect
5555
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
5656
github.com/golang/protobuf v1.5.2 // indirect
5757
github.com/google/cel-go v0.12.6 // indirect

pkg/manager/controllers/circuitbreaker/circuitbreaker_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ var (
5353
PodNamespace = os.Getenv(constants.EnvPodNamespace)
5454

5555
defaultRequeueTime = 60 * time.Second
56-
concurrentReconciles = flag.Int("ctrlmesh-server-workers", 3, "Max concurrent workers for CtrlMesh Server controller.")
56+
concurrentReconciles = flag.Int("ctrlmesh-breaker-workers", 3, "Max concurrent workers for CtrlMesh Server controller.")
5757
)
5858

5959
// CircuitBreakerReconciler reconciles a CircuitBreaker object

pkg/manager/controllers/shardingconfigserver/grpc_server.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ import (
2424
"sync"
2525

2626
"connectrpc.com/connect"
27-
"github.com/gogo/protobuf/proto"
2827
"google.golang.org/grpc/codes"
2928
"google.golang.org/grpc/status"
29+
"google.golang.org/protobuf/proto"
3030
v1 "k8s.io/api/core/v1"
3131
"k8s.io/apimachinery/pkg/api/errors"
3232
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

pkg/proxy/proto/grpc.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,16 @@ package proto
1919

2020
import (
2121
"context"
22+
"crypto/tls"
2223
"fmt"
2324
"math/rand"
25+
"net"
2426
"net/http"
2527
"time"
2628

2729
"connectrpc.com/connect"
28-
"github.com/gogo/protobuf/proto"
2930
"golang.org/x/net/http2"
31+
"google.golang.org/protobuf/proto"
3032
"k8s.io/apimachinery/pkg/api/errors"
3133
"k8s.io/klog/v2"
3234

@@ -98,7 +100,7 @@ func (c *grpcClient) connect(ctx context.Context, initChan chan struct{}) {
98100
continue
99101
}
100102

101-
addr := fmt.Sprintf("%s:%d", leader.PodIP, managerState.Status.Ports.GrpcLeaderElectionPort)
103+
addr := fmt.Sprintf("https://%s:%d", leader.PodIP, managerState.Status.Ports.GrpcLeaderElectionPort)
102104
klog.Infof("Preparing to connect ctrlmesh-manager %v", addr)
103105
func() {
104106
ctxWithCancel, cancel := context.WithCancel(ctx)
@@ -107,6 +109,14 @@ func (c *grpcClient) connect(ctx context.Context, initChan chan struct{}) {
107109
client := &http.Client{
108110
Transport: &http2.Transport{
109111
AllowHTTP: true,
112+
DialTLSContext: func(ctx context.Context, network, addr string, _ *tls.Config) (net.Conn, error) {
113+
// TODO:
114+
// If you're also using this client for non-h2c traffic, you may want
115+
// to delegate to tls.Dial if the network isn't TCP or the addr isn't
116+
// in an allowlist.
117+
d := net.Dialer{Timeout: 5 * time.Second}
118+
return d.DialContext(ctx, network, addr)
119+
},
110120
},
111121
}
112122
grpcCtrlMeshClient := protoconnect.NewControllerMeshClient(client, addr, connect.WithGRPC())

pkg/proxy/proto/proto_manager.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import (
2323
"os"
2424
"sync"
2525

26-
"github.com/gogo/protobuf/proto"
26+
"google.golang.org/protobuf/proto"
2727
"k8s.io/klog/v2"
2828

2929
"github.com/KusionStack/controller-mesh/pkg/apis/ctrlmesh/constants"

pkg/proxy/proto/strorage.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222
"io"
2323
"os"
2424

25-
"github.com/gogo/protobuf/proto"
25+
"google.golang.org/protobuf/proto"
2626
"k8s.io/klog/v2"
2727

2828
ctrlmeshproto "github.com/KusionStack/controller-mesh/pkg/apis/ctrlmesh/proto"

0 commit comments

Comments
 (0)