32 lines
998 B
Go
32 lines
998 B
Go
package cri
|
|
|
|
import (
|
|
"fmt"
|
|
"net"
|
|
"time"
|
|
|
|
"google.golang.org/grpc"
|
|
pb "k8s.io/kubernetes/pkg/kubelet/apis/cri/v1alpha1/runtime"
|
|
)
|
|
|
|
// GetClientConn is a convenience for connecting to a gprc unix socket.
|
|
func GetClientConn(connStr string, timeout time.Duration) (*grpc.ClientConn, error) {
|
|
conn, err := grpc.Dial(connStr, grpc.WithInsecure(), grpc.WithTimeout(timeout),
|
|
grpc.WithDialer(func(addr string, timeout time.Duration) (net.Conn, error) {
|
|
return net.DialTimeout("unix", addr, timeout)
|
|
}))
|
|
if err != nil {
|
|
return nil, fmt.Errorf("failed to connect: %v", err)
|
|
}
|
|
return conn, nil
|
|
}
|
|
|
|
// NewRuntimeServiceClient is a passthrough to kubernetes CRI v1alpha1/runtime
|
|
func NewRuntimeServiceClient(conn *grpc.ClientConn) pb.RuntimeServiceClient {
|
|
return pb.NewRuntimeServiceClient(conn)
|
|
}
|
|
|
|
// NewImageServiceClient is a passthrough to kubernetes CRI v1alpha1/runtime
|
|
func NewImageServiceClient(conn *grpc.ClientConn) pb.ImageServiceClient {
|
|
return pb.NewImageServiceClient(conn)
|
|
}
|