talos

Форк
0
/
local.go 
52 строки · 1.4 Кб
1
// This Source Code Form is subject to the terms of the Mozilla Public
2
// License, v. 2.0. If a copy of the MPL was not distributed with this
3
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
4

5
package cluster
6

7
import (
8
	"context"
9
	"errors"
10

11
	"google.golang.org/grpc"
12
	"google.golang.org/grpc/credentials/insecure"
13

14
	"github.com/siderolabs/talos/pkg/machinery/client"
15
	"github.com/siderolabs/talos/pkg/machinery/constants"
16
)
17

18
// LocalClientProvider builds Talos client to connect to same-node apid instance over file socket.
19
type LocalClientProvider struct {
20
	client *client.Client
21
}
22

23
// Client returns Talos client instance for default (if no endpoints are given) or
24
// specific endpoints.
25
//
26
// Client implements ClientProvider interface.
27
func (c *LocalClientProvider) Client(endpoints ...string) (*client.Client, error) {
28
	if len(endpoints) > 0 {
29
		return nil, errors.New("custom endpoints not supported with LocalClientProvider")
30
	}
31

32
	var err error
33

34
	if c.client == nil {
35
		c.client, err = client.New(context.TODO(), client.WithUnixSocket(constants.APISocketPath), client.WithGRPCDialOptions(grpc.WithTransportCredentials(insecure.NewCredentials())))
36
	}
37

38
	return c.client, err
39
}
40

41
// Close all the client connections.
42
func (c *LocalClientProvider) Close() error {
43
	if c.client != nil {
44
		if err := c.client.Close(); err != nil {
45
			return err
46
		}
47

48
		c.client = nil
49
	}
50

51
	return nil
52
}
53

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.