Skip to content

Commit 0546691

Browse files
committed
controller, grpc: use WithConnectParams when creating a grpc client
Use the new grpc client builder option `WithConnectParams` since the option `WithBlock` and the client factory function `DialContext` were deprecated. Signed-off-by: Miguel Duarte Barroso <[email protected]>
1 parent 648e909 commit 0546691

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

pkg/cri/runtime.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ import (
77
"time"
88

99
"github.com/opencontainers/runtime-spec/specs-go"
10+
1011
"google.golang.org/grpc"
1112
"google.golang.org/grpc/credentials/insecure"
13+
1214
cri "k8s.io/cri-api/pkg/apis/runtime/v1"
1315
"k8s.io/kubelet/pkg/types"
1416
)
@@ -18,7 +20,7 @@ type Runtime struct {
1820
Client cri.RuntimeServiceClient
1921
}
2022

21-
// New returns a connection to the CRI runtime
23+
// NewRuntime returns a connection to the CRI runtime
2224
func NewRuntime(socketPath string, timeout time.Duration) (*Runtime, error) {
2325
if socketPath == "" {
2426
return nil, fmt.Errorf("path to CRI socket missing")
@@ -102,13 +104,10 @@ func connect(socketPath string, timeout time.Duration) (*grpc.ClientConn, error)
102104
return nil, fmt.Errorf("endpoint is not set")
103105
}
104106

105-
ctx, cancelFn := context.WithTimeout(context.Background(), timeout)
106-
defer cancelFn()
107-
conn, err := grpc.DialContext(
108-
ctx,
107+
conn, err := grpc.NewClient(
109108
criServerAddress(socketPath),
110109
grpc.WithTransportCredentials(insecure.NewCredentials()),
111-
grpc.WithBlock(),
110+
grpc.WithConnectParams(grpc.ConnectParams{MinConnectTimeout: timeout}),
112111
)
113112
if err != nil {
114113
return nil, fmt.Errorf("error connecting to endpoint '%s': %v", socketPath, err)

0 commit comments

Comments
 (0)