mirror of
https://github.com/k3s-io/k3s.git
synced 2024-06-07 19:41:36 +00:00
0d4caf4e24
* Wait for cri-dockerd socket * Consolidate cri utility functions Signed-off-by: Derek Nola <derek.nola@suse.com>
40 lines
903 B
Go
40 lines
903 B
Go
//go:build linux
|
|
// +build linux
|
|
|
|
package cri
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"google.golang.org/grpc"
|
|
runtimeapi "k8s.io/cri-api/pkg/apis/runtime/v1"
|
|
k8sutil "k8s.io/kubernetes/pkg/kubelet/util"
|
|
)
|
|
|
|
const socketPrefix = "unix://"
|
|
|
|
// Connection connects to a CRI socket at the given path.
|
|
func Connection(ctx context.Context, address string) (*grpc.ClientConn, error) {
|
|
addr, dialer, err := k8sutil.GetAddressAndDialer(socketPrefix + address)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
conn, err := grpc.Dial(addr, grpc.WithInsecure(), grpc.WithTimeout(3*time.Second), grpc.WithContextDialer(dialer), grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(maxMsgSize)))
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
c := runtimeapi.NewRuntimeServiceClient(conn)
|
|
_, err = c.Version(ctx, &runtimeapi.VersionRequest{
|
|
Version: "0.1.0",
|
|
})
|
|
if err != nil {
|
|
conn.Close()
|
|
return nil, err
|
|
}
|
|
|
|
return conn, nil
|
|
}
|