@@ -5,18 +5,20 @@ import (
55 "net"
66 "net/url"
77 "strconv"
8+ "time"
89
910 "github.com/oam-dev/cluster-gateway/pkg/config"
1011 "github.com/pkg/errors"
1112 "google.golang.org/grpc"
1213 grpccredentials "google.golang.org/grpc/credentials"
14+ "google.golang.org/grpc/keepalive"
1315 k8snet "k8s.io/apimachinery/pkg/util/net"
1416 restclient "k8s.io/client-go/rest"
1517 konnectivity "sigs.k8s.io/apiserver-network-proxy/konnectivity-client/pkg/client"
1618 "sigs.k8s.io/apiserver-network-proxy/pkg/util"
1719)
1820
19- var DialerGetter = func () (k8snet.DialFunc , error ) {
21+ var DialerGetter = func (ctx context. Context ) (k8snet.DialFunc , error ) {
2022 tlsCfg , err := util .GetClientTLSConfig (
2123 config .ClusterProxyCAFile ,
2224 config .ClusterProxyCertFile ,
@@ -26,18 +28,21 @@ var DialerGetter = func() (k8snet.DialFunc, error) {
2628 if err != nil {
2729 return nil , err
2830 }
29- tunnel , err := konnectivity .CreateSingleUseGrpcTunnel (
30- context . TODO () ,
31+ dialerTunnel , err := konnectivity .CreateSingleUseGrpcTunnel (
32+ ctx ,
3133 net .JoinHostPort (config .ClusterProxyHost , strconv .Itoa (config .ClusterProxyPort )),
3234 grpc .WithTransportCredentials (grpccredentials .NewTLS (tlsCfg )),
35+ grpc .WithKeepaliveParams (keepalive.ClientParameters {
36+ Time : time .Second * 5 ,
37+ }),
3338 )
3439 if err != nil {
3540 return nil , err
3641 }
37- return tunnel .DialContext , nil
42+ return dialerTunnel .DialContext , nil
3843}
3944
40- func NewConfigFromCluster (c * ClusterGateway ) (* restclient.Config , error ) {
45+ func NewConfigFromCluster (ctx context. Context , c * ClusterGateway ) (* restclient.Config , error ) {
4146 cfg := & restclient.Config {}
4247 // setting up endpoint
4348 switch c .Spec .Access .Endpoint .Type {
@@ -69,7 +74,7 @@ func NewConfigFromCluster(c *ClusterGateway) (*restclient.Config, error) {
6974 cfg .Host = c .Name // the same as the cluster name
7075 cfg .Insecure = true
7176 cfg .CAData = nil
72- dail , err := DialerGetter ()
77+ dail , err := DialerGetter (ctx )
7378 if err != nil {
7479 return nil , err
7580 }
0 commit comments