kuma

Форк
0
/
context.go 
62 строки · 2.3 Кб
1
package cmd
2

3
import (
4
	"path/filepath"
5
	"runtime"
6

7
	"github.com/pkg/errors"
8

9
	kumadp_config "github.com/kumahq/kuma/app/kuma-dp/pkg/config"
10
	"github.com/kumahq/kuma/app/kuma-dp/pkg/dataplane/envoy"
11
	kumadp "github.com/kumahq/kuma/pkg/config/app/kuma-dp"
12
	"github.com/kumahq/kuma/pkg/core/runtime/component"
13
	core_xds "github.com/kumahq/kuma/pkg/core/xds"
14
	"github.com/kumahq/kuma/pkg/log"
15
	leader_memory "github.com/kumahq/kuma/pkg/plugins/leader/memory"
16
)
17

18
// RootContext contains variables, functions and components that can be overridden when extending kuma-dp or running the test.
19
type RootContext struct {
20
	ComponentManager         component.Manager
21
	BootstrapGenerator       envoy.BootstrapConfigFactoryFunc
22
	BootstrapDynamicMetadata map[string]string
23
	DataplaneTokenGenerator  func(cfg *kumadp.Config) (component.Component, error)
24
	Config                   *kumadp.Config
25
	LogLevel                 log.LogLevel
26
}
27

28
var features = []string{core_xds.FeatureTCPAccessLogViaNamedPipe}
29

30
// defaultDataplaneTokenGenerator uses only given tokens or paths from the
31
// config.
32
func defaultDataplaneTokenGenerator(cfg *kumadp.Config) (component.Component, error) {
33
	if cfg.DataplaneRuntime.Token != "" {
34
		path := filepath.Join(cfg.DataplaneRuntime.ConfigDir, cfg.Dataplane.Name)
35
		if err := writeFile(path, []byte(cfg.DataplaneRuntime.Token), 0o600); err != nil {
36
			runLog.Error(err, "unable to create file with dataplane token")
37
			return nil, err
38
		}
39
		cfg.DataplaneRuntime.TokenPath = path
40
	}
41

42
	if cfg.DataplaneRuntime.TokenPath != "" {
43
		if err := kumadp_config.ValidateTokenPath(cfg.DataplaneRuntime.TokenPath); err != nil {
44
			return nil, errors.Wrapf(err, "dataplane token is invalid, in Kubernetes you must mount a serviceAccount token, in universal you must start your proxy with a generated token.")
45
		}
46
	}
47

48
	return component.ComponentFunc(func(<-chan struct{}) error {
49
		return nil
50
	}), nil
51
}
52

53
func DefaultRootContext() *RootContext {
54
	config := kumadp.DefaultConfig()
55
	return &RootContext{
56
		ComponentManager:         component.NewManager(leader_memory.NewNeverLeaderElector()),
57
		BootstrapGenerator:       envoy.NewRemoteBootstrapGenerator(runtime.GOOS, features),
58
		Config:                   &config,
59
		BootstrapDynamicMetadata: map[string]string{},
60
		DataplaneTokenGenerator:  defaultDataplaneTokenGenerator,
61
	}
62
}
63

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

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

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

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