7
"github.com/pkg/errors"
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"
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)
28
var features = []string{core_xds.FeatureTCPAccessLogViaNamedPipe}
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")
39
cfg.DataplaneRuntime.TokenPath = path
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.")
48
return component.ComponentFunc(func(<-chan struct{}) error {
53
func DefaultRootContext() *RootContext {
54
config := kumadp.DefaultConfig()
56
ComponentManager: component.NewManager(leader_memory.NewNeverLeaderElector()),
57
BootstrapGenerator: envoy.NewRemoteBootstrapGenerator(runtime.GOOS, features),
59
BootstrapDynamicMetadata: map[string]string{},
60
DataplaneTokenGenerator: defaultDataplaneTokenGenerator,