Skip to content

Commit

Permalink
controller, grpc: use WithConnectParams when creating a grpc client
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
maiqueb committed Dec 3, 2024
1 parent 648e909 commit 0546691
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions pkg/cri/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ import (
"time"

"github.com/opencontainers/runtime-spec/specs-go"

"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"

cri "k8s.io/cri-api/pkg/apis/runtime/v1"
"k8s.io/kubelet/pkg/types"
)
Expand All @@ -18,7 +20,7 @@ type Runtime struct {
Client cri.RuntimeServiceClient
}

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

ctx, cancelFn := context.WithTimeout(context.Background(), timeout)
defer cancelFn()
conn, err := grpc.DialContext(
ctx,
conn, err := grpc.NewClient(
criServerAddress(socketPath),
grpc.WithTransportCredentials(insecure.NewCredentials()),
grpc.WithBlock(),
grpc.WithConnectParams(grpc.ConnectParams{MinConnectTimeout: timeout}),
)
if err != nil {
return nil, fmt.Errorf("error connecting to endpoint '%s': %v", socketPath, err)
Expand Down

0 comments on commit 0546691

Please sign in to comment.