mirror of
https://github.com/siderolabs/talos.git
synced 2025-10-27 14:31:11 +01:00
Dynamically map Kubernetes and Talos API ports to an available port on the host, so every cluster gets its own unique set of parts. As part of the changes, refactor the provision library and interfaces, dropping old weird interfaces replacing with (hopefully) much more descriprive names. Signed-off-by: Dmitry Sharshakov <dmitry.sharshakov@siderolabs.com> Signed-off-by: Andrey Smirnov <andrey.smirnov@siderolabs.com>
59 lines
1.6 KiB
Go
59 lines
1.6 KiB
Go
// This Source Code Form is subject to the terms of the Mozilla Public
|
|
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
package cri
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"time"
|
|
|
|
"google.golang.org/grpc"
|
|
"google.golang.org/grpc/credentials/insecure"
|
|
runtimeapi "k8s.io/cri-api/pkg/apis/runtime/v1"
|
|
|
|
"github.com/siderolabs/talos/pkg/grpc/dialer"
|
|
)
|
|
|
|
// Client is a lightweight implementation of CRI client.
|
|
type Client struct {
|
|
conn *grpc.ClientConn
|
|
runtimeClient runtimeapi.RuntimeServiceClient
|
|
imagesClient runtimeapi.ImageServiceClient
|
|
}
|
|
|
|
// maxMsgSize use 16MB as the default message size limit.
|
|
// grpc library default is 4MB.
|
|
const maxMsgSize = 1024 * 1024 * 16
|
|
|
|
// NewClient builds CRI client.
|
|
func NewClient(endpoint string, connectionTimeout time.Duration) (*Client, error) {
|
|
ctx, cancel := context.WithTimeout(context.Background(), connectionTimeout)
|
|
defer cancel()
|
|
|
|
conn, err := grpc.DialContext(ctx, endpoint,
|
|
grpc.WithTransportCredentials(insecure.NewCredentials()),
|
|
grpc.WithBlock(),
|
|
grpc.FailOnNonTempDialError(false),
|
|
grpc.WithBackoffMaxDelay(3*time.Second), //nolint:staticcheck
|
|
grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(maxMsgSize)),
|
|
grpc.WithContextDialer(dialer.DialUnix()),
|
|
grpc.WithSharedWriteBuffer(true),
|
|
)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("error connecting to CRI: %w", err)
|
|
}
|
|
|
|
return &Client{
|
|
conn: conn,
|
|
runtimeClient: runtimeapi.NewRuntimeServiceClient(conn),
|
|
imagesClient: runtimeapi.NewImageServiceClient(conn),
|
|
}, nil
|
|
}
|
|
|
|
// Close connection.
|
|
func (c *Client) Close() error {
|
|
return c.conn.Close()
|
|
}
|