mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-28 22:17:14 +00:00
Merge pull request #109778 from mythi/grpc-go-update
grpc: move to use grpc.WithTransportCredentials()
This commit is contained in:
commit
631a5a849a
@ -22,6 +22,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
|
"google.golang.org/grpc/credentials/insecure"
|
||||||
|
|
||||||
"k8s.io/kubelet/pkg/apis/podresources/v1"
|
"k8s.io/kubelet/pkg/apis/podresources/v1"
|
||||||
"k8s.io/kubelet/pkg/apis/podresources/v1alpha1"
|
"k8s.io/kubelet/pkg/apis/podresources/v1alpha1"
|
||||||
@ -41,7 +42,10 @@ func GetV1alpha1Client(socket string, connectionTimeout time.Duration, maxMsgSiz
|
|||||||
ctx, cancel := context.WithTimeout(context.Background(), connectionTimeout)
|
ctx, cancel := context.WithTimeout(context.Background(), connectionTimeout)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
conn, err := grpc.DialContext(ctx, addr, grpc.WithInsecure(), grpc.WithContextDialer(dialer), grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(maxMsgSize)))
|
conn, err := grpc.DialContext(ctx, addr,
|
||||||
|
grpc.WithTransportCredentials(insecure.NewCredentials()),
|
||||||
|
grpc.WithContextDialer(dialer),
|
||||||
|
grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(maxMsgSize)))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, fmt.Errorf("error dialing socket %s: %v", socket, err)
|
return nil, nil, fmt.Errorf("error dialing socket %s: %v", socket, err)
|
||||||
}
|
}
|
||||||
@ -57,7 +61,10 @@ func GetV1Client(socket string, connectionTimeout time.Duration, maxMsgSize int)
|
|||||||
ctx, cancel := context.WithTimeout(context.Background(), connectionTimeout)
|
ctx, cancel := context.WithTimeout(context.Background(), connectionTimeout)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
conn, err := grpc.DialContext(ctx, addr, grpc.WithInsecure(), grpc.WithContextDialer(dialer), grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(maxMsgSize)))
|
conn, err := grpc.DialContext(ctx, addr,
|
||||||
|
grpc.WithTransportCredentials(insecure.NewCredentials()),
|
||||||
|
grpc.WithContextDialer(dialer),
|
||||||
|
grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(maxMsgSize)))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, fmt.Errorf("error dialing socket %s: %v", socket, err)
|
return nil, nil, fmt.Errorf("error dialing socket %s: %v", socket, err)
|
||||||
}
|
}
|
||||||
|
@ -24,6 +24,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
|
"google.golang.org/grpc/credentials/insecure"
|
||||||
|
|
||||||
"k8s.io/klog/v2"
|
"k8s.io/klog/v2"
|
||||||
api "k8s.io/kubelet/pkg/apis/deviceplugin/v1beta1"
|
api "k8s.io/kubelet/pkg/apis/deviceplugin/v1beta1"
|
||||||
@ -117,7 +118,9 @@ func dial(unixSocketPath string) (api.DevicePluginClient, *grpc.ClientConn, erro
|
|||||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
c, err := grpc.DialContext(ctx, unixSocketPath, grpc.WithInsecure(), grpc.WithBlock(),
|
c, err := grpc.DialContext(ctx, unixSocketPath,
|
||||||
|
grpc.WithTransportCredentials(insecure.NewCredentials()),
|
||||||
|
grpc.WithBlock(),
|
||||||
grpc.WithContextDialer(func(ctx context.Context, addr string) (net.Conn, error) {
|
grpc.WithContextDialer(func(ctx context.Context, addr string) (net.Conn, error) {
|
||||||
return (&net.Dialer{}).DialContext(ctx, "unix", addr)
|
return (&net.Dialer{}).DialContext(ctx, "unix", addr)
|
||||||
}),
|
}),
|
||||||
|
@ -25,6 +25,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
|
"google.golang.org/grpc/credentials/insecure"
|
||||||
|
|
||||||
"k8s.io/apimachinery/pkg/util/wait"
|
"k8s.io/apimachinery/pkg/util/wait"
|
||||||
"k8s.io/klog/v2"
|
"k8s.io/klog/v2"
|
||||||
@ -191,7 +192,9 @@ func (m *Stub) Register(kubeletEndpoint, resourceName string, pluginSockDir stri
|
|||||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
conn, err := grpc.DialContext(ctx, kubeletEndpoint, grpc.WithInsecure(), grpc.WithBlock(),
|
conn, err := grpc.DialContext(ctx, kubeletEndpoint,
|
||||||
|
grpc.WithTransportCredentials(insecure.NewCredentials()),
|
||||||
|
grpc.WithBlock(),
|
||||||
grpc.WithContextDialer(func(ctx context.Context, addr string) (net.Conn, error) {
|
grpc.WithContextDialer(func(ctx context.Context, addr string) (net.Conn, error) {
|
||||||
return (&net.Dialer{}).DialContext(ctx, "unix", addr)
|
return (&net.Dialer{}).DialContext(ctx, "unix", addr)
|
||||||
}))
|
}))
|
||||||
|
@ -24,6 +24,7 @@ import (
|
|||||||
|
|
||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
"google.golang.org/grpc/codes"
|
"google.golang.org/grpc/codes"
|
||||||
|
"google.golang.org/grpc/credentials/insecure"
|
||||||
"google.golang.org/grpc/status"
|
"google.golang.org/grpc/status"
|
||||||
"k8s.io/klog/v2"
|
"k8s.io/klog/v2"
|
||||||
|
|
||||||
@ -51,7 +52,10 @@ func NewRemoteImageService(endpoint string, connectionTimeout time.Duration) (in
|
|||||||
ctx, cancel := context.WithTimeout(context.Background(), connectionTimeout)
|
ctx, cancel := context.WithTimeout(context.Background(), connectionTimeout)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
conn, err := grpc.DialContext(ctx, addr, grpc.WithInsecure(), grpc.WithContextDialer(dialer), grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(maxMsgSize)))
|
conn, err := grpc.DialContext(ctx, addr,
|
||||||
|
grpc.WithTransportCredentials(insecure.NewCredentials()),
|
||||||
|
grpc.WithContextDialer(dialer),
|
||||||
|
grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(maxMsgSize)))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
klog.ErrorS(err, "Connect remote image service failed", "address", addr)
|
klog.ErrorS(err, "Connect remote image service failed", "address", addr)
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -25,6 +25,7 @@ import (
|
|||||||
|
|
||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
"google.golang.org/grpc/codes"
|
"google.golang.org/grpc/codes"
|
||||||
|
"google.golang.org/grpc/credentials/insecure"
|
||||||
"google.golang.org/grpc/status"
|
"google.golang.org/grpc/status"
|
||||||
"k8s.io/klog/v2"
|
"k8s.io/klog/v2"
|
||||||
|
|
||||||
@ -76,7 +77,10 @@ func NewRemoteRuntimeService(endpoint string, connectionTimeout time.Duration) (
|
|||||||
ctx, cancel := context.WithTimeout(context.Background(), connectionTimeout)
|
ctx, cancel := context.WithTimeout(context.Background(), connectionTimeout)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
conn, err := grpc.DialContext(ctx, addr, grpc.WithInsecure(), grpc.WithContextDialer(dialer), grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(maxMsgSize)))
|
conn, err := grpc.DialContext(ctx, addr,
|
||||||
|
grpc.WithTransportCredentials(insecure.NewCredentials()),
|
||||||
|
grpc.WithContextDialer(dialer),
|
||||||
|
grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(maxMsgSize)))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
klog.ErrorS(err, "Connect remote runtime failed", "address", addr)
|
klog.ErrorS(err, "Connect remote runtime failed", "address", addr)
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -30,6 +30,7 @@ import (
|
|||||||
"k8s.io/klog/v2"
|
"k8s.io/klog/v2"
|
||||||
|
|
||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
|
"google.golang.org/grpc/credentials/insecure"
|
||||||
"k8s.io/client-go/tools/record"
|
"k8s.io/client-go/tools/record"
|
||||||
registerapi "k8s.io/kubelet/pkg/apis/pluginregistration/v1"
|
registerapi "k8s.io/kubelet/pkg/apis/pluginregistration/v1"
|
||||||
"k8s.io/kubernetes/pkg/kubelet/pluginmanager/cache"
|
"k8s.io/kubernetes/pkg/kubelet/pluginmanager/cache"
|
||||||
@ -178,7 +179,9 @@ func dial(unixSocketPath string, timeout time.Duration) (registerapi.Registratio
|
|||||||
ctx, cancel := context.WithTimeout(context.Background(), timeout)
|
ctx, cancel := context.WithTimeout(context.Background(), timeout)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
c, err := grpc.DialContext(ctx, unixSocketPath, grpc.WithInsecure(), grpc.WithBlock(),
|
c, err := grpc.DialContext(ctx, unixSocketPath,
|
||||||
|
grpc.WithTransportCredentials(insecure.NewCredentials()),
|
||||||
|
grpc.WithBlock(),
|
||||||
grpc.WithContextDialer(func(ctx context.Context, addr string) (net.Conn, error) {
|
grpc.WithContextDialer(func(ctx context.Context, addr string) (net.Conn, error) {
|
||||||
return (&net.Dialer{}).DialContext(ctx, "unix", addr)
|
return (&net.Dialer{}).DialContext(ctx, "unix", addr)
|
||||||
}),
|
}),
|
||||||
|
@ -26,6 +26,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
|
"google.golang.org/grpc/credentials/insecure"
|
||||||
"k8s.io/klog/v2"
|
"k8s.io/klog/v2"
|
||||||
|
|
||||||
registerapi "k8s.io/kubelet/pkg/apis/pluginregistration/v1"
|
registerapi "k8s.io/kubelet/pkg/apis/pluginregistration/v1"
|
||||||
@ -155,7 +156,9 @@ func dial(unixSocketPath string, timeout time.Duration) (registerapi.Registratio
|
|||||||
ctx, cancel := context.WithTimeout(context.Background(), timeout)
|
ctx, cancel := context.WithTimeout(context.Background(), timeout)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
c, err := grpc.DialContext(ctx, unixSocketPath, grpc.WithInsecure(), grpc.WithBlock(),
|
c, err := grpc.DialContext(ctx, unixSocketPath,
|
||||||
|
grpc.WithTransportCredentials(insecure.NewCredentials()),
|
||||||
|
grpc.WithBlock(),
|
||||||
grpc.WithContextDialer(func(ctx context.Context, addr string) (net.Conn, error) {
|
grpc.WithContextDialer(func(ctx context.Context, addr string) (net.Conn, error) {
|
||||||
return (&net.Dialer{}).DialContext(ctx, "unix", addr)
|
return (&net.Dialer{}).DialContext(ctx, "unix", addr)
|
||||||
}),
|
}),
|
||||||
|
@ -24,6 +24,7 @@ import (
|
|||||||
|
|
||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
"google.golang.org/grpc/codes"
|
"google.golang.org/grpc/codes"
|
||||||
|
"google.golang.org/grpc/credentials/insecure"
|
||||||
grpchealth "google.golang.org/grpc/health/grpc_health_v1"
|
grpchealth "google.golang.org/grpc/health/grpc_health_v1"
|
||||||
"google.golang.org/grpc/metadata"
|
"google.golang.org/grpc/metadata"
|
||||||
"google.golang.org/grpc/status"
|
"google.golang.org/grpc/status"
|
||||||
@ -55,7 +56,7 @@ func (p grpcProber) Probe(host, service string, port int, timeout time.Duration)
|
|||||||
opts := []grpc.DialOption{
|
opts := []grpc.DialOption{
|
||||||
grpc.WithUserAgent(fmt.Sprintf("kube-probe/%s.%s", v.Major, v.Minor)),
|
grpc.WithUserAgent(fmt.Sprintf("kube-probe/%s.%s", v.Major, v.Minor)),
|
||||||
grpc.WithBlock(),
|
grpc.WithBlock(),
|
||||||
grpc.WithInsecure(), //credentials are currently not supported
|
grpc.WithTransportCredentials(insecure.NewCredentials()), //credentials are currently not supported
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), timeout)
|
ctx, cancel := context.WithTimeout(context.Background(), timeout)
|
||||||
|
@ -28,6 +28,7 @@ import (
|
|||||||
csipbv1 "github.com/container-storage-interface/spec/lib/go/csi"
|
csipbv1 "github.com/container-storage-interface/spec/lib/go/csi"
|
||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
"google.golang.org/grpc/codes"
|
"google.golang.org/grpc/codes"
|
||||||
|
"google.golang.org/grpc/credentials/insecure"
|
||||||
"google.golang.org/grpc/status"
|
"google.golang.org/grpc/status"
|
||||||
api "k8s.io/api/core/v1"
|
api "k8s.io/api/core/v1"
|
||||||
"k8s.io/apimachinery/pkg/api/resource"
|
"k8s.io/apimachinery/pkg/api/resource"
|
||||||
@ -534,7 +535,7 @@ func newGrpcConn(addr csiAddr, metricsManager *MetricsManager) (*grpc.ClientConn
|
|||||||
|
|
||||||
return grpc.Dial(
|
return grpc.Dial(
|
||||||
string(addr),
|
string(addr),
|
||||||
grpc.WithInsecure(),
|
grpc.WithTransportCredentials(insecure.NewCredentials()),
|
||||||
grpc.WithContextDialer(func(ctx context.Context, target string) (net.Conn, error) {
|
grpc.WithContextDialer(func(ctx context.Context, target string) (net.Conn, error) {
|
||||||
return (&net.Dialer{}).DialContext(ctx, network, target)
|
return (&net.Dialer{}).DialContext(ctx, network, target)
|
||||||
}),
|
}),
|
||||||
|
@ -30,6 +30,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
|
"google.golang.org/grpc/credentials/insecure"
|
||||||
|
|
||||||
utilnet "k8s.io/apimachinery/pkg/util/net"
|
utilnet "k8s.io/apimachinery/pkg/util/net"
|
||||||
"k8s.io/apiserver/pkg/apis/apiserver"
|
"k8s.io/apiserver/pkg/apis/apiserver"
|
||||||
@ -214,7 +215,8 @@ func (u *udsGRPCConnector) connect(_ context.Context) (proxier, error) {
|
|||||||
// we cannot use ctx just for dialing and control the connection lifetime separately.
|
// we cannot use ctx just for dialing and control the connection lifetime separately.
|
||||||
// See https://github.com/kubernetes-sigs/apiserver-network-proxy/issues/357.
|
// See https://github.com/kubernetes-sigs/apiserver-network-proxy/issues/357.
|
||||||
tunnelCtx := context.TODO()
|
tunnelCtx := context.TODO()
|
||||||
tunnel, err := client.CreateSingleUseGrpcTunnel(tunnelCtx, udsName, dialOption, grpc.WithInsecure())
|
tunnel, err := client.CreateSingleUseGrpcTunnel(tunnelCtx, udsName, dialOption,
|
||||||
|
grpc.WithTransportCredentials(insecure.NewCredentials()))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -29,6 +29,7 @@ import (
|
|||||||
"k8s.io/klog/v2"
|
"k8s.io/klog/v2"
|
||||||
|
|
||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
|
"google.golang.org/grpc/credentials/insecure"
|
||||||
|
|
||||||
kmsapi "k8s.io/apiserver/pkg/storage/value/encrypt/envelope/v1beta1"
|
kmsapi "k8s.io/apiserver/pkg/storage/value/encrypt/envelope/v1beta1"
|
||||||
)
|
)
|
||||||
@ -64,7 +65,7 @@ func NewGRPCService(endpoint string, callTimeout time.Duration) (Service, error)
|
|||||||
s := &gRPCService{callTimeout: callTimeout}
|
s := &gRPCService{callTimeout: callTimeout}
|
||||||
s.connection, err = grpc.Dial(
|
s.connection, err = grpc.Dial(
|
||||||
addr,
|
addr,
|
||||||
grpc.WithInsecure(),
|
grpc.WithTransportCredentials(insecure.NewCredentials()),
|
||||||
grpc.WithUnaryInterceptor(s.interceptor),
|
grpc.WithUnaryInterceptor(s.interceptor),
|
||||||
grpc.WithDefaultCallOptions(grpc.WaitForReady(true)),
|
grpc.WithDefaultCallOptions(grpc.WaitForReady(true)),
|
||||||
grpc.WithContextDialer(
|
grpc.WithContextDialer(
|
||||||
|
Loading…
Reference in New Issue
Block a user